Simpact Cyan
Population based event driven simulation using mNRM
configsettings.h
Go to the documentation of this file.
1 #ifndef CONFIGSETTINGS_H
2 
3 #define CONFIGSETTINGS_H
4 
9 #include "configreader.h"
10 #include "util.h"
11 #include <stdint.h>
12 #include <limits>
13 
22 {
23 public:
25  ConfigSettings(const ConfigSettings &src) { m_keyValues = src.m_keyValues; }
26  ~ConfigSettings();
27 
28  ConfigSettings &operator=(const ConfigSettings &src) { m_keyValues = src.m_keyValues; return *this; }
29 
31  bool load(const std::string &fileName);
32 
34  void clear();
35 
37  void getKeys(std::vector<std::string> &keys) const;
38 
41  bool getKeyValue(const std::string &key, std::string &value, const std::vector<std::string> &allowedValues = std::vector<std::string>() );
42 
45  // std::numeric_limits<double>::min() is the smallest in absolute value, can't use that here!
46  bool getKeyValue(const std::string &key, double &value, double minValue = -std::numeric_limits<double>::infinity(),
47  double maxValue = std::numeric_limits<double>::infinity());
48 
51  // std::numeric_limits<double>::min() is the smallest in absolute value, can't use that here!
52  bool getKeyValue(const std::string &key, std::vector<double> &values,
53  double minValue = -std::numeric_limits<double>::infinity(),
54  double maxValue = std::numeric_limits<double>::infinity());
55 
58  bool getKeyValue(const std::string &key, int &value, int minValue = std::numeric_limits<int>::min(),
59  int maxValue = std::numeric_limits<int>::max());
60 
63  bool getKeyValue(const std::string &key, int64_t &value, int64_t minValue = std::numeric_limits<int64_t>::min(),
64  int64_t maxValue = std::numeric_limits<int64_t>::max());
65 
67  bool getKeyValue(const std::string &key, bool &value);
68 
69  bool getStringKeyValue(const std::string &key, std::string &value, bool &used) const;
70 
73  void getUnusedKeys(std::vector<std::string> &keys) const;
74 
76  void clearUsageFlags();
77 
79  void merge(const ConfigSettings &src);
80 private:
81  std::map<std::string, std::pair<std::string, bool> > m_keyValues;
82 };
83 
84 #endif // CONFIGSETTINGS_H
85 
void getUnusedKeys(std::vector< std::string > &keys) const
Stores a list of keys that have not been read by any of the getKeyValue functions into keys (allows y...
Definition: configsettings.cpp:118
Base class which allows an error message to be set.
Definition: errorbase.h:49
void clear()
Clears the loaded key/value pairs.
Definition: configsettings.cpp:50
Helper class to read configuration settings, more advanced than ConfigReader.
Definition: configsettings.h:21
void getKeys(std::vector< std::string > &keys) const
Returns a list of all the keys in the read config file.
Definition: configsettings.cpp:55
void clearUsageFlags()
Resets the markers that keep track of wether or not a key has been read.
Definition: configsettings.cpp:206
bool load(const std::string &fileName)
Loads the key/value pairs from the config file specified by fileName.
Definition: configsettings.cpp:19
void merge(const ConfigSettings &src)
Merges the specified config settings object into the current one.
Definition: configsettings.cpp:217
bool getKeyValue(const std::string &key, std::string &value, const std::vector< std::string > &allowedValues=std::vector< std::string >())
Stores the string value for key parameter key into argument value, checking if the value is one of th...