charon-core  0.3.1
ParameteredObject.hxx
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  */
28 #ifndef _PARAMETERED_OBJECT_HXX_
29 #define _PARAMETERED_OBJECT_HXX_
30 
31 #define CHARON_SUPERNODES
32 
33 #include "ParameteredObject.h"
34 #include "ParameterFile.hxx"
35 #include "Parameter.hxx"
36 #include "Slots.hxx"
37 
38 template<class T>
40  const std::string& name, const std::string& doc, const T& defVal,
41  const std::string& type) {
42  param.setDefault(defVal);
43  param() = defVal;
44  ParameteredObject::_addParameter(param, name, doc, type.c_str());
45 }
46 
47 template <typename T>
48 void ParameteredObject::setParameter(std::string name, T value) {
49  if(_parameters.find(name) != _parameters.end()) {
50  Parameter<T>& p = dynamic_cast<Parameter<T>&>(*_parameters[name]);
51  //p.operator T() = value;
52  p=value;
53  }
54  else
55  throw std::invalid_argument("parameter not found");
56 }
57 
58 template<typename T>
60  const std::string& className, const std::string& name,
61  const std::string& doc) :
62  ParameteredObject(className, name, doc) {
64  "parameters", "templatetype", "template type",
65  "{int;float;double}", "double");
66 }
67 
68 template<typename T>
70 {
71 
72 }
73 
74 template<typename T>
76  return TypeDetector::type(typeid(T).name());
77 }
78 
79 #endif // _PARAMETERED_OBJECT_HXX_
Base class for serializable objects.
Base class for templated classes derived from ParameteredObject.
Declaration of the base class ParameteredObject.
Implementation of the AbstractParameter interface for one single parameter.
Definition: Parameter.h:153
void setDefault(const T &value)
Set default value.
Definition: Parameter.hxx:61
virtual const std::string getTemplateType() const
get template type as string
std::map< std::string, AbstractParameter * > _parameters
This vector stores all parameters that have to be saved/restored.
Implementation of the template class ParameterFile.
Implementation of the abstract class Slot and template classes InputSlot and OutputSlot.
void _addParameter(AbstractParameter &param, const std::string &name, const std::string &doc, const std::string &type="")
Add parameters.
Implementation of the abstract class AbstractParameter and template classes Parameter and ParameterLi...
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.
charon_core_DLL_PUBLIC std::string type(const std::string &typeInfo)
Get type representation.
TemplatedParameteredObject(const std::string &className, const std::string &name="", const std::string &doc="")
Default constructor.