aslParametersManager.h
Go to the documentation of this file.
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ASLPARAMETERSMANAGER_H
#define ASLPARAMETERSMANAGER_H
#include "aslUValue.h"
#include <boost/program_options.hpp>
#include <map>
#include <typeinfo>
namespace asl
{
class PrefixStore;
template <typename T> class Parameter
{
public:
Parameter(const char* key_,
const char* description_,
const char* units_ = "");
Parameter(T defaultValue,
const char* key_,
const char* description_,
const char* units_ = "");
inline const T & v() const;
inline T & v();
inline std::shared_ptr<T> p();
private:
UValue<T> parameter;
const std::string key;
const std::string description;
const std::string units;
};
class ParametersManager
{
public:
ParametersManager();
~ParametersManager();
void enable();
template <typename T> void add(UValue<T> parameter,
const char* key,
const char* description,
const char* units);
template <typename T> void add(UValue<std::map<std::string, T>> parameter,
const char* key,
const char* description,
const char* units);
template <typename T> void add(UValue<T> parameter,
T defaultValue,
const char* key,
const char* description,
const char* units);
template <typename T>
void addPrefix(const std::string prefix,
std::shared_ptr<std::map<std::string, T>> destinationMap);
void load(std::string paramFile);
std::string getDir();
static ParametersManager * current;
protected:
boost::program_options::options_description parametersOptions;
std::string parametersFileDirectory;
std::vector<std::shared_ptr<PrefixStore>> prefixes;
void populateMaps(boost::program_options::variables_map & vm);
void writeParametersFile(const std::string fileName);
std::string parametersFileStr;
};
class ApplicationParametersManager: public ParametersManager
{
public:
ApplicationParametersManager(const char* applicationName_,
const char* applicationVersion_);
void load(int argc, char* argv[]);
private:
UValue<std::string> platform;
UValue<std::string> device;
std::string applicationName;
std::string applicationVersion;
};
//-------------------------- Implementation --------------------------
template <typename T> const T & Parameter<T>::v() const
{
return parameter.v();
}
template <typename T> T & Parameter<T>::v()
{
return parameter.v();
}
template <typename T> std::shared_ptr<T> Parameter<T>::p()
{
return parameter.p;
}
} //namespace asl
#endif // ASLPARAMETERSMANAGER_H
asl::ApplicationParametersManager
Definition: aslParametersManager.h:159
asl::ApplicationParametersManager::ApplicationParametersManager
ApplicationParametersManager(const char *applicationName_, const char *applicationVersion_)
asl::ApplicationParametersManager::load
void load(int argc, char *argv[])
asl::Parameter::v
const T & v() const
Definition: aslParametersManager.h:179
asl::Parameter::v
T & v()
asl::Parameter::p
std::shared_ptr< T > p()
Definition: aslParametersManager.h:190
asl::Parameter::p
std::shared_ptr< T > p()
asl::Parameter::v
const T & v() const
asl::Parameter::Parameter
Parameter(const char *key_, const char *description_, const char *units_="")
asl::Parameter::Parameter
Parameter(T defaultValue, const char *key_, const char *description_, const char *units_="")
asl::ParametersManager
Definition: aslParametersManager.h:98
asl::ParametersManager::populateMaps
void populateMaps(boost::program_options::variables_map &vm)
asl::ParametersManager::addPrefix
void addPrefix(const std::string prefix, std::shared_ptr< std::map< std::string, T >> destinationMap)
asl::ParametersManager::current
static ParametersManager * current
Definition: aslParametersManager.h:134
asl::ParametersManager::load
void load(std::string paramFile)
asl::ParametersManager::getDir
std::string getDir()
asl::ParametersManager::~ParametersManager
~ParametersManager()
asl::ParametersManager::ParametersManager
ParametersManager()
asl::ParametersManager::add
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.
asl::ParametersManager::parametersFileStr
std::string parametersFileStr
Content of the parameters file.
Definition: aslParametersManager.h:148
asl::ParametersManager::parametersOptions
boost::program_options::options_description parametersOptions
Definition: aslParametersManager.h:137
asl::ParametersManager::add
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.
asl::ParametersManager::prefixes
std::vector< std::shared_ptr< PrefixStore > > prefixes
Definition: aslParametersManager.h:141
asl::ParametersManager::add
void add(UValue< T > parameter, const char *key, const char *description, const char *units)
Adds a Parameter to ParametersManager.
asl::ParametersManager::parametersFileDirectory
std::string parametersFileDirectory
Definition: aslParametersManager.h:138
asl::ParametersManager::writeParametersFile
void writeParametersFile(const std::string fileName)
asl::ParametersManager::enable
void enable()
Enables parameter loader.
asl::UValue
Updatable value. This class stores value and its TimeStamp.
Definition: aslUValue.h:35
asl
Advanced Simulation Library.
Definition: aslDataInc.h:31
aslUValue.h