/// - Provides undo support through the global undo system.
class KeyValue : public EntityKeyValue
{
-typedef UnsortedSet<KeyObserver> KeyObservers;
-
-std::size_t m_refcount;
-KeyObservers m_observers;
-CopiedString m_string;
-const char* m_empty;
-ObservedUndoableObject<CopiedString> m_undo;
-static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged;
-public:
+ typedef UnsortedSet<KeyObserver> 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<CopiedString> 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 notify(){
+ m_entityKeyValueChanged();
+ KeyObservers::reverse_iterator i = m_observers.rbegin();
+ while ( i != m_observers.rend() )
+ {
+ ( *i++ )( c_str() );
+ }
}
-}
-void importState( const CopiedString& string ){
- m_string = string;
+ void importState( const CopiedString& string ){
+ m_string = string;
- notify();
-}
-typedef MemberCaller<KeyValue, void(const CopiedString&), &KeyValue::importState> UndoImportCaller;
+ notify();
+ }
+ typedef MemberCaller<KeyValue, void(const CopiedString&), &KeyValue::importState> UndoImportCaller;
};
/// \brief An unsorted list of key/value pairs.