#include <algorithm>
#include <cassert>
-#include <cstdlib>
#include <sstream>
#include "misc.h"
/// Our case insensitive less() function as required by UCI protocol
-bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
-
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
- return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
+
+ return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
+ [](char c1, char c2) { return tolower(c1) < tolower(c2); });
}
std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
for (size_t idx = 0; idx < om.size(); ++idx)
- for (OptionsMap::const_iterator it = om.begin(); it != om.end(); ++it)
- if (it->second.idx == idx)
+ for (const auto& it : om)
+ if (it.second.idx == idx)
{
- const Option& o = it->second;
- os << "\noption name " << it->first << " type " << o.type;
+ const Option& o = it.second;
+ os << "\noption name " << it.first << " type " << o.type;
if (o.type != "button")
os << " default " << o.defaultValue;
break;
}
+
return os;
}
{}
Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
-{ std::ostringstream ss; ss << v; defaultValue = currentValue = ss.str(); }
-
+{ defaultValue = currentValue = std::to_string(v); }
Option::operator int() const {
assert(type == "check" || type == "spin");
- return (type == "spin" ? atoi(currentValue.c_str()) : currentValue == "true");
+ return (type == "spin" ? stoi(currentValue) : currentValue == "true");
}
Option::operator std::string() const {
if ( (type != "button" && v.empty())
|| (type == "check" && v != "true" && v != "false")
- || (type == "spin" && (atoi(v.c_str()) < min || atoi(v.c_str()) > max)))
+ || (type == "spin" && (stoi(v) < min || stoi(v) > max)))
return *this;
if (type != "button")