29 #ifndef Pt_SerializationContext_h
30 #define Pt_SerializationContext_h
33 #include <Pt/TypeInfo.h>
34 #include <Pt/FixupInfo.h>
35 #include <Pt/SerializationInfo.h>
36 #include <Pt/SerializationSurrogate.h>
42 class SerializationContextImpl;
48 SerializationContext();
50 virtual ~SerializationContext();
52 inline void enableReferencing(
bool enabled)
53 { _refsEnabled = enabled; }
55 inline bool isReferencing()
const
56 {
return _refsEnabled; }
63 void registerSurrogate(
const std::string& typeName,
68 void registerSurrogate(
const char* typeName,
79 const BasicSerializationSurrogate<T>* getSurrogate()
const;
83 friend const BasicSerializationSurrogate<T>* getSurrogate(SerializationContext*);
85 const SerializationSurrogate* getSurrogate(
const std::type_info& ti)
const;
91 bool beginSave(
const void* p,
const char* name)
92 {
return onBeginSave(p, name); }
97 void prepareId(
const void* p)
100 const char* getId(
const void* p)
101 {
return onGetId(p); }
103 const char* makeId(
const void* p)
104 {
return onMakeId(p); }
107 void beginLoad(
void* obj,
const std::type_info& ti,
108 const char* name,
const char*
id)
109 { onBeginLoad(obj, ti, name,
id); }
114 void rebindTarget(
const char*
id,
void* obj)
115 { onRebindTarget(
id, obj); }
117 void rebindFixup(
const char*
id,
void* obj,
void* prev)
118 { onRebindFixup(
id, obj, prev); }
120 void prepareFixup(
void* obj,
const char*
id, FixupInfo::FixupHandler fh,
unsigned mid)
121 { onPrepareFixup(obj,
id, fh, mid); }
127 virtual void onClear();
129 virtual bool onBeginSave(
const void* p,
const char* name);
131 virtual void onFinishSave();
133 virtual void onPrepareId(
const void* p);
135 virtual const char* onGetId(
const void* p);
137 virtual const char* onMakeId(
const void* p);
139 virtual void onBeginLoad(
void* obj,
const std::type_info& fixupInfo,
140 const char* name,
const char*
id);
142 virtual void onFinishLoad();
144 virtual void onRebindTarget(
const char*
id,
void* obj);
146 virtual void onRebindFixup(
const char*
id,
void* obj,
void* prev);
148 virtual void onPrepareFixup(
void* obj,
const char*
id, FixupInfo::FixupHandler fh,
unsigned mid);
150 virtual void onFixup();
153 void registerSurrogate(
const std::type_info& ti, SerializationSurrogate* surrogate);
155 SerializationContext(
const SerializationContext& );
157 SerializationContext& operator=(
const SerializationContext& );
160 SerializationContextImpl* _cache;
165 template <
typename T>
168 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
172 surr->compose(si, type);
177 template <
typename T>
180 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
184 surr->decompose(si, type);
190 template <
typename T>
193 const SerializationSurrogate* surr = this->
getSurrogate(
typeid(T) );
197 return static_cast<const BasicSerializationSurrogate<T>*
>(surr);
201 template <
typename T>
206 SerializationSurrogate* surr =
new BasicSerializationSurrogate<T>(typeName,
compose,
decompose);
211 template <
typename T>
216 SerializationSurrogate* surr =
new BasicSerializationSurrogate<T>(typeName,
compose,
decompose);
222 #endif // Pt_SerializationContext_h
const BasicSerializationSurrogate< T > * getSurrogate() const
Find a surrogate for a type.
Definition: SerializationContext.h:191
bool compose(const SerializationInfo &si, T &type) const
Returns true if the type could be composed with a surrogate.
Definition: SerializationContext.h:166
void registerSurrogate(const std::string &typeName, void(*compose)(const Pt::SerializationInfo &si, T &type), void(*decompose)(Pt::SerializationInfo &si, const T &type))
Register a serialization surrogate function pair.
Definition: SerializationContext.h:202
Represents arbitrary types during serialization.
Definition: SerializationInfo.h:58
bool decompose(SerializationInfo &si, const T &type)
Returns true if the type could be decomposed with a surrogate.
Definition: SerializationContext.h:178
void setTypeName(const std::string &type)
Sets the type name.