X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fucioption.h;h=f0787132a7f68104d3804987ef638accd821788e;hp=b5648af5f04b18c781992d8ff1119bcb4e63a333;hb=9cb187762a68e431559ee9e4b1ed8c6f16826d89;hpb=9fc602bae74b8e09bd45ace3b42a8ce84d56b23c diff --git a/src/ucioption.h b/src/ucioption.h index b5648af5..f0787132 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -17,28 +17,58 @@ 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); + + 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"); + } + + operator std::string() const { + assert(type == "string"); + return currentValue; + } + +private: + friend std::ostream& operator<<(std::ostream&, const OptionsMap&); + + std::string defaultValue, currentValue, type; + int min, max; + size_t idx; +}; + + +/// Custom comparator because UCI options should be case insensitive +struct CaseInsensitiveLess { + bool operator() (const std::string&, const std::string&) const; +}; + -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 bool button_was_pressed(const std::string& buttonName); -extern void set_option_value(const std::string& optionName,const std::string& newValue); -extern void push_button(const std::string& buttonName); +/// 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)