charon-core
0.3.1
|
Base class for serializable objects. More...
#include <charon-core/ParameteredObject.h>
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 ParameterFile & | getMetadata () |
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... | |
Slot * | getSlot (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... | |
AbstractParameter & | getParameter (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 ¶m, const std::string &name, const std::string &doc, const std::string &type="") |
Add parameters. More... | |
template<class T > | |
void | _addParameter (Parameter< T > ¶m, 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. | |
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.
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.
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.
|
inlineprivate |
Implementation needed to compile with MSVC.
Definition at line 104 of file ParameteredObject.h.
|
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.
className | Initialization value for className property. |
name | Instance name (auto generation if empty) |
doc | Class docstring (for metadata) |
Definition at line 39 of file ParameteredObject.cpp.
References _active, _addParameter(), _className, _createMetadata, _instanceName, _metadata, _setDynamic(), and ParameterFile::set().
|
virtual |
Updates the parametered object list (_objectList)
Definition at line 71 of file ParameteredObject.cpp.
References _initialized, and finalize().
|
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.
slot | New slot to add |
name | parameter name to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
type | Parameter type (string representation) |
Definition at line 157 of file ParameteredObject.cpp.
|
protected |
slot | New slot to add |
name | parameter name to pass to AbstractParameter::init() |
displayname | parameter displyname to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
type | Parameter 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().
|
protected |
slot | New slot to add |
name | parameter name to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
type | Parameter type (string representation) |
Definition at line 190 of file ParameteredObject.cpp.
|
protected |
slot | New slot to add |
name | parameter name to pass to AbstractParameter::init() |
displayname | parameter displyname to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
type | Parameter 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().
|
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())
param | New parameter to add |
name | parameter name to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
type | Parameter type (string representation) |
Definition at line 138 of file ParameteredObject.cpp.
References _addSomething(), _parameters, AbstractParameter::getDefaultString(), AbstractParameter::guessType(), AbstractParameter::init(), and TypeDetector::type().
|
protected |
Useful if you want to initialize the parameters not in their constructor.
param | New parameter to add |
name | parameter name to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
defVal | new default Value |
type | Parameter type (string representation) |
Definition at line 39 of file ParameteredObject.hxx.
References _addParameter(), and Parameter< T >::setDefault().
|
protected |
This function does nothing, if _createMetadata is set to false.
extension | section of metadata file where to add (e.g. parameters, inputs, outputs) |
name | parameter name to pass to AbstractParameter::init() |
doc | parameter docstring (for metadata generation) |
type | Parameter type (string representation) |
defaultValue | Default value, if any |
true | Parameter/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().
|
protected |
Determine target leaves of the execution workflow (i.e. Parametered Objects with no targets connected to output slots).
Definition at line 340 of file ParameteredObject.cpp.
References _outputs.
|
protected |
Tags from the base class or previous calls to this function will be overwritten
tags | List 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().
|
virtual |
Check if all slots with property optional set to false are connected.
true | all 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.
|
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.
|
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.
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.
Definition at line 363 of file ParameteredObject.cpp.
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.
pf | ParameterFile to read connections from. |
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.
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.
Definition at line 564 of file ParameteredObject.cpp.
References _parameters.
Slot * ParameteredObject::getSlot | ( | const std::string & | slotName | ) | const |
slotName | Name of the slot to look for |
std::invalid_argument | if slot does not exist |
Definition at line 515 of file ParameteredObject.cpp.
References _inputs, _instanceName, _outputs, fixCase(), getClassName(), getName(), and sout.
|
virtual |
Returns the template type of a derived class of ParameteredObject. Most of the derived classes are templated.
Reimplemented in TemplatedParameteredObject< T >.
Definition at line 597 of file ParameteredObject.cpp.
|
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.
|
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.
pf | ParameterFile 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.
pf | ParameterFile to save to. |
man | Pointer to the currently active PluginManager |
Definition at line 480 of file ParameteredObject.cpp.
|
virtual |
Is called by _load. Can be used for additional initialization upon a load operation
pf | parameter file to be loaded |
man | The plugin manager, from which loadWorkflow() is called. |
Reimplemented in ParameteredGroupObject.
Definition at line 744 of file ParameteredObject.cpp.
References initialize().
|
virtual |
Is called by _save. Can be used for additional initialization upon a save operation
pf | parameter file to be saved |
Reimplemented in ParameteredGroupObject.
Definition at line 751 of file ParameteredObject.cpp.
|
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.
file | parameter 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.
message | Error 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().
|
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.
propagate | reset dependent objects too |
Definition at line 322 of file ParameteredObject.cpp.
References _executed, _outputs, getClassName(), getName(), setExecuted(), and sout.
|
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.
|
protected |
slot | select 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.
pf | ParameterFile to save to. |
Definition at line 435 of file ParameteredObject.cpp.
References _inputs, _outputs, Slot::connected(), onSave(), Slot::save(), and saveParameters().
|
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.
pf | ParameterFile to save to. |
Definition at line 421 of file ParameteredObject.cpp.
References _className, _instanceName, _parameters, ParameterFile::get(), ParameterFile::isSet(), and ParameterFile::set().
|
inlinevirtual |
value | New value of _executed |
Reimplemented in ParameteredGroupObject.
Definition at line 378 of file ParameteredObject.h.
Parameter< bool > ParameteredObject::_active |
If this is set to false, the Plugin will not be executed.
Definition at line 391 of file ParameteredObject.h.
|
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.