EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
Config.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CORE_CONFIG_HPP_
2 #define ORG_EEROS_CORE_CONFIG_HPP_
3 
4 #include <utility>
5 #include <sstream>
6 #include <cstdlib>
7 #include <cmath>
8 #include <vector>
9 #include <map>
10 #include <functional>
11 #include <array>
12 #include <string.h>
13 
14 namespace eeros {
15  namespace config {
16 
18  std::function<int(const char *, char *, int)> set;
19  std::function<int(const char *, const char *, int)> get;
20  };
21 
23  {
24  bool operator()(const char *first, const char *second)
25  {
26  return strcmp(first, second) < 0;
27  }
28  };
29 
35  class Config {
36  public:
41  Config(const char *path = nullptr);
45  virtual ~Config();
46 
50  virtual void loadDefaults();
56  virtual bool save(const char *path = nullptr) = 0;
62  virtual bool load(const char *path = nullptr) = 0;
63 
64  protected:
65  virtual void add(const char *name, int &value);
66  virtual void add(const char *name, double &value);
67  virtual void add(const char *name, std::size_t length, int *start, int *end, int default_value = -1);
68  virtual void add(const char *name, std::size_t length, double *start, double *end, double default_value = NAN);
69  virtual void add(const char *name, std::string &value);
70 
71  template < typename T, std::size_t N >
72  void add(const char *name, std::array<T,N> &value);
73 
74  const char *path;
75  std::map<const char*, ConfigPropertyAccessor, CharPtrCompare> properties;
76  };
77 
78 
79  template < typename T, std::size_t N >
80  void Config::add(const char *name, std::array<T,N> &value) {
81  add(name, N, value.begin(), value.end());
82  }
83  }
84 }
85 
86 #endif // ORG_EEROS_CORE_CONFIG_HPP_
Definition: Config.hpp:17
Definition: Config.hpp:14
Configuration.
Definition: Config.hpp:35
Definition: Config.hpp:22
virtual void add(const char *name, int &value)
Definition: Config.cpp:16
const char * path
Definition: Config.hpp:74
std::map< const char *, ConfigPropertyAccessor, CharPtrCompare > properties
Definition: Config.hpp:75
bool operator()(const char *first, const char *second)
Definition: Config.hpp:24