OpenWalnut  1.5.0dev
Public Member Functions | Protected Types | Protected Attributes | List of all members
WModuleProjectFileCombiner Class Reference

This class is able to parse project files and create the appropriate module graph inside a specified container. More...

#include <WModuleProjectFileCombiner.h>

+ Inheritance diagram for WModuleProjectFileCombiner:
+ Collaboration diagram for WModuleProjectFileCombiner:

Public Member Functions

 WModuleProjectFileCombiner (std::shared_ptr< WModuleContainer > target)
 Creates an empty combiner. More...
 
 WModuleProjectFileCombiner ()
 Creates an empty combiner. More...
 
virtual ~WModuleProjectFileCombiner ()
 Destructor. More...
 
virtual void apply ()
 Apply the internal module structure to the target container. More...
 
virtual bool parse (std::string line, unsigned int lineNumber)
 This method parses the specified line and interprets it to fill the internal module graph structure. More...
 
virtual void done ()
 Called whenever the end of the project file has been reached. More...
 
virtual void save (std::ostream &output)
 Saves the state to the specified stream. More...
 
virtual WProjectFileIO::SPtr clone (WProjectFile *project) const
 Create a clone of the IO. More...
 
virtual std::shared_ptr< WModulemapToModule (unsigned int id) const
 Map a given project file ID to a module. More...
 
virtual unsigned int mapFromModule (std::shared_ptr< WModule > module) const
 Map a given module to project file ID. More...
 
- Public Member Functions inherited from WModuleCombiner
 WModuleCombiner (std::shared_ptr< WModuleContainer > target)
 Creates an empty combiner. More...
 
 WModuleCombiner ()
 Creates an empty combiner. More...
 
virtual ~WModuleCombiner ()
 Destructor. More...
 
virtual void run ()
 Run thread and call apply(). More...
 
- Public Member Functions inherited from WThreadedRunner
 WThreadedRunner ()
 Default constructor. More...
 
virtual ~WThreadedRunner ()
 Destructor. More...
 
void run (THREADFUNCTION f)
 Run thread. More...
 
void wait (bool requestFinish=false)
 Wait for the thread to be finished. More...
 
virtual void requestStop ()
 This method's purpose is to request a stop without waiting for it. More...
 
virtual boost::signals2::connection subscribeSignal (THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
 Connects a specified notify function with a signal this thread instance is offering. More...
 
const WBoolFlagisCrashed () const
 Checks whether this thread has been crashed. More...
 
const std::string & getCrashMessage () const
 Get the message of the exception finally causing the crash. More...
 
void setThreadName (std::string name)
 Set the name of the thread. More...
 
std::string getThreadName () const
 Returns the current thread name. More...
 
- Public Member Functions inherited from WProjectFileIO
 WProjectFileIO ()
 Default constructor. More...
 
virtual ~WProjectFileIO ()
 Destructor. 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...
 
void setProject (WProjectFile *project)
 Set the project using this parser. More...
 
ApplyOrder getApplyOrder () const
 Return the apply order of this IO. More...
 

Protected Types

typedef std::pair< unsigned int, std::shared_ptr< WModule > > ModuleID
 The module ID type. More...
 
typedef std::map< unsigned int, std::shared_ptr< WModule > > ModuleIDMap
 Map between ID and Module. More...
 
typedef std::pair< unsigned int, std::string > Connector
 A connector is described by ID and name. More...
 
typedef std::pair< Connector, ConnectorConnection
 A connection is a pair of connectors. More...
 
typedef std::pair< unsigned int, std::string > Property
 A property is a pair of ID and name. More...
 
typedef std::pair< Property, std::string > PropertyValue
 A property value is a property and the new value as string. More...
 

Protected Attributes

std::map< unsigned int, std::shared_ptr< WModule > > m_modules
 All Modules. More...
 
std::list< Connectionm_connections
 All connections. More...
 
std::list< PropertyValuem_properties
 All properties. More...
 
- Protected Attributes inherited from WModuleCombiner
std::shared_ptr< WModuleContainerm_container
 The module container to use for the modules. More...
 
- Protected Attributes inherited from WThreadedRunner
boost::thread m_thread
 Thread instance. More...
 
WBoolFlag m_shutdownFlag
 Condition getting fired whenever the thread should quit. More...
 
WBoolFlag m_isCrashed
 True whenever an exception is thrown during threadMain. More...
 
std::string m_crashMessage
 The crash message. More...
 

Additional Inherited Members

- Public Types inherited from WThreadedRunner
typedef std::shared_ptr< WThreadedRunnerSPtr
 Abbreviation to a shared_ptr to this type. More...
 
typedef std::shared_ptr< const WThreadedRunnerConstSPtr
 Abbreviation to a const shared_ptr to this type. More...
 
typedef boost::function< void(void) > THREADFUNCTION
 Type used for simple thread functions. More...
 
- Public Types inherited from WProjectFileIO
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...
 
- Static Public Member Functions inherited from WThreadedRunner
static void setThisThreadName (std::string name)
 Static function to set the name of the calling thread. More...
 
- Protected Member Functions inherited from WModuleCombiner
virtual void threadMain ()
 Function that has to be overwritten for execution. More...
 
- Protected Member Functions inherited from WThreadedRunner
virtual void notifyStop ()
 Gets called when the thread should be stopped. More...
 
void yield () const
 Give remaining execution timeslice to another thread. More...
 
void sleep (const int32_t t) const
 Sets thread asleep. More...
 
void msleep (const int32_t t) const
 Sets thread asleep. More...
 
void waitForStop ()
 Let the thread sleep until a stop request was given. More...
 
virtual void onThreadException (const WException &e)
 This method is called if an exception was caught, which came from the custom thread code. More...
 
void handleDeadlyException (const WException &e, std::string sender="WThreadedRunner")
 Handle the specified exception which was not caught in the thread, which basically means the thread has crashed. More...
 
- Protected Member Functions inherited from WProjectFileIO
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...
 

Detailed Description

This class is able to parse project files and create the appropriate module graph inside a specified container.

It is also derived from WProjectFileIO to allow WProjectFile to fill this combiner.

Definition at line 46 of file WModuleProjectFileCombiner.h.

Member Typedef Documentation

◆ Connection

A connection is a pair of connectors.

Definition at line 155 of file WModuleProjectFileCombiner.h.

◆ Connector

typedef std::pair< unsigned int, std::string > WModuleProjectFileCombiner::Connector
protected

A connector is described by ID and name.

Definition at line 150 of file WModuleProjectFileCombiner.h.

◆ ModuleID

typedef std::pair< unsigned int, std::shared_ptr< WModule > > WModuleProjectFileCombiner::ModuleID
protected

The module ID type.

A pair of ID and pointer to module.

Definition at line 135 of file WModuleProjectFileCombiner.h.

◆ ModuleIDMap

typedef std::map< unsigned int, std::shared_ptr< WModule > > WModuleProjectFileCombiner::ModuleIDMap
protected

Map between ID and Module.

Definition at line 140 of file WModuleProjectFileCombiner.h.

◆ Property

typedef std::pair< unsigned int, std::string > WModuleProjectFileCombiner::Property
protected

A property is a pair of ID and name.

Definition at line 165 of file WModuleProjectFileCombiner.h.

◆ PropertyValue

typedef std::pair< Property, std::string > WModuleProjectFileCombiner::PropertyValue
protected

A property value is a property and the new value as string.

Definition at line 170 of file WModuleProjectFileCombiner.h.

Constructor & Destructor Documentation

◆ WModuleProjectFileCombiner() [1/2]

WModuleProjectFileCombiner::WModuleProjectFileCombiner ( std::shared_ptr< WModuleContainer target)
explicit

Creates an empty combiner.

Parameters
targetthe target container where to add the modules to.

Definition at line 58 of file WModuleProjectFileCombiner.cpp.

◆ WModuleProjectFileCombiner() [2/2]

WModuleProjectFileCombiner::WModuleProjectFileCombiner ( )

Creates an empty combiner.

This constructor automatically uses the kernel's root container as target container.

Definition at line 64 of file WModuleProjectFileCombiner.cpp.

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~WModuleProjectFileCombiner()

WModuleProjectFileCombiner::~WModuleProjectFileCombiner ( )
virtual

Destructor.

Definition at line 70 of file WModuleProjectFileCombiner.cpp.

References m_modules.

Member Function Documentation

◆ apply()

void WModuleProjectFileCombiner::apply ( )
virtual

Apply the internal module structure to the target container.

Be aware, that this operation might take some time, as modules can be connected only if they are "ready", which, at least with WDataModule modules, might take some time. It applies the loaded project file.

Note
the loader for project files is very tolerant. It does not abort. It tries to load as much as possible. The only exception that gets thrown whenever the file could not be opened.
Exceptions
WFileNotFoundwhenever the project file could not be opened.

Implements WModuleCombiner.

Definition at line 224 of file WModuleProjectFileCombiner.cpp.

References WProjectFileIO::addError(), WProjectFileIO::addWarning(), WGEColormapping::instance(), m_connections, WModuleCombiner::m_container, m_modules, m_properties, and string_utils::toString().

Referenced by done().

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

◆ clone()

WProjectFileIO::SPtr WModuleProjectFileCombiner::clone ( WProjectFile project) const
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.

Implements WProjectFileIO.

Definition at line 76 of file WModuleProjectFileCombiner.cpp.

References WModuleProjectFileCombiner().

+ Here is the call graph for this function:

◆ done()

void WModuleProjectFileCombiner::done ( )
virtual

Called whenever the end of the project file has been reached.

This is useful if your specific parser class wants to do some post processing after parsing line by line.

Reimplemented from WProjectFileIO.

Definition at line 372 of file WModuleProjectFileCombiner.cpp.

References apply().

+ Here is the call graph for this function:

◆ mapFromModule()

unsigned int WModuleProjectFileCombiner::mapFromModule ( std::shared_ptr< WModule module) const
virtual

Map a given module to project file ID.

This method must not be used by WModuleProjectFileCombiner, as it builds this mapping. All other WProjectFileIO implementations are allowed to use it in their save and apply methods (NOT in parse()).

Parameters
modulethe module to map
Returns
the ID, or numeric_limits< unisigned int >::max() if module not known.

Definition at line 474 of file WModuleProjectFileCombiner.cpp.

References m_modules.

◆ mapToModule()

std::shared_ptr< WModule > WModuleProjectFileCombiner::mapToModule ( unsigned int  id) const
virtual

Map a given project file ID to a module.

This method must not be used by WModuleProjectFileCombiner, as it builds this mapping. All other WProjectFileIO implementations are allowed to use it in their save and apply methods (NOT in parse()).

Parameters
idthe id
Returns
the module, or NULL if ID is not known.

Definition at line 462 of file WModuleProjectFileCombiner.cpp.

References m_modules.

◆ parse()

bool WModuleProjectFileCombiner::parse ( std::string  line,
unsigned int  lineNumber 
)
virtual

This method parses the specified line and interprets it to fill the internal module graph structure.

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

Implements WProjectFileIO.

Definition at line 84 of file WModuleProjectFileCombiner.cpp.

References WProjectFileIO::addError(), WDataModuleInput::create(), wlog::debug(), WModuleFactory::getModuleFactory(), m_connections, m_modules, and m_properties.

+ Here is the call graph for this function:

◆ save()

void WModuleProjectFileCombiner::save ( std::ostream &  output)
virtual

Saves the state to the specified stream.

Parameters
outputthe stream to print the state to.

Implements WProjectFileIO.

Definition at line 377 of file WModuleProjectFileCombiner.cpp.

References WKernel::getRootContainer(), WKernel::getRunningKernel(), WGEColormapping::instance(), m_modules, and WProjectFileIO::printProperties().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_connections

std::list< Connection > WModuleProjectFileCombiner::m_connections
protected

All connections.

Definition at line 160 of file WModuleProjectFileCombiner.h.

Referenced by apply(), and parse().

◆ m_modules

std::map< unsigned int, std::shared_ptr< WModule > > WModuleProjectFileCombiner::m_modules
protected

All Modules.

Definition at line 145 of file WModuleProjectFileCombiner.h.

Referenced by apply(), mapFromModule(), mapToModule(), parse(), save(), and ~WModuleProjectFileCombiner().

◆ m_properties

std::list< PropertyValue > WModuleProjectFileCombiner::m_properties
protected

All properties.

Definition at line 175 of file WModuleProjectFileCombiner.h.

Referenced by apply(), and parse().


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