X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fentitylib.h;h=326f2c7c6c9939f273ef160531e5117f1046fd96;hb=2f3b74eff8ba0ca83d3f7d14fe11f93483d22c89;hp=83f35f02ea959b758f4f9afbfa0cc587aee44fa2;hpb=9c4c8b725fdca551dc9379b77ebd9c498d0c6f28;p=xonotic%2Fnetradiant.git diff --git a/libs/entitylib.h b/libs/entitylib.h index 83f35f02..326f2c7c 100644 --- a/libs/entitylib.h +++ b/libs/entitylib.h @@ -293,80 +293,80 @@ void render( RenderStateFlags state ) const { /// - Provides undo support through the global undo system. class KeyValue : public EntityKeyValue { -typedef UnsortedSet KeyObservers; - -std::size_t m_refcount; -KeyObservers m_observers; -CopiedString m_string; -const char* m_empty; -ObservedUndoableObject m_undo; -static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged; -public: + typedef UnsortedSet KeyObservers; -KeyValue( const char* string, const char* empty ) - : m_refcount( 0 ), m_string( string ), m_empty( empty ), m_undo( m_string, UndoImportCaller( *this ) ){ - notify(); -} -~KeyValue(){ - ASSERT_MESSAGE( m_observers.empty(), "KeyValue::~KeyValue: observers still attached" ); -} + std::size_t m_refcount; + KeyObservers m_observers; + CopiedString m_string; + const char* m_empty; + ObservedUndoableObject m_undo; + static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged; -static void setKeyValueChangedFunc( EntityCreator::KeyValueChangedFunc func ){ - m_entityKeyValueChanged = func; -} +public: + KeyValue( const char* string, const char* empty ) + : m_refcount( 0 ), m_string( string ), m_empty( empty ), m_undo( m_string, UndoImportCaller( *this ) ){ + notify(); + } + ~KeyValue(){ + ASSERT_MESSAGE( m_observers.empty(), "KeyValue::~KeyValue: observers still attached" ); + } -void IncRef(){ - ++m_refcount; -} -void DecRef(){ - if ( --m_refcount == 0 ) { - delete this; + static void setKeyValueChangedFunc( EntityCreator::KeyValueChangedFunc func ){ + m_entityKeyValueChanged = func; } -} -void instanceAttach( MapFile* map ){ - m_undo.instanceAttach( map ); -} -void instanceDetach( MapFile* map ){ - m_undo.instanceDetach( map ); -} + void IncRef(){ + ++m_refcount; + } + void DecRef(){ + if ( --m_refcount == 0 ) { + delete this; + } + } -void attach( const KeyObserver& observer ){ - ( *m_observers.insert ( observer ) )( c_str() ); -} -void detach( const KeyObserver& observer ){ - observer( m_empty ); - m_observers.erase( observer ); -} -const char* c_str() const { - if ( string_empty( m_string.c_str() ) ) { - return m_empty; + void instanceAttach( MapFile* map ){ + m_undo.instanceAttach( map ); } - return m_string.c_str(); -} -void assign( const char* other ){ - if ( !string_equal( m_string.c_str(), other ) ) { - m_undo.save(); - m_string = other; - notify(); + void instanceDetach( MapFile* map ){ + m_undo.instanceDetach( map ); } -} -void notify(){ - m_entityKeyValueChanged(); - KeyObservers::reverse_iterator i = m_observers.rbegin(); - while ( i != m_observers.rend() ) - { - ( *i++ )( c_str() ); + void attach( const KeyObserver& observer ){ + ( *m_observers.insert ( observer ) )( c_str() ); + } + void detach( const KeyObserver& observer ){ + observer( m_empty ); + m_observers.erase( observer ); + } + const char* c_str() const { + if ( string_empty( m_string.c_str() ) ) { + return m_empty; + } + return m_string.c_str(); + } + void assign( const char* other ){ + if ( !string_equal( m_string.c_str(), other ) ) { + m_undo.save(); + m_string = other; + notify(); + } } -} -void importState( const CopiedString& string ){ - m_string = string; + void notify(){ + m_entityKeyValueChanged(); + KeyObservers::reverse_iterator i = m_observers.rbegin(); + while ( i != m_observers.rend() ) + { + ( *i++ )( c_str() ); + } + } - notify(); -} -typedef MemberCaller UndoImportCaller; + void importState( const CopiedString& string ){ + m_string = string; + + notify(); + } + typedef MemberCaller UndoImportCaller; }; /// \brief An unsorted list of key/value pairs. @@ -419,18 +419,6 @@ private: } m_observerMutex = false; } - void forEachKeyValue_notifyInsert(){ - for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i ) - { - notifyInsert( ( *i ).first.c_str(), *( *i ).second ); - } - } - void forEachKeyValue_notifyErase(){ - for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i ) - { - notifyErase( ( *i ).first.c_str(), *( *i ).second ); - } - } void insert( const char* key, const KeyValuePtr& keyValue ){ KeyValues::iterator i = m_keyValues.insert( KeyValues::value_type( key, keyValue ) );