X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fucioption.h;h=b8622e51d124baee07a75040ffe82d258476e4bc;hb=750ac9ac5098f3423a753f56e86e7d5089771d21;hp=e68e438b4ad66dae49846415db5f9b12a51481b7;hpb=fb50e16cdda68e05d08ed3992a04e5a396a461e3;p=stockfish diff --git a/src/ucioption.h b/src/ucioption.h index e68e438b..b8622e51 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -17,25 +17,72 @@ along with this program. If not, see . */ - #if !defined(UCIOPTION_H_INCLUDED) #define UCIOPTION_H_INCLUDED -//// -//// Includes -//// - +#include +#include +#include #include -//// -//// Prototypes -//// +struct OptionsMap; + +/// UCIOption class implements an option as defined by UCI protocol +class UCIOption { +public: + UCIOption() {} // Required by std::map::operator[] + UCIOption(const char* v); + UCIOption(bool v, std::string type = "check"); + UCIOption(int v, int min, int max); + + template T value() const; + void operator=(const std::string& v); + void operator=(bool v) { *this = std::string(v ? "true" : "false"); } + +private: + friend std::ostream& operator<<(std::ostream&, const OptionsMap&); + + std::string defaultValue, currentValue, type; + int min, max; + size_t idx; +}; + + +/// UCIOption::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"; +} + + +/// 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 void init_uci_options(); -extern void print_uci_options(); -extern bool get_option_value_bool(const std::string& optionName); -extern int get_option_value_int(const std::string& optionName); -extern std::string get_option_value_string(const std::string& optionName); -extern void set_option_value(const std::string& optionName,const std::string& newValue); +extern std::ostream& operator<<(std::ostream&, const OptionsMap&); +extern OptionsMap Options; #endif // !defined(UCIOPTION_H_INCLUDED)