Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
add overload for bool value
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Aug 2, 2021
1 parent 18f4b31 commit fa36f80
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions include/popl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,15 @@ inline void Value<std::string>::parse(OptionName what_name, const char* value)
}


template <>
inline void Value<bool>::parse(OptionName /*what_name*/, const char* value)
{
bool val =
((value != nullptr) && ((strcmp(value, "1") == 0) || (strcmp(value, "true") == 0) || (strcmp(value, "True") == 0) || (strcmp(value, "TRUE") == 0)));
add_value(val);
}


template <class T>
inline void Value<T>::parse(OptionName what_name, const char* value)
{
Expand Down Expand Up @@ -810,11 +819,9 @@ inline Switch::Switch(const std::string& short_name, const std::string& long_nam
}


inline void Switch::parse(OptionName /*what_name*/, const char* value)
inline void Switch::parse(OptionName /*what_name*/, const char* /*value*/)
{
bool val = (value == nullptr || strlen(value) == 0 || strcmp(value, "1") == 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 ||
strcmp(value, "TRUE") == 0);
add_value(val);
add_value(true);
}


Expand Down Expand Up @@ -931,8 +938,8 @@ inline void OptionParser::parse(const std::string& ini_filename)
std::string line;

auto trim = [](std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); }));
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());
return s;
};

Expand All @@ -956,7 +963,7 @@ inline void OptionParser::parse(const std::string& ini_filename)
continue;
if (line.front() == '#')
continue;
std::cout << " line: " << line << "\n";

if ((line.front() == '[') && (line.back() == ']'))
{
section = trim_copy(line.substr(1, line.size() - 2));
Expand All @@ -967,7 +974,6 @@ inline void OptionParser::parse(const std::string& ini_filename)
continue;

std::string key = section.empty() ? key_value.first : section + "." + key_value.first;
std::cout << "key: " << key << ", value: " << key_value.second << ", section: " << section << "\n";
Option_ptr option = find_option(key);
if (option && (option->attribute() == Attribute::inactive))
option = nullptr;
Expand Down

0 comments on commit fa36f80

Please sign in to comment.