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)
45 const Copyable& get() const
52 template<typename Copyable>
53 class ObservedUndoableObject : public Undoable
55 typedef Callback1<const Copyable&> ImportCallback;
58 ImportCallback m_importCallback;
59 UndoObserver* m_undoQueue;
63 ObservedUndoableObject<Copyable>(Copyable& object, const ImportCallback& importCallback)
64 : m_object(object), m_importCallback(importCallback), m_undoQueue(0), m_map(0)
67 ~ObservedUndoableObject()
76 void instanceAttach(MapFile* map)
79 m_undoQueue = GlobalUndoSystem().observer(this);
81 void instanceDetach(MapFile* map)
85 GlobalUndoSystem().release(this);
96 m_undoQueue->save(this);
100 UndoMemento* exportState() const
102 return new BasicUndoMemento<Copyable>(m_object);
104 void importState(const UndoMemento* state)
107 m_importCallback((static_cast<const BasicUndoMemento<Copyable>*>(state))->get());
111 template<typename Copyable>
112 class UndoableObject : public Undoable
115 UndoObserver* m_undoQueue;
119 UndoableObject(Copyable& object)
120 : m_object(object), m_undoQueue(0), m_map(0)
126 void instanceAttach(MapFile* map)
129 m_undoQueue = GlobalUndoSystem().observer(this);
131 void instanceDetach(MapFile* map)
135 GlobalUndoSystem().release(this);
146 m_undoQueue->save(this);
150 UndoMemento* exportState() const
152 return new BasicUndoMemento<Copyable>(m_object);
154 void importState(const UndoMemento* state)
157 m_object = (static_cast<const BasicUndoMemento<Copyable>*>(state))->get();