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");
352 if constexpr (!Derived::isObjectTrackingSupported::value) {
358 else if constexpr (std::is_base_of<mira::Object, T>::value) {
362 return this->
template isReflectedAsPointer<T>();
412 address(iAddress),
type(iType) {}
416 assert(address != NULL);
468 std::map<int, std::string>::const_iterator it =
mObjectIDToName.find(objectID);
482 if(this->
template isTrackingEnabled<T>()) {
485 typename ObjectSet::iterator i =
mObjects.find(o);
489 this->
This()->pointerReference(i->objectID);
502 assert(this->
template isTrackingEnabled<T>());
516 std::string objectName = meta.getName();
520 MIRA_THROW(XIO,
"Pointer conflict: the object '" << objectName <<
521 "' at address " << &
member <<
522 " was serialized already (probably by a pointer). " 523 "Try to resolve this conflict by serializing the " 524 "object BEFORE the pointer that points to that " 530 mObjectIDToName.emplace(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:452
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:427
ObjectSet mObjects
Definition: Serializer.h:437
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
const std::string & getHumanReadableFullID(int objectID) const
Returns the full human readable object id / name for the given internal objectID. ...
Definition: Serializer.h:465
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:436
boost::mpl::bool_< true > isObjectTrackingSupported
Definition: Serializer.h:133
std::map< int, std::string > ObjectIDToNameMap
Definition: Serializer.h:439
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:78
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:479
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:409
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:405
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
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:411
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::pair< ObjectSet, ObjectIDToNameMap > TrackingState
Definition: Serializer.h:442
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:408
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:447
std::stack< TrackingState > mTrackingStack
Definition: Serializer.h:443
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:440
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:414
void pointer(T *&pointer)
Is called if the member is a pointer.
Definition: RecursiveMemberReflector.h:345
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: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 * address
Definition: Serializer.h:407
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