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

Class loading project files. More...

#include <WProjectFile.h>

+ Inheritance diagram for WProjectFile:
+ Collaboration diagram for WProjectFile:

Public Types

typedef std::shared_ptr< WProjectFileSPtr
 Abbreviation for a shared pointer. More...
 
typedef std::shared_ptr< const WProjectFileConstSPtr
 Abbreviation for const shared pointer. More...
 
typedef boost::function< void(boost::filesystem::path, std::vector< std::string >, std::vector< std::string >) > ProjectLoadCallback
 A callback function type reporting bach a finished load job. More...
 
typedef boost::signals2::signal< void(boost::filesystem::path, std::vector< std::string >, std::vector< std::string >) > ProjectLoadCallbackSignal
 A callback function signal type reporting bach a finished load job. More...
 
- 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 Member Functions

 WProjectFile (boost::filesystem::path project)
 Default constructor. More...
 
 WProjectFile (boost::filesystem::path project, ProjectLoadCallback doneCallback)
 Default constructor. More...
 
virtual ~WProjectFile ()
 Destructor. More...
 
virtual void load ()
 Parses the project file and applies it. More...
 
virtual void save ()
 Saves the current state to the file specified in the constructor. More...
 
virtual void save (const std::list< std::shared_ptr< WProjectFileIO > > &writer)
 Saves the current state to the file specified in the constructor. More...
 
virtual void save (const std::vector< std::shared_ptr< WProjectFileIO > > &writer)
 Saves the current state to the file specified in the constructor. More...
 
std::shared_ptr< WModulemapToModule (unsigned int id) const
 Map a given project file ID to a module. More...
 
unsigned int mapFromModule (std::shared_ptr< WModule > module) const
 Map a given module to project file ID. More...
 
- Public Member Functions inherited from WThreadedRunner
 WThreadedRunner ()
 Default constructor. More...
 
virtual ~WThreadedRunner ()
 Destructor. More...
 
virtual void run ()
 Run thread. 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...
 

Static Public Member Functions

static std::shared_ptr< WProjectFileIOgetCameraWriter ()
 Returns an instance of the Camera writer. More...
 
static std::shared_ptr< WProjectFileIOgetModuleWriter ()
 Returns an instance of the module writer. More...
 
static std::shared_ptr< WProjectFileIOgetROIWriter ()
 Returns an instance of the ROI writer. More...
 
static void registerParser (WProjectFileIO::SPtr parser)
 Register a custom project file parser. More...
 
static void deregisterParser (WProjectFileIO::SPtr parser)
 Remove parser from registry. 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

virtual void threadMain ()
 Function that has to be overwritten for execution. More...
 
virtual void onThreadException (const WException &e)
 Do custom exception handling. 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...
 
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 Attributes

boost::filesystem::path m_project
 The project file to parse. More...
 
std::list< std::shared_ptr< WProjectFileIO > > m_parsers
 The parser instances. More...
 
std::list< std::shared_ptr< WProjectFileIO > > m_writers
 The writer instances. 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...
 

Private Types

typedef WSharedSequenceContainer< std::vector< WProjectFileIO::SPtr > > ParserList
 Type used for returning lists of parser prototypes. More...
 

Private Attributes

ProjectLoadCallbackSignal m_signalLoadDone
 Signal used to callback someone that the loader was finished. More...
 
boost::signals2::connection m_signalLoadDoneConnection
 Connection managing the signal m_signalLoadDone. More...
 
std::shared_ptr< WModuleProjectFileCombinerm_moduleIO
 This is the only WProjectFileIO instance which is needed. More...
 

Static Private Attributes

static ParserList m_additionalParsers
 List of all additional parser prototypes. More...
 

Detailed Description

Class loading project files.

This class opens an file and reads it line by line. It delegates the actual parsing to each of the known WProjectFileIO instances which then do their job.

Definition at line 48 of file WProjectFile.h.

Member Typedef Documentation

◆ ConstSPtr

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

Abbreviation for const shared pointer.

Definition at line 60 of file WProjectFile.h.

◆ ParserList

Type used for returning lists of parser prototypes.

Definition at line 211 of file WProjectFile.h.

◆ ProjectLoadCallback

typedef boost::function< void( boost::filesystem::path, std::vector< std::string >, std::vector< std::string > ) > WProjectFile::ProjectLoadCallback

A callback function type reporting bach a finished load job.

The given string vector contains a list of errors if any.

Definition at line 65 of file WProjectFile.h.

◆ ProjectLoadCallbackSignal

typedef boost::signals2::signal< void( boost::filesystem::path, std::vector< std::string >, std::vector< std::string > ) > WProjectFile::ProjectLoadCallbackSignal

A callback function signal type reporting bach a finished load job.

The given string vector contains a list of errors if any.

Definition at line 71 of file WProjectFile.h.

◆ SPtr

typedef std::shared_ptr< WProjectFile > WProjectFile::SPtr

Abbreviation for a shared pointer.

Definition at line 55 of file WProjectFile.h.

Constructor & Destructor Documentation

◆ WProjectFile() [1/2]

WProjectFile::WProjectFile ( boost::filesystem::path  project)
explicit

Default constructor.

It does NOT parse the file. Parsing is done by using load.

Parameters
projectthe project file to load or save.

Definition at line 47 of file WProjectFile.cpp.

References WSharedObject< T >::getReadTicket(), m_additionalParsers, m_moduleIO, m_parsers, and m_writers.

+ Here is the call graph for this function:

◆ WProjectFile() [2/2]

WProjectFile::WProjectFile ( boost::filesystem::path  project,
ProjectLoadCallback  doneCallback 
)

Default constructor.

It does NOT parse the file. Parsing is done by using load.

Parameters
projectthe project file to load.
doneCallbackgets called whenever the load thread finishes.

Definition at line 92 of file WProjectFile.cpp.

References WSharedObject< T >::getReadTicket(), m_additionalParsers, m_moduleIO, m_parsers, and m_writers.

+ Here is the call graph for this function:

◆ ~WProjectFile()

WProjectFile::~WProjectFile ( )
virtual

Destructor.

Definition at line 138 of file WProjectFile.cpp.

References m_parsers, m_signalLoadDoneConnection, and m_writers.

Member Function Documentation

◆ deregisterParser()

void WProjectFile::deregisterParser ( WProjectFileIO::SPtr  parser)
static

Remove parser from registry.

The change takes effect when creating a new instance of WProjectFile.

Parameters
parserthe parser to remove. If not existing, nothing happens.

Definition at line 319 of file WProjectFile.cpp.

References m_additionalParsers, and WSharedSequenceContainer< S >::remove().

+ Here is the call graph for this function:

◆ getCameraWriter()

std::shared_ptr< WProjectFileIO > WProjectFile::getCameraWriter ( )
static

Returns an instance of the Camera writer.

Returns
the writer able to output the camera configuration to a stream.

Definition at line 146 of file WProjectFile.cpp.

Referenced by WMainWindow::projectSaveCameraOnly().

+ Here is the caller graph for this function:

◆ getModuleWriter()

std::shared_ptr< WProjectFileIO > WProjectFile::getModuleWriter ( )
static

Returns an instance of the module writer.

Returns
the writer able to output the module configuration to a stream.

Definition at line 151 of file WProjectFile.cpp.

Referenced by WMainWindow::projectSaveModuleOnly().

+ Here is the caller graph for this function:

◆ getROIWriter()

std::shared_ptr< WProjectFileIO > WProjectFile::getROIWriter ( )
static

Returns an instance of the ROI writer.

Returns
the writer able to output the ROI configuration to a stream.

Definition at line 156 of file WProjectFile.cpp.

Referenced by WMainWindow::projectSaveROIOnly().

+ Here is the caller graph for this function:

◆ load()

void WProjectFile::load ( )
virtual

Parses the project file and applies it.

It applies the project file asynchronously!

Definition at line 161 of file WProjectFile.cpp.

References WKernel::getRootContainer(), WKernel::getRunningKernel(), and WThreadedRunner::run().

+ Here is the call graph for this function:

◆ mapFromModule()

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

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 329 of file WProjectFile.cpp.

References m_moduleIO.

Referenced by WQtNetworkEditorProjectFileIO::save().

+ Here is the caller graph for this function:

◆ mapToModule()

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

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 324 of file WProjectFile.cpp.

References m_moduleIO.

Referenced by WQtNetworkEditorProjectFileIO::done().

+ Here is the caller graph for this function:

◆ onThreadException()

void WProjectFile::onThreadException ( const WException e)
protectedvirtual

Do custom exception handling.

Parameters
ethe exception

Reimplemented from WThreadedRunner.

Definition at line 294 of file WProjectFile.cpp.

References WKernel::getRootContainer(), WKernel::getRunningKernel(), and WThreadedRunner::handleDeadlyException().

+ Here is the call graph for this function:

◆ registerParser()

void WProjectFile::registerParser ( WProjectFileIO::SPtr  parser)
static

Register a custom project file parser.

Use this to add and re-read information from project files. The change takes effect when creating a new instance of WProjectFile. The custom parser needs to implement WProjectFileIO::clone as this is used for instancing the parser for each project file.

Note
: See WQtNetworkEditorProjectFileIO for a working example.
Parameters
parserthe parser. Can be added multiple times.

Definition at line 304 of file WProjectFile.cpp.

References WSharedObject< T >::getWriteTicket(), and m_additionalParsers.

Referenced by WQtNetworkEditor::WQtNetworkEditor().

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

◆ save() [1/3]

void WProjectFile::save ( )
virtual

Saves the current state to the file specified in the constructor.

Definition at line 198 of file WProjectFile.cpp.

References m_writers.

Referenced by save().

+ Here is the caller graph for this function:

◆ save() [2/3]

void WProjectFile::save ( const std::list< std::shared_ptr< WProjectFileIO > > &  writer)
virtual

Saves the current state to the file specified in the constructor.

This also supports a custom list of writers. This is useful to only write some parts of the state.

Parameters
writerthe list of writers to use.

Definition at line 176 of file WProjectFile.cpp.

References wlog::info(), and m_project.

+ Here is the call graph for this function:

◆ save() [3/3]

void WProjectFile::save ( const std::vector< std::shared_ptr< WProjectFileIO > > &  writer)
virtual

Saves the current state to the file specified in the constructor.

This also supports a custom list of writers. This is useful to only write some parts of the state.

Parameters
writerthe list of writers to use.

Definition at line 170 of file WProjectFile.cpp.

References save().

+ Here is the call graph for this function:

◆ threadMain()

void WProjectFile::threadMain ( )
protectedvirtual

Function that has to be overwritten for execution.

It gets executed in a separate thread after run() has been called.

Reimplemented from WThreadedRunner.

Definition at line 203 of file WProjectFile.cpp.

References wlog::error(), WKernel::getRootContainer(), WKernel::getRunningKernel(), wlog::info(), m_parsers, m_project, m_signalLoadDone, m_signalLoadDoneConnection, string_utils::toString(), and wlog::warn().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_additionalParsers

WProjectFile::ParserList WProjectFile::m_additionalParsers
staticprivate

List of all additional parser prototypes.

Handled as singleton.

Definition at line 227 of file WProjectFile.h.

Referenced by deregisterParser(), registerParser(), and WProjectFile().

◆ m_moduleIO

std::shared_ptr< WModuleProjectFileCombiner > WProjectFile::m_moduleIO
private

This is the only WProjectFileIO instance which is needed.

It is used to map ID to module.

Definition at line 232 of file WProjectFile.h.

Referenced by mapFromModule(), mapToModule(), and WProjectFile().

◆ m_parsers

std::list< std::shared_ptr< WProjectFileIO > > WProjectFile::m_parsers
protected

The parser instances.

They are used to parse the file.

Definition at line 193 of file WProjectFile.h.

Referenced by threadMain(), WProjectFile(), and ~WProjectFile().

◆ m_project

boost::filesystem::path WProjectFile::m_project
protected

The project file to parse.

Definition at line 188 of file WProjectFile.h.

Referenced by save(), and threadMain().

◆ m_signalLoadDone

ProjectLoadCallbackSignal WProjectFile::m_signalLoadDone
private

Signal used to callback someone that the loader was finished.

Definition at line 216 of file WProjectFile.h.

Referenced by threadMain().

◆ m_signalLoadDoneConnection

boost::signals2::connection WProjectFile::m_signalLoadDoneConnection
private

Connection managing the signal m_signalLoadDone.

This is the one and only connection allowed and will be disconnected upon thread has finished.

Definition at line 222 of file WProjectFile.h.

Referenced by threadMain(), and ~WProjectFile().

◆ m_writers

std::list< std::shared_ptr< WProjectFileIO > > WProjectFile::m_writers
protected

The writer instances.

They are used to write the file.

Definition at line 198 of file WProjectFile.h.

Referenced by save(), WProjectFile(), and ~WProjectFile().


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