charon-core  0.3.1
Parameter.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 */
44 #ifndef _Parameter_H
45 #define _Parameter_H
46 
47 #include "AbstractData.hxx"
48 #include "DllEx.h"
49 #include <string>
50 
51 class ParameteredObject;
52 class ParameterFile;
53 
58 private:
61 
62 protected:
64  std::string _name;
65 
68 
70 
78  std::string _followLink(
79  const ParameterFile& pf, const std::string paramName) const;
80 
81 public:
82  AbstractParameter();
83 
85 
91  void init(ParameteredObject* parent, const std::string& name);
92 
93  virtual ~AbstractParameter();
94 
96  ParameteredObject& getParent();
97 
99  const ParameteredObject& getParent() const;
100 
102  std::string getName() const;
103 
105 
106  virtual std::string guessType() const = 0;
107 
109 
116  virtual void save(ParameterFile& pf) const = 0;
117 
119 
123  virtual void load(const ParameterFile& pf) = 0;
124 
126 
130  virtual std::string getDefaultString() = 0;
131 
139  virtual void intoStream(std::ostream & os) const = 0;
140 };
141 
143 
147 std::ostream charon_core_DLL_PUBLIC & operator<< (
148  std::ostream& os, const AbstractParameter& param);
149 
152 template <typename T>
154  public AbstractParameter, public AbstractData<T> {
155 private:
158 
161 
162 public:
167  Parameter(T defaultValue = T());
168 
169  virtual ~Parameter();
170 
172 
176  virtual T& operator=(const T& B);
177 
179 
184  virtual Parameter<T>& operator=(const Parameter<T>& B);
185 
187  virtual operator T() const;
188 
191  void setDefault(const T& value);
192 
193  // overload inherited functions
194  virtual std::string guessType() const;
195  virtual const T& operator()() const;
196  virtual T& operator()();
197  virtual void save(ParameterFile& pf) const;
198  virtual void load(const ParameterFile& pf);
199  virtual std::string getDefaultString();
200 
207  virtual void intoStream(std::ostream & os) const;
208 };
209 
212 template <typename T>
214  public AbstractParameter, public AbstractMultiData<T> {
215 private:
217  std::vector<T> _value;
218 
220  std::string _defaultValue;
221 
222 public:
224 
229  ParameterList(std::string defaultValue = "");
230 
231  virtual ~ParameterList();
232 
234 
235  void setDefault(const std::string& value);
236 
238 
242  virtual std::vector<T>& operator=(const std::vector<T>& B);
243 
245 
249  virtual ParameterList<T>& operator=(const ParameterList<T>& B);
250 
252  operator std::vector<T>() const;
253 
255  std::vector<T>& operator()();
256 
258  const std::vector<T>& operator()() const;
259 
260  virtual std::string guessType() const;
261  virtual void save(ParameterFile& pf) const;
262  virtual void load(const ParameterFile& pf);
263  virtual std::string getDefaultString();
264 
265  // inherited by AbstractMultiData<T>
266  virtual std::size_t size() const;
267  virtual const T& operator[](std::size_t pos) const;
268  virtual T& operator[](std::size_t pos);
269 
276  virtual void intoStream(std::ostream & os) const;
277 };
278 
279 #endif // _Parameter_H
virtual std::string getDefaultString()=0
Get default value.
ParameteredObject * _parent
Parent ParameteredObject.
Definition: Parameter.h:67
virtual std::string guessType() const =0
Try to guess type.
This class serves to store parameters used within the Charon Project.
Definition: ParameterFile.h:68
#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
Common interface for read-write access to multiple data members like arrays etc.
Base class for serializable objects.
virtual std::size_t size() const =0
Access to number of members.
#define charon_core_LOCAL
Preprocessor macro to define this class/function as hidden, i.e.
Definition: DllEx.h:85
virtual void intoStream(std::ostream &os) const =0
Inserts the value of the Parameter at the end of a stream.
std::string _name
Parameter name.
Definition: Parameter.h:64
virtual T & operator=(const T &B)=0
data assignment operator
T _defaultValue
default value
Definition: Parameter.h:157
Interface for data assignment and readout.
Implementation of the AbstractParameter interface for one single parameter.
Definition: Parameter.h:153
virtual T & operator[](std::size_t pos)=0
Access to specific member (read-write).
virtual void save(ParameterFile &pf) const =0
Save to ParameterFile.
Implementation of the AbstractParameter interface for a list of parameters.
Definition: Parameter.h:213
#define charon_core_DLL_PUBLIC
Preprocessor macro to define this class/function as public visible, i.e.
Definition: DllEx.h:82
std::ostream charon_core_DLL_PUBLIC & operator<<(std::ostream &os, const AbstractParameter &param)
Parameter stream output operator.
Definition: Parameter.cpp:60
Dynamic library API import/export prprocessor macros.
std::vector< T > _value
Internal value (list).
Definition: Parameter.h:217
T _value
current value
Definition: Parameter.h:160
virtual T & operator()()=0
Call operator.
virtual void load(const ParameterFile &pf)=0
Load from ParameterFile.
std::string _defaultValue
Default value, string representation, separated by ";".
Definition: Parameter.h:220
Declaration and implementation of the abstract class AbstractData.