00001 //---------------------------------------------------------------------------- 00002 /** @file GoBoardSynchronizer.h */ 00003 //---------------------------------------------------------------------------- 00004 00005 #ifndef GO_BOARDSYNCHRONIZER_H 00006 #define GO_BOARDSYNCHRONIZER_H 00007 00008 #include "GoPlayerMove.h" 00009 00010 class GoBoard; 00011 00012 //---------------------------------------------------------------------------- 00013 00014 /** Synchronize two boards. */ 00015 class GoBoardSynchronizer 00016 { 00017 public: 00018 /** Create a synchronizer. 00019 The publisher board can be at any position; the subscriber match that 00020 position the first time BoardSynchronizer::UpdateSubscriber is called. 00021 */ 00022 GoBoardSynchronizer(const GoBoard& publisher); 00023 00024 virtual ~GoBoardSynchronizer(); 00025 00026 /** Set the board that will subscribe to all the changes of the publisher. 00027 Can only be called once. 00028 */ 00029 void SetSubscriber(GoBoard& subscriber); 00030 00031 /** Update the subscriber board. 00032 Calls Init, Play, Undo and/or SetToPlay to update the 00033 subscriber to the current state of the publisher. 00034 If no subscriber was set with SetSubscriber, this function does 00035 nothing. 00036 */ 00037 void UpdateSubscriber(); 00038 00039 protected: 00040 /** @name Hook functions for incremental update events */ 00041 // @{ 00042 00043 /** Board was initialized with new size. 00044 Default implementation does nothing. 00045 */ 00046 virtual void OnBoardChange(); 00047 00048 /** Move about to be executed. 00049 Default implementation does nothing. 00050 */ 00051 virtual void PrePlay(GoPlayerMove move); 00052 00053 /** Move was executed. 00054 Default implementation does nothing. 00055 */ 00056 virtual void OnPlay(GoPlayerMove move); 00057 00058 /** Move about to be undone. 00059 Default implementation does nothing. 00060 */ 00061 virtual void PreUndo(); 00062 00063 /** Move was undone. 00064 Default implementation does nothing. 00065 */ 00066 virtual void OnUndo(); 00067 00068 // @} 00069 00070 private: 00071 const GoBoard& m_publisher; 00072 00073 GoBoard* m_subscriber; 00074 00075 /** Not implemented */ 00076 GoBoardSynchronizer(const GoBoardSynchronizer&); 00077 00078 /** Not implemented */ 00079 GoBoardSynchronizer& operator=(const GoBoardSynchronizer&); 00080 00081 void ExecuteSubscriber(const GoPlayerMove& move); 00082 00083 int FindNuCommon() const; 00084 00085 void UpdateFromInit(); 00086 00087 void UpdateIncremental(); 00088 00089 void UpdateToPlay(); 00090 }; 00091 00092 //---------------------------------------------------------------------------- 00093 00094 #endif // GO_BOARDSYNCHRONIZER_H 00095