40 const std::string& name,
const std::string& description) :
41 _createMetadata(true),
42 _className(className), _instanceName(name),
43 _initialized(false), _executed(false) {
51 if (description.find(
"\n") != std::string::npos) {
52 raise(
"do not use newlines in descriptions! (replace e.g. by <br>)");
66 "If this is set to false,"
67 "the plugin and all following ones are not executed",
78 sout <<
"(WW) requesting metadata, "
79 "but metadata cache has been cleared." << std::endl;
85 const std::string& name,
const std::string& doc,
86 const std::string&
type,
const std::string& defaultValue) {
87 std::string nameL = name;
89 nameL.begin(), nameL.end(), nameL.begin(), (int(*)(int)) tolower);
92 if (doc.find(
"\n") != std::string::npos) {
93 raise(
"do not use newlines in docstrings! (replace e.g. by <br>)");
104 sout <<
"(EE) ******************************************************\n"
105 <<
"(EE) The parameter or slot \"" << name
106 <<
"\" has already been defined!\n"
107 <<
"(EE) Slots and Parameter names must be unique "
108 <<
"for each Plugin!\n"
109 <<
"(EE) ******************************************************\n"
117 assert(type.length());
119 std::vector<std::string> someList;
126 someList.push_back(name);
130 if (defaultValue.length()) {
139 const std::string& name,
const std::string& doc,
140 const std::string&
type) {
142 param.
init(
this, name);
145 std::string guessedType =
type;
146 if (!guessedType.size())
158 const std::string& doc,
const std::string&
type) {
165 std::string guessedType =
type;
166 if (!guessedType.size())
170 slot.
init(
this, name,displayname, guessedType);
175 _inputs.insert(std::make_pair(name, &slot));
185 +
".optional",
"true");
191 const std::string& doc,
const std::string&
type) {
196 const std::string& doc,
const std::string&
type) {
198 std::string guessedType =
type;
199 if (!guessedType.size())
203 slot.
init(
this, name,displayname, guessedType);
208 _outputs.insert(std::make_pair(name, &slot));
214 +
".multi",
"false");
217 +
".optional",
"false");
233 <<
" \"" << this->
getName() <<
"\"" << std::endl;
258 std::set<ParameteredObject*> targetObjects;
259 std::map<std::string, Slot*>::const_iterator it;
261 const std::set<Slot*>& ts = it->second->getTargets();
262 std::set<Slot*>::const_iterator ti = ts.begin();
263 for (; ti!=ts.end();ti++) {
264 targetObjects.insert(&(*ti)->getParent());
269 std::set<ParameteredObject*>::iterator curObj = targetObjects.begin();
270 for (; curObj != targetObjects.end(); curObj++) {
279 std::set<ParameteredObject*> targetObjects;
280 const std::set<Slot*>& ts = slot.
getTargets();
281 std::set<Slot*>::const_iterator ti = ts.begin();
282 for (; ti!=ts.end();ti++) {
283 targetObjects.insert(&(*ti)->getParent());
287 std::set<ParameteredObject*>::iterator curObj = targetObjects.begin();
288 for (; curObj != targetObjects.end(); curObj++) {
295 raise(
"This plugin must be initialized before execution!");
297 sout <<
"(WW) this plugin has not overridden execute() or does call "
298 <<
"ParameteredObject::execute() directly which is deprecated."
303 std::map<std::string, Slot*>::const_iterator cur;
305 cur->second->prepare();
308 cur->second->prepare();
313 std::map<std::string, Slot*>::const_iterator cur;
315 cur->second->finalize();
318 cur->second->finalize();
325 <<
" \"" <<
getName() <<
"\"" << std::endl;
329 for (std::map<std::string, Slot*>::iterator it =
_outputs.begin();
331 std::set<Slot*> targets = it->second->getTargets();
332 std::set<Slot*>::iterator tIt;
333 for(tIt = targets.begin(); tIt != targets.end(); tIt ++)
334 (*tIt)->getParent().resetExecuted(propagate);
341 std::set<ParameteredObject*> res;
342 std::set<ParameteredObject*> children;
343 std::map<std::string, Slot*>::const_iterator outIter;
344 std::set<Slot*>::const_iterator tIter;
346 const std::set<Slot*>& targets = outIter->second->getTargets();
347 for(tIter = targets.begin(); tIter != targets.end(); tIter++)
348 children.insert(&((*tIter)->getParent()));
350 if(children.size() > 0) {
351 std::set<ParameteredObject*>::const_iterator cIter;
352 for (cIter = children.begin(); cIter != children.end(); cIter++) {
353 const std::set<ParameteredObject*>& targets =
354 (*cIter)->_getTargetNodes();
355 res.insert(targets.begin(), targets.end());
364 std::set<std::string> res;
365 std::map<std::string, Slot*>::const_iterator slotIter;
366 std::set<Slot*> targets;
367 std::set<Slot*>::const_iterator targetIter;
369 for (slotIter =
_inputs.begin(); slotIter !=
_inputs.end(); slotIter++) {
370 if (slotIter->second->connected()) {
371 targets = slotIter->second->getTargets();
372 for (targetIter = targets.begin();
373 targetIter != targets.end(); targetIter++)
374 res.insert((*targetIter)->getParent()._instanceName);
378 if (slotIter->second->connected()) {
379 targets = slotIter->second->getTargets();
380 for (targetIter = targets.begin();
381 targetIter != targets.end(); targetIter++)
382 res.insert((*targetIter)->getParent()._instanceName);
390 std::set<std::string> res;
391 std::map<std::string, Slot*>::const_iterator slotIter;
392 std::set<std::string> slotNames;
393 std::set<std::string>::const_iterator slot, resItem;
394 std::vector<std::string> targetList;
395 std::vector<std::string>::const_iterator target;
398 for (slotIter =
_inputs.begin(); slotIter !=
_inputs.end(); slotIter++)
399 slotNames.insert(slotIter->second->getName());
401 slotNames.insert(slotIter->second->getName());
402 for (slot = slotNames.begin(); slot != slotNames.end(); slot++) {
408 for (target = targetList.begin(); target != targetList.end(); target++)
409 res.insert(target->substr(0, target->find(
".")));
413 for (resItem = res.begin(); resItem != res.end(); resItem++) {
414 std::string
type = pf.
get<std::string> (*resItem +
".type");
430 std::map<std::string, AbstractParameter*>::const_iterator par;
432 par->second->save(pf);
440 std::map<std::string, Slot*>::const_iterator slotIter;
442 for (slotIter =
_inputs.begin(); slotIter !=
_inputs.end(); slotIter++)
444 Slot* sl=slotIter->second;
451 Slot* sl=slotIter->second;
464 std::ostringstream msg;
465 msg << __FILE__ <<
":" << __LINE__;
466 msg <<
"\n\tclassname and type do not match!";
469 msg <<
"\n\ttype: " << pf.
get<std::string>(_instanceName +
".type");
470 throw std::runtime_error(msg.str().c_str());
475 std::map<std::string, AbstractParameter*>::const_iterator par;
477 par->second->load(pf);
483 std::map<std::string, Slot*>::const_iterator slotIter;
484 for (slotIter =
_inputs.begin(); slotIter !=
_inputs.end(); slotIter++)
485 slotIter->second->load(pf, man);
487 slotIter->second->load(pf, man);
494 std::map<std::string, Slot*>::const_iterator slotIter;
496 for (slotIter =
_inputs.begin(); slotIter !=
_inputs.end(); slotIter++) {
497 const Slot* cur = slotIter->second;
500 <<
"." << cur->
getName() << std::endl;
505 const Slot* cur = slotIter->second;
508 <<
"." << cur->
getName() << std::endl;
516 std::map<std::string, Slot*>::const_iterator slot;
531 std::string slotNameFixed =
fixCase(slotName);
533 <<
"." << slotName <<
" (fixed: " << slotNameFixed <<
")"
537 slot =
_inputs.find(slotNameFixed);
541 slot =
_outputs.find(slotNameFixed);
547 throw std::invalid_argument(
548 std::string(
"Slot \"") + slotName +
"\" in instance \""
553 const std::map<std::string, Slot*>&
558 const std::map<std::string, Slot*>&
563 const std::map<std::string, AbstractParameter*>&
577 if(templateType.length() > 0)
578 msg +=
"<" + templateType +
">" ;
579 msg +=
" \"" + this->
getName() +
"\" : " + message ;
581 throw std::runtime_error(msg) ;
586 const std::string & name)
const {
590 throw std::invalid_argument(
591 std::string(
"Parameter ") + name +
" in instance \""
593 +
"\" does not exist!");
611 bool ParameteredObject::isDynamic() {
616 sout <<
"(WW) called isDynamic() without enabled metadata generation"
623 std::string nameL=name, curL;
625 nameL.begin(), nameL.end(), nameL.begin(),(int(*)(int)) tolower);
626 std::set<std::string> names;
627 std::map<std::string, Slot*>::const_iterator sIter;
628 std::map<std::string, AbstractParameter*>::const_iterator pIter;
630 names.insert(sIter->first);
633 names.insert(sIter->first);
636 names.insert(pIter->first);
638 std::set<std::string>::const_iterator nIter;
639 for(nIter=names.begin(); nIter!=names.end(); nIter++) {
642 curL.begin(),curL.end(), curL.begin(),(int(*)(int)) tolower);
647 raise(
"Parameter/Slot " + name +
" not found!");
648 return std::string();
669 const std::string &extension,
const std::string &name)
676 sout <<
"(EE) ******************************************************\n"
677 <<
"(EE) The parameter or slot \"" << name
678 <<
"\" has not been defined!\n"
679 <<
"(EE) Slots and Parameter names must be unique "
680 <<
"for each Plugin!\n"
681 <<
"(EE) ******************************************************\n"
687 std::vector<std::string> someList;
693 std::vector<std::string>::iterator found = std::find(
694 someList.begin(), someList.end(), name);
695 if (found != someList.end()) {
708 someList.erase(found);
734 raise(
"Plugin is already initialized!");
740 raise(
"Plugin was not initialied, or has been already finalized");
746 if(man->initializePluginOnLoad()) {
virtual std::string getDefaultString()=0
Get default value.
std::string fixCase(const std::string &parOrSlotName) const
restore parameter/slot name casing
void clearMetadata()
delete metadata cache to save some space
void init(ParameteredObject *parent, const std::string &name)
Initialize new parameter.
virtual std::string guessType() const =0
Try to guess slot type.
virtual void saveParameters(ParameterFile &pf) const
Save parameters to parameter file.
virtual std::string guessType() const =0
Try to guess type.
virtual void finalize()
finalize plugin
virtual const std::string getTemplateType() const
get template type as string
Interface for a plugin manager.
Provides an interface for a plugin manager.
This class serves to store parameters used within the Charon Project.
void _prepareSlots()
prepare slot data
bool getOptional() const
return value of _optional;
void init(ParameteredObject *parent, std::string name, std::string type)
initialize parent and name
Parameter object handling.
virtual void run()
Update object.
SplitStream sout
Dummy instance for usage in other files (for interface too).
bool _removeSomething(const std::string &extension, const std::string &name)
Remove something. Iverse of _addSomething.
void erase(std::string parameter)
Delete a parameter from the parameter list.
virtual void onSave(ParameterFile &pf) const
Custom Save operation.
Convenience file to iclude all ParameteredObject dependencies and Template functions.
void raise(const std::string &message) const
throw an exception with information about the ParameteredObject
bool connected() const
Check if slot is connected.
std::vector< T > getList(std::string parameter) const
If multiple values are set, return a list containing these values.
virtual void onLoad(const ParameterFile &pf, const PluginManagerInterface *man)
Custom Load operation.
const ParameterFile & getMetadata()
get metadata
void clear()
Clear parameter list.
void _setDynamic(bool v)
Specifies if the ParameteredObject is dynamic.
std::map< std::string, Slot * > _inputs
Input slots.
void _setTags(const std::string &tags)
Register additional tag names for grouping ParameteredObjects.
std::set< std::string > getNeighbours() const
Get connected neighbours of the current object.
ParameteredObject & getParent()
get parent object
void _removeOutputSlot(std::string name)
Remove an output slot.
bool _initialized
status of initialization
virtual void loadParameters(const ParameterFile &pf)
Load parameter from parameter file.
void runPreceeding() const
run all preceeding objects
const std::map< std::string, Slot * > & getOutputSlots() const
Get all output slots as map.
void _commitSlots()
commit slot data
std::set< ParameteredObject * > _getTargetNodes()
get target nodes
virtual std::string getName() const
Get slot name.
virtual std::set< Slot * > getTargets() const =0
Get pointers to the connected targets.
void _removeInputSlot(std::string name)
Remove an input slot.
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...
void save(ParameterFile &pf) const
Save own content to the given parameter file.
void set(std::string parameter, const T &value=T())
Set a parameter to the given single value.
std::map< std::string, AbstractParameter * > _parameters
This vector stores all parameters that have to be saved/restored.
bool getMulti() const
return value of _multiSlot;
std::string _instanceName
Name of the instance.
virtual ~ParameteredObject()
Delete parametered object.
T get(std::string parameter) const
Get the value of a specified parameter.
bool isSet(std::string parameter) const
Check if a givem parameter has already been set.
virtual void resetExecuted(bool propagate=true)
reset execution status
Parameter< bool > _active
ParameteredObject activation state.
const std::string & getClassName() const
class name
Slot * getSlot(const std::string &slotName) const
Get pointer to some slot (by name)
void _addParameter(AbstractParameter ¶m, const std::string &name, const std::string &doc, const std::string &type="")
Add parameters.
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.
const std::map< std::string, Slot * > & getInputSlots() const
Get all input slots as map.
bool _createMetadata
Specifies if the ParameteredObject should create metadata information.
bool _executed
status of execution (set to true during ParameteredObject::execute())
charon_core_DLL_PUBLIC std::string type(const std::string &typeInfo)
Get type representation.
Commom properties of slot objects.
virtual void execute()
execute plugin code
void _addOutputSlot(Slot &slot, const std::string &name, const std::string &doc, const std::string &type="")
Register output slot.
Declaration of class SplitStream.
virtual void initialize()
initialize plugin
virtual void prepareDynamicInterface(const ParameterFile &file)
prepare interface of parameters and slots
const std::string & getName() const
instance name
void loadSlots(const ParameterFile &pf, const PluginManagerInterface *man)
Load slot connection from parameter file.
virtual std::string getDisplayName() const
Get slot display name.
virtual void save(ParameterFile &pf) const
Save slot connections This function disconnects already established connections in the parameterFile ...
std::map< std::string, Slot * > _outputs
Output slots.
ParameteredObject()
forbid instantiation without className etc.
const std::map< std::string, AbstractParameter * > & getParameters() const
Get all Parameters as a map.
virtual void setExecuted(bool value)
set property _executed
std::string _className
Class name.
Data manager based on parameter files.
ParameterFile _metadata
Class tracking.
virtual bool connected() const
Check if object is ready for work.