historyState.h
Go to the documentation of this file.
00001 /* historyState.h
00002  */
00003 #ifndef _HISTORYSTATE_H
00004 #define _HISTORYSTATE_H
00005 #include "osl/state/numEffectState.h"
00006 #include "osl/stl/vector.h"
00007 namespace osl
00008 {
00009   namespace state
00010   {
00011     class HistoryState
00012 #if OSL_WORDSIZE == 32
00013       : public misc::Align16New
00014 #endif
00015     {
00016       NumEffectState initial_state;
00017       mutable NumEffectState current;
00018       mutable bool dirty;
00019       vector<Move> moves;
00020     public:
00021       HistoryState();
00022       explicit HistoryState(const SimpleState& initial);
00023       ~HistoryState();
00024 
00025       void setRoot(const SimpleState&);
00026       void makeMove(Move move);
00027       void unmakeMove();
00028 
00029       void makeMovePass();
00030       void unmakeMovePass();
00031       
00032       const NumEffectState& state() const {
00033         if (dirty)
00034           update();
00035         return current; 
00036       }
00037       operator const NumEffectState& () const { return state(); }
00038       const NumEffectState& initialState() const { return initial_state; }
00039       bool empty() const { return moves.empty(); }
00040       const vector<Move>& history() const { return moves; }
00041       bool isConsistent() const { return state().isConsistent(); }
00042     private:
00043       void update() const;
00044     };
00045     class DoUndoMoveLock 
00046     {
00047       HistoryState& state;
00048     public:
00049       DoUndoMoveLock(HistoryState& s, Move move) : state(s)
00050       {
00051         state.makeMove(move);
00052       }
00053       ~DoUndoMoveLock() 
00054       {
00055         state.unmakeMove();
00056       }
00057     };
00058   }
00059   using state::HistoryState;
00060   using state::DoUndoMoveLock;
00061 }
00062 
00063 
00064 #endif /* _HISTORYSTATE_H */
00065 // ;;; Local Variables:
00066 // ;;; mode:c++
00067 // ;;; c-basic-offset:2
00068 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines