charon-core  0.3.1
DataManagerParameterFile.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  */
22 #ifndef DATAMANAGERPARAMETERFILE_HXX
23 #define DATAMANAGERPARAMETERFILE_HXX
24 
25 #include "Slots.hxx"
26 #include "FileTool.h"
27 
28 namespace DataManagers {
30 
61  template <typename T>
63  public Slot::DataManager<T> {
64  private:
68  const std::string _filename;
70  std::string _paramName;
71  public:
73 
77  const Slot& slot, const std::string& config = "");
78  virtual void setData(const T& data);
79  virtual T getData();
80  virtual std::string getConfig() const;
81  };
82 }
83 
84 template<typename T>
86  const Slot& slot, const std::string& config) :
87  _filename("lastRunParameterCache.wrp")
88 {
91  }
92  if (config.size()) {
93  _paramName = config;
94  }
95  else {
96  _paramName = slot.getParent().getName() + "." + slot.getName();
97  }
98 }
99 
100 template<typename T>
102  _pf.load (_filename);
103  _pf.set<T>(_paramName, data);
104  _pf.save (_filename);
105  _pf.clear ();
106 }
107 
108 template<typename T>
110  _pf.load(_filename);
111  T val = _pf.get<T>(_paramName);
112  _pf.clear();
113  return val;
114 }
115 
116 template<typename T>
118  return _paramName;
119 }
120 
122 // \{
123 template<>
125  const Slot& slot, const std::string& config) {
126  return new DataManagers::DataManagerParameterFile<int>(slot, config);
127 }
128 
129 template<>
131  const Slot& slot, const std::string& config) {
132  return new DataManagers::DataManagerParameterFile<float>(slot, config);
133 }
134 
135 template<>
137  const Slot& slot, const std::string& config) {
138  return new DataManagers::DataManagerParameterFile<double>(slot, config);
139 }
140 
141 template<>
143  const Slot& slot, const std::string& config) {
145 }
146 // \}
147 
148 #endif // DATAMANAGERPARAMETERFILE_HXX
static DataManager< T > * getManager(const Slot &slot, const std::string &config="")
get data manager from configuration string
Definition: Slots.hxx:467
std::string _paramName
parameter name in the file
This class serves to store parameters used within the Charon Project.
Definition: ParameterFile.h:68
DataManagerParameterFile(const Slot &slot, const std::string &config="")
create manager
interface of data management classes
Definition: Slots.h:216
Declaration of FileTool methods.
#define charon_core_LOCAL
Preprocessor macro to define this class/function as hidden, i.e.
Definition: DllEx.h:85
bool charon_core_DLL_PUBLIC exists(const std::string &file)
Check if file exists.
Definition: FileTool.cpp:154
ParameteredObject & getParent()
get parent object
Definition: Slots.cpp:65
virtual std::string getConfig() const
get configuration string
virtual std::string getName() const
Get slot name.
Definition: Slots.cpp:73
virtual void setData(const T &data)
write data
const std::string _filename
paraneter file name
parameter file based implementation of a data manager
Implementation of the abstract class Slot and template classes InputSlot and OutputSlot.
Commom properties of slot objects.
Definition: Slots.h:47
bool save(std::string fileName) const
Save parameters and values to a plain text file.
const std::string & getName() const
instance name
ParameterFile _pf
parameter file to store parameter