charon-core  0.3.1
ParameteredObject.cpp
Go to the documentation of this file.
1 /* This file is part of Charon.
2 
3  Charon is free software: you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Charon is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public License
14  along with Charon. If not, see <http://www.gnu.org/licenses/>.
15  */
30 #include <algorithm>
31 #include <cassert>
32 #include <stdexcept>
35 #include <charon-core/StringTool.h>
38 
39 ParameteredObject::ParameteredObject(const std::string& className,
40  const std::string& name, const std::string& description) :
41  _createMetadata(true),
42  _className(className), _instanceName(name),
43  _initialized(false), _executed(false) {
44 
45  // avoid empty instance name, use dummy value if needed
46  if (_instanceName == "") {
47  _instanceName = _className + "0";
48  }
49 
50  // forbid invalid descriptions
51  if (description.find("\n") != std::string::npos) {
52  raise("do not use newlines in descriptions! (replace e.g. by <br>)");
53  }
54 
55  if (_createMetadata) {
56  _metadata.set<std::string> (_className + ".doc", description);
57  _metadata.set<std::string> (_className + ".parameters");
58  _metadata.set<std::string> (_className + ".inputs");
59  _metadata.set<std::string> (_className + ".outputs");
60  }
61 
62  _setDynamic(false);
63 
64  // additional Active
65  _addParameter(_active, "active",
66  "If this is set to false,"
67  "the plugin and all following ones are not executed",
68  true, "bool");
69 }
70 
72  if(_initialized)
73  finalize();
74 }
75 
77  if (!_createMetadata) {
78  sout << "(WW) requesting metadata, "
79  "but metadata cache has been cleared." << std::endl;
80  }
81  return _metadata;
82 }
83 
84 bool ParameteredObject::_addSomething(const std::string& extension,
85  const std::string& name, const std::string& doc,
86  const std::string& type, const std::string& defaultValue) {
87  std::string nameL = name;
88  std::transform(
89  nameL.begin(), nameL.end(), nameL.begin(), (int(*)(int)) tolower);
90 
91  // forbid invalid docstrings
92  if (doc.find("\n") != std::string::npos) {
93  raise("do not use newlines in docstrings! (replace e.g. by <br>)");
94  }
95 
96  // Check that param is not yet registered.
97  // Parameters can only be assigned once!
98  if( _parameters.find(name) != _parameters.end() ||
99  _inputs.find(name) != _inputs.end() ||
100  _outputs.find(name) != _outputs.end() ||
101  _parameters.find(nameL) != _parameters.end() ||
102  _inputs.find(nameL) != _inputs.end() ||
103  _outputs.find(nameL) != _outputs.end()) {
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"
110  << std::endl;
111  return false;
112  }
113 
114  if (_createMetadata) {
115  // Here, type has to be set explicitly.
116  // Use guessType, if no type has been given.
117  assert(type.length());
118 
119  std::vector<std::string> someList;
120  // get all elements of the given section
121  if (_metadata.isSet(_className + "." + extension)) {
122  someList = _metadata.getList<std::string> (
123  _className + "." + extension);
124  }
125 
126  someList.push_back(name);
127  _metadata.set<std::string>(_className+"."+extension, someList);
128  _metadata.set<std::string>(_className+"."+name + ".type", type);
129  _metadata.set<std::string>(_className+"."+name + ".doc", doc);
130  if (defaultValue.length()) {
131  _metadata.set<std::string> (_className + "." + name, defaultValue);
132  }
133  }
134 
135  return true;
136 }
137 
139  const std::string& name, const std::string& doc,
140  const std::string& type) {
141  // assign parameter to this object
142  param.init(this, name);
143 
144  // if type is given, we do not need guessing
145  std::string guessedType = type;
146  if (!guessedType.size())
147  guessedType = param.guessType();
148 
149  // add metadata
150  if (_addSomething("parameters", name, doc, guessedType,
151  param.getDefaultString())) {
152  // and add it to the parameters list
153  _parameters.insert(std::make_pair(name, &param));
154  }
155 }
156 
157 void ParameteredObject::_addInputSlot(Slot& slot, const std::string& name,
158  const std::string& doc, const std::string& type) {
159  _addInputSlot(slot,name,name,doc,type);
160 }
161 
162 void ParameteredObject::_addInputSlot(Slot &slot, const std::string &name,const std::string &displayname, const std::string &doc, const std::string &type)
163 {
164  // if type is given, we do not need guessing
165  std::string guessedType = type;
166  if (!guessedType.size())
167  guessedType = slot.guessType();
168 
169  // assign parameter to this object
170  slot.init(this, name,displayname, guessedType);
171 
172  // add metadata
173  if (_addSomething("inputs", name, doc, guessedType)) {
174  // and add it to the inputs slot list
175  _inputs.insert(std::make_pair(name, &slot));
176 
177  if (_createMetadata) {
178  _metadata.set<std::string> (_className + "." + name
179  + ".displayname", slot.getDisplayName());
180  if (slot.getMulti())
181  _metadata.set<std::string> (_className + "." + name
182  + ".multi", "true");
183  if (slot.getOptional())
184  _metadata.set<std::string> (_className + "." + name
185  + ".optional", "true");
186  }
187  }
188 }
189 
190 void ParameteredObject::_addOutputSlot(Slot& slot, const std::string& name,
191  const std::string& doc, const std::string& type) {
192  _addOutputSlot(slot,name,name,doc,type);
193 }
194 
195 void ParameteredObject::_addOutputSlot(Slot& slot, const std::string& name, const std::string& displayname,
196  const std::string& doc, const std::string& type) {
197  // if type is given, we do not need guessing
198  std::string guessedType = type;
199  if (!guessedType.size())
200  guessedType = slot.guessType();
201 
202  // assign parameter to this object
203  slot.init(this, name,displayname, guessedType);
204 
205  // add metadata
206  if (_addSomething("outputs", name, doc, guessedType)) {
207  // and add it to the output slot list
208  _outputs.insert(std::make_pair(name, &slot));
209  if (_createMetadata) {
210  _metadata.set<std::string> (_className + "." + name
211  + ".displayname", slot.getDisplayName());
212  if (!slot.getMulti())
213  _metadata.set<std::string> (_className + "." + name
214  + ".multi", "false");
215  if (!slot.getOptional())
216  _metadata.set<std::string> (_className + "." + name
217  + ".optional", "false");
218  }
219  }
220 }
221 
222 void ParameteredObject::_setTags(const std::string& tags) {
223  if(_createMetadata) {
224  _metadata.set<std::string> (_className + ".tags", tags);
225  }
226 }
227 
228 
230  // avoid duplicate execution
231  if (_executed) {
232  sout << "(DD) Skipping reexecution of " << this->getClassName()
233  << " \"" << this->getName() << "\"" << std::endl;
234  return;
235  }
236 
237  // check requirements
238  if (!connected()) {
239  ParameteredObject::raise("not (completely) connected!");
240  }
241 
242  runPreceeding();
243 
244  // now all inputs are ready, execute the current object
245  // by calling the template function
246  sout << "(II) Executing " << getClassName() << " \"";
247  sout << getName() << "\"" << std::endl;
248  _prepareSlots();
249  execute();
250  _commitSlots();
251 
252  // post execution code
253  _executed = true;
254 }
255 
257  // collect preceeding objects
258  std::set<ParameteredObject*> targetObjects;
259  std::map<std::string, Slot*>::const_iterator it;
260  for (it = _inputs.begin(); it != _inputs.end(); 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());
265  }
266  }
267 
268  // run all preceeding objects
269  std::set<ParameteredObject*>::iterator curObj = targetObjects.begin();
270  for (; curObj != targetObjects.end(); curObj++) {
271  if (*curObj) {
272  (*curObj)->run();
273  }
274  }
275 }
276 
277 void ParameteredObject::runPreceeding(const Slot& slot) const {
278  // collect preceeding objects
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());
284  }
285 
286  // run all preceeding objects
287  std::set<ParameteredObject*>::iterator curObj = targetObjects.begin();
288  for (; curObj != targetObjects.end(); curObj++) {
289  (*curObj)->run();
290  }
291 }
292 
294  if(!_initialized)
295  raise("This plugin must be initialized before execution!");
296  // empty default implementation
297  sout << "(WW) this plugin has not overridden execute() or does call "
298  << "ParameteredObject::execute() directly which is deprecated."
299  << std::endl;
300 }
301 
303  std::map<std::string, Slot*>::const_iterator cur;
304  for (cur = _inputs.begin(); cur != _inputs.end(); cur++) {
305  cur->second->prepare();
306  }
307  for (cur = _outputs.begin(); cur != _outputs.end(); cur++) {
308  cur->second->prepare();
309  }
310 }
311 
313  std::map<std::string, Slot*>::const_iterator cur;
314  for (cur = _inputs.begin(); cur != _inputs.end(); cur++) {
315  cur->second->finalize();
316  }
317  for (cur = _outputs.begin(); cur != _outputs.end(); cur++) {
318  cur->second->finalize();
319  }
320 }
321 
322 void ParameteredObject::resetExecuted(bool propagate) {
323  if (_executed) {
324  sout << "(II) resetting execution state of " << getClassName()
325  << " \"" << getName() << "\"" << std::endl;
326  }
327  setExecuted(false);
328  if (propagate) {
329  for (std::map<std::string, Slot*>::iterator it = _outputs.begin();
330  it != _outputs.end(); it++) {
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);
335  }
336  }
337 
338 }
339 
340 std::set<ParameteredObject*> ParameteredObject::_getTargetNodes() {
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;
345  for (outIter = _outputs.begin(); outIter != _outputs.end(); outIter++) {
346  const std::set<Slot*>& targets = outIter->second->getTargets();
347  for(tIter = targets.begin(); tIter != targets.end(); tIter++)
348  children.insert(&((*tIter)->getParent()));
349  }
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());
356  }
357  }
358  else
359  res.insert(this);
360  return res;
361 }
362 
363 std::set<std::string> ParameteredObject::getNeighbours() const {
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;
368 
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);
375  }
376  }
377  for (slotIter = _outputs.begin(); slotIter != _outputs.end(); slotIter++) {
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);
383  }
384  }
385  return res;
386 }
387 
388 std::set<std::string> ParameteredObject::getNeighbours(
389  const ParameterFile& pf) const {
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;
396 
397  // find names of the connected objects
398  for (slotIter = _inputs.begin(); slotIter != _inputs.end(); slotIter++)
399  slotNames.insert(slotIter->second->getName());
400  for (slotIter = _outputs.begin(); slotIter != _outputs.end(); slotIter++)
401  slotNames.insert(slotIter->second->getName());
402  for (slot = slotNames.begin(); slot != slotNames.end(); slot++) {
403  // skip unset parameters (not connected)
404  if (!pf.isSet(_instanceName + "." + *slot))
405  continue;
406  // add targets of the set ones
407  targetList = pf.getList<std::string> (_instanceName + "." + *slot);
408  for (target = targetList.begin(); target != targetList.end(); target++)
409  res.insert(target->substr(0, target->find(".")));
410  }
411 
412  // make sure that these objects exist and have the correct type
413  for (resItem = res.begin(); resItem != res.end(); resItem++) {
414  std::string type = pf.get<std::string> (*resItem + ".type");
415  //getInstance(type, *resItem);
416  }
417 
418  return res;
419 }
420 
422  // set _instanceName.type
423  if (pf.isSet(_instanceName + ".type")) {
424  assert(pf.get<std::string>(_instanceName + ".type")
425  == _className);
426  } else
427  pf.set<std::string> (_instanceName + ".type", _className);
428 
429  // save parameters
430  std::map<std::string, AbstractParameter*>::const_iterator par;
431  for (par = _parameters.begin(); par != _parameters.end(); par++)
432  par->second->save(pf);
433 }
434 
436  // save parameters
437  saveParameters(pf);
438 
439  // save slots
440  std::map<std::string, Slot*>::const_iterator slotIter;
441 
442  for (slotIter = _inputs.begin(); slotIter != _inputs.end(); slotIter++)
443  {
444  Slot* sl=slotIter->second;
445  if(sl->connected())
446  sl->save(pf);
447  }
448 
449  for (slotIter = _outputs.begin(); slotIter != _outputs.end(); slotIter++)
450  {
451  Slot* sl=slotIter->second;
452  if(sl->connected())
453  sl->save(pf);
454  }
455  onSave(pf);
456 }
457 
459  // check type
460  assert(pf.isSet(_instanceName + ".type"));
461 #ifndef NDEBUG
462  if(StringTool::toLowerCase(pf.get<std::string>(_instanceName + ".type"))
464  std::ostringstream msg;
465  msg << __FILE__ << ":" << __LINE__;
466  msg << "\n\tclassname and type do not match!";
467  msg << "\n\tclassname: " << _className;
468  msg << "\n\tinstance name: " << _instanceName;
469  msg << "\n\ttype: " << pf.get<std::string>(_instanceName + ".type");
470  throw std::runtime_error(msg.str().c_str());
471  }
472 #endif
473 
474  // load parameters
475  std::map<std::string, AbstractParameter*>::const_iterator par;
476  for (par = _parameters.begin(); par != _parameters.end(); par++)
477  par->second->load(pf);
478 }
479 
481  const PluginManagerInterface * man) {
482  // load slot connections
483  std::map<std::string, Slot*>::const_iterator slotIter;
484  for (slotIter = _inputs.begin(); slotIter != _inputs.end(); slotIter++)
485  slotIter->second->load(pf, man);
486  for (slotIter = _outputs.begin(); slotIter != _outputs.end(); slotIter++)
487  slotIter->second->load(pf, man);
488 
489 
490  onLoad(pf,man);
491 }
492 
494  std::map<std::string, Slot*>::const_iterator slotIter;
495  bool res = true;
496  for (slotIter = _inputs.begin(); slotIter != _inputs.end(); slotIter++) {
497  const Slot* cur = slotIter->second;
498  if (!cur->getOptional() && !cur->connected()) {
499  sout << "(WW) unconnected: " << cur->getParent().getName()
500  << "." << cur->getName() << std::endl;
501  res = false;
502  }
503  }
504  for (slotIter = _outputs.begin(); slotIter != _outputs.end(); slotIter++) {
505  const Slot* cur = slotIter->second;
506  if (!cur->getOptional() && !cur->connected()) {
507  sout << "(WW) unconnected: " << cur->getParent().getName()
508  << "." << cur->getName() << std::endl;
509  res = false;
510  }
511  }
512  return res;
513 }
514 
515 Slot* ParameteredObject::getSlot(const std::string& slotName) const {
516  std::map<std::string, Slot*>::const_iterator slot;
517  // try input slot
518  slot = _inputs.find(slotName);
519  if (slot != _inputs.end()) {
520  return slot->second;
521  }
522  // try output slot
523  slot = _outputs.find(slotName);
524  if (slot != _outputs.end()) {
525  return slot->second;
526  }
527 
528  // try to fix slot casing
529  // this is more expensive than simple map lookup,
530  // so this is done only if needed
531  std::string slotNameFixed = fixCase(slotName);
532  sout << "(WW) getSlot: wrong slot casing: " << _instanceName
533  << "." << slotName << " (fixed: " << slotNameFixed << ")"
534  << std::endl;
535 
536  // try again with fixed name
537  slot = _inputs.find(slotNameFixed);
538  if (slot != _inputs.end()) {
539  return slot->second;
540  }
541  slot = _outputs.find(slotNameFixed);
542  if (slot != _outputs.end()) {
543  return slot->second;
544  }
545 
546  // if everything else fails
547  throw std::invalid_argument(
548  std::string("Slot \"") + slotName + "\" in instance \""
549  + getName() + "\" of plugin \"" + getClassName()
550  + "\" not found!");
551 }
552 
553 const std::map<std::string, Slot*>&
555  return _inputs;
556 }
557 
558 const std::map<std::string, Slot*>&
560  return _outputs;
561 }
562 
563 const std::map<std::string, AbstractParameter*>&
565  return _parameters;
566 }
567 
569  _createMetadata = false;
570  _metadata.clear();
571 }
572 
573 void ParameteredObject::raise(const std::string& message) const
574 {
575  std::string msg = this->getClassName() ;
576  const std::string& templateType = this->getTemplateType() ;
577  if(templateType.length() > 0)
578  msg += "<" + templateType + ">" ;
579  msg += " \"" + this->getName() + "\" : " + message ;
580 
581  throw std::runtime_error(msg) ;
582 }
583 
584 
585 AbstractParameter & ParameteredObject::getParameter(
586  const std::string & name) const {
587  if (_parameters.find(name) != _parameters.end()) {
588  return *(_parameters.find(name)->second);
589  } else {
590  throw std::invalid_argument(
591  std::string("Parameter ") + name + " in instance \""
592  + getName() + "\" of plugin \"" + getClassName()
593  + "\" does not exist!");
594  }
595 }
596 
597 const std::string ParameteredObject::getTemplateType() const {
598  return "";
599 }
600 
602  initialize();
603 }
604 
606  if (_createMetadata) {
607  _metadata.set(_className + ".isDynamicModule", v);
608  }
609 }
610 
611 bool ParameteredObject::isDynamic() {
612  if (_createMetadata) {
613  return _metadata.get<bool>(_className + ".isDynamicModule", false);
614  }
615  else {
616  sout << "(WW) called isDynamic() without enabled metadata generation"
617  << std::endl;
618  return false;
619  }
620 }
621 
622 std::string ParameteredObject::fixCase(const std::string& name) const {
623  std::string nameL=name, curL;
624  std::transform(
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;
629  for(sIter=_inputs.begin();sIter!=_inputs.end();sIter++) {
630  names.insert(sIter->first);
631  }
632  for(sIter=_outputs.begin();sIter!=_outputs.end();sIter++) {
633  names.insert(sIter->first);
634  }
635  for(pIter=_parameters.begin();pIter!=_parameters.end();pIter++) {
636  names.insert(pIter->first);
637  }
638  std::set<std::string>::const_iterator nIter;
639  for(nIter=names.begin(); nIter!=names.end(); nIter++) {
640  curL=*nIter;
641  std::transform(
642  curL.begin(),curL.end(), curL.begin(),(int(*)(int)) tolower);
643  if (nameL==curL) {
644  return *nIter;
645  }
646  }
647  raise("Parameter/Slot " + name + " not found!");
648  return std::string();
649 }
650 
652 {
653  // remove metadata
654  if (_removeSomething("inputs", name)) {
655  // and remove it from the input slot list
656  if(_inputs.find(name)!=_inputs.end()) {
657  _inputs.erase(name);
658  }
659  if(_metadata.isSet(_className + "." + name+ ".multi")) {
660  _metadata.erase(_className + "." + name+ ".multi");
661  }
662  if(_metadata.isSet(_className + "." + name+ ".optional")) {
663  _metadata.erase(_className + "." + name+ ".optional");
664  }
665  }
666 }
667 
669  const std::string &extension, const std::string &name)
670 {
671  // Check that param is registered.
672  // Parameters can only be assigned once!
673  if( _parameters.find(name) == _parameters.end() ||
674  _inputs.find(name) == _inputs.end() ||
675  _outputs.find(name) == _outputs.end()) {
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"
682  << std::endl;
683  return false;
684  }
685 
686  if (_createMetadata) {
687  std::vector<std::string> someList;
688  // get all elements of the given section
689  if (_metadata.isSet(_className + "." + extension)) {
690  someList = _metadata.getList<std::string> (_className + "."
691  + extension);
692  }
693  std::vector<std::string>::iterator found = std::find(
694  someList.begin(), someList.end(), name);
695  if (found != someList.end()) {
696  if(_metadata.isSet(_className+"."+name + ".type")) {
697  _metadata.erase(_className+"."+name + ".type");
698  }
699  if(_metadata.isSet(_className+"."+name + ".doc")) {
700  _metadata.erase(_className+"."+name + ".doc");
701  }
702  if(_metadata.isSet(_className + "." + name)) {
703  _metadata.erase(_className + "." + name);
704  }
705  if(_metadata.isSet(_className+"."+extension)) {
706  _metadata.erase(_className+"."+extension);
707  }
708  someList.erase(found);
709  _metadata.set<std::string>(_className+"."+extension, someList);
710  }
711  }
712 
713  return true;
714 }
715 
716 void ParameteredObject::_removeOutputSlot(std::string name) {
717  // remove metadata
718  if (_removeSomething("outputs", name)) {
719  // and remove it from the output slot list
720  if(_outputs.find(name)!=_outputs.end()) {
721  _outputs.erase(name);
722  }
723  if(_metadata.isSet(_className + "." + name+ ".multi")) {
724  _metadata.erase(_className + "." + name+ ".multi");
725  }
726  if(_metadata.isSet(_className + "." + name+ ".optional")) {
727  _metadata.erase(_className + "." + name+ ".optional");
728  }
729  }
730 }
731 
733  if(this->_initialized)
734  raise("Plugin is already initialized!");
735  _initialized=true;
736 }
737 
739  if(!_initialized)
740  raise("Plugin was not initialied, or has been already finalized");
741  _initialized=false;
742 }
743 
745  const ParameterFile&, const PluginManagerInterface* man) {
746  if(man->initializePluginOnLoad()) {
747  initialize();
748  }
749 }
750 
752 }
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.
Definition: Parameter.cpp:32
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.
Definition: ParameterFile.h:68
void _prepareSlots()
prepare slot data
bool getOptional() const
return value of _optional;
Definition: Slots.cpp:81
void init(ParameteredObject *parent, std::string name, std::string type)
initialize parent and name
Definition: Slots.cpp:35
Parameter object handling.
Definition: Parameter.h:57
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.
Definition: Slots.cpp:85
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
Definition: Slots.cpp:65
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.
Definition: Slots.cpp:73
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.
Declaration of StringTool methods.
bool getMulti() const
return value of _multiSlot;
Definition: Slots.cpp:77
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 &param, 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.
Definition: Slots.h:47
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.
Definition: Slots.cpp:484
virtual void save(ParameterFile &pf) const
Save slot connections This function disconnects already established connections in the parameterFile ...
Definition: Slots.cpp:125
std::map< std::string, Slot * > _outputs
Output slots.
std::string charon_core_DLL_PUBLIC toLowerCase(std::string s)
Convert a string to lowercase.
Definition: StringTool.cpp:55
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.