47 #ifndef _MIRA_DESERIALIZER_H_ 48 #define _MIRA_DESERIALIZER_H_ 98 template <
typename Derived>
132 template <
typename T>
143 this->
This()->member(name.c_str(), value,
"");
152 if(this->
template isTrackingEnabled<T>())
165 static_assert(!boost::is_fundamental<T>::value,
166 "Pointers on fundamental types cannot be serialized");
173 static_assert(!boost::is_pointer<T>::value,
174 "Pointers on pointers cannot be serialized");
201 std::string
type = this->
This()->pointerClassType();
204 pointer = T::CLASS().newInstance(
type);
207 MIRA_THROW(XIO,
"Cannot deserialize the polymorphic member pointer '" 208 << meta.
getName() <<
"'. The specified class '" <<
type 209 <<
"' is not known to the class factory.");
231 static_assert(
sizeof(T)==0,
"You tried to deserialize an abstract " 232 "class that is not an mira::Object");
256 template<
template<
class>
class SType,
class T>
258 SType<void> >& pointerMap)
269 TwithoutConst* rawConstFreePtr =
const_cast<TwithoutConst*
>(rawPtr);
271 void* p =
static_cast<void*
>(rawConstFreePtr);
272 auto it = pointerMap.find(p);
273 if(it==pointerMap.end()) {
277 SType<void> voidptr(ptr, p);
278 pointerMap.insert(std::make_pair(p, voidptr));
281 ptr = SType<T>(it->second,
static_cast<T*
>(it->second.get()));
290 return Derived::isObjectTrackingSupported::value &&
292 (this->
template isReflectedAsPointer<T>() ||
293 std::is_base_of<mira::Object, T>::value);
345 if(!this->
template isTrackingEnabled<T>())
346 MIRA_THROW(XRuntime,
"Cannot use a reference for the object with id'" 347 << objectId <<
"' where object tracking is disabled");
351 if((std::size_t)objectId>=
mObjects.size())
352 MIRA_THROW(XRuntime,
"Unresolved reference to unknown object with id '" 355 return serialization::void_downcast<T>(
mObjects[objectId]);
367 if(!this->
template isTrackingEnabled<T>())
368 MIRA_THROW(XRuntime,
"Cannot use a reference for the object '" 369 << fullId <<
"' where object tracking is disabled");
372 MIRA_THROW(XLogical,
"Cannot use a reference for the object '" 373 << fullId <<
"' since Deserializer does not support " 374 "human readable IDs");
379 MIRA_THROW(XRuntime,
"Unresolved reference to unknown object '" 382 return serialization::void_downcast<T>(it->second);
392 assert(this->
template isTrackingEnabled<T>());
400 mObjectNameToInstance.insert(std::make_pair(fullId,
pointer));
TypeId typeId()
Generates unique IDs for different types.
Definition: TypeId.h:94
StdSharedPointerMap mStdSharedPointers
Definition: Deserializer.h:328
static int checkForcedVersion(const std::string &variable)
Definition: ReflectorInterface.h:841
Type trait that indicates whether pointer tracking can be enabled for this type.
Definition: IsObjectTrackable.h:68
T * resolveReference(int objectId)
Resolves a pointer reference to a previously stored object with the specified full id...
Definition: Deserializer.h:343
VersionType version(VersionType version, const T *caller=NULL)
Specifies the current class version and returns the version found in the data stream.
Definition: ReflectorInterface.h:242
void sharedPointerReset(std::shared_ptr< T > &ptr, T *rawPtr)
Definition: Deserializer.h:251
bool isTrackingEnabled() const
Returns true, if object tracking is enabled for the type T.
Definition: Deserializer.h:289
void pointer(T *&pointer)
Definition: Deserializer.h:157
void deserialize(const std::string &name, T &value)
Deserializes the specified object value with the given name.
Definition: Deserializer.h:133
boost::mpl::bool_< false > isReadOnly
Definition: Deserializer.h:104
void pushObjectTrackingStore()
Definition: Deserializer.h:311
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
const std::string & getCurrentMemberFullID() const
Returns the full human readable object id / name of the current member being reflected.
Definition: RecursiveMemberReflector.h:470
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:862
void pointerAbstract(T *&pointer, int typeId)
Definition: Deserializer.h:224
static int forcedDeserializeVersion()
Returns either the version number from value of environment variable 'MIRA_FORCE_DESERIALIZE_VERSION'...
Definition: Deserializer.h:118
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::vector< void * > ObjectsVector
Definition: Deserializer.h:302
std::map< std::string, void * > ObjectNameToInstanceMap
Definition: Deserializer.h:298
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Derived * This()
"Curiously recurring template pattern" (CRTP).
Definition: AbstractReflector.h:246
const ReflectMemberMeta & getCurrentMemberMeta() const
Returns the meta-information of the current member that is reflected.
Definition: RecursiveMemberReflector.h:459
std::pair< ObjectsVector, ObjectNameToInstanceMap > TrackingState
Definition: Deserializer.h:306
static bool usesHumanReadableIDs()
Returns true, if the concrete derived Reflector supports human readable IDs.
Definition: ReflectorInterface.h:801
std::map< void *, std::shared_ptr< void > > StdSharedPointerMap
Definition: Deserializer.h:327
void pointerPolymorphic(T *&pointer, int typeId)
Is called if a reflected pointer is a polymorphic pointer to an object that is derived from mira::Obj...
Definition: RecursiveMemberReflector.h:367
ObjectNameToInstanceMap mObjectNameToInstance
maps full id names to instance pointers
Definition: Deserializer.h:300
void sharedPointerReset(boost::shared_ptr< T > &ptr, T *rawPtr)
Definition: Deserializer.h:245
void pointerNormal(T *&pointer, int typeId)
Is called if a reflected pointer is a "normal" pointer.
Definition: RecursiveMemberReflector.h:352
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
std::map< void *, boost::shared_ptr< void > > BoostSharedPointerMap
Definition: Deserializer.h:324
boost::mpl::bool_< true > isObjectTrackingSupported
Definition: Deserializer.h:105
ObjectsVector mObjects
maps the ids to the instance pointers
Definition: Deserializer.h:304
void popObjectTrackingStore()
Definition: Deserializer.h:316
void sharedPointerReset(SType< T > &ptr, T *rawPtr, std::map< void *, SType< void > > &pointerMap)
Definition: Deserializer.h:257
void trackObject(T &member)
Definition: Deserializer.h:149
BoostSharedPointerMap mBoostSharedPointers
Definition: Deserializer.h:325
void pointer(T *&pointer)
Is called if the member is a pointer.
Definition: RecursiveMemberReflector.h:325
std::string pointerClassType()
Must be overwritten from the concrete deserializer and is called if the pointer that is deserialized ...
Definition: Deserializer.h:242
void pointerPolymorphic(T *&pointer, int typeId)
Definition: Deserializer.h:193
Deserializer()
The constructor.
Definition: Deserializer.h:111
std::stack< TrackingState > mTrackingStack
Definition: Deserializer.h:307
The RecursiveMemberReflector extents the RecursiveMemberReflectorBase class and implements the member...
Definition: RecursiveMemberReflector.h:853
void * void_upcast(T *pointer)
Safe cast for casting from a pointer upwards to void* while taking care of polymorphism and multiple ...
Definition: VoidCast.h:108
void pointerNormal(T *&pointer, int typeId)
Definition: Deserializer.h:183
Is a special reflector that is used for deserialization.
Definition: Deserializer.h:99
virtual int getTypeId() const =0
Return unique id for the class.
T * resolveReference(const std::string &fullId)
Same as the above method, but here the object id can be specified as full human readable id...
Definition: Deserializer.h:365