Thinker *Thinker::Unserialize(LArchive &a) { unsigned id; a << id; void *v = NULL; if (a.GetPtr(id, v)) return static_cast<Thinker*>(v); // already unserialized, just return the appropriate pointer // not unserialized yet, so let's do it now: unsigned type; a << type; TypeInfo *t = TypeInfo::Find(type); if (!t) { return NULL; // TODO: How to handle errors? using exceptions? } Thinker *p = t->factory(); a.SetPtr(id, p); // order is important: consider the case a -> b -> a, where -> is a pointer p->mp = a.active_map; // a small kludge, some Marshal functions need to have a valid Map* p->Marshal(a); return p; }