/** * memento.h * Implemented by Blueprint Technologies, Inc. */ #ifndef _memento_h #define _memento_h #include using namespace std; /** * Abstract data type for this pattern. */ class State { }; /** * Stores internal state of the Originator object. The memento * may store as much or as little of the originator's state as * necessary at its originator's discretion. */ class Memento { private: State* state; public: Memento(): state(0) { }; Memento( State* state ) { this -> state = state; } State* getState() { return state; }; void setState( State* state ) { this -> state = state; }; }; /** * Responsible for the memento's safekeeping. Never operates * on or examines the contents of a memento. We'll use a * double-ended queue for this. */ typedef deque< Memento* > Caretaker; /** * Creates a memento containing a snapshot of its current * internal state. Uses the memento to restore its internal * state. */ class Originator { private: State* state; public: Originator(): state(0) { }; void setMemento( Memento* memento ) { state = memento -> getState(); }; Memento* createMemento() { return new Memento( state ); }; }; #endif