#include "math/vector.h"
#include "math/aabb.h"
#include "undolib.h"
-#include "string/string.h"
+#include "string/pooledstring.h"
#include "generic/referencecounted.h"
#include "scenelib.h"
#include "container/container.h"
};
-typedef Callback1<const char*> KeyObserver;
-
/// \brief A key/value pair of strings.
///
/// - Notifies observers when value changes - value changes to "" on destruction.
/// - Provides undo support through the global undo system.
-class KeyValue
+class KeyValue : public EntityKeyValue
{
typedef UnsortedSet<KeyObserver> KeyObservers;
public:
typedef KeyValue Value;
- class Observer
+ static StringPool& getPool()
{
- public:
- virtual void insert(const char* key, Value& value) = 0;
- virtual void erase(const char* key, Value& value) = 0;
- };
-
+ return Static<StringPool, KeyContext>::instance();
+ }
private:
static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged;
static Counter* m_counter;
EntityClass* m_eclass;
+ class KeyContext{};
+ typedef Static<StringPool, KeyContext> KeyPool;
+ typedef PooledString<KeyPool> Key;
typedef SmartPointer<KeyValue> KeyValuePtr;
- typedef UnsortedMap<CopiedString, KeyValuePtr > KeyValues;
+ typedef UnsortedMap<Key, KeyValuePtr> KeyValues;
KeyValues m_keyValues;
typedef UnsortedSet<Observer*> Observers;
(*i).second->instanceDetach(m_undo.map());
}
- CopiedString key((*i).first);
+ Key key((*i).first);
KeyValuePtr value((*i).second);
m_keyValues.erase(i);
notifyErase(key.c_str(), *value);
}
~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");
}