X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fucioption.h;h=f0787132a7f68104d3804987ef638accd821788e;hp=d0d655cd9f8825023b5e148edfb684904efba42f;hb=9cb187762a68e431559ee9e4b1ed8c6f16826d89;hpb=b6b0878da807436cd99631ebecc982b31fca7cce diff --git a/src/ucioption.h b/src/ucioption.h index d0d655cd..f0787132 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -25,21 +25,34 @@ #include #include +struct OptionsMap; + +/// UCIOption class implements an option as defined by UCI protocol class UCIOption { public: - UCIOption() {} // To be used in a std::map - UCIOption(const char* defaultValue); - UCIOption(bool defaultValue, std::string type = "check"); - UCIOption(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 operator=(const std::string& v); + void operator=(bool v) { *this = std::string(v ? "true" : "false"); } + + operator int() const { + assert(type == "check" || type == "button" || type == "spin"); + return (type == "spin" ? atoi(currentValue.c_str()) : currentValue == "true"); + } - void set_value(const std::string& v); - template T value() const; + operator std::string() const { + assert(type == "string"); + return currentValue; + } private: - friend struct OptionsMap; + friend std::ostream& operator<<(std::ostream&, const OptionsMap&); std::string defaultValue, currentValue, type; - int minValue, maxValue; + int min, max; size_t idx; }; @@ -53,32 +66,9 @@ struct CaseInsensitiveLess { /// Our options container is actually a map with a customized c'tor struct OptionsMap : public std::map { OptionsMap(); - std::string print_all() const; }; +extern std::ostream& operator<<(std::ostream&, const OptionsMap&); extern OptionsMap Options; - -/// Option::value() definition and specializations -template -T UCIOption::value() const { - - assert(type == "spin"); - return T(atoi(currentValue.c_str())); -} - -template<> -inline std::string UCIOption::value() const { - - assert(type == "string"); - return currentValue; -} - -template<> -inline bool UCIOption::value() const { - - assert(type == "check" || type == "button"); - return currentValue == "true"; -} - #endif // !defined(UCIOPTION_H_INCLUDED)