- bool m_isContainer;
-
- EntityKeyValues(EntityClass* eclass) :
- m_eclass(eclass),
- m_undo(m_keyValues, UndoImportCaller(*this)),
- m_instanced(false),
- m_observerMutex(false),
- m_isContainer(!eclass->fixedsize)
- {
- }
- EntityKeyValues(const EntityKeyValues& other) :
- Entity(other),
- m_eclass(&other.getEntityClass()),
- m_undo(m_keyValues, UndoImportCaller(*this)),
- m_instanced(false),
- m_observerMutex(false),
- m_isContainer(other.m_isContainer)
- {
- for(KeyValues::const_iterator i = other.m_keyValues.begin(); i != other.m_keyValues.end(); ++i)
- {
- insert((*i).first.c_str(), (*i).second->c_str());
- }
- }
- ~EntityKeyValues()
- {
- ASSERT_MESSAGE(m_observers.empty(), "EntityKeyValues::~EntityKeyValues: observers still attached");
- }
-
- static void setKeyValueChangedFunc(EntityCreator::KeyValueChangedFunc func)
- {
- m_entityKeyValueChanged = func;
- KeyValue::setKeyValueChangedFunc(func);
- }
- static void setCounter(Counter* counter)
- {
- m_counter = counter;
- }
-
- void importState(const KeyValues& keyValues)
- {
- for(KeyValues::iterator i = m_keyValues.begin(); i != m_keyValues.end();)
- {
- erase(i++);
- }
-
- for(KeyValues::const_iterator i = keyValues.begin(); i != keyValues.end(); ++i)
- {
- insert((*i).first.c_str(), (*i).second);
- }
-
- m_entityKeyValueChanged();
- }
- typedef MemberCaller1<EntityKeyValues, const KeyValues&, &EntityKeyValues::importState> UndoImportCaller;
-
- void attach(Observer& observer)
- {
- ASSERT_MESSAGE(!m_observerMutex, "observer cannot be attached during iteration");
- m_observers.insert(&observer);
- for(KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i)
- {
- observer.insert((*i).first.c_str(), *(*i).second);
- }
- }
- void detach(Observer& observer)
- {
- ASSERT_MESSAGE(!m_observerMutex, "observer cannot be detached during iteration");
- m_observers.erase(&observer);
- for(KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i)
- {
- observer.erase((*i).first.c_str(), *(*i).second);
- }
- }
-
- void forEachKeyValue_instanceAttach(MapFile* map)
- {
- for(KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i)
- {
- (*i).second->instanceAttach(map);
- }
- }
- void forEachKeyValue_instanceDetach(MapFile* map)
- {
- for(KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i)
- {
- (*i).second->instanceDetach(map);
- }
- }
-
- void instanceAttach(MapFile* map)
- {
- if(m_counter != 0)
- {
- m_counter->increment();
- }
-
- m_instanced = true;
- forEachKeyValue_instanceAttach(map);
- m_undo.instanceAttach(map);
- }
- void instanceDetach(MapFile* map)
- {
- if(m_counter != 0)
- {
- m_counter->decrement();
- }
-
- m_undo.instanceDetach(map);
- forEachKeyValue_instanceDetach(map);
- m_instanced = false;
- }
-
- // entity
- EntityClass& getEntityClass() const
- {
- return *m_eclass;
- }
- void forEachKeyValue(Visitor& visitor) const
- {
- for(KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i)
- {
- visitor.visit((*i).first.c_str(), (*i).second->c_str());
- }
- }
- void setKeyValue(const char* key, const char* value)
- {
- if(value[0] == '\0'
- /*|| string_equal(EntityClass_valueForKey(*m_eclass, key), value)*/) // don't delete values equal to default
- {
- erase(key);
- }
- else
- {
- insert(key, value);
- }
- m_entityKeyValueChanged();
- }
- const char* getKeyValue(const char* key) const
- {
- KeyValues::const_iterator i = m_keyValues.find(key);
- if(i != m_keyValues.end())
- {
- return (*i).second->c_str();
- }
-
- return EntityClass_valueForKey(*m_eclass, key);
- }
-
- bool isContainer() const
- {
- return m_isContainer;
- }
+ bool m_isContainer;
+
+ EntityKeyValues( EntityClass* eclass ) :
+ m_eclass( eclass ),
+ m_undo( m_keyValues, UndoImportCaller( *this ) ),
+ m_instanced( false ),
+ m_observerMutex( false ),
+ m_isContainer( !eclass->fixedsize ){
+ }
+ EntityKeyValues( const EntityKeyValues& other ) :
+ Entity( other ),
+ m_eclass( &other.getEntityClass() ),
+ m_undo( m_keyValues, UndoImportCaller( *this ) ),
+ m_instanced( false ),
+ m_observerMutex( false ),
+ m_isContainer( other.m_isContainer ){
+ for ( KeyValues::const_iterator i = other.m_keyValues.begin(); i != other.m_keyValues.end(); ++i )
+ {
+ insert( ( *i ).first.c_str(), ( *i ).second->c_str() );
+ }
+ }
+ ~EntityKeyValues(){
+ for ( Observers::iterator i = m_observers.begin(); i != m_observers.end(); )
+ {
+ // post-increment to allow current element to be removed safely
+ ( *i++ )->clear();
+ }
+ ASSERT_MESSAGE( m_observers.empty(), "EntityKeyValues::~EntityKeyValues: observers still attached" );
+ }
+
+ static void setKeyValueChangedFunc( EntityCreator::KeyValueChangedFunc func ){
+ m_entityKeyValueChanged = func;
+ KeyValue::setKeyValueChangedFunc( func );
+ }
+ static void setCounter( Counter* counter ){
+ m_counter = counter;
+ }
+
+ void importState( const KeyValues& keyValues ){
+ for ( KeyValues::iterator i = m_keyValues.begin(); i != m_keyValues.end(); )
+ {
+ erase( i++ );
+ }
+
+ for ( KeyValues::const_iterator i = keyValues.begin(); i != keyValues.end(); ++i )
+ {
+ insert( ( *i ).first.c_str(), ( *i ).second );
+ }
+
+ m_entityKeyValueChanged();
+ }
+ typedef MemberCaller<EntityKeyValues, void(const KeyValues&), &EntityKeyValues::importState> UndoImportCaller;
+
+ void attach( Observer& observer ){
+ ASSERT_MESSAGE( !m_observerMutex, "observer cannot be attached during iteration" );
+ m_observers.insert( &observer );
+ for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
+ {
+ observer.insert( ( *i ).first.c_str(), *( *i ).second );
+ }
+ }
+ void detach( Observer& observer ){
+ ASSERT_MESSAGE( !m_observerMutex, "observer cannot be detached during iteration" );
+ m_observers.erase( &observer );
+ for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
+ {
+ observer.erase( ( *i ).first.c_str(), *( *i ).second );
+ }
+ }
+
+ void forEachKeyValue_instanceAttach( MapFile* map ){
+ for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
+ {
+ ( *i ).second->instanceAttach( map );
+ }
+ }
+ void forEachKeyValue_instanceDetach( MapFile* map ){
+ for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
+ {
+ ( *i ).second->instanceDetach( map );
+ }
+ }
+
+ void instanceAttach( MapFile* map ){
+ if ( m_counter != 0 ) {
+ m_counter->increment();
+ }
+
+ m_instanced = true;
+ forEachKeyValue_instanceAttach( map );
+ m_undo.instanceAttach( map );
+ }
+ void instanceDetach( MapFile* map ){
+ if ( m_counter != 0 ) {
+ m_counter->decrement();
+ }
+
+ m_undo.instanceDetach( map );
+ forEachKeyValue_instanceDetach( map );
+ m_instanced = false;
+ }
+
+ // entity
+ EntityClass& getEntityClass() const {
+ return *m_eclass;
+ }
+ void forEachKeyValue( Visitor& visitor ) const {
+ for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
+ {
+ visitor.visit( ( *i ).first.c_str(), ( *i ).second->c_str() );
+ }
+ }
+ void setKeyValue( const char* key, const char* value ){
+ if ( value[0] == '\0'
+ /*|| string_equal(EntityClass_valueForKey(*m_eclass, key), value)*/ ) { // don't delete values equal to default
+ erase( key );
+ }
+ else
+ {
+ insert( key, value );
+ }
+ m_entityKeyValueChanged();
+ }
+ const char* getKeyValue( const char* key ) const {
+ KeyValues::const_iterator i = m_keyValues.find( key );
+ if ( i != m_keyValues.end() ) {
+ return ( *i ).second->c_str();
+ }
+
+ return EntityClass_valueForKey( *m_eclass, key );
+ }
+
+ bool isContainer() const {
+ return m_isContainer;
+ }