Synchronize two boards. More...
#include <GoBoardSynchronizer.h>
Public Member Functions | |
GoBoardSynchronizer (const GoBoard &publisher) | |
Create a synchronizer. | |
virtual | ~GoBoardSynchronizer () |
void | SetSubscriber (GoBoard &subscriber) |
Set the board that will subscribe to all the changes of the publisher. | |
void | UpdateSubscriber () |
Update the subscriber board. | |
Protected Member Functions | |
Hook functions for incremental update events | |
virtual void | OnBoardChange () |
Board was initialized with new size. | |
virtual void | PrePlay (GoPlayerMove move) |
Move about to be executed. | |
virtual void | OnPlay (GoPlayerMove move) |
Move was executed. | |
virtual void | PreUndo () |
Move about to be undone. | |
virtual void | OnUndo () |
Move was undone. | |
Private Member Functions | |
GoBoardSynchronizer (const GoBoardSynchronizer &) | |
Not implemented. | |
GoBoardSynchronizer & | operator= (const GoBoardSynchronizer &) |
Not implemented. | |
void | ExecuteSubscriber (const GoPlayerMove &move) |
int | FindNuCommon () const |
void | UpdateFromInit () |
void | UpdateIncremental () |
void | UpdateToPlay () |
Private Attributes | |
const GoBoard & | m_publisher |
GoBoard * | m_subscriber |
Synchronize two boards.
Definition at line 15 of file GoBoardSynchronizer.h.
GoBoardSynchronizer::GoBoardSynchronizer | ( | const GoBoard & | publisher | ) |
Create a synchronizer.
The publisher board can be at any position; the subscriber match that position the first time BoardSynchronizer::UpdateSubscriber is called.
Definition at line 14 of file GoBoardSynchronizer.cpp.
GoBoardSynchronizer::~GoBoardSynchronizer | ( | ) | [virtual] |
Definition at line 20 of file GoBoardSynchronizer.cpp.
GoBoardSynchronizer::GoBoardSynchronizer | ( | const GoBoardSynchronizer & | ) | [private] |
Not implemented.
void GoBoardSynchronizer::ExecuteSubscriber | ( | const GoPlayerMove & | move | ) | [private] |
Definition at line 41 of file GoBoardSynchronizer.cpp.
References m_subscriber, OnPlay(), GoBoard::Play(), and PrePlay().
Referenced by UpdateFromInit(), and UpdateIncremental().
int GoBoardSynchronizer::FindNuCommon | ( | ) | const [private] |
Definition at line 30 of file GoBoardSynchronizer.cpp.
References m_publisher, m_subscriber, GoBoard::Move(), and GoBoard::MoveNumber().
Referenced by UpdateIncremental().
void GoBoardSynchronizer::OnBoardChange | ( | ) | [protected, virtual] |
Board was initialized with new size.
Default implementation does nothing.
Definition at line 48 of file GoBoardSynchronizer.cpp.
Referenced by UpdateFromInit().
void GoBoardSynchronizer::OnPlay | ( | GoPlayerMove | move | ) | [protected, virtual] |
Move was executed.
Default implementation does nothing.
Definition at line 57 of file GoBoardSynchronizer.cpp.
References SG_UNUSED().
Referenced by ExecuteSubscriber().
void GoBoardSynchronizer::OnUndo | ( | ) | [protected, virtual] |
Move was undone.
Default implementation does nothing.
Definition at line 66 of file GoBoardSynchronizer.cpp.
Referenced by UpdateIncremental().
GoBoardSynchronizer& GoBoardSynchronizer::operator= | ( | const GoBoardSynchronizer & | ) | [private] |
Not implemented.
void GoBoardSynchronizer::PrePlay | ( | GoPlayerMove | move | ) | [protected, virtual] |
Move about to be executed.
Default implementation does nothing.
Definition at line 52 of file GoBoardSynchronizer.cpp.
References SG_UNUSED().
Referenced by ExecuteSubscriber().
void GoBoardSynchronizer::PreUndo | ( | ) | [protected, virtual] |
Move about to be undone.
Default implementation does nothing.
Definition at line 62 of file GoBoardSynchronizer.cpp.
Referenced by UpdateIncremental().
void GoBoardSynchronizer::SetSubscriber | ( | GoBoard & | subscriber | ) |
Set the board that will subscribe to all the changes of the publisher.
Can only be called once.
Definition at line 24 of file GoBoardSynchronizer.cpp.
References m_subscriber, and SG_ASSERT.
Referenced by GoAutoBookState::GoAutoBookState(), and GoPlayer::GoPlayer().
void GoBoardSynchronizer::UpdateFromInit | ( | ) | [private] |
Definition at line 70 of file GoBoardSynchronizer.cpp.
References ExecuteSubscriber(), GoBoard::Init(), m_publisher, m_subscriber, GoBoard::Move(), GoBoard::MoveNumber(), OnBoardChange(), GoBoard::Setup(), and GoBoard::Size().
Referenced by UpdateSubscriber().
void GoBoardSynchronizer::UpdateIncremental | ( | ) | [private] |
Definition at line 79 of file GoBoardSynchronizer.cpp.
References ExecuteSubscriber(), FindNuCommon(), m_publisher, m_subscriber, GoBoard::Move(), GoBoard::MoveNumber(), OnUndo(), PreUndo(), SG_ASSERT, and GoBoard::Undo().
Referenced by UpdateSubscriber().
void GoBoardSynchronizer::UpdateSubscriber | ( | ) |
Update the subscriber board.
Calls Init, Play, Undo and/or SetToPlay to update the subscriber to the current state of the publisher. If no subscriber was set with SetSubscriber, this function does nothing.
Definition at line 96 of file GoBoardSynchronizer.cpp.
References GoBoard::GetHashCode(), m_publisher, m_subscriber, GoBoard::Rules(), GoBoard::Setup(), SG_ASSERT, GoBoard::Size(), UpdateFromInit(), UpdateIncremental(), and UpdateToPlay().
Referenced by GoGtpEngine::BoardChanged(), GoGtpEngine::RulesChanged(), GoGtpEngine::SetPlayer(), and GoAutoBookState::Synchronize().
void GoBoardSynchronizer::UpdateToPlay | ( | ) | [private] |
Definition at line 110 of file GoBoardSynchronizer.cpp.
References m_publisher, m_subscriber, GoBoard::SetToPlay(), and GoBoard::ToPlay().
Referenced by UpdateSubscriber().
const GoBoard& GoBoardSynchronizer::m_publisher [private] |
Definition at line 63 of file GoBoardSynchronizer.h.
Referenced by FindNuCommon(), UpdateFromInit(), UpdateIncremental(), UpdateSubscriber(), and UpdateToPlay().
GoBoard* GoBoardSynchronizer::m_subscriber [private] |
Definition at line 65 of file GoBoardSynchronizer.h.
Referenced by ExecuteSubscriber(), FindNuCommon(), SetSubscriber(), UpdateFromInit(), UpdateIncremental(), UpdateSubscriber(), and UpdateToPlay().