SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Properties.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #ifndef swcdb_core_config_Properties_h
8 #define swcdb_core_config_Properties_h
9 
10 
11 #include "swcdb/core/Exception.h"
12 #include "swcdb/core/MutexSptd.h"
15 
16 
17 namespace SWC { namespace Config {
18 
19 class Properties {
20 
21  typedef std::map<std::string, Property::Value::Ptr> Map;
22  typedef std::map<std::string, std::string> AliasMap;
23 
24  public:
25 
27 
29  Properties() noexcept : mutex(), m_map(), m_alias_map() { }
30 
31  Properties(Properties&&) = delete;
32  Properties(const Properties&) = delete;
34  Properties& operator=(const Properties&) = delete;
35 
37  ~Properties() noexcept {
38  reset();
39  }
40 
41  void reset() noexcept;
42 
43  void load_from(const Config::Parser::Options& opts,
44  bool only_guarded=false);
45 
46  void load(const std::string& fname,
47  const Config::ParserConfig& filedesc,
48  const Config::ParserConfig& cmddesc,
49  bool allow_unregistered=false, bool only_guarded=false);
50 
51  void reload(const std::string& fname,
52  const Config::ParserConfig& filedesc,
53  const Config::ParserConfig& cmddesc);
54 
55  void alias(const char* primary, const char* secondary);
56 
57  void set(const char* name, Property::Value::Ptr p);
58 
59  bool SWC_PURE_FUNC has(const char* name) const noexcept;
60 
61  bool defaulted(const char* name) const;
62 
63  std::string to_string(const char* name) const;
64 
65  void get_names(Strings& names) const;
66 
67  void remove(const char* name);
68 
69  Property::Value::Ptr get_ptr(const char* name, bool null_ok=false) const;
70 
71  template <typename T>
72  SWC_SHOULD_NOT_INLINE
73  T* get(const char* name) const {
74  return Property::Value::get_pointer<T>(get_ptr(name));
75  }
76 
77  std::string get_str(const char* name) const {
78  return get<Property::Value_string>(name)->get();
79  }
80 
81  std::string get_str(const char* name, const std::string& v) const {
82  return has(name) ? get_str(name) : v;
83  }
84 
85  Strings get_strs(const char* name) const {
86  return get<Property::Value_strings>(name)->get();
87  }
88 
89  bool get_bool(const char* name) const {
90  return get<Property::Value_bool>(name)->get();
91  }
92 
93  bool get_bool(const char* name, bool v) const {
94  return has(name) ? get_bool(name) : v;
95  }
96 
97  bool get_gbool(const char* name) const {
98  return get<Property::Value_bool_g>(name)->get();
99  }
100 
101  int32_t get_enum(const char* name) const {
102  return get<Property::Value_enum>(name)->get();
103  }
104 
105  int32_t get_genum(const char* name) const {
106  return get<Property::Value_enum_g>(name)->get();
107  }
108 
109  uint8_t get_i8(const char* name) const {
110  return get<Property::Value_uint8>(name)->get();
111  }
112 
113  uint16_t get_i16(const char* name) const {
114  return get<Property::Value_uint16>(name)->get();
115  }
116 
117  uint16_t get_i16(const char* name, uint16_t v) const {
118  return has(name) ? get_i16(name) : v;
119  }
120 
121  int32_t get_i32(const char* name) const {
122  return get<Property::Value_int32>(name)->get();
123  }
124 
125  int32_t get_i32(const char* name, int32_t v) const {
126  return has(name) ? get_i32(name) : v;
127  }
128 
129  int64_t get_i64(const char* name) const {
130  return get<Property::Value_int64>(name)->get();
131  }
132 
133 
134  void print(std::ostream& out, bool include_default = false) const;
135 
136  private:
137 
140 };
141 
142 
143 
144 }}
145 
146 #ifdef SWC_IMPL_SOURCE
148 #endif
149 
150 #endif // swcdb_core_config_Properties_h
SWC::Config::Properties::reload
void reload(const std::string &fname, const Config::ParserConfig &filedesc, const Config::ParserConfig &cmddesc)
Definition: Properties.cc:50
SWC::Config::Parser
Definition: PropertiesParser.h:168
SWC::Config::Properties::mutex
Core::MutexSptd mutex
Definition: Properties.h:26
SWC::Config::Properties::get_strs
Strings get_strs(const char *name) const
Definition: Properties.h:85
SWC::Config::Properties::remove
void remove(const char *name)
Definition: Properties.cc:108
SWC::Config::Properties::get_i8
uint8_t get_i8(const char *name) const
Definition: Properties.h:109
SWC::Config::Properties::get_genum
int32_t get_genum(const char *name) const
Definition: Properties.h:105
SWC::Config::Properties::get_i64
int64_t get_i64(const char *name) const
Definition: Properties.h:129
SWC::Config::Properties::get_i32
int32_t get_i32(const char *name) const
Definition: Properties.h:121
SWC::Config::Properties::get_gbool
bool get_gbool(const char *name) const
Definition: Properties.h:97
SWC::Config::Properties::print
void print(std::ostream &out, bool include_default=false) const
Definition: Properties.cc:140
SWC::Config::Properties::get
SWC_SHOULD_NOT_INLINE T * get(const char *name) const
Definition: Properties.h:73
SWC::Config::Properties::defaulted
bool defaulted(const char *name) const
Definition: Properties.cc:94
SWC::Config::Properties::get_i16
uint16_t get_i16(const char *name) const
Definition: Properties.h:113
SWC::Config::Properties::get_names
void get_names(Strings &names) const
Definition: Properties.cc:102
Properties.cc
SWC::Config::Properties::operator=
Properties & operator=(const Properties &)=delete
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
Exception.h
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
Property.h
SWC::Config::Properties::set
void set(const char *name, Property::Value::Ptr p)
Definition: Properties.cc:70
SWC::Config::Properties::Properties
Properties(Properties &&)=delete
SWC_PURE_FUNC
#define SWC_PURE_FUNC
Definition: Compat.h:108
SWC::Config::Properties::has
bool SWC_PURE_FUNC has(const char *name) const noexcept
Definition: Properties.cc:82
SWC::Config::Properties::~Properties
SWC_CAN_INLINE ~Properties() noexcept
Definition: Properties.h:37
SWC::Config::Properties::Map
std::map< std::string, Property::Value::Ptr > Map
Definition: Properties.h:21
SWC::Config::Properties::load
void load(const std::string &fname, const Config::ParserConfig &filedesc, const Config::ParserConfig &cmddesc, bool allow_unregistered=false, bool only_guarded=false)
Definition: Properties.cc:32
SWC::Config::Properties::get_str
std::string get_str(const char *name, const std::string &v) const
Definition: Properties.h:81
SWC::Config::Properties::AliasMap
std::map< std::string, std::string > AliasMap
Definition: Properties.h:22
SWC::Config::ParserConfig
Definition: PropertiesParser.h:64
SWC::Config::Properties::get_i16
uint16_t get_i16(const char *name, uint16_t v) const
Definition: Properties.h:117
SWC::Config::Properties::m_alias_map
AliasMap m_alias_map
Definition: Properties.h:139
SWC::Config::Properties::operator=
Properties & operator=(Properties &&)=delete
SWC::Config::Properties::load_from
void load_from(const Config::Parser::Options &opts, bool only_guarded=false)
Definition: Properties.cc:20
SWC::Core::Vector< std::string >
MutexSptd.h
SWC::Config::T
const uint64_t T
Definition: Property.h:27
SWC::Config::Properties::get_str
std::string get_str(const char *name) const
Definition: Properties.h:77
SWC::Config::Properties::to_string
std::string to_string(const char *name) const
Definition: Properties.cc:98
SWC::Config::Properties::get_ptr
Property::Value::Ptr get_ptr(const char *name, bool null_ok=false) const
Definition: Properties.cc:119
SWC::Core::MutexSptd
Definition: MutexSptd.h:16
SWC::Config::Properties::get_i32
int32_t get_i32(const char *name, int32_t v) const
Definition: Properties.h:125
SWC::Config::Properties
Definition: Properties.h:19
SWC::Config::Properties::m_map
Map m_map
Definition: Properties.h:138
SWC::Config::Properties::get_bool
bool get_bool(const char *name, bool v) const
Definition: Properties.h:93
SWC::Config::Properties::get_enum
int32_t get_enum(const char *name) const
Definition: Properties.h:101
SWC::Config::Properties::Properties
Properties(const Properties &)=delete
SWC::Config::Properties::get_bool
bool get_bool(const char *name) const
Definition: Properties.h:89
SWC::Config::Properties::alias
void alias(const char *primary, const char *secondary)
Definition: Properties.cc:64
SWC::Config::Properties::reset
void reset() noexcept
Definition: Properties.cc:13
SWC::Config::Properties::Properties
SWC_CAN_INLINE Properties() noexcept
Definition: Properties.h:29
PropertiesParser.h