More idiomatic signature for operator=()
Return a reference instead of void so to enable chained assignments like "p = q = Position(...);" Suggested by Rein Halbersma. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>sf_2.3.1_base
parent
7d2530873e
commit
775488340e
|
@ -89,7 +89,7 @@ CheckInfo::CheckInfo(const Position& pos) {
|
|||
/// object do not depend on any external data so we detach state pointer from
|
||||
/// the source one.
|
||||
|
||||
void Position::operator=(const Position& pos) {
|
||||
Position& Position::operator=(const Position& pos) {
|
||||
|
||||
memcpy(this, &pos, sizeof(Position));
|
||||
startState = *st;
|
||||
|
@ -97,6 +97,8 @@ void Position::operator=(const Position& pos) {
|
|||
nodes = 0;
|
||||
|
||||
assert(pos_is_ok());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public:
|
|||
Position(const Position& p) { *this = p; }
|
||||
Position(const Position& p, Thread* t) { *this = p; thisThread = t; }
|
||||
Position(const std::string& f, bool c960, Thread* t) { from_fen(f, c960, t); }
|
||||
void operator=(const Position&);
|
||||
Position& operator=(const Position&);
|
||||
|
||||
// Text input/output
|
||||
void from_fen(const std::string& fen, bool isChess960, Thread* th);
|
||||
|
|
|
@ -134,18 +134,20 @@ UCIOption::UCIOption(int v, int minv, int maxv, Fn* f) : type("spin"), min(minv)
|
|||
/// check for option's limits, but we could receive the new value directly from
|
||||
/// the user by console window, so let's check the bounds anyway.
|
||||
|
||||
void UCIOption::operator=(const string& v) {
|
||||
UCIOption& UCIOption::operator=(const string& v) {
|
||||
|
||||
assert(!type.empty());
|
||||
|
||||
if ( (type != "button" && v.empty())
|
||||
|| (type == "check" && v != "true" && v != "false")
|
||||
|| (type == "spin" && (atoi(v.c_str()) < min || atoi(v.c_str()) > max)))
|
||||
return;
|
||||
return *this;
|
||||
|
||||
if (type != "button")
|
||||
currentValue = v;
|
||||
|
||||
if (on_change)
|
||||
(*on_change)(*this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
UCIOption(const char* v, Fn* = NULL);
|
||||
UCIOption(int v, int min, int max, Fn* = NULL);
|
||||
|
||||
void operator=(const std::string& v);
|
||||
UCIOption& operator=(const std::string& v);
|
||||
|
||||
operator int() const {
|
||||
assert(type == "check" || type == "spin");
|
||||
|
|
Loading…
Reference in New Issue