OpenWalnut  1.4.0
Public Types | Public Member Functions | Protected Member Functions | Private Attributes
WProjectFileIO Class Reference

A base class for all parts of OpenWalnut which can be serialized to a project file. More...

#include <WProjectFileIO.h>

+ Inheritance diagram for WProjectFileIO:

List of all members.

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".
WProjectFilegetProject () 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.
WProjectFilem_project
 The project using this parser.
ApplyOrder m_applyOrder
 The order in which the "done" functions are called.

Detailed Description

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.


Member Typedef Documentation

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.


Member Enumeration Documentation

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.


Constructor & Destructor Documentation

Default constructor.

Definition at line 34 of file WProjectFileIO.cpp.

Destructor.

Definition at line 41 of file WProjectFileIO.cpp.


Member Function Documentation

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.

Parameters:
descriptionthe 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.

Parameters:
descriptionthe 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.

Parameters:
projectthe project file using this parser instance.
Returns:
Cloned 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.

Returns:
the order

Definition at line 131 of file WProjectFileIO.cpp.

References m_applyOrder.

const std::vector< std::string > & WProjectFileIO::getErrors ( ) const

Get error list.

Returns:
the list

Definition at line 56 of file WProjectFileIO.cpp.

References m_errors.

WProjectFile * WProjectFileIO::getProject ( ) const [protected]

The project using this parser.

Returns:
the project

Definition at line 126 of file WProjectFileIO.cpp.

References m_project.

const std::vector< std::string > & WProjectFileIO::getWarnings ( ) const

Get warnings list.

Returns:
the 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.

Returns:
true if there where.

Definition at line 51 of file WProjectFileIO.cpp.

References m_errors.

Checks whether there where warnings during load or save.

Returns:
true if there where.

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.

Parameters:
linethe current line as string
lineNumberthe current line number. Useful for error/warning/debugging output.
Returns:
true if the line could be parsed.

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.

Parameters:
outputthe output stream to print to
propsthe properties to recursively print
indentthe indentation level
prefixthe prefix (name prefix of property)
indexthe ID to use
indexPrefixuse 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.

Parameters:
outputthe stream to print the state to.

Implemented in WModuleProjectFileCombiner, WGEProjectFileIO, and WRoiProjectFileIO.

Set the order of calls to "done".

Parameters:
orderthe order.

Definition at line 136 of file WProjectFileIO.cpp.

References m_applyOrder.

Set the project using this parser.

Parameters:
projectthe project

Definition at line 121 of file WProjectFileIO.cpp.

References m_project.


Member Data Documentation

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().

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().


The documentation for this class was generated from the following files: