charon-core  0.3.1
ParameteredObject Class Reference

Base class for serializable objects. More...

#include <charon-core/ParameteredObject.h>

Inheritance diagram for ParameteredObject:

Public Types

enum  build_type { UNDEFINED_BUILD = 0, DEBUG_BUILD = 1, RELEASE_BUILD = 2 }
 defined build type More...
 
enum  template_type { TYPE_DOUBLE = 0, TYPE_FLOAT = 1, TYPE_INT = 2 }
 Integer which represents a template type. More...
 

Public Member Functions

virtual ~ParameteredObject ()
 Delete parametered object. More...
 
void clearMetadata ()
 delete metadata cache to save some space More...
 
bool executed () const
 get execution status
 
std::string fixCase (const std::string &parOrSlotName) const
 restore parameter/slot name casing
 
const ParameterFilegetMetadata ()
 get metadata
 
virtual void initialize ()
 initialize plugin More...
 
virtual void loadParameters (const ParameterFile &pf)
 Load parameter from parameter file. More...
 
void loadSlots (const ParameterFile &pf, const PluginManagerInterface *man)
 Load slot connection from parameter file. More...
 
virtual void onLoad (const ParameterFile &pf, const PluginManagerInterface *man)
 Custom Load operation. More...
 
virtual void onSave (ParameterFile &pf) const
 Custom Save operation. More...
 
virtual void prepareDynamicInterface (const ParameterFile &file)
 prepare interface of parameters and slots More...
 
virtual void resetExecuted (bool propagate=true)
 reset execution status More...
 
virtual void run ()
 Update object. More...
 
void save (ParameterFile &pf) const
 Save own content to the given parameter file. More...
 
virtual void saveParameters (ParameterFile &pf) const
 Save parameters to parameter file. More...
 
virtual void setExecuted (bool value)
 set property _executed More...
 
getter of plugin information
const std::string & getClassName () const
 class name
 
const std::string & getName () const
 instance name
 
virtual const std::string getTemplateType () const
 get template type as string More...
 
SlotgetSlot (const std::string &slotName) const
 Get pointer to some slot (by name) More...
 
const std::map< std::string,
Slot * > & 
getInputSlots () const
 Get all input slots as map. More...
 
const std::map< std::string,
Slot * > & 
getOutputSlots () const
 Get all output slots as map. More...
 
const std::map< std::string,
AbstractParameter * > & 
getParameters () const
 Get all Parameters as a map. More...
 
slot management
std::set< std::string > getNeighbours () const
 Get connected neighbours of the current object. More...
 
std::set< std::string > getNeighbours (const ParameterFile &pf) const
 Get connected neighbours of the current object. More...
 
virtual bool connected () const
 Check if object is ready for work. More...
 
void raise (const std::string &message) const
 throw an exception with information about the ParameteredObject More...
 
AbstractParametergetParameter (const std::string &name) const
 
template<typename T >
void setParameter (std::string name, T value)
 
bool isDynamic ()
 

Public Attributes

Parameter< bool > _active
 ParameteredObject activation state. More...
 

Protected Member Functions

 ParameteredObject (const std::string &className, const std::string &name="", const std::string &doc="")
 Default constructor. More...
 
void _addInputSlot (Slot &slot, const std::string &name, const std::string &displayname, const std::string &doc, const std::string &type)
 Register input slot. More...
 
void _addOutputSlot (Slot &slot, const std::string &name, const std::string &displayname, const std::string &doc, const std::string &type)
 Register output slot. More...
 
void _addParameter (AbstractParameter &param, const std::string &name, const std::string &doc, const std::string &type="")
 Add parameters. More...
 
template<class T >
void _addParameter (Parameter< T > &param, const std::string &name, const std::string &doc, const T &defVal, const std::string &type="")
 Same function but adding a default value. More...
 
bool _addSomething (const std::string &extension, const std::string &name, const std::string &doc, const std::string &type, const std::string &defaultValue="")
 Common code for _addParameter, _addInputSlot, _addOutputSlot. More...
 
void _commitSlots ()
 commit slot data
 
std::set< ParameteredObject * > _getTargetNodes ()
 get target nodes More...
 
void _prepareSlots ()
 prepare slot data
 
void _removeInputSlot (std::string name)
 Remove an input slot.
 
void _removeOutputSlot (std::string name)
 Remove an output slot.
 
bool _removeSomething (const std::string &extension, const std::string &name)
 Remove something. Iverse of _addSomething.
 
void _setDynamic (bool v)
 Specifies if the ParameteredObject is dynamic.
 
void _setTags (const std::string &tags)
 Register additional tag names for grouping ParameteredObjects. More...
 
virtual void execute ()
 execute plugin code More...
 
virtual void finalize ()
 finalize plugin More...
 
void runPreceeding () const
 run all preceeding objects
 
void runPreceeding (const Slot &slot) const
 run all preceeding objects connected to a particular slot More...
 
Register input/output slots.
void _addInputSlot (Slot &slot, const std::string &name, const std::string &doc, const std::string &type="")
 These functions needs to be called by the derived class in order to register all objects which can be used as inputs or outputs. More...
 
void _addOutputSlot (Slot &slot, const std::string &name, const std::string &doc, const std::string &type="")
 Register output slot. More...
 

Private Member Functions

 ParameteredObject (const ParameteredObject &)
 forbid copying More...
 
 ParameteredObject ()
 forbid instantiation without className etc.
 

Private Attributes

std::string _className
 Class name.
 
bool _createMetadata
 Specifies if the ParameteredObject should create metadata information.
 
bool _executed
 status of execution (set to true during ParameteredObject::execute())
 
bool _initialized
 status of initialization
 
std::map< std::string, Slot * > _inputs
 Input slots.
 
std::string _instanceName
 Name of the instance.
 
ParameterFile _metadata
 Class tracking. More...
 
std::map< std::string, Slot * > _outputs
 Output slots.
 
std::map< std::string,
AbstractParameter * > 
_parameters
 This vector stores all parameters that have to be saved/restored.
 

Detailed Description

This is the base class for objects that should be able to save and reload their settings in/from a ParameterFile. Derive all savable/restorable classes from this one. Reimplement the execute() method to perform calculations.

Remarks
  • Object names cannot be changed after instantiation because this could mess up the parameter file store.

Metadata Generation

Per default, all generated plugins are created with their metadata description stored within the ParameteredObject. It can be retrieved via getMetadata(). Calling clearMetadata(), the metadata cache is cleared e.g. to save space. Usually, you do not have to care about this, since metadata generation is handled by the PluginManager.

Definition at line 69 of file ParameteredObject.h.

Member Enumeration Documentation

Enumerator
UNDEFINED_BUILD 

The build type was not defined explicitly, make no assumptions about the release/debug configuration.

DEBUG_BUILD 

the object was compiled in debug mode

RELEASE_BUILD 

the object was compiled in release mode

Definition at line 325 of file ParameteredObject.h.

Enumerator
TYPE_DOUBLE 

The template type of the instance is double.

TYPE_FLOAT 

The template type of the instance is float.

TYPE_INT 

The template type of the instance is integer.

Definition at line 318 of file ParameteredObject.h.

Constructor & Destructor Documentation

ParameteredObject::ParameteredObject ( const ParameteredObject )
inlineprivate

Implementation needed to compile with MSVC.

Definition at line 104 of file ParameteredObject.h.

ParameteredObject::ParameteredObject ( const std::string &  className,
const std::string &  name = "",
const std::string &  doc = "" 
)
protected

Init class name with given string. If no instance name is given, a dummy name "[className]0" is assumed. This name is not guaranteed to be unique. For auto-generation of unique names, use a PluginManager.

Parameters
classNameInitialization value for className property.
nameInstance name (auto generation if empty)
docClass docstring (for metadata)

Definition at line 39 of file ParameteredObject.cpp.

References _active, _addParameter(), _className, _createMetadata, _instanceName, _metadata, _setDynamic(), and ParameterFile::set().

ParameteredObject::~ParameteredObject ( )
virtual

Updates the parametered object list (_objectList)

Definition at line 71 of file ParameteredObject.cpp.

References _initialized, and finalize().

Member Function Documentation

void ParameteredObject::_addInputSlot ( Slot slot,
const std::string &  name,
const std::string &  doc,
const std::string &  type = "" 
)
protected

The object is only valid configured, if all slots with property optional set to false are connected to slots of some other object. Per default, only one connection can be established per input source, if you want multiple connections to input slots, set the property multislot to true. Per default, output slots can have an arbitrary number of targets. The call syntax is similar to _addParameter.

_addInput/OutputSlot() has to be called multiple times to add more then one slot.Register input slot.

Parameters
slotNew slot to add
nameparameter name to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
typeParameter type (string representation)

Definition at line 157 of file ParameteredObject.cpp.

void ParameteredObject::_addInputSlot ( Slot slot,
const std::string &  name,
const std::string &  displayname,
const std::string &  doc,
const std::string &  type 
)
protected
Parameters
slotNew slot to add
nameparameter name to pass to AbstractParameter::init()
displaynameparameter displyname to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
typeParameter type (string representation)

Definition at line 162 of file ParameteredObject.cpp.

References _addSomething(), _className, _createMetadata, _inputs, _metadata, Slot::getDisplayName(), Slot::getMulti(), Slot::getOptional(), Slot::guessType(), Slot::init(), ParameterFile::set(), and TypeDetector::type().

void ParameteredObject::_addOutputSlot ( Slot slot,
const std::string &  name,
const std::string &  doc,
const std::string &  type = "" 
)
protected
Parameters
slotNew slot to add
nameparameter name to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
typeParameter type (string representation)

Definition at line 190 of file ParameteredObject.cpp.

void ParameteredObject::_addOutputSlot ( Slot slot,
const std::string &  name,
const std::string &  displayname,
const std::string &  doc,
const std::string &  type 
)
protected
Parameters
slotNew slot to add
nameparameter name to pass to AbstractParameter::init()
displaynameparameter displyname to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
typeParameter type (string representation)

Definition at line 195 of file ParameteredObject.cpp.

References _addSomething(), _className, _createMetadata, _metadata, _outputs, Slot::getDisplayName(), Slot::getMulti(), Slot::getOptional(), Slot::guessType(), Slot::init(), ParameterFile::set(), and TypeDetector::type().

void ParameteredObject::_addParameter ( AbstractParameter param,
const std::string &  name,
const std::string &  doc,
const std::string &  type = "" 
)
protected

If _createMetadata is true, the parameter is also recorded to the class information in the _metadata parameter file. To be recorded correctly, you have also to specify the parameter docstring and type (e.g. int, float, or arbitrary). If type is an empty string, AbstractParameter will guess the type, which works on basic types like int, float (see class TypeDetector) This assigns the parameter to this object. Each parameter can only be assigned once, of assigned twice, an error occurs (raises exception in AbstractParameter::init())

Parameters
paramNew parameter to add
nameparameter name to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
typeParameter type (string representation)

Definition at line 138 of file ParameteredObject.cpp.

References _addSomething(), _parameters, AbstractParameter::getDefaultString(), AbstractParameter::guessType(), AbstractParameter::init(), and TypeDetector::type().

template<class T >
void ParameteredObject::_addParameter ( Parameter< T > &  param,
const std::string &  name,
const std::string &  doc,
const T &  defVal,
const std::string &  type = "" 
)
protected

Useful if you want to initialize the parameters not in their constructor.

Parameters
paramNew parameter to add
nameparameter name to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
defValnew default Value
typeParameter type (string representation)

Definition at line 39 of file ParameteredObject.hxx.

References _addParameter(), and Parameter< T >::setDefault().

bool ParameteredObject::_addSomething ( const std::string &  extension,
const std::string &  name,
const std::string &  doc,
const std::string &  type,
const std::string &  defaultValue = "" 
)
protected

This function does nothing, if _createMetadata is set to false.

Parameters
extensionsection of metadata file where to add (e.g. parameters, inputs, outputs)
nameparameter name to pass to AbstractParameter::init()
docparameter docstring (for metadata generation)
typeParameter type (string representation)
defaultValueDefault value, if any
Return values
trueParameter/Slot name is unique

Definition at line 84 of file ParameteredObject.cpp.

References _className, _createMetadata, _inputs, _metadata, _outputs, _parameters, ParameterFile::getList(), ParameterFile::isSet(), ParameterFile::set(), sout, and TypeDetector::type().

std::set< ParameteredObject * > ParameteredObject::_getTargetNodes ( )
protected

Determine target leaves of the execution workflow (i.e. Parametered Objects with no targets connected to output slots).

Returns
set of target nodes

Definition at line 340 of file ParameteredObject.cpp.

References _outputs.

void ParameteredObject::_setTags ( const std::string &  tags)
protected

Tags from the base class or previous calls to this function will be overwritten

Parameters
tagsList of tags as single ;-separated string

Definition at line 222 of file ParameteredObject.cpp.

References _className, _createMetadata, _metadata, and ParameterFile::set().

void ParameteredObject::clearMetadata ( )

deletes the content of _metadata, sets _createMetadata to false to prevent _metadata to be written after this call.

Definition at line 568 of file ParameteredObject.cpp.

References _createMetadata, _metadata, and ParameterFile::clear().

bool ParameteredObject::connected ( ) const
virtual

Check if all slots with property optional set to false are connected.

Return values
trueall neccessary slots are connected

Definition at line 493 of file ParameteredObject.cpp.

References _inputs, _outputs, Slot::connected(), Slot::getName(), getName(), Slot::getOptional(), Slot::getParent(), and sout.

void ParameteredObject::execute ( )
protectedvirtual

The default implementation does nothing at all. Override this function implementing new modules. This function may be pure virtual in future releases.

Reimplemented in ParameteredGroupObject, ForStatement, VirtualSlotSwitch, Statement, GroupObject, and SlotBundle.

Definition at line 293 of file ParameteredObject.cpp.

References _initialized, and sout.

void ParameteredObject::finalize ( )
protectedvirtual

The default implementation does nothing at all. Override this function implementing new modules. This function may be pure virtual in future releases.

Reimplemented in ParameteredGroupObject, and SlotBundle.

Definition at line 738 of file ParameteredObject.cpp.

References _initialized.

const std::map< std::string, Slot * > & ParameteredObject::getInputSlots ( ) const

Returns a map linking the names of the input slots to the Slots itself.

Returns
Map containing all input slots

Definition at line 554 of file ParameteredObject.cpp.

References _inputs.

std::set< std::string > ParameteredObject::getNeighbours ( ) const

This is based on the "real" slot connections, i.e. independend of some parameter file content.

Returns
set of neighbours

Definition at line 363 of file ParameteredObject.cpp.

References _inputs, and _outputs.

std::set< std::string > ParameteredObject::getNeighbours ( const ParameterFile pf) const

This is based on the content of the given ParameterFile, i.e. the connected objects need not to exist really. This is also independend of the existing connections of the current object, it is only based on the connections saved in the parameter file. Nonexistent objects are created.

Parameters
pfParameterFile to read connections from.
Returns
set of neighbours

Definition at line 388 of file ParameteredObject.cpp.

References _inputs, _instanceName, _outputs, ParameterFile::get(), ParameterFile::getList(), ParameterFile::isSet(), and TypeDetector::type().

const std::map< std::string, Slot * > & ParameteredObject::getOutputSlots ( ) const

Returns a map linking the names of the output slots to the Slots itself.

Returns
Map containing all output slots

Definition at line 559 of file ParameteredObject.cpp.

References _outputs.

const std::map< std::string, AbstractParameter * > & ParameteredObject::getParameters ( ) const

Returns a map linking the names of the parameters to the parameters itself.

Returns
Map containing all output slots

Definition at line 564 of file ParameteredObject.cpp.

References _parameters.

Slot * ParameteredObject::getSlot ( const std::string &  slotName) const
Parameters
slotNameName of the slot to look for
Exceptions
std::invalid_argumentif slot does not exist
Returns
requested slot

Definition at line 515 of file ParameteredObject.cpp.

References _inputs, _instanceName, _outputs, fixCase(), getClassName(), getName(), and sout.

const std::string ParameteredObject::getTemplateType ( ) const
virtual

Returns the template type of a derived class of ParameteredObject. Most of the derived classes are templated.

Returns
Template type as std::string

Reimplemented in TemplatedParameteredObject< T >.

Definition at line 597 of file ParameteredObject.cpp.

void ParameteredObject::initialize ( )
virtual

The default implementation does nothing at all. Override this function implementing new modules. This function may be pure virtual in future releases.

Reimplemented in ParameteredGroupObject, and SlotBundle.

Definition at line 732 of file ParameteredObject.cpp.

References _initialized.

void ParameteredObject::loadParameters ( const ParameterFile pf)
virtual

Loads parameters of the current object from the given parameter file. All registered parameters are loaded from the ParameterFile. Slot connections are NOT loaded. This function does only touch the current object and no connected one.

Parameters
pfParameterFile to load from.

Definition at line 458 of file ParameteredObject.cpp.

References _className, _instanceName, _parameters, ParameterFile::get(), ParameterFile::isSet(), and StringTool::toLowerCase().

void ParameteredObject::loadSlots ( const ParameterFile pf,
const PluginManagerInterface man 
)

PluginManager is used to get pointers to the connected objects. Calls load on all input and output slots passing the given parameters. InstanceName is used as prefix.

Parameters
pfParameterFile to save to.
manPointer to the currently active PluginManager

Definition at line 480 of file ParameteredObject.cpp.

References _inputs, _outputs, and onLoad().

void ParameteredObject::onLoad ( const ParameterFile pf,
const PluginManagerInterface man 
)
virtual

Is called by _load. Can be used for additional initialization upon a load operation

Parameters
pfparameter file to be loaded
manThe plugin manager, from which loadWorkflow() is called.

Reimplemented in ParameteredGroupObject.

Definition at line 744 of file ParameteredObject.cpp.

References initialize().

void ParameteredObject::onSave ( ParameterFile pf) const
virtual

Is called by _save. Can be used for additional initialization upon a save operation

Parameters
pfparameter file to be saved

Reimplemented in ParameteredGroupObject.

Definition at line 751 of file ParameteredObject.cpp.

void ParameteredObject::prepareDynamicInterface ( const ParameterFile file)
virtual

This function may change the number and kind of slots/parameters depending on certain parameters in the ParameterFile. Since the interface may change depending on the parameter file content, such modules are called dynamic modules.

The default implementation does nothing and is suitable for all non-dynamic modules. Re-implement this function in dynamic modules.

Note
Make sure that ParameteredObject::_setDynamic() is called in the constructor if implementing a dynamic module!
Parameters
fileparameter file describing the workflow

Reimplemented in VirtualSlotSwitch, ParameteredGroupObject, and SlotBundle.

Definition at line 601 of file ParameteredObject.cpp.

References initialize().

void ParameteredObject::raise ( const std::string &  message) const

Throws an excption of class std::runtime_error with additional information about the class type, template type and the ParameteredObject.

Parameters
messageError message which will appended to the what c-string of the std::exception

Definition at line 573 of file ParameteredObject.cpp.

References getClassName(), getName(), and getTemplateType().

void ParameteredObject::resetExecuted ( bool  propagate = true)
virtual

This sets the propety _executed to false. Per default, all depending objects are resetted too, but setting the propagate parameter to false, only the object itself will be resetted.

This function is virtual to be able to react to the reset signal. Make sure you call this base function on overriding resetExecuted.

Parameters
propagatereset dependent objects too

Definition at line 322 of file ParameteredObject.cpp.

References _executed, _outputs, getClassName(), getName(), setExecuted(), and sout.

void ParameteredObject::run ( )
virtual

This function calls run on all InputSlots, then the execute function is run. After execution, the executed flag is set. This function returns immediately, if the executed flag is set already to avoid duplicate execution.

Definition at line 229 of file ParameteredObject.cpp.

References _commitSlots(), _executed, _prepareSlots(), connected(), execute(), getClassName(), getName(), raise(), runPreceeding(), and sout.

void ParameteredObject::runPreceeding ( const Slot slot) const
protected
Parameters
slotselect slot where preceeding objects should be run

Definition at line 277 of file ParameteredObject.cpp.

References Slot::getTargets().

void ParameteredObject::save ( ParameterFile pf) const

All registered parameters are saved to the ParameterFile. This function does NOT touch any slot. InstanceName is used as prefix.

Parameters
pfParameterFile to save to.

Definition at line 435 of file ParameteredObject.cpp.

References _inputs, _outputs, Slot::connected(), onSave(), Slot::save(), and saveParameters().

void ParameteredObject::saveParameters ( ParameterFile pf) const
virtual

Saves parameters of the current parametered object to the given parameter file. All registered parameters are saved to the ParameterFile. Slot connections are NOT stored. This function does only touch the current object and no connected one.

Parameters
pfParameterFile to save to.

Definition at line 421 of file ParameteredObject.cpp.

References _className, _instanceName, _parameters, ParameterFile::get(), ParameterFile::isSet(), and ParameterFile::set().

virtual void ParameteredObject::setExecuted ( bool  value)
inlinevirtual
Parameters
valueNew value of _executed

Reimplemented in ParameteredGroupObject.

Definition at line 378 of file ParameteredObject.h.

Member Data Documentation

Parameter< bool > ParameteredObject::_active

If this is set to false, the Plugin will not be executed.

Definition at line 391 of file ParameteredObject.h.

ParameterFile ParameteredObject::_metadata
private

This parameterfile is used for metadata generation and stores the name of this class with its parameters and slots.

Definition at line 78 of file ParameteredObject.h.


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