]> git.sesse.net Git - stockfish/blobdiff - src/ucioption.h
Remove the now redundant TT prefetch call from Position::do_move.
[stockfish] / src / ucioption.h
index b8622e51d124baee07a75040ffe82d258476e4bc..87411a44929e93ede02be81d186cf81822566e95 100644 (file)
@@ -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-2014 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
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#if !defined(UCIOPTION_H_INCLUDED)
+#ifndef UCIOPTION_H_INCLUDED
 #define UCIOPTION_H_INCLUDED
 
-#include <cassert>
-#include <cstdlib>
 #include <map>
 #include <string>
 
-struct OptionsMap;
+namespace UCI {
 
-/// 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<typename T> 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&);
+class Option;
 
-  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 std::map
+typedef std::map<std::string, Option, CaseInsensitiveLess> OptionsMap;
 
-/// UCIOption::value() definition and specializations
-template<typename T>
-T UCIOption::value() const {
-
-  assert(type == "spin");
-  return T(atoi(currentValue.c_str()));
-}
+/// Option class implements an option as defined by UCI protocol
+class Option {
 
-template<>
-inline std::string UCIOption::value<std::string>() const {
+  typedef void (*OnChange)(const Option&);
 
-  assert(type == "string");
-  return currentValue;
-}
-
-template<>
-inline bool UCIOption::value<bool>() const {
+public:
+  Option(OnChange = NULL);
+  Option(bool v, OnChange = NULL);
+  Option(const char* v, OnChange = NULL);
+  Option(int v, int min, int max, OnChange = NULL);
 
-  assert(type == "check" || type == "button");
-  return currentValue == "true";
-}
+  Option& operator=(const std::string& v);
+  void operator<<(const Option& o);
+  operator int() const;
+  operator std::string() const;
 
+private:
+  friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
 
-/// Custom comparator because UCI options should be case insensitive
-struct CaseInsensitiveLess {
-  bool operator() (const std::string&, const std::string&) const;
+  std::string defaultValue, currentValue, type;
+  int min, max;
+  size_t idx;
+  OnChange on_change;
 };
 
+void init(OptionsMap&);
+void loop(int argc, char* argv[]);
 
-/// Our options container is actually a map with a customized c'tor
-struct OptionsMap : public std::map<std::string, UCIOption, CaseInsensitiveLess> {
-  OptionsMap();
-};
+} // namespace UCI
 
-extern std::ostream& operator<<(std::ostream&, const OptionsMap&);
-extern OptionsMap Options;
+extern UCI::OptionsMap Options;
 
-#endif // !defined(UCIOPTION_H_INCLUDED)
+#endif // #ifndef UCIOPTION_H_INCLUDED