ASL 0.1.7
Advanced Simulation Library
aslParametersManager.h
Go to the documentation of this file.
1/*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24#ifndef ASLPARAMETERSMANAGER_H
25#define ASLPARAMETERSMANAGER_H
26
27#include "aslUValue.h"
28#include <boost/program_options.hpp>
29#include <map>
30#include <typeinfo>
31
32namespace asl
33{
34
35 class PrefixStore;
36
44 template <typename T> class Parameter
45 {
46 public:
61 Parameter(const char* key_,
62 const char* description_,
63 const char* units_ = "");
77 Parameter(T defaultValue,
78 const char* key_,
79 const char* description_,
80 const char* units_ = "");
81 inline const T & v() const;
82 inline T & v();
83 inline std::shared_ptr<T> p();
84
85 private:
86 UValue<T> parameter;
87 const std::string key;
88 const std::string description;
89 const std::string units;
90 };
91
92
98 {
99 public:
103 void enable();
105 template <typename T> void add(UValue<T> parameter,
106 const char* key,
107 const char* description,
108 const char* units);
110 template <typename T> void add(UValue<std::map<std::string, T>> parameter,
111 const char* key,
112 const char* description,
113 const char* units);
115 template <typename T> void add(UValue<T> parameter,
116 T defaultValue,
117 const char* key,
118 const char* description,
119 const char* units);
122 template <typename T>
123 void addPrefix(const std::string prefix,
124 std::shared_ptr<std::map<std::string, T>> destinationMap);
127 void load(std::string paramFile);
132 std::string getDir();
133
135
136 protected:
137 boost::program_options::options_description parametersOptions;
141 std::vector<std::shared_ptr<PrefixStore>> prefixes;
142
143 void populateMaps(boost::program_options::variables_map & vm);
146 void writeParametersFile(const std::string fileName);
148 std::string parametersFileStr;
149 };
150
151
159 {
160 public:
161 ApplicationParametersManager(const char* applicationName_,
162 const char* applicationVersion_);
163
166 void load(int argc, char* argv[]);
167
168 private:
169 UValue<std::string> platform;
170 UValue<std::string> device;
171 std::string applicationName;
172 std::string applicationVersion;
173 };
174
175
176//-------------------------- Implementation --------------------------
177
178
179 template <typename T> const T & Parameter<T>::v() const
180 {
181 return parameter.v();
182 }
183
184
185 template <typename T> T & Parameter<T>::v()
186 {
187 return parameter.v();
188 }
189
190 template <typename T> std::shared_ptr<T> Parameter<T>::p()
191 {
192 return parameter.p;
193 }
194
195} //namespace asl
196#endif // ASLPARAMETERSMANAGER_H
ApplicationParametersManager(const char *applicationName_, const char *applicationVersion_)
void load(int argc, char *argv[])
const T & v() const
std::shared_ptr< T > p()
Parameter(const char *key_, const char *description_, const char *units_="")
Parameter(T defaultValue, const char *key_, const char *description_, const char *units_="")
void populateMaps(boost::program_options::variables_map &vm)
void load(std::string paramFile)
std::string getDir()
void add(UValue< T > parameter, T defaultValue, const char *key, const char *description, const char *units)
Adds a Parameter with a default value to ParametersManager.
std::string parametersFileStr
Content of the parameters file.
boost::program_options::options_description parametersOptions
void add(UValue< std::map< std::string, T > > parameter, const char *key, const char *description, const char *units)
Adds a group of parameters with common prefix to ParametersManager.
void add(UValue< T > parameter, const char *key, const char *description, const char *units)
Adds a Parameter to ParametersManager.
static ParametersManager * current
void addPrefix(const std::string prefix, std::shared_ptr< std::map< std::string, T > > destinationMap)
std::vector< std::shared_ptr< PrefixStore > > prefixes
void writeParametersFile(const std::string fileName)
void enable()
Enables parameter loader.
Updatable value. This class stores value and its TimeStamp.
Definition: aslUValue.h:35
Advanced Simulation Library.
Definition: aslDataInc.h:31