bool hasConfig = persistentObject->Contains("configTx");
Dictionary::Ptr update = persistentObject->Get("update");
- if (hasConfig) {
+ if (hasConfig && ClassExists(type)) {
DynamicObject::Ptr object = Create(type, update);
object->Register();
} else {
type + "': Objects of this type already exist."));
GetClasses()[type] = factory;
+
+ /* restore persistent objects that match the newly-registered class */
+ map<pair<String, String>, Dictionary::Ptr>::iterator prev, st;
+ for (st = m_PersistentUpdates.begin(); st != m_PersistentUpdates.end(); st++)
+ {
+ /* check type of the update */
+ if (st->first.first != type) {
+ st++;
+ continue;
+ }
+
+ Dictionary::Ptr update = st->second;
+ bool hasConfig = update->Contains("configTx");
+ if (!hasConfig) {
+ st++;
+ continue;
+ }
+
+ DynamicObject::Ptr object = Create(type, update);
+ object->Register();
+
+ prev = st;
+ st++;
+ m_PersistentUpdates.erase(prev);
+ }
+
+}
+
+bool DynamicObject::ClassExists(const String& type)
+{
+ return (GetClasses().find(type) != GetClasses().end());
}
DynamicObject::Ptr DynamicObject::Create(const String& type, const Dictionary::Ptr& serializedUpdate)
}
void DynamicObject::OnAttributeChanged(const String& name, const Value& oldValue)
-{ }
\ No newline at end of file
+{ }
static void RestoreObjects(const String& filename);
static void RegisterClass(const String& type, Factory factory);
+ static bool ClassExists(const String& type);
static DynamicObject::Ptr Create(const String& type, const Dictionary::Ptr& serializedUpdate);
static double GetCurrentTx(void);