OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
WProjectFileIO Class Referenceabstract

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

#include <WProjectFileIO.h>

+ Inheritance diagram for WProjectFileIO:
+ Collaboration diagram for WProjectFileIO:

Public Types

enum  ApplyOrder { PRE_MODULES = 0 , POST_MODULES }
 When to apply this parser. More...
 
typedef std::shared_ptr< WProjectFileIOSPtr
 Abbreviation for a shared pointer. More...
 
typedef std::shared_ptr< const WProjectFileIOConstSPtr
 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...
 
WProjectFilegetProject () 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...
 
WProjectFilem_project
 The project using this parser. More...
 
ApplyOrder m_applyOrder
 The order in which the "done" functions are called. More...
 

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

◆ ConstSPtr

typedef std::shared_ptr< const WProjectFileIO > WProjectFileIO::ConstSPtr

Abbreviation for const shared pointer.

Definition at line 57 of file WProjectFileIO.h.

◆ SPtr

typedef std::shared_ptr< WProjectFileIO > WProjectFileIO::SPtr

Abbreviation for a shared pointer.

Definition at line 52 of file WProjectFileIO.h.

Member Enumeration Documentation

◆ ApplyOrder

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

◆ WProjectFileIO()

WProjectFileIO::WProjectFileIO ( )

Default constructor.

Definition at line 33 of file WProjectFileIO.cpp.

◆ ~WProjectFileIO()

WProjectFileIO::~WProjectFileIO ( )
virtual

Destructor.

Definition at line 40 of file WProjectFileIO.cpp.

Member Function Documentation

◆ addError()

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 70 of file WProjectFileIO.cpp.

References wlog::error(), and m_errors.

Referenced by WModuleProjectFileCombiner::apply(), WRoiProjectFileIO::done(), and WModuleProjectFileCombiner::parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addWarning()

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 76 of file WProjectFileIO.cpp.

References m_warnings, and wlog::warn().

Referenced by WModuleProjectFileCombiner::apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clone()

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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.

◆ done()

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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.

Definition at line 45 of file WProjectFileIO.cpp.

◆ getApplyOrder()

WProjectFileIO::ApplyOrder WProjectFileIO::getApplyOrder ( ) const

Return the apply order of this IO.

Returns
the order

Definition at line 130 of file WProjectFileIO.cpp.

References m_applyOrder.

◆ getErrors()

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

Get error list.

Returns
the list

Definition at line 55 of file WProjectFileIO.cpp.

References m_errors.

◆ getProject()

WProjectFile * WProjectFileIO::getProject ( ) const
protected

The project using this parser.

Returns
the project

Definition at line 125 of file WProjectFileIO.cpp.

References m_project.

Referenced by WQtNetworkEditorProjectFileIO::done(), and WQtNetworkEditorProjectFileIO::save().

+ Here is the caller graph for this function:

◆ getWarnings()

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

Get warnings list.

Returns
the list

Definition at line 65 of file WProjectFileIO.cpp.

References m_warnings.

◆ hadErrors()

bool WProjectFileIO::hadErrors ( ) const

Checks whether there where errors during load or save.

Returns
true if there where.

Definition at line 50 of file WProjectFileIO.cpp.

References m_errors.

◆ hadWarnings()

bool WProjectFileIO::hadWarnings ( ) const

Checks whether there where warnings during load or save.

Returns
true if there where.

Definition at line 60 of file WProjectFileIO.cpp.

References m_warnings.

◆ parse()

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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.

◆ printProperties()

void WProjectFileIO::printProperties ( std::ostream &  output,
std::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 82 of file WProjectFileIO.cpp.

Referenced by WModuleProjectFileCombiner::save(), and WRoiProjectFileIO::save().

+ Here is the caller graph for this function:

◆ 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 WQtNetworkEditorProjectFileIO, WRoiProjectFileIO, WModuleProjectFileCombiner, and WGEProjectFileIO.

◆ setApplyOrder()

void WProjectFileIO::setApplyOrder ( WProjectFileIO::ApplyOrder  order)
protected

Set the order of calls to "done".

Parameters
orderthe order.

Definition at line 135 of file WProjectFileIO.cpp.

References m_applyOrder.

Referenced by WQtNetworkEditorProjectFileIO::WQtNetworkEditorProjectFileIO().

+ Here is the caller graph for this function:

◆ setProject()

void WProjectFileIO::setProject ( WProjectFile project)

Set the project using this parser.

Parameters
projectthe project

Definition at line 120 of file WProjectFileIO.cpp.

References m_project.

Member Data Documentation

◆ m_applyOrder

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

◆ m_errors

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

◆ m_project

WProjectFile* WProjectFileIO::m_project
private

The project using this parser.

Definition at line 215 of file WProjectFileIO.h.

Referenced by getProject(), and setProject().

◆ m_warnings

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: