OpenWalnut
1.4.0
|
A base class for all parts of OpenWalnut which can be serialized to a project file. More...
#include <WProjectFileIO.h>
Public Types | |
enum | ApplyOrder { PRE_MODULES = 0, POST_MODULES } |
When to apply this parser. More... | |
typedef boost::shared_ptr < WProjectFileIO > | SPtr |
Abbreviation for a shared pointer. | |
typedef boost::shared_ptr < const WProjectFileIO > | ConstSPtr |
Abbreviation for const shared pointer. | |
Public Member Functions | |
WProjectFileIO () | |
Default constructor. | |
virtual | ~WProjectFileIO () |
Destructor. | |
virtual bool | parse (std::string line, unsigned int lineNumber)=0 |
This method parses the specified line and interprets it. | |
virtual void | done () |
Called whenever the end of the project file has been reached. | |
virtual void | save (std::ostream &output)=0 |
Saves the state to the specified stream. | |
bool | hadErrors () const |
Checks whether there where errors during load or save. | |
const std::vector< std::string > & | getErrors () const |
Get error list. | |
bool | hadWarnings () const |
Checks whether there where warnings during load or save. | |
const std::vector< std::string > & | getWarnings () const |
Get warnings list. | |
virtual SPtr | clone (WProjectFile *project) const =0 |
Create a clone of the IO. | |
void | setProject (WProjectFile *project) |
Set the project using this parser. | |
ApplyOrder | getApplyOrder () const |
Return the apply order of this IO. | |
Protected Member Functions | |
void | addError (std::string description) |
Add an error. | |
void | addWarning (std::string description) |
Add an warning. | |
void | printProperties (std::ostream &output, boost::shared_ptr< WProperties > props, std::string indent, std::string prefix, unsigned int index, std::string indexPrefix="") |
Recursively prints the properties and nested properties. | |
void | setApplyOrder (ApplyOrder order) |
Set the order of calls to "done". | |
WProjectFile * | getProject () const |
The project using this parser. | |
Private Attributes | |
std::vector< std::string > | m_errors |
List of errors if any. | |
std::vector< std::string > | m_warnings |
List of warnings if any. | |
WProjectFile * | m_project |
The project using this parser. | |
ApplyOrder | m_applyOrder |
The order in which the "done" functions are called. |
A base class for all parts of OpenWalnut which can be serialized to a project file.
It is used by WProjectFile to actually parse the file line by line. Derive from this class if you write your own parser and use it to fill your internal data structures. But write it in a very error-tolerant way. We want to avoid that small problems in the project file cause the whole file to be useless.
In general, each IO implementation has the chance to parse each line. After parsing all lines, the done method gets called. This method should contain code to actually apply the settings loaded. You should avoid doing this in the parse method itself.
Definition at line 46 of file WProjectFileIO.h.
typedef boost::shared_ptr< const WProjectFileIO > WProjectFileIO::ConstSPtr |
Abbreviation for const shared pointer.
Definition at line 57 of file WProjectFileIO.h.
typedef boost::shared_ptr< WProjectFileIO > WProjectFileIO::SPtr |
Abbreviation for a shared pointer.
Definition at line 52 of file WProjectFileIO.h.
When to apply this parser.
This might be important in some cases. Note that you can only decide whether you want to apply your changes before or after the modules have been added.
Definition at line 143 of file WProjectFileIO.h.
Default constructor.
Definition at line 34 of file WProjectFileIO.cpp.
WProjectFileIO::~WProjectFileIO | ( | ) | [virtual] |
Destructor.
Definition at line 41 of file WProjectFileIO.cpp.
void WProjectFileIO::addError | ( | std::string | description | ) | [protected] |
Add an error.
Use this when you encounter some difficulties during parsing or applying settings. Provide useful errors. They will be presented to the user.
description | the error description |
Definition at line 71 of file WProjectFileIO.cpp.
References wlog::error(), and m_errors.
Referenced by WModuleProjectFileCombiner::apply(), WRoiProjectFileIO::done(), and WModuleProjectFileCombiner::parse().
void WProjectFileIO::addWarning | ( | std::string | description | ) | [protected] |
Add an warning.
Use this when you encounter some difficulties during parsing or applying settings. Provide useful warnings. They will be presented to the user.
description | the error description |
Definition at line 77 of file WProjectFileIO.cpp.
References m_warnings, and wlog::warn().
Referenced by WModuleProjectFileCombiner::apply().
virtual SPtr WProjectFileIO::clone | ( | WProjectFile * | project | ) | const [pure virtual] |
Create a clone of the IO.
This is especially useful for custom parsers registered at WProjectFile::registerParser. Implement this function.
project | the project file using this parser instance. |
Implemented in WModuleProjectFileCombiner, WGEProjectFileIO, and WRoiProjectFileIO.
void WProjectFileIO::done | ( | ) | [virtual] |
Called whenever the end of the project file has been reached.
Use this to actually apply your loaded settings. Do this in a error-tolerant way and apply as most settings as possible even if some other settings are erroneous. Add errors with addError. Try avoiding exceptions if possible.
Reimplemented in WModuleProjectFileCombiner, WGEProjectFileIO, and WRoiProjectFileIO.
Definition at line 46 of file WProjectFileIO.cpp.
Return the apply order of this IO.
Definition at line 131 of file WProjectFileIO.cpp.
References m_applyOrder.
const std::vector< std::string > & WProjectFileIO::getErrors | ( | ) | const |
Get error list.
Definition at line 56 of file WProjectFileIO.cpp.
References m_errors.
WProjectFile * WProjectFileIO::getProject | ( | ) | const [protected] |
The project using this parser.
Definition at line 126 of file WProjectFileIO.cpp.
References m_project.
const std::vector< std::string > & WProjectFileIO::getWarnings | ( | ) | const |
Get warnings list.
Definition at line 66 of file WProjectFileIO.cpp.
References m_warnings.
bool WProjectFileIO::hadErrors | ( | ) | const |
Checks whether there where errors during load or save.
Definition at line 51 of file WProjectFileIO.cpp.
References m_errors.
bool WProjectFileIO::hadWarnings | ( | ) | const |
Checks whether there where warnings during load or save.
Definition at line 61 of file WProjectFileIO.cpp.
References m_warnings.
virtual bool WProjectFileIO::parse | ( | std::string | line, |
unsigned int | lineNumber | ||
) | [pure virtual] |
This method parses the specified line and interprets it.
It gets called line by line by WProjectFile. You should avoid applying anything of the loaded information here. You should use done for this.
line | the current line as string |
lineNumber | the current line number. Useful for error/warning/debugging output. |
Implemented in WModuleProjectFileCombiner, WGEProjectFileIO, and WRoiProjectFileIO.
void WProjectFileIO::printProperties | ( | std::ostream & | output, |
boost::shared_ptr< WProperties > | props, | ||
std::string | indent, | ||
std::string | prefix, | ||
unsigned int | index, | ||
std::string | indexPrefix = "" |
||
) | [protected] |
Recursively prints the properties and nested properties.
output | the output stream to print to |
props | the properties to recursively print |
indent | the indentation level |
prefix | the prefix (name prefix of property) |
index | the ID to use |
indexPrefix | use this to add a prefix to the index |
Definition at line 83 of file WProjectFileIO.cpp.
Referenced by WRoiProjectFileIO::save(), and WModuleProjectFileCombiner::save().
virtual void WProjectFileIO::save | ( | std::ostream & | output | ) | [pure virtual] |
Saves the state to the specified stream.
output | the stream to print the state to. |
Implemented in WModuleProjectFileCombiner, WGEProjectFileIO, and WRoiProjectFileIO.
void WProjectFileIO::setApplyOrder | ( | WProjectFileIO::ApplyOrder | order | ) | [protected] |
Set the order of calls to "done".
order | the order. |
Definition at line 136 of file WProjectFileIO.cpp.
References m_applyOrder.
void WProjectFileIO::setProject | ( | WProjectFile * | project | ) |
Set the project using this parser.
project | the project |
Definition at line 121 of file WProjectFileIO.cpp.
References m_project.
ApplyOrder WProjectFileIO::m_applyOrder [private] |
The order in which the "done" functions are called.
Definition at line 220 of file WProjectFileIO.h.
Referenced by getApplyOrder(), and setApplyOrder().
std::vector< std::string > WProjectFileIO::m_errors [private] |
List of errors if any.
Definition at line 205 of file WProjectFileIO.h.
Referenced by addError(), getErrors(), and hadErrors().
WProjectFile* WProjectFileIO::m_project [private] |
The project using this parser.
Definition at line 215 of file WProjectFileIO.h.
Referenced by getProject(), and setProject().
std::vector< std::string > WProjectFileIO::m_warnings [private] |
List of warnings if any.
Definition at line 210 of file WProjectFileIO.h.
Referenced by addWarning(), getWarnings(), and hadWarnings().