inline void serializeRefCountedSmartPtr(SmartPtrT **ppt, SF::Archive &ar) { if (ar.isRead()) { if (ar.isFlagSet(Archive::POINTER)) { *ppt = new SmartPtrT; } T *pt = NULL; ar & pt; ContextRead &ctx = ar.getIstream()->getTrackingContext(); if (!ctx.getEnabled()) { // No pointer tracking. **ppt = SmartPtrT(pt); } else { // Pointer tracking enabled, so some extra gymnastics involved. void *pv = NULL; if (pt && ctx.getEnabled() && ctx.query((void *)pt, typeid(SmartPtrT), pv)) { SmartPtrT *ps_prev = reinterpret_cast<SmartPtrT *>(pv); **ppt = *ps_prev; } else if (pt) { if (ctx.getEnabled()) { ctx.add((void *)pt, typeid(SmartPtrT), *ppt); } **ppt = SmartPtrT(pt); } } } else /*if (ar.isWrite())*/ { T *pt = NULL; if (*ppt) { pt = (**ppt).get(); } ar & pt; } }
inline void serializeSimpleSmartPtr(SmartPtrT **ppt, SF::Archive &ar) { if (ar.isRead()) { if (ar.isFlagSet(Archive::POINTER)) { *ppt = new SmartPtrT(); } T *pt = NULL; ar & pt; (**ppt).reset(pt); } else if (ar.isWrite()) { T *pt = NULL; if (*ppt && (**ppt).get()) { pt = (**ppt).operator->(); } ar & pt; } }