ASL  0.1.6
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 
32 namespace asl
33 {
34 
35  class PrefixStore;
36 
44  template <typename T> class Parameter
45  {
46  public:
59  Parameter(const char* key_,
60  const char* description_,
61  const char* units_ = "");
75  Parameter(T defaultValue,
76  const char* key_,
77  const char* description_,
78  const char* units_ = "");
79  inline const T & v() const;
80  inline T & v();
81  inline std::shared_ptr<T> p();
82 
83  private:
84  UValue<T> parameter;
85  const std::string key;
86  const std::string description;
87  const std::string units;
88  };
89 
90 
96  {
97  public:
101  void enable();
103  template <typename T> void add(UValue<T> parameter,
104  const char* key,
105  const char* description,
106  const char* units);
108  template <typename T> void add(UValue<std::map<std::string, T>> parameter,
109  const char* key,
110  const char* description,
111  const char* units);
113  template <typename T> void add(UValue<T> parameter,
114  T defaultValue,
115  const char* key,
116  const char* description,
117  const char* units);
120  template <typename T>
121  void addPrefix(const std::string prefix,
122  std::shared_ptr<std::map<std::string, T>> destinationMap);
125  void load(std::string paramFile);
130  std::string getDir();
131 
133 
134  protected:
135  boost::program_options::options_description parametersOptions;
139  std::vector<std::shared_ptr<PrefixStore>> prefixes;
140 
141  void populateMaps(boost::program_options::variables_map & vm);
144  void writeParametersFile(const std::string fileName);
146  std::string parametersFileStr;
147  };
148 
149 
157  {
158  public:
159  ApplicationParametersManager(const char* applicationName_,
160  const char* applicationVersion_);
161 
164  void load(int argc, char* argv[]);
165 
166  private:
167  UValue<std::string> platform;
168  UValue<std::string> device;
169  std::string applicationName;
170  std::string applicationVersion;
171  };
172 
173 
174 //-------------------------- Implementation --------------------------
175 
176 
177  template <typename T> const T & Parameter<T>::v() const
178  {
179  return parameter.v();
180  }
181 
182 
183  template <typename T> T & Parameter<T>::v()
184  {
185  return parameter.v();
186  }
187 
188  template <typename T> std::shared_ptr<T> Parameter<T>::p()
189  {
190  return parameter.p;
191  }
192 
193 } //namespace asl
194 #endif // ASLPARAMETERSMANAGER_H
ApplicationParametersManager(const char *applicationName_, const char *applicationVersion_)
void enable()
Enables parameter loader.
Advanced Simulation Library.
Definition: aslDataInc.h:30
static ParametersManager * current
void populateMaps(boost::program_options::variables_map &vm)
boost::program_options::options_description parametersOptions
std::string getDir()
std::shared_ptr< T > p()
const T & v() const
void addPrefix(const std::string prefix, std::shared_ptr< std::map< std::string, T >> destinationMap)
Updatable value. This class stores value and its TimeStamp.
Definition: aslBasicBC.h:41
std::vector< std::shared_ptr< PrefixStore > > prefixes
void writeParametersFile(const std::string fileName)
Parameter(const char *key_, const char *description_, const char *units_="")
void load(std::string paramFile)
std::string parametersFileStr
Content of the parameters file.
void load(int argc, char *argv[])
void add(UValue< T > parameter, const char *key, const char *description, const char *units)
Adds a Parameter to ParametersManager.