25 #ifndef __CLOCKUTILS_INIPARSER_INIPARSER_H__ 26 #define __CLOCKUTILS_INIPARSER_INIPARSER_H__ 72 typename std::enable_if<!std::is_enum<T>::value,
ClockError>::type
getValue(
const std::string & section,
const std::string & field, T & value)
const {
73 auto it = _data.find(section);
74 if (it == _data.end()) {
77 for (
const std::tuple<std::string, std::string, size_t, std::string> & t : it->second) {
78 if (std::get<SECTION>(t) == section && std::get<FIELD>(t) == field) {
79 std::stringstream ss(std::get<VALUE>(t));
80 if ((ss >> value).fail() || !ss.eof()) {
91 typename std::enable_if<std::is_enum<T>::value,
ClockError>::type
getValue(
const std::string & section,
const std::string & field, T & value)
const {
92 auto it = _data.find(section);
93 if (it == _data.end()) {
96 for (
const std::tuple<std::string, std::string, size_t, std::string> & t : it->second) {
97 if (std::get<SECTION>(t) == section && std::get<FIELD>(t) == field) {
98 std::stringstream ss(std::get<VALUE>(t));
100 if ((ss >> v).fail() || !ss.eof()) {
118 typename std::enable_if<!std::is_enum<T>::value,
void>::type
setValue(
const std::string & section,
const std::string & field,
const T & value) {
119 std::stringstream ss;
121 setValue(section, field, ss.str());
125 typename std::enable_if<std::is_enum<T>::value,
void>::type
setValue(
const std::string & section,
const std::string & field,
const T & value) {
126 std::stringstream ss;
128 setValue(section, field, ss.str());
131 void setValue(
const std::string & section,
const std::string & field,
const std::string & value) {
132 if (_data.find(section) == _data.end()) {
134 _allLines[section].push_back(
"[" + section +
"]");
135 _data[section].push_back(make_tuple(section, field, 1, value));
136 _allLines[section].push_back(
"");
139 for (std::tuple<std::string, std::string, size_t, std::string> & t : _data[section]) {
140 if (std::get<SECTION>(t) == section && std::get<FIELD>(t) == field) {
141 std::get<VALUE>(t) = value;
146 if (_allLines[section].back() ==
"" && std::get<INDEX>(_data[section].back()) != _allLines[section].size() - 1) {
147 _data[section].push_back(make_tuple(section, field, _allLines[section].size() - 1, value));
149 _data[section].push_back(make_tuple(section, field, _allLines[section].size(), value));
151 _allLines[section].push_back(
"");
157 std::vector<std::string> getAllSections()
const;
162 std::vector<std::string> getAllEntries(
const std::string & section)
const;
168 void removeEntry(
const std::string & section,
const std::string & entry);
182 std::map<std::string, std::vector<std::tuple<std::string, std::string, size_t, std::string>>> _data;
183 std::map<std::string, std::vector<std::string>> _allLines;
190 ClockError CLOCK_INIPARSER_API IniParser::getValue<std::string>(
const std::string & section,
const std::string & field, std::string & value)
const;
0x6 value couldn't be cast in expected type
std::enable_if<!std::is_enum< T >::value, ClockError >::type getValue(const std::string §ion, const std::string &field, T &value) const
fetches value from parsed ini file
std::enable_if< std::is_enum< T >::value, ClockError >::type getValue(const std::string §ion, const std::string &field, T &value) const
0x0 method call succeeded
void setValue(const std::string §ion, const std::string &field, const std::string &value)
#define CLOCK_INIPARSER_API
this class is used for parsing configuration files
std::enable_if< std::is_enum< T >::value, void >::type setValue(const std::string §ion, const std::string &field, const T &value)
std::enable_if<!std::is_enum< T >::value, void >::type setValue(const std::string §ion, const std::string &field, const T &value)
sets value for a variable