X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fucioption.h;h=b8622e51d124baee07a75040ffe82d258476e4bc;hb=ae65ab25d55afd51ac50044b505a7d7d7ecd90c5;hp=a5da2e440b768e50f3fa11f50700e11983f3b2e0;hpb=786564068bb22c750c41649733d4aa6733accaec;p=stockfish diff --git a/src/ucioption.h b/src/ucioption.h index a5da2e44..b8622e51 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -25,61 +25,64 @@ #include #include -class Option { +struct OptionsMap; + +/// UCIOption class implements an option as defined by UCI protocol +class UCIOption { public: - Option() {} // To be used in a std::map - Option(const char* defaultValue); - Option(bool defaultValue, std::string type = "check"); - Option(int defaultValue, int minValue, int maxValue); + UCIOption() {} // Required by std::map::operator[] + UCIOption(const char* v); + UCIOption(bool v, std::string type = "check"); + UCIOption(int v, int min, int max); - void set_value(const std::string& v); template T value() const; + void operator=(const std::string& v); + void operator=(bool v) { *this = std::string(v ? "true" : "false"); } private: - friend class OptionsMap; + friend std::ostream& operator<<(std::ostream&, const OptionsMap&); std::string defaultValue, currentValue, type; - int minValue, maxValue; + int min, max; size_t idx; }; -/// Custom comparator because UCI options should not be case sensitive -struct CaseInsensitiveLess { - bool operator() (const std::string&, const std::string&) const; -}; - - -/// Our options container is actually a map with a customized c'tor -class OptionsMap : public std::map { -public: - OptionsMap(); - std::string print_all() const; -}; - -extern OptionsMap Options; - - -/// Option::value() definition and specializations +/// UCIOption::value() definition and specializations template -T Option::value() const { +T UCIOption::value() const { assert(type == "spin"); return T(atoi(currentValue.c_str())); } template<> -inline std::string Option::value() const { +inline std::string UCIOption::value() const { assert(type == "string"); return currentValue; } template<> -inline bool Option::value() const { +inline bool UCIOption::value() const { assert(type == "check" || type == "button"); return currentValue == "true"; } + +/// Custom comparator because UCI options should be case insensitive +struct CaseInsensitiveLess { + bool operator() (const std::string&, const std::string&) const; +}; + + +/// Our options container is actually a map with a customized c'tor +struct OptionsMap : public std::map { + OptionsMap(); +}; + +extern std::ostream& operator<<(std::ostream&, const OptionsMap&); +extern OptionsMap Options; + #endif // !defined(UCIOPTION_H_INCLUDED)