47 #ifndef _MIRA_SERIALIZER_H_ 48 #define _MIRA_SERIALIZER_H_ 54 #include <boost/type_traits/is_fundamental.hpp> 55 #include <boost/type_traits/is_pointer.hpp> 125 template <
typename Derived>
163 bool acceptDesiredVersion =
false) {
168 if (!acceptDesiredVersion && it->second !=
version) {
170 "': " << (int)(it->second) <<
", but desiring a version " 171 "is not supported by the type's serialization. " 172 "Using type's current version " << (int)
version <<
" instead.";
178 "': " << (int)(it->second) <<
", but current version " 179 "(=maximum implemented version) is: " << (int)
version <<
180 ". Using that current version instead.";
187 template <
typename T>
189 bool acceptDesiredVersion =
false) {
203 template <
typename T>
205 const std::string& comment=
"")
215 T& value_const =
const_cast<T&
>(value);
216 this->
This()->member(name.c_str(), value_const, comment.c_str());
227 if(this->
template isTrackingEnabled<T>())
240 static_assert(!boost::is_fundamental<T>::value,
241 "Pointers on fundamental types cannot be serialized");
248 static_assert(!boost::is_pointer<T>::value,
249 "Pointers on pointers cannot be serialized");
253 this->
This()->pointerNull();
266 this->
This()->pointerWithoutClassType();
295 static_assert(
sizeof(T)==0,
"You tried to serialize an abstract class " 296 "that is not an mira::Object");
351 return Derived::isObjectTrackingSupported::value &&
353 (this->
template isReflectedAsPointer<T>() ||
354 std::is_base_of<mira::Object, T>::value);
403 address(iAddress),
type(iType) {}
407 assert(address != NULL);
459 std::map<int, std::string>::const_iterator it =
mObjectIDToName.find(objectID);
473 if(this->
template isTrackingEnabled<T>()) {
476 typename ObjectSet::iterator i =
mObjects.find(o);
480 this->
This()->pointerReference(i->objectID);
493 assert(this->
template isTrackingEnabled<T>());
500 std::pair<typename ObjectSet::const_iterator, bool> res =
mObjects.insert(o);
507 std::string objectName = meta.getName();
511 MIRA_THROW(XIO,
"Pointer conflict: the object '" << objectName <<
512 "' at address " << &
member <<
513 " was serialized already (probably by a pointer). " 514 "Try to resolve this conflict by serializing the " 515 "object BEFORE the pointer that points to that " 521 mObjectIDToName.insert(std::make_pair(o.objectID, this->getCurrentMemberFullID()));
TypeId typeId()
Generates unique IDs for different types.
Definition: TypeId.h:94
void desireClassVersions(const ClassVersionMap &versions)
implements ReflectorInterface (for documentation see ReflectorInterface)
Definition: Serializer.h:158
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
void pointerAbstract(T *&pointer, int typeId)
Definition: Serializer.h:288
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 popObjectTrackingStore()
Definition: Serializer.h:443
serialization::ClassVersionMap ClassVersionMap
Definition: ReflectorInterface.h:294
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
AObject & operator=(const AObject &rhs)
Definition: Serializer.h:418
ObjectSet mObjects
Definition: Serializer.h:428
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
const std::string & getHumanReadableFullID(int objectID) const
Returns the full human readable object id / name for the given internal objectID. ...
Definition: Serializer.h:456
Is a special reflector that is used for serialization.
Definition: Serializer.h:126
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::set< AObject > ObjectSet
Definition: Serializer.h:427
boost::mpl::bool_< true > isObjectTrackingSupported
Definition: Serializer.h:133
std::map< int, std::string > ObjectIDToNameMap
Definition: Serializer.h:430
ClassVersionMap mDesiredClassVersions
Definition: Serializer.h:193
void serialize(const std::string &name, const T &value, const std::string &comment="")
Serializes the specified object value under the given name.
Definition: Serializer.h:204
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
void pointerWithoutClassType()
Is called if a pointer points to a non-polymorphic type and hence the object can be stored without sp...
Definition: Serializer.h:329
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
VersionType queryDesiredClassVersion(VersionType version, bool acceptDesiredVersion=false)
Definition: Serializer.h:188
Abstract base class for most Reflectors.
Definition: AbstractReflector.h:160
int objectID
Definition: Serializer.h:400
static bool usesHumanReadableIDs()
Returns true, if the concrete derived Reflector supports human readable IDs.
Definition: ReflectorInterface.h:801
Is used to store the type and the address of all previously serialized objects in a map...
Definition: Serializer.h:396
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
bool isTrackingEnabled() const
Returns true, if object tracking is enabled for the type T.
Definition: Serializer.h:350
Serializer()
The constructor.
Definition: Serializer.h:138
AObject(void *iAddress, int iType)
Definition: Serializer.h:402
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::pair< ObjectSet, ObjectIDToNameMap > TrackingState
Definition: Serializer.h:433
void pointerPolymorphic(T *&pointer, int typeId)
Definition: Serializer.h:273
boost::mpl::bool_< true > isReadOnly
Definition: Serializer.h:132
void trackObject(T &member)
Definition: Serializer.h:224
int type
Definition: Serializer.h:399
void pointerNormal(T *&pointer, int typeId)
Definition: Serializer.h:261
virtual std::string const & getIdentifier() const
Return identifier for the class.
void pushObjectTrackingStore()
Definition: Serializer.h:438
std::stack< TrackingState > mTrackingStack
Definition: Serializer.h:434
Base::VersionType VersionType
Definition: Serializer.h:154
typename ReflectorInterface< ConcreteBinarySerializer< mira::BinaryOstream, BinaryFormatVersion, false > >::VersionType VersionType
Definition: AbstractReflector.h:165
static int forcedSerializeVersion()
Returns either the version number from value of environment variable 'MIRA_FORCE_SERIALIZE_VERSION', or -1 (= do not force a version).
Definition: Serializer.h:145
ObjectIDToNameMap mObjectIDToName
Definition: Serializer.h:431
void pointer(T *&pointer)
Definition: Serializer.h:232
Definition: LoggingCore.h:76
void pointerWithClassType(const std::string &type)
Is called if a pointer points to a polymorphic type and hence the object must be stored with specifyi...
Definition: Serializer.h:340
bool operator<(const AObject &rhs) const
Definition: Serializer.h:405
void pointer(T *&pointer)
Is called if the member is a pointer.
Definition: RecursiveMemberReflector.h:325
Base::ClassVersionMap ClassVersionMap
Definition: Serializer.h:155
void pointerNull()
Is called by the pointer() method to indicate that a pointer that is to be serialized is a NULL-point...
Definition: Serializer.h:317
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 * address
Definition: Serializer.h:398
void pointerReference(int referencedObjectID)
Is called by the pointer() method if an object, a pointer references, was already serialized and a re...
Definition: Serializer.h:308
VersionType queryDesiredClassVersion(VersionType version, const std::string &type, bool acceptDesiredVersion=false)
Definition: Serializer.h:162