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()));
291 if constexpr (!Derived::isObjectTrackingSupported::value) {
297 else if constexpr (std::is_base_of<mira::Object, T>::value) {
301 return this->
template isReflectedAsPointer<T>();
354 if(!this->
template isTrackingEnabled<T>())
355 MIRA_THROW(XRuntime,
"Cannot use a reference for the object with id'" 356 << objectId <<
"' where object tracking is disabled");
360 if((std::size_t)objectId>=
mObjects.size())
361 MIRA_THROW(XRuntime,
"Unresolved reference to unknown object with id '" 364 return serialization::void_downcast<T>(
mObjects[objectId]);
376 if(!this->
template isTrackingEnabled<T>())
377 MIRA_THROW(XRuntime,
"Cannot use a reference for the object '" 378 << fullId <<
"' where object tracking is disabled");
381 MIRA_THROW(XLogical,
"Cannot use a reference for the object '" 382 << fullId <<
"' since Deserializer does not support " 383 "human readable IDs");
388 MIRA_THROW(XRuntime,
"Unresolved reference to unknown object '" 391 return serialization::void_downcast<T>(it->second);
401 assert(this->
template isTrackingEnabled<T>());
409 mObjectNameToInstance.emplace(fullId,
pointer);
TypeId typeId()
Generates unique IDs for different types.
Definition: TypeId.h:94
StdSharedPointerMap mStdSharedPointers
Definition: Deserializer.h:337
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:352
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:320
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:490
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:883
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:311
std::map< std::string, void * > ObjectNameToInstanceMap
Definition: Deserializer.h:307
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
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:479
std::pair< ObjectsVector, ObjectNameToInstanceMap > TrackingState
Definition: Deserializer.h:315
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:336
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:387
ObjectNameToInstanceMap mObjectNameToInstance
maps full id names to instance pointers
Definition: Deserializer.h:309
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:372
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:333
boost::mpl::bool_< true > isObjectTrackingSupported
Definition: Deserializer.h:105
ObjectsVector mObjects
maps the ids to the instance pointers
Definition: Deserializer.h:313
void popObjectTrackingStore()
Definition: Deserializer.h:325
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:334
void pointer(T *&pointer)
Is called if the member is a pointer.
Definition: RecursiveMemberReflector.h:345
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:316
The RecursiveMemberReflector extents the RecursiveMemberReflectorBase class and implements the member...
Definition: RecursiveMemberReflector.h:874
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:374