Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoBoardSynchronizer.h

Go to the documentation of this file.
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     GoBoardSynchronizer(const GoBoard& publisher);
00022 
00023     virtual ~GoBoardSynchronizer();
00024 
00025     /** Set the board that will subscribe to all the changes of the publisher.
00026         Can only be called once. */
00027     void SetSubscriber(GoBoard& subscriber);
00028 
00029     /** Update the subscriber board.
00030         Calls Init, Play, Undo and/or SetToPlay to update the
00031         subscriber to the current state of the publisher.
00032         If no subscriber was set with SetSubscriber, this function does
00033         nothing. */
00034     void UpdateSubscriber();
00035 
00036 protected:
00037     /** @name Hook functions for incremental update events */
00038     // @{
00039 
00040     /** Board was initialized with new size.
00041         Default implementation does nothing. */
00042     virtual void OnBoardChange();
00043 
00044     /** Move about to be executed.
00045         Default implementation does nothing. */
00046     virtual void PrePlay(GoPlayerMove move);
00047 
00048     /** Move was executed.
00049         Default implementation does nothing. */
00050     virtual void OnPlay(GoPlayerMove move);
00051 
00052     /** Move about to be undone.
00053         Default implementation does nothing. */
00054     virtual void PreUndo();
00055 
00056     /** Move was undone.
00057         Default implementation does nothing. */
00058     virtual void OnUndo();
00059 
00060     // @}
00061 
00062 private:
00063     const GoBoard& m_publisher;
00064 
00065     GoBoard* m_subscriber;
00066 
00067     /** Not implemented */
00068     GoBoardSynchronizer(const GoBoardSynchronizer&);
00069 
00070     /** Not implemented */
00071     GoBoardSynchronizer& operator=(const GoBoardSynchronizer&);
00072 
00073     void ExecuteSubscriber(const GoPlayerMove& move);
00074 
00075     int FindNuCommon() const;
00076 
00077     void UpdateFromInit();
00078 
00079     void UpdateIncremental();
00080 
00081     void UpdateToPlay();
00082 };
00083 
00084 //----------------------------------------------------------------------------
00085 
00086 #endif // GO_BOARDSYNCHRONIZER_H
00087 


Sun Mar 13 2011 Doxygen 1.7.1