X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fucioption.h;h=f0787132a7f68104d3804987ef638accd821788e;hp=e68e438b4ad66dae49846415db5f9b12a51481b7;hb=ad43ce143664953087b44dd3b4324f77c212bd46;hpb=fb50e16cdda68e05d08ed3992a04e5a396a461e3 diff --git a/src/ucioption.h b/src/ucioption.h index e68e438b..f0787132 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -17,25 +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; +}; + + +/// 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)