Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
official-stockfish
GitHub Repository: official-stockfish/Stockfish
Path: blob/master/src/ucioption.h
376 views
1
/*
2
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3
Copyright (C) 2004-2025 The Stockfish developers (see AUTHORS file)
4
5
Stockfish is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
Stockfish is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef UCIOPTION_H_INCLUDED
20
#define UCIOPTION_H_INCLUDED
21
22
#include <cstddef>
23
#include <functional>
24
#include <iosfwd>
25
#include <map>
26
#include <optional>
27
#include <string>
28
29
namespace Stockfish {
30
// Define a custom comparator, because the UCI options should be case-insensitive
31
struct CaseInsensitiveLess {
32
bool operator()(const std::string&, const std::string&) const;
33
};
34
35
class OptionsMap;
36
37
// The Option class implements each option as specified by the UCI protocol
38
class Option {
39
public:
40
using OnChange = std::function<std::optional<std::string>(const Option&)>;
41
42
Option(const OptionsMap*);
43
Option(OnChange = nullptr);
44
Option(bool v, OnChange = nullptr);
45
Option(const char* v, OnChange = nullptr);
46
Option(int v, int minv, int maxv, OnChange = nullptr);
47
Option(const char* v, const char* cur, OnChange = nullptr);
48
49
Option& operator=(const std::string&);
50
operator int() const;
51
operator std::string() const;
52
bool operator==(const char*) const;
53
bool operator!=(const char*) const;
54
55
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
56
57
int operator<<(const Option&) = delete;
58
59
private:
60
friend class OptionsMap;
61
friend class Engine;
62
friend class Tune;
63
64
65
std::string defaultValue, currentValue, type;
66
int min, max;
67
size_t idx;
68
OnChange on_change;
69
const OptionsMap* parent = nullptr;
70
};
71
72
class OptionsMap {
73
public:
74
using InfoListener = std::function<void(std::optional<std::string>)>;
75
76
OptionsMap() = default;
77
OptionsMap(const OptionsMap&) = delete;
78
OptionsMap(OptionsMap&&) = delete;
79
OptionsMap& operator=(const OptionsMap&) = delete;
80
OptionsMap& operator=(OptionsMap&&) = delete;
81
82
void add_info_listener(InfoListener&&);
83
84
void setoption(std::istringstream&);
85
86
const Option& operator[](const std::string&) const;
87
88
void add(const std::string&, const Option& option);
89
90
std::size_t count(const std::string&) const;
91
92
private:
93
friend class Engine;
94
friend class Option;
95
96
friend std::ostream& operator<<(std::ostream&, const OptionsMap&);
97
98
// The options container is defined as a std::map
99
using OptionsStore = std::map<std::string, Option, CaseInsensitiveLess>;
100
101
OptionsStore options_map;
102
InfoListener info;
103
};
104
105
}
106
#endif // #ifndef UCIOPTION_H_INCLUDED
107
108