OpenWalnut
1.5.0dev
|
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 std::shared_ptr< WProjectFileIO > | SPtr |
Abbreviation for a shared pointer. More... | |
typedef std::shared_ptr< const WProjectFileIO > | ConstSPtr |
Abbreviation for const shared pointer. More... | |
Public Member Functions | |
WProjectFileIO () | |
Default constructor. More... | |
virtual | ~WProjectFileIO () |
Destructor. More... | |
virtual bool | parse (std::string line, unsigned int lineNumber)=0 |
This method parses the specified line and interprets it. More... | |
virtual void | done () |
Called whenever the end of the project file has been reached. More... | |
virtual void | save (std::ostream &output)=0 |
Saves the state to the specified stream. More... | |
bool | hadErrors () const |
Checks whether there where errors during load or save. More... | |
const std::vector< std::string > & | getErrors () const |
Get error list. More... | |
bool | hadWarnings () const |
Checks whether there where warnings during load or save. More... | |
const std::vector< std::string > & | getWarnings () const |
Get warnings list. More... | |
virtual SPtr | clone (WProjectFile *project) const =0 |
Create a clone of the IO. More... | |
void | setProject (WProjectFile *project) |
Set the project using this parser. More... | |
ApplyOrder | getApplyOrder () const |
Return the apply order of this IO. More... | |
Protected Member Functions | |
void | addError (std::string description) |
Add an error. More... | |
void | addWarning (std::string description) |
Add an warning. More... | |
void | printProperties (std::ostream &output, std::shared_ptr< WProperties > props, std::string indent, std::string prefix, unsigned int index, std::string indexPrefix="") |
Recursively prints the properties and nested properties. More... | |
void | setApplyOrder (ApplyOrder order) |
Set the order of calls to "done". More... | |
WProjectFile * | getProject () const |
The project using this parser. More... | |
Private Attributes | |
std::vector< std::string > | m_errors |
List of errors if any. More... | |
std::vector< std::string > | m_warnings |
List of warnings if any. More... | |
WProjectFile * | m_project |
The project using this parser. More... | |
ApplyOrder | m_applyOrder |
The order in which the "done" functions are called. More... | |
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 std::shared_ptr< const WProjectFileIO > WProjectFileIO::ConstSPtr |
Abbreviation for const shared pointer.
Definition at line 57 of file WProjectFileIO.h.
typedef std::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.
WProjectFileIO::WProjectFileIO | ( | ) |
Default constructor.
Definition at line 33 of file WProjectFileIO.cpp.
|
virtual |
Destructor.
Definition at line 40 of file WProjectFileIO.cpp.
|
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 70 of file WProjectFileIO.cpp.
References wlog::error(), and m_errors.
Referenced by WModuleProjectFileCombiner::apply(), WRoiProjectFileIO::done(), and WModuleProjectFileCombiner::parse().
|
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 76 of file WProjectFileIO.cpp.
References m_warnings, and wlog::warn().
Referenced by WModuleProjectFileCombiner::apply().
|
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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.
|
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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.
Definition at line 45 of file WProjectFileIO.cpp.
WProjectFileIO::ApplyOrder WProjectFileIO::getApplyOrder | ( | ) | const |
Return the apply order of this IO.
Definition at line 130 of file WProjectFileIO.cpp.
References m_applyOrder.
const std::vector< std::string > & WProjectFileIO::getErrors | ( | ) | const |
Get error list.
Definition at line 55 of file WProjectFileIO.cpp.
References m_errors.
|
protected |
The project using this parser.
Definition at line 125 of file WProjectFileIO.cpp.
References m_project.
Referenced by WQtNetworkEditorProjectFileIO::done(), and WQtNetworkEditorProjectFileIO::save().
const std::vector< std::string > & WProjectFileIO::getWarnings | ( | ) | const |
Get warnings list.
Definition at line 65 of file WProjectFileIO.cpp.
References m_warnings.
bool WProjectFileIO::hadErrors | ( | ) | const |
Checks whether there where errors during load or save.
Definition at line 50 of file WProjectFileIO.cpp.
References m_errors.
bool WProjectFileIO::hadWarnings | ( | ) | const |
Checks whether there where warnings during load or save.
Definition at line 60 of file WProjectFileIO.cpp.
References m_warnings.
|
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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.
|
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 82 of file WProjectFileIO.cpp.
Referenced by WModuleProjectFileCombiner::save(), and WRoiProjectFileIO::save().
|
pure virtual |
Saves the state to the specified stream.
output | the stream to print the state to. |
Implemented in WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.
|
protected |
Set the order of calls to "done".
order | the order. |
Definition at line 135 of file WProjectFileIO.cpp.
References m_applyOrder.
Referenced by WQtNetworkEditorProjectFileIO::WQtNetworkEditorProjectFileIO().
void WProjectFileIO::setProject | ( | WProjectFile * | project | ) |
Set the project using this parser.
project | the project |
Definition at line 120 of file WProjectFileIO.cpp.
References m_project.
|
private |
The order in which the "done" functions are called.
Definition at line 220 of file WProjectFileIO.h.
Referenced by getApplyOrder(), and setApplyOrder().
|
private |
List of errors if any.
Definition at line 205 of file WProjectFileIO.h.
Referenced by addError(), getErrors(), and hadErrors().
|
private |
The project using this parser.
Definition at line 215 of file WProjectFileIO.h.
Referenced by getProject(), and setProject().
|
private |
List of warnings if any.
Definition at line 210 of file WProjectFileIO.h.
Referenced by addWarning(), getWarnings(), and hadWarnings().