charon-core  0.3.1
ParameteredObject.h
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 */
39 #ifndef _ParameteredObject_H
40 #define _ParameteredObject_H
41 
42 #include <set>
43 #include "ParameterFile.h"
44 #include "Parameter.h"
45 #include "Slots.h"
46 #include "DllEx.h"
47 
49 
51 
70 private:
73 
75 
79 
81  std::string _className;
82 
84  std::string _instanceName;
85 
87  std::map<std::string, AbstractParameter*> _parameters;
88 
90  std::map<std::string, Slot*> _inputs;
91 
93  std::map<std::string, Slot*> _outputs;
94 
97 
99  bool _executed;
100 
102 
105 
108 
109 protected:
111  void _setDynamic(bool v);
112 
114  void _removeInputSlot(std::string name);
115 
117  void _removeOutputSlot(std::string name);
118 
120  bool _removeSomething(const std::string &extension, const std::string &name);
121 
123 
132  bool _addSomething(
133  const std::string& extension, const std::string& name,
134  const std::string& doc, const std::string& type,
135  const std::string& defaultValue = "");
136 
138 
152  void _addParameter(AbstractParameter& param, const std::string& name,
153  const std::string& doc, const std::string& type = "");
154 
156 
164  template<class T>
165  void _addParameter(
166  Parameter<T>& param, const std::string& name,
167  const std::string& doc, const T& defVal,
168  const std::string& type = "");
169 
171 
185  // \{
187 
192  void _addInputSlot(Slot& slot, const std::string& name,
193  const std::string& doc, const std::string& type = "");
194 
196 
201  void _addOutputSlot(Slot& slot, const std::string& name,
202  const std::string& doc, const std::string& type = "");
203  // \}
204 
206 
212  void _addInputSlot(Slot& slot, const std::string& name, const std::string& displayname,
213  const std::string& doc, const std::string& type);
214 
216 
222  void _addOutputSlot(Slot& slot, const std::string& name, const std::string& displayname,
223  const std::string& doc, const std::string& type);
224 
226 
230  void _setTags(const std::string& tags) ;
231 
233 
244  #define _addFunction(x)\
245  if (!this && &x) {\
246  throw 42;\
247  }
248 
250 
262  #define _addConstructor(x)\
263  if (!this && new x) {\
264  throw 42;\
265  }
266 
268 
276  ParameteredObject(const std::string& className,
277  const std::string& name = "", const std::string& doc = "");
278 
279 
281 
285  std::set<ParameteredObject*> _getTargetNodes();
286 
288 
292  virtual void execute();
293 
295 
299  virtual void finalize();
300 
302  void runPreceeding() const;
303 
306 
308  void runPreceeding(const Slot& slot) const;
309 
311  void _prepareSlots();
312 
314  void _commitSlots();
315 
316 public:
319  TYPE_DOUBLE = 0,
320  TYPE_FLOAT = 1,
321  TYPE_INT = 2
322  };
323 
325  enum build_type {
328  UNDEFINED_BUILD = 0,
329  DEBUG_BUILD = 1,
330  RELEASE_BUILD = 2
331  };
332 
334 
336  virtual ~ParameteredObject();
337 
339 
344  void save(ParameterFile& pf) const;
345 
347  const ParameterFile& getMetadata();
348 
350 
353  void clearMetadata();
354 
356  std::string fixCase(const std::string& parOrSlotName) const;
357 
359 
366  virtual void run();
367 
369 
373  virtual void initialize();
374 
376 
378  virtual void setExecuted(bool value) {
379  _executed = value;
380 
381  }
382 
384  bool executed() const {
385  return _executed;
386  }
387 
389 
392 
393 
395 #define PARAMETEREDOBJECT_AVOID_REEXECUTION \
396  sout << "(WW) using deprecated AVOID_REEXECUTION macro" << std::endl;
397 
399 
409  virtual void resetExecuted(bool propagate = true);
410 
412 
427  virtual void prepareDynamicInterface(const ParameterFile& file);
428 
430  //\{
431 
433  inline const std::string& getClassName() const {
434  return _className;
435  }
436 
438  inline const std::string& getName() const {
439  return _instanceName;
440  }
441 
443 
447  virtual const std::string getTemplateType() const;
448 
450 
454  Slot* getSlot(const std::string& slotName) const;
455 
456 
457 
459 
462  const std::map<std::string, Slot*>& getInputSlots() const;
463 
464 
466 
469  const std::map<std::string, Slot*>& getOutputSlots() const;
470 
472 
476  const std::map<std::string, AbstractParameter*>& getParameters() const;
477  //\}
478 
480 
488  virtual void saveParameters(ParameterFile& pf) const;
489 
491 
500  virtual void loadParameters(const ParameterFile& pf);
501 
503 
509  void loadSlots(
510  const ParameterFile& pf, const PluginManagerInterface* man);
511 
512 
514 
518  virtual void onLoad(const ParameterFile& pf,const PluginManagerInterface* man);
519 
521 
524  virtual void onSave(ParameterFile& pf) const;
525 
527  // \{
528 
530 
534  std::set<std::string> getNeighbours() const;
535 
537 
546  std::set<std::string> getNeighbours(const ParameterFile& pf) const;
547 
549 
553  virtual bool connected() const;
554 
556 
562  void raise(const std::string& message) const ;
563 
564  AbstractParameter& getParameter(const std::string & name) const;
565  template <typename T>
566  void setParameter(std::string name, T value);
567 
568  bool isDynamic();
569  // \}
570 };
571 
574 
576 
579 template <typename T>
581  public ParameteredObject {
582 public:
584 
590  TemplatedParameteredObject(const std::string& className,
591  const std::string& name = "", const std::string& doc = "");
592 
593  virtual const std::string getTemplateType() const;
594 
595  virtual ~TemplatedParameteredObject();
596 };
597 
598 
599 #endif // _ParameteredObject_H
virtual const std::string getTemplateType() const
get template type as string
#define charon_DEPRECATED
handle deprecated messages on GCC and MSVC
Definition: DllEx.h:87
Interface for a plugin manager.
This class serves to store parameters used within the Charon Project.
Definition: ParameterFile.h:68
build_type
defined build type
#define charon_core_PUBLIC
Preprocessor macro to define this class/function as public visible, i.e.
Definition: DllEx.h:81
Parameter object handling.
Definition: Parameter.h:57
template_type
Integer which represents a template type.
Base class for serializable objects.
ParameteredObject(const ParameteredObject &)
forbid copying
Declaration of class ParameterFile.
std::map< std::string, Slot * > _inputs
Input slots.
Base class for templated classes derived from ParameteredObject.
Declaration of the abstract class Slot and template classes InputSlot and OutputSlot.
Declaration of the abstract class AbstractParameter and template classes Parameter and ParameterList...
bool _initialized
status of initialization
Implementation of the AbstractParameter interface for one single parameter.
Definition: Parameter.h:153
#define charon_core_DLL_PUBLIC
Preprocessor macro to define this class/function as public visible, i.e.
Definition: DllEx.h:82
std::map< std::string, AbstractParameter * > _parameters
This vector stores all parameters that have to be saved/restored.
charon_DEPRECATED typedef ParameteredObject::template_type template_type
for transition to ParameteredObject::template_type
std::string _instanceName
Name of the instance.
Dynamic library API import/export prprocessor macros.
Parameter< bool > _active
ParameteredObject activation state.
const std::string & getClassName() const
class name
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
const std::string & getName() const
instance name
std::map< std::string, Slot * > _outputs
Output slots.
bool executed() const
get execution status
charon_plugins_DLL_PUBLIC int run(int(&method)())
Execute given function and catch exceptions.
virtual void setExecuted(bool value)
set property _executed
std::string _className
Class name.
ParameterFile _metadata
Class tracking.