X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fundolib.h;h=06d474bf56b13fcaa5d546d3acaa6f1ba72cb0a2;hb=42856811f2b174e37a761bfcb9fbeb8c6af2f558;hp=5b118fa80a24f1baab8ca43dc9f9e858eb82c34a;hpb=12b372f89ce109a4db9d510884fbe7d05af79870;p=xonotic%2Fnetradiant.git diff --git a/libs/undolib.h b/libs/undolib.h index 5b118fa8..06d474bf 100644 --- a/libs/undolib.h +++ b/libs/undolib.h @@ -1,25 +1,25 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined (INCLUDED_UNDOLIB_H) +#if !defined ( INCLUDED_UNDOLIB_H ) #define INCLUDED_UNDOLIB_H #include "iundo.h" @@ -30,132 +30,112 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA template class BasicUndoMemento : public UndoMemento { - Copyable m_data; +Copyable m_data; public: - BasicUndoMemento(const Copyable& data) - : m_data(data) - { - } - - void release() - { - delete this; - } - - const Copyable& get() const - { - return m_data; - } +BasicUndoMemento( const Copyable& data ) + : m_data( data ){ +} + +void release(){ + delete this; +} + +const Copyable& get() const { + return m_data; +} }; template class ObservedUndoableObject : public Undoable { - typedef Callback1 ImportCallback; +typedef Callback ImportCallback; - Copyable& m_object; - ImportCallback m_importCallback; - UndoObserver* m_undoQueue; - MapFile* m_map; +Copyable& m_object; +ImportCallback m_importCallback; +UndoObserver* m_undoQueue; +MapFile* m_map; public: - ObservedUndoableObject(Copyable& object, const ImportCallback& importCallback) - : m_object(object), m_importCallback(importCallback), m_undoQueue(0), m_map(0) - { - } - ~ObservedUndoableObject() - { - } - - MapFile* map() - { - return m_map; - } - - void instanceAttach(MapFile* map) - { - m_map = map; - m_undoQueue = GlobalUndoSystem().observer(this); - } - void instanceDetach(MapFile* map) - { - m_map = 0; - m_undoQueue = 0; - GlobalUndoSystem().release(this); - } - - void save() - { - if(m_map != 0) - { - m_map->changed(); - } - if(m_undoQueue != 0) - { - m_undoQueue->save(this); - } - } - - UndoMemento* exportState() const - { - return new BasicUndoMemento(m_object); - } - void importState(const UndoMemento* state) - { - save(); - m_importCallback((static_cast*>(state))->get()); - } +ObservedUndoableObject( Copyable & object, const ImportCallback &importCallback ) + : m_object( object ), m_importCallback( importCallback ), m_undoQueue( 0 ), m_map( 0 ) +{ +} +~ObservedUndoableObject(){ +} + +MapFile* map(){ + return m_map; +} + +void instanceAttach( MapFile* map ){ + m_map = map; + m_undoQueue = GlobalUndoSystem().observer( this ); +} +void instanceDetach( MapFile* map ){ + m_map = 0; + m_undoQueue = 0; + GlobalUndoSystem().release( this ); +} + +void save(){ + if ( m_map != 0 ) { + m_map->changed(); + } + if ( m_undoQueue != 0 ) { + m_undoQueue->save( this ); + } +} + +UndoMemento* exportState() const { + return new BasicUndoMemento( m_object ); +} +void importState( const UndoMemento* state ){ + save(); + m_importCallback( ( static_cast*>( state ) )->get() ); +} }; template class UndoableObject : public Undoable { - Copyable& m_object; - UndoObserver* m_undoQueue; - MapFile* m_map; +Copyable& m_object; +UndoObserver* m_undoQueue; +MapFile* m_map; public: - UndoableObject(Copyable& object) - : m_object(object), m_undoQueue(0), m_map(0) - {} - ~UndoableObject() - { - } - - void instanceAttach(MapFile* map) - { - m_map = map; - m_undoQueue = GlobalUndoSystem().observer(this); - } - void instanceDetach(MapFile* map) - { - m_map = 0; - m_undoQueue = 0; - GlobalUndoSystem().release(this); - } - - void save() - { - if(m_map != 0) - { - m_map->changed(); - } - if(m_undoQueue != 0) - { - m_undoQueue->save(this); - } - } - - UndoMemento* exportState() const - { - return new BasicUndoMemento(m_object); - } - void importState(const UndoMemento* state) - { - save(); - m_object = (static_cast*>(state))->get(); - } +UndoableObject( Copyable& object ) + : m_object( object ), m_undoQueue( 0 ), m_map( 0 ) +{} +~UndoableObject(){ +} + +void instanceAttach( MapFile* map ){ + m_map = map; + m_undoQueue = GlobalUndoSystem().observer( this ); +} +void instanceDetach( MapFile* map ){ + m_map = 0; + m_undoQueue = 0; + GlobalUndoSystem().release( this ); +} + +void save(){ + if ( m_map != 0 ) { + m_map->changed(); + } + if ( m_undoQueue != 0 ) { + m_undoQueue->save( this ); + } +} + +UndoMemento* exportState() const { + return new BasicUndoMemento( m_object ); +} +void importState( const UndoMemento* state ){ + save(); + m_object = ( static_cast*>( state ) )->get(); +} }; #endif