2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined ( INCLUDED_UNDOLIB_H )
23 #define INCLUDED_UNDOLIB_H
28 #include "generic/callback.h"
30 template<typename Copyable>
31 class BasicUndoMemento : public UndoMemento
35 BasicUndoMemento( const Copyable& data )
43 const Copyable& get() const {
49 template<typename Copyable>
50 class ObservedUndoableObject : public Undoable
52 typedef Callback1<const Copyable&> ImportCallback;
55 ImportCallback m_importCallback;
56 UndoObserver* m_undoQueue;
60 ObservedUndoableObject<Copyable>( Copyable & object, const ImportCallback &importCallback )
61 : m_object( object ), m_importCallback( importCallback ), m_undoQueue( 0 ), m_map( 0 )
64 ~ObservedUndoableObject(){
71 void instanceAttach( MapFile* map ){
73 m_undoQueue = GlobalUndoSystem().observer( this );
75 void instanceDetach( MapFile* map ){
78 GlobalUndoSystem().release( this );
85 if ( m_undoQueue != 0 ) {
86 m_undoQueue->save( this );
90 UndoMemento* exportState() const {
91 return new BasicUndoMemento<Copyable>( m_object );
93 void importState( const UndoMemento* state ){
95 m_importCallback( ( static_cast<const BasicUndoMemento<Copyable>*>( state ) )->get() );
99 template<typename Copyable>
100 class UndoableObject : public Undoable
103 UndoObserver* m_undoQueue;
107 UndoableObject( Copyable& object )
108 : m_object( object ), m_undoQueue( 0 ), m_map( 0 )
113 void instanceAttach( MapFile* map ){
115 m_undoQueue = GlobalUndoSystem().observer( this );
117 void instanceDetach( MapFile* map ){
120 GlobalUndoSystem().release( this );
127 if ( m_undoQueue != 0 ) {
128 m_undoQueue->save( this );
132 UndoMemento* exportState() const {
133 return new BasicUndoMemento<Copyable>( m_object );
135 void importState( const UndoMemento* state ){
137 m_object = ( static_cast<const BasicUndoMemento<Copyable>*>( state ) )->get();