X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fucioption.h;h=df8797fe1b0b3766ebbdd7c9e5c4b6994247c50e;hp=b9c16cd913dab970780fc38f04966f209c388103;hb=55df3fa2d7631ed67e46f9433aa7f3a71c18e5e7;hpb=04108d45414c70c796d9378b247207b574e22414 diff --git a/src/ucioption.h b/src/ucioption.h index b9c16cd9..df8797fe 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,61 +20,50 @@ #if !defined(UCIOPTION_H_INCLUDED) #define UCIOPTION_H_INCLUDED -#include -#include #include #include -class Option { -public: - Option() {} // To allow insertion in a std::map - Option(const char* defaultValue); - Option(bool defaultValue, std::string type = "check"); - Option(int defaultValue, int minValue, int maxValue); +namespace UCI { - void set_value(const std::string& v); - template T value() const; +class Option; -private: - friend void init_uci_options(); - friend std::string options_to_uci(); - - std::string defaultValue, currentValue, type; - size_t idx; - int minValue, maxValue; +/// Custom comparator because UCI options should be case insensitive +struct CaseInsensitiveLess { + bool operator() (const std::string&, const std::string&) const; }; -template -inline T Option::value() const { - - assert(type == "spin"); - return T(atoi(currentValue.c_str())); -} +/// Our options container is actually a std::map +typedef std::map OptionsMap; -template<> -inline std::string Option::value() const { +/// Option class implements an option as defined by UCI protocol +class Option { - assert(type == "string"); - return currentValue; -} + typedef void (Fn)(const Option&); -template<> -inline bool Option::value() const { +public: + Option(Fn* = NULL); + Option(bool v, Fn* = NULL); + Option(const char* v, Fn* = NULL); + Option(int v, int min, int max, Fn* = NULL); - assert(type == "check" || type == "button"); - return currentValue == "true"; -} + Option& operator=(const std::string& v); + operator int() const; + operator std::string() const; +private: + friend std::ostream& operator<<(std::ostream&, const OptionsMap&); -// Custom comparator because UCI options should not be case sensitive -struct CaseInsensitiveLess { - bool operator() (const std::string&, const std::string&) const; + std::string defaultValue, currentValue, type; + int min, max; + size_t idx; + Fn* on_change; }; -typedef std::map OptionsMap; +void init(OptionsMap&); +void loop(const std::string&); + +} // namespace UCI -extern OptionsMap Options; -extern void init_uci_options(); -extern std::string options_to_uci(); +extern UCI::OptionsMap Options; #endif // !defined(UCIOPTION_H_INCLUDED)