From 54e8a580c542fc88008d31d4a66f7249908885b7 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sun, 20 Apr 2008 21:52:42 +0200 Subject: [PATCH] Rename delegate members, trying to avoid confusion. --- src/core/delegators/behaviour.h | 22 ++++--- src/core/delegators/defaultstate.h | 10 ++-- src/core/delegators/moveserializer.h | 22 +++---- src/core/delegators/state.h | 94 +++++++++++++++--------------- src/core/delegators/validator.h | 18 +++--- src/variants/crazyhouse/behaviour.cpp | 2 +- src/variants/crazyhouse/moveserializer.cpp | 2 +- src/variants/crazyhouse/state.cpp | 6 +- src/variants/crazyhouse/validator.cpp | 4 +- 9 files changed, 92 insertions(+), 88 deletions(-) rewrite src/core/delegators/state.h (67%) diff --git a/src/core/delegators/behaviour.h b/src/core/delegators/behaviour.h index 1f890ec..2447a94 100644 --- a/src/core/delegators/behaviour.h +++ b/src/core/delegators/behaviour.h @@ -16,24 +16,28 @@ namespace Delegators { class Behaviour : public IBehaviour { protected: - const IBehaviour* m_behaviour; + const IBehaviour* m_dgate_behaviour; public: - Behaviour(const IBehaviour* behaviour) : m_behaviour(behaviour) { } - virtual ~Behaviour() { delete m_behaviour; } + Behaviour(const IBehaviour* behaviour) : m_dgate_behaviour(behaviour) { } + virtual ~Behaviour() { delete m_dgate_behaviour; } virtual void captureOn(IState* state, const Point& square) const { - m_behaviour->captureOn(state, square); + m_dgate_behaviour->captureOn(state, square); + } + virtual void move(IState* state, const Move& m) const { + m_dgate_behaviour->move(state, m); + } + virtual void advanceTurn(IState* state) const { + m_dgate_behaviour->advanceTurn(state); } - virtual void move(IState* state, const Move& m) const { m_behaviour->move(state, m); } - virtual void advanceTurn(IState* state) const { m_behaviour->advanceTurn(state); } virtual Point captureSquare(const IState* state, const Move& m) const { - return m_behaviour->captureSquare(state, m); + return m_dgate_behaviour->captureSquare(state, m); } virtual const IColor* opponent(const IColor* player) const { - return m_behaviour->opponent(player); + return m_dgate_behaviour->opponent(player); } virtual Point direction(const IColor* player) const { - return m_behaviour->direction(player); + return m_dgate_behaviour->direction(player); } }; diff --git a/src/core/delegators/defaultstate.h b/src/core/delegators/defaultstate.h index 654fcca..b3c08f1 100644 --- a/src/core/delegators/defaultstate.h +++ b/src/core/delegators/defaultstate.h @@ -11,7 +11,7 @@ namespace Delegators { class DefaultState : public State, public ::DefaultState { protected: - ::DefaultState* m_state; + ::DefaultState* m_dgate_defaultstate; public: DefaultState(IState* state) : State(state) { @@ -22,14 +22,14 @@ public: abort(); } - m_state = dstate; - m_state->setDelegator(this); + m_dgate_defaultstate = dstate; + m_dgate_defaultstate->setDelegator(this); } - virtual ~DefaultState() { delete m_state; } + virtual ~DefaultState() { delete m_dgate_defaultstate; } virtual std::vector theoreticalMoves(const Piece& piece, const Point& src) const - { return m_state->theoreticalMoves(piece, src); } + { return m_dgate_defaultstate->theoreticalMoves(piece, src); } }; } // namespace Delegators diff --git a/src/core/delegators/moveserializer.h b/src/core/delegators/moveserializer.h index 8a11a3d..f6483a2 100644 --- a/src/core/delegators/moveserializer.h +++ b/src/core/delegators/moveserializer.h @@ -17,29 +17,29 @@ namespace Delegators { class MoveSerializer : public IMoveSerializer { protected: - IMoveSerializer* m_serializer; + IMoveSerializer* m_dgate_serializer; public: MoveSerializer(IMoveSerializer* serializer) - : m_serializer(serializer) { - m_serializer->setDelegator(this); + : m_dgate_serializer(serializer) { + m_dgate_serializer->setDelegator(this); } - virtual ~MoveSerializer() { delete m_serializer; } + virtual ~MoveSerializer() { delete m_dgate_serializer; } virtual QString serialize(const Move& move, const IState* ref) const { - return m_serializer->serialize(move, ref); + return m_dgate_serializer->serialize(move, ref); } virtual Move deserialize(const QString& str, const IState* ref) const { - return m_serializer->deserialize(str, ref); + return m_dgate_serializer->deserialize(str, ref); } - virtual QString symbol(const IType* type) const { return m_serializer->symbol(type); } + virtual QString symbol(const IType* type) const { return m_dgate_serializer->symbol(type); } virtual QString suffix(const Move& move, const IState* ref) const { - return m_serializer->suffix(move, ref); + return m_dgate_serializer->suffix(move, ref); } - virtual QString type() const { return m_serializer->type(); } + virtual QString type() const { return m_dgate_serializer->type(); } virtual void setDelegator(IMoveSerializer* delegator) { - m_serializer->setDelegator(delegator); + m_dgate_serializer->setDelegator(delegator); } virtual QString san(const Move& move, const IState* ref) const { - return m_serializer->san(move, ref); + return m_dgate_serializer->san(move, ref); } }; diff --git a/src/core/delegators/state.h b/src/core/delegators/state.h dissimilarity index 67% index a2155ae..237d728 100644 --- a/src/core/delegators/state.h +++ b/src/core/delegators/state.h @@ -1,47 +1,47 @@ -/* - Copyright (c) 2007 Paolo Capriotti - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. -*/ - -#ifndef DELEGATORS__STATE_H -#define DELEGATORS__STATE_H - -#include "../state.h" - -/** - * @brief Namespace holding delegators to core Tagua components. - */ -namespace Delegators { - -class State : virtual public IState { -protected: - IState* m_state; -public: - State(IState* state) : m_state(state) { m_state->setDelegator(this); } - virtual ~State() { delete m_state; } - - virtual IState* clone() const { return new State(m_state->clone()); } - virtual void setup() { m_state->setup(); } - virtual const Board* board() const { return m_state->board(); } - virtual Board* board() { return m_state->board(); } - virtual const IColor* turn() const { return m_state->turn(); } - virtual void setTurn(const IColor* turn) { m_state->setTurn(turn); } - virtual bool equals(IState* other) const { return m_state->equals(other); } - virtual void assign(const IState* other) { m_state->assign(other); } - virtual void move(const Move& move) { m_state->move(move); } - virtual TaguaObject* flags() { return m_state->flags(); } - virtual const TaguaObject* flags() const { return m_state->flags(); } - virtual int rank(int n, const IColor* turn) const { return m_state->rank(n, turn); } - virtual const IPoolCollection* pools() const { return m_state->pools(); } - virtual IPoolCollection* pools() { return m_state->pools(); } - virtual const IBehaviour* behaviour() const { return m_state->behaviour(); } - virtual void setDelegator(IState* state) { m_state->setDelegator(state); } -}; - -} - -#endif // DELEGATORS__STATE_H +/* + Copyright (c) 2007 Paolo Capriotti + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. +*/ + +#ifndef DELEGATORS__STATE_H +#define DELEGATORS__STATE_H + +#include "../state.h" + +/** + * @brief Namespace holding delegators to core Tagua components. + */ +namespace Delegators { + +class State : virtual public IState { +protected: + IState* m_dgate_state; +public: + State(IState* state) : m_dgate_state(state) { m_dgate_state->setDelegator(this); } + virtual ~State() { delete m_dgate_state; } + + virtual IState* clone() const { return new State(m_dgate_state->clone()); } + virtual void setup() { m_dgate_state->setup(); } + virtual const Board* board() const { return m_dgate_state->board(); } + virtual Board* board() { return m_dgate_state->board(); } + virtual const IColor* turn() const { return m_dgate_state->turn(); } + virtual void setTurn(const IColor* turn) { m_dgate_state->setTurn(turn); } + virtual bool equals(IState* other) const { return m_dgate_state->equals(other); } + virtual void assign(const IState* other) { m_dgate_state->assign(other); } + virtual void move(const Move& move) { m_dgate_state->move(move); } + virtual TaguaObject* flags() { return m_dgate_state->flags(); } + virtual const TaguaObject* flags() const { return m_dgate_state->flags(); } + virtual int rank(int n, const IColor* turn) const { return m_dgate_state->rank(n, turn); } + virtual const IPoolCollection* pools() const { return m_dgate_state->pools(); } + virtual IPoolCollection* pools() { return m_dgate_state->pools(); } + virtual const IBehaviour* behaviour() const { return m_dgate_state->behaviour(); } + virtual void setDelegator(IState* state) { m_dgate_state->setDelegator(state); } +}; + +} + +#endif // DELEGATORS__STATE_H diff --git a/src/core/delegators/validator.h b/src/core/delegators/validator.h index 4a021dd..9e32c99 100644 --- a/src/core/delegators/validator.h +++ b/src/core/delegators/validator.h @@ -16,28 +16,28 @@ namespace Delegators { class Validator : public IValidator { protected: - IValidator* m_validator; + IValidator* m_dgate_validator; public: Validator(IValidator* validator) - : m_validator(validator) { - m_validator->setDelegator(this); + : m_dgate_validator(validator) { + m_dgate_validator->setDelegator(this); } - virtual ~Validator() { delete m_validator; } + virtual ~Validator() { delete m_dgate_validator; } virtual bool pseudolegal(const IState* state, Move& move) const { - return m_validator->pseudolegal(state, move); + return m_dgate_validator->pseudolegal(state, move); } virtual bool legal(const IState* state, Move& move) const { - return m_validator->legal(state, move); + return m_dgate_validator->legal(state, move); } virtual bool attacks(const IState* state, const IColor* player, const Point& square, const Piece& target = Piece()) const { - return m_validator->attacks(state, player, square, target); + return m_dgate_validator->attacks(state, player, square, target); } virtual const IColor* mover(const IState* state, const Move& move) const { - return m_validator->mover(state, move); + return m_dgate_validator->mover(state, move); } virtual void setDelegator(IValidator* delegator) { - return m_validator->setDelegator(delegator); + return m_dgate_validator->setDelegator(delegator); } }; diff --git a/src/variants/crazyhouse/behaviour.cpp b/src/variants/crazyhouse/behaviour.cpp index 6cd2058..d2be9a2 100644 --- a/src/variants/crazyhouse/behaviour.cpp +++ b/src/variants/crazyhouse/behaviour.cpp @@ -29,7 +29,7 @@ void Behaviour::captureOn(IState* state, const Point& square) const { } state->pools()->pool(opponent(captured.color()))->insert(-1, captured); } - m_behaviour->captureOn(state, square); + m_dgate_behaviour->captureOn(state, square); } } // namespace Crazyhouse diff --git a/src/variants/crazyhouse/moveserializer.cpp b/src/variants/crazyhouse/moveserializer.cpp index 42ced9f..762b313 100644 --- a/src/variants/crazyhouse/moveserializer.cpp +++ b/src/variants/crazyhouse/moveserializer.cpp @@ -19,7 +19,7 @@ MoveSerializer::MoveSerializer(IMoveSerializer* serializer) QString MoveSerializer::serialize(const Move& move, const IState* ref) const { if (move.drop() == Piece()) - return m_serializer->serialize(move, ref); + return m_dgate_serializer->serialize(move, ref); QString res; if (type() == "decorated") { diff --git a/src/variants/crazyhouse/state.cpp b/src/variants/crazyhouse/state.cpp index af2ae84..33fe50d 100644 --- a/src/variants/crazyhouse/state.cpp +++ b/src/variants/crazyhouse/state.cpp @@ -32,13 +32,13 @@ State::State(IState* state) State::~State() { delete m_pools; } IState* State::clone() const { - State* s = new State(m_state->clone()); + State* s = new State(m_dgate_state->clone()); s->m_pools = m_pools->clone(); return s; } void State::assign(const IState* other) { - m_state->assign(other); + m_dgate_state->assign(other); const IPoolCollection* pools = other->pools(); if (pools) { delete m_pools; @@ -64,7 +64,7 @@ void State::move(const Move& m) { behaviour()->advanceTurn(this); } else { - m_state->move(m); + m_dgate_state->move(m); if (m.promotion()) { Piece promoted = board()->get(m.dst()); promoted.set("promoted", true); diff --git a/src/variants/crazyhouse/validator.cpp b/src/variants/crazyhouse/validator.cpp index b416123..69fd79b 100644 --- a/src/variants/crazyhouse/validator.cpp +++ b/src/variants/crazyhouse/validator.cpp @@ -35,7 +35,7 @@ bool Validator::pseudolegal(const IState* state, Move& move) const { Piece dropped = move.drop(); if (dropped == Piece()) { - return m_validator->pseudolegal(state, move); + return m_dgate_validator->pseudolegal(state, move); } else { // dropping on a valid square @@ -60,7 +60,7 @@ const IColor* Validator::mover(const IState* state, const Move& move) const { if (move.drop() != Piece()) return move.drop().color(); else - return m_validator->mover(state, move); + return m_dgate_validator->mover(state, move); } } // namespace Crazyhouse -- 2.11.4.GIT