ztsdb
config.hpp
1 // (C) 2016 Leonardo Silvestri
2 //
3 // This file is part of ztsdb.
4 //
5 // ztsdb is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // ztsdb is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
17 
18 
19 #ifndef CONFIG_HPP
20 #define CONFIG_HPP
21 
22 
23 #include <map>
24 #include "juice/variant.hpp"
25 
26 
27 namespace cfg {
28 
29  typedef Juice::Variant<int64_t,
30  double,
31  std::string> CfgVariant;
32 
33  enum ct_type { INT, DOUBLE, STRING };
34 
35  struct CfgMap {
36  CfgMap();
37 
38  int insert(const std::string& s, CfgVariant value);
39  void set(const std::string& s, CfgVariant value);
40  CfgVariant get(const std::string& s) const;
41 
42  typedef std::map<std::string, CfgVariant> configmap_t;
43  typedef std::pair<std::string, CfgVariant> kv_t;
44 
45  configmap_t::iterator begin() { return m.begin(); }
46  configmap_t::iterator end() { return m.end(); }
47 
48  CfgVariant operator[](const std::string& s);
49 
50  private:
51  configmap_t m;
52  };
53 
54  typedef std::map<std::string, CfgVariant> configmap_t;
55  typedef std::pair<std::string, CfgVariant> kv_t;
56 
57  extern CfgMap cfgmap;
58 
59 }
60 
61 #endif
cfg::CfgMap
Definition: config.hpp:35