inicpp
C++ parser of INI files with schema validation.
types.h
1 #ifndef INICPP_TYPES_H
2 #define INICPP_TYPES_H
3 
4 #include <stdexcept>
5 #include <string>
6 #include <type_traits>
7 
8 
9 namespace inicpp
10 {
15  {
16  public:
19  {
20  }
22  internal_enum_type(const std::string &value) : data_(value)
23  {
24  }
26  internal_enum_type(const char *value) : data_(value)
27  {
28  }
31  {
32  this->operator=(other);
33  }
35  explicit internal_enum_type(bool)
36  {
37  throw std::runtime_error("");
38  }
40  explicit internal_enum_type(int64_t)
41  {
42  throw std::runtime_error("");
43  }
45  explicit internal_enum_type(uint64_t)
46  {
47  throw std::runtime_error("");
48  }
50  explicit internal_enum_type(double)
51  {
52  throw std::runtime_error("");
53  }
54 
57  {
58  data_ = other.data_;
59  return *this;
60  }
62  operator std::string() const
63  {
64  return data_;
65  }
71  operator double() const
72  {
73  throw std::runtime_error("Enum type cannot be converted to double");
74  }
76  bool operator==(const internal_enum_type &other)
77  {
78  return data_ == other.data_;
79  }
81  bool operator!=(const internal_enum_type &other)
82  {
83  return !(*this == other);
84  }
86  bool operator<(const internal_enum_type &other)
87  {
88  return data_ < other.data_;
89  }
90 
91  private:
93  std::string data_;
94  };
95 
96 
102  enum class option_type : char { boolean_e, signed_e, unsigned_e, float_e, enum_e, string_e, invalid_e };
103 
104  // modern C++11 way of typedef
105  using boolean_ini_t = bool;
106  using signed_ini_t = int64_t;
107  using unsigned_ini_t = uint64_t;
108  using float_ini_t = double;
110  using string_ini_t = std::string;
111 
116  enum class option_item : bool { single, list };
117 
122  enum class item_requirement : bool { mandatory, optional };
123 
129  enum class schema_mode : bool { strict, relaxed };
130 
137  template <typename ValueType> option_type get_option_enum_type()
138  {
139  if (std::is_same<ValueType, boolean_ini_t>::value) {
140  return option_type::boolean_e;
141  } else if (std::is_same<ValueType, signed_ini_t>::value) {
142  return option_type::signed_e;
143  } else if (std::is_same<ValueType, unsigned_ini_t>::value) {
144  return option_type::unsigned_e;
145  } else if (std::is_same<ValueType, float_ini_t>::value) {
146  return option_type::float_e;
147  } else if (std::is_same<ValueType, string_ini_t>::value) {
148  return option_type::string_e;
149  } else if (std::is_same<ValueType, enum_ini_t>::value) {
150  return option_type::enum_e;
151  } else {
152  return option_type::invalid_e;
153  }
154  }
155 }
156 
157 #endif // INICPP_TYPES_H
bool operator<(const internal_enum_type &other)
Definition: types.h:86
internal_enum_type(const char *value)
Definition: types.h:26
Definition: config.h:15
bool operator!=(const internal_enum_type &other)
Definition: types.h:81
internal_enum_type(uint64_t)
Definition: types.h:45
internal_enum_type(const internal_enum_type &other)
Definition: types.h:30
internal_enum_type & operator=(const internal_enum_type &other)
Definition: types.h:56
internal_enum_type(double)
Definition: types.h:50
internal_enum_type(int64_t)
Definition: types.h:40
internal_enum_type(const std::string &value)
Definition: types.h:22
bool operator==(const internal_enum_type &other)
Definition: types.h:76