47 #ifndef _MIRA_RECURSIVEMEMBERREFLECTOR_H_ 48 #define _MIRA_RECURSIVEMEMBERREFLECTOR_H_ 50 #include <type_traits> 80 namespace serialization {
95 template <
typename T,
typename Reflector>
101 template <
typename T,
typename Reflector>
127 friend class ClassFactoryDefaultConstClassBuilder;
132 XMemberNotFound(ex) {}
134 void raise(
bool recursive =
false)
override 232 template <
typename Derived>
240 mCurrentMemberMeta(nullptr) {}
282 if(Derived::isReadOnly::value) {
283 auto val =
static_cast<int32
>(
member);
284 this->
This()->atomic(val);
287 this->
This()->atomic(val);
288 member =
static_cast<T
>(val);
302 this->
This()->invoke(member);
312 this->
This()->object(member);
333 if constexpr (std::is_base_of_v<mira::Object, T>) {
336 else if constexpr (std::is_abstract_v<T>) {
355 this->
This()->invokePointerObject(*pointer);
373 typedef serialization::PolymorphicPointerReflectorRegistrar<Derived> OurRegistrar;
375 typename OurRegistrar::ReflectorRef r =
376 OurRegistrar::instance().getPolymorphicPointerReflector(
typeId);
381 catch (XPolymorphicPointerReflectorNotRegistered&) {
385 "Cannot reflect the polymorphic member pointer '" 387 <<
"' was not registered with this serializer '" << typeName<Derived>()
389 #ifndef MIRA_REGISTER_LEGACY_SERIALIZERS
390 <<
" (Registration with legacy serializers must be explicitly enabled" 391 " by activating the option REGISTER_LEGACY_SERIALIZERS" 392 " [GlobalConfig, requires recompilation])";
409 this->
This()->invokePointerObject(*pointer);
431 typedef serialization::PolymorphicPointerReflectorRegistrar<Derived> OurRegistrar;
433 if(!OurRegistrar::isDestroyed())
434 OurRegistrar::instance().template registerClass<T>();
450 typedef serialization::PolymorphicPointerReflectorRegistrar<Derived> OurRegistrar;
451 if(!OurRegistrar::isDestroyed())
452 OurRegistrar::instance().template unregisterClass<T>();
461 assert(mCurrentMemberMeta!=NULL);
462 return *mCurrentMemberMeta;
473 return mCurrentMemberFullID;
483 template <
typename T>
494 this->
This()->trackObject(member);
505 static_assert(
sizeof(T) == 0,
"Trying to reflect unknown type.");
512 this->
This()->invokeTrackObject(member);
513 this->
This()->atomic(member);
520 this->
This()->invokeTrackObject(member);
521 this->
This()->enumeration(member);
528 this->
This()->invokeTrackObject(member);
529 std::size_t size =
sizeof(
member)
530 / (static_cast<const char*>(static_cast<const void*>(&
member[1]))
531 -
static_cast<const char*
>(
static_cast<const void*
>(&
member[0])));
534 serialization::Array<ItemType> array(
member, size);
542 this->
This()->invokeTrackObject(member);
545 "Trying to call reflectComplex<T>() with IsCollection<T> == true " 546 "- something is wrong.");
548 this->
This()->invoke(member);
550 this->
This()->object(member);
557 this->
This()->invokeTrackObject(member);
560 static_assert(!isTransparent::value,
561 "Trying to call reflectCollection<T>() with IsTransparentSerializable<T> == " 562 "true - something is wrong.");
563 this->
This()->collection(member);
570 this->
This()->pointer(member);
579 this->
This()->pointerNormal(member, typeId<T>());
595 this->
This()->pointerPolymorphic(member,
typeId);
605 this->
This()->pointerAbstract(member, typeId<T>());
615 if constexpr (std::is_pointer_v<Type>) {
621 else if constexpr (std::is_class_v<Type>) {
629 else if constexpr (std::is_enum_v<Type>) {
632 else if constexpr (std::is_array_v<Type>) {
655 this->
This()->invokeMemberOverwrite(member, meta);
676 std::string prevFullID;
678 prevFullID = mCurrentMemberFullID;
681 if(mCurrentMemberFullID.empty()) {
683 MIRA_THROW(XLogical,
"Top-level member cannot be 'inline'. " 684 "It must have an ID != NULL!");
685 mCurrentMemberFullID=meta.
id;
686 }
else if(meta.
id!=
nullptr)
687 mCurrentMemberFullID = mCurrentMemberFullID +
"." + meta.
id;
692 if(meta.
id !=
nullptr)
693 mCurrentMemberMeta = &meta;
708 mCurrentMemberFullID=prevFullID;
710 mCurrentMemberMeta = prevMeta;
717 mCurrentMemberFullID=prevFullID;
719 mCurrentMemberMeta = prevMeta;
742 }
catch (XMemberNotFound& ex) {
752 (Derived::isReadOnly::value ?
"serializing" :
"deserializing") <<
753 " '" << meta.
getName() <<
"'");
762 template<
typename T,
typename U>
764 const U& defaultValue)
770 }
catch (XMemberNotFound&) {
771 if(!Derived::isReadOnly::value) {
773 "using the default value instead.";
792 (Derived::isReadOnly::value ?
"serializing" :
"deserializing") <<
793 " '" << meta.
getName() <<
"'");
811 }
catch (XMemberNotFound&) {
818 (Derived::isReadOnly::value ?
"serializing" :
"deserializing") <<
819 " '" << meta.
getName() <<
"'");
828 std::string mCurrentMemberFullID;
852 template <
typename Derived>
865 this->
This()->pushObjectTrackingStore();
867 this->
This()->popObjectTrackingStore();
876 this->
This()->pushObjectTrackingStore();
879 this->
This()->popObjectTrackingStore();
889 this->
This()->pushObjectTrackingStore();
891 this->
This()->popObjectTrackingStore();
898 this->
This()->pushObjectTrackingStore();
900 this->
This()->popObjectTrackingStore();
909 this->
template member<T, T>(name,
member, comment, defaultValue, flags);
912 template<
typename T,
typename U>
916 this->
This()->pushObjectTrackingStore();
919 this->
This()->popObjectTrackingStore();
928 const char* comment,
const T& defaultValue,
930 this->
template member<T, T>(name,
member,
setter, comment, defaultValue, flags);
933 template<
typename T,
typename U>
935 const char* comment,
const U& defaultValue,
938 this->
This()->pushObjectTrackingStore();
941 this->
This()->popObjectTrackingStore();
947 const char* comment,
const T& defaultValue,
949 this->
template member<T, T>(name,
getter,
setter, comment, defaultValue, flags);
952 template<
typename T,
typename U>
954 const char* comment,
const U& defaultValue,
957 this->
This()->pushObjectTrackingStore();
960 this->
This()->popObjectTrackingStore();
968 this->
This()->pushObjectTrackingStore();
970 this->
This()->popObjectTrackingStore();
980 this->
This()->pushObjectTrackingStore();
982 this->
This()->popObjectTrackingStore();
992 this->
This()->pushObjectTrackingStore();
994 this->
This()->popObjectTrackingStore();
1002 this->
This()->pushObjectTrackingStore();
1004 this->
This()->popObjectTrackingStore();
1008 template<
typename T>
1012 this->
template property<T, T>(name,
member, comment, defaultValue, std::move(hint), flags);
1015 template<
typename T,
typename U>
1020 this->
This()->pushObjectTrackingStore();
1023 this->
This()->popObjectTrackingStore();
1030 template<
typename T>
1032 const char* comment,
const T& defaultValue,
1035 this->
template property<T, T>(name,
member,
setter, comment, defaultValue, std::move(hint), flags);
1038 template<
typename T,
typename U>
1040 const char* comment,
const U& defaultValue,
1044 this->
This()->pushObjectTrackingStore();
1047 this->
This()->popObjectTrackingStore();
1051 template<
typename T>
1053 const char* comment,
const T& defaultValue,
1056 this->
template property<T, T>(name,
getter,
setter, comment, defaultValue, std::move(hint), flags);
1059 template<
typename T,
typename U>
1061 const char* comment,
const U& defaultValue,
1065 this->
This()->pushObjectTrackingStore();
1068 this->
This()->popObjectTrackingStore();
1077 template<
typename T>
1080 this->
This()->pushObjectTrackingStore();
1082 this->
This()->popObjectTrackingStore();
1093 template<
typename T>
1097 this->
This()->pushObjectTrackingStore();
1099 this->
This()->popObjectTrackingStore();
1108 template<
typename T>
1112 this->
This()->pushObjectTrackingStore();
1114 this->
This()->popObjectTrackingStore();
TypeId typeId()
Generates unique IDs for different types.
Definition: TypeId.h:94
This object can use object tracking internally, but the object tracking system's state remains unchan...
Definition: ReflectControlFlags.h:82
void reflectPointerAbstract(T *&member)
Type C3: for members that are pointers to abstract classes not derived from mira::Object.
Definition: RecursiveMemberReflector.h:603
Type trait that indicates whether pointer tracking can be enabled for this type.
Definition: IsObjectTrackable.h:68
void object(T &member)
Is called for each complex object.
Definition: RecursiveMemberReflector.h:301
ReflectedAsPointer()=default
Provides safe casts for casting from a pointer to void* and vice versa while taking care of polymorph...
void property(const char *name, T &member, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1016
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:998
void member(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:934
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void reflectPointerPolymorphic(T *&member)
Type C2: for members that are pointers to polymorphic classes derived from mira::Object.
Definition: RecursiveMemberReflector.h:584
void member(const char *name, const T &member, Setter< T > setter, const char *comment, const T &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:927
Abstract base class for most Reflectors.
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 property(const char *name, T &member, const char *comment, const T &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1009
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
void trackObject(T &member)
Definition: RecursiveMemberReflector.h:317
Class object which supports some kind of class reflection.
Definition: Class.h:97
#define MIRA_RETHROW(ex, msg)
Macro for rethrowing an exception with file and line information and for adding additional informatio...
Definition: Exception.h:148
Contains toString and fromString functions for converting data types to strings and the other way rou...
#define MIRA_DEFINE_SERIALIZABLE_EXCEPTION(Ex, Base)
Macro for easily defining a new serializable exception class.
Definition: Exceptions.h:66
Setter< T > setter(void(*f)(const T &))
Creates a Setter for global or static class methods taking the argument by const reference.
Definition: GetterSetter.h:443
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
Type trait that indicates whether a type can be serialized as an atomic value.
Definition: IsAtomicSerializable.h:83
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:964
Provided for convenience.
Definition: Singleton.h:564
void chooseReflect(T &member)
Detect the members type (A1,A2,A3,B1,B2,C) and choose the appropriate function.
Definition: RecursiveMemberReflector.h:612
Provides type trait that indicates whether a type should be serialized "transparently".
Provides type trait that indicates whether pointer/object tracking should be enabled for a certain ty...
Contains internal accessor class that abstracts from the underlying getter and setter classes or dire...
void invokeMemberWithDefault(T &member, const ReflectMemberMeta &meta, const U &defaultValue)
Delegates to invokeMember() and handles any occurring XMemberNotFound exception by setting the member...
Definition: RecursiveMemberReflector.h:763
void pointerAbstract(T *&pointer, int typeId)
Is called if a reflected pointer is a pointer to an abstract class.
Definition: RecursiveMemberReflector.h:406
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Marker for indicating parameters that should be ignored if they are missing in the config file...
void property(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1039
A property hint gives optional instructions to the property editor, i.e.
Definition: PropertyHint.h:82
Derived * This()
"Curiously recurring template pattern" (CRTP).
Definition: AbstractReflector.h:246
Wrapper class for reflecting arrays.
XMemberNotFound_NoDefault() MIRA_NOEXCEPT_OR_NOTHROW
Definition: RecursiveMemberReflector.h:128
const ReflectMemberMeta & getCurrentMemberMeta() const
Returns the meta-information of the current member that is reflected.
Definition: RecursiveMemberReflector.h:459
void property(const char *name, const std::string &id, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:976
Abstract base class for most Reflectors.
Definition: AbstractReflector.h:160
static bool usesHumanReadableIDs()
Returns true, if the concrete derived Reflector supports human readable IDs.
Definition: ReflectorInterface.h:801
Marker for indicating parameters that should be ignored if they are missing in the config file...
Definition: IgnoreMissing.h:73
Can be thrown by subclasses of RecursiveMemberReflectorBase to indicate that they did not find a cert...
Definition: RecursiveMemberReflector.h:123
$Header file containing base classes to enable class creation using a class factory$ ...
Implementation of the InstantiationPolicy that is used by the Singleton template. ...
Definition: Singleton.h:339
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
void delegate(Getter< T > getter, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Delegates the serialization directly to the specified member, without creating a separate compound fo...
Definition: RecursiveMemberReflector.h:1109
static bool isReflectedAsPointer()
For internal use only: Returns true, if the type T is ever reflected as pointer within the current tr...
Definition: RecursiveMemberReflector.h:484
SetReflectedAsPointer()
Definition: RecursiveMemberReflector.h:103
A singleton template class that can be freely configured using policies that control the instantiatio...
Definition: Singleton.h:531
void pointerNormal(T *&pointer, int typeId)
Is called if a reflected pointer is a "normal" pointer.
Definition: RecursiveMemberReflector.h:352
No flags.
Definition: ReflectControlFlags.h:65
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
void invokeTrackObject(T &member)
tracks the given object (if pointer tracking is enabled for type T)
Definition: RecursiveMemberReflector.h:491
void reflectPointer(T &member)
Type C: for members that are pointers.
Definition: RecursiveMemberReflector.h:568
Core class of the logging library.
void delegate(T &member, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Delegates the serialization directly to the specified member, without creating a separate compound fo...
Definition: RecursiveMemberReflector.h:1078
void reflectUnknown(T &member)
Definition: RecursiveMemberReflector.h:503
void invokePointerObject(T &member)
Is called to reflect objects of pointers.
Definition: RecursiveMemberReflector.h:727
bool value
Definition: RecursiveMemberReflector.h:98
void property(const char *name, const T &member, Setter< T > setter, const char *comment, const T &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1031
Getter< T > getter(T(*f)())
Creates a Getter for global or static class methods returning the result by value.
Definition: GetterSetter.h:136
The RecursiveMemberReflectorBase is a base class for all Reflectors that are used to visit the reflec...
Definition: RecursiveMemberReflector.h:233
static void unregisterClass()
Unregisters the class.
Definition: RecursiveMemberReflector.h:448
Provides type trait that indicates whether a type is a collection.
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1060
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const T &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1052
void invokeMemberWithoutDefault(T &member, const ReflectMemberMeta &meta)
Delegates to invokeMember() and rethrows any occurring XMemberNotFound exception as XIO exception...
Definition: RecursiveMemberReflector.h:738
void member(const char *name, T &member, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:913
virtual std::string const & getIdentifier() const
Return identifier for the class.
void member(const char *name, const std::string &id, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:873
RecursiveMemberReflectorBase()
The constructor.
Definition: RecursiveMemberReflector.h:239
#define MIRA_NOEXCEPT_OR_NOTHROW
Definition: NoExcept.h:99
#define MIRA_OBJECT(classIdentifier)
Use this MACRO if you like the factory to automatically extract the class name from the given identif...
Definition: FactoryMacros.h:179
XMemberNotFound_NoDefault(XMemberNotFound &ex) MIRA_NOEXCEPT_OR_NOTHROW
Definition: RecursiveMemberReflector.h:131
Implementation of the CreationPolicy that is used by the Singleton template.
Definition: Singleton.h:190
Base class for exceptions.
Definition: Exception.h:199
void member(const char *name, const T &member, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:886
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Specifies a class member for reflection/serialization.
Definition: ReflectorInterface.h:375
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
For internal use only: Holds value=true, if the type T is ever reflected as pointer with Reflector wi...
Definition: RecursiveMemberReflector.h:96
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const T &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:946
void invokeMember(T &member, const ReflectMemberMeta &meta)
Is called to invoke this Reflector on the member with the specified meta information.
Definition: RecursiveMemberReflector.h:653
Provides type trait that indicates whether a type can be serialized as atomic value.
void property(const char *name, const T &member, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:988
void pointer(T *&pointer)
Is called if the member is a pointer.
Definition: RecursiveMemberReflector.h:325
void delegate(const T &member, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Delegates the serialization directly to the specified member, without creating a separate compound fo...
Definition: RecursiveMemberReflector.h:1094
void reflectCollection(T &member)
Type B?c: for collection types.
Definition: RecursiveMemberReflector.h:555
static constexpr auto MIRA_REFLECTOR_TOPLEVEL_NAME
Use this when a reflector needs to choose a name for serializing an object.
Definition: RecursiveMemberReflector.h:249
void invokeMemberOverwrite(T &member, const ReflectMemberMeta &meta)
The actual invokeMember implementation that is called from invokeMember().
Definition: RecursiveMemberReflector.h:665
void enumeration(T &member)
Is called by the if the member is an enumeration.
Definition: RecursiveMemberReflector.h:281
ReflectCtrlFlags
Control Flags that can modify the behavior of certain reflectors.
Definition: ReflectControlFlags.h:63
void reflectEnumeration(T &member)
Type A2: for enums.
Definition: RecursiveMemberReflector.h:518
void collection(T &member)
Is called for each complex object or array, where the IsCollection<T> trait is true_type.
Definition: RecursiveMemberReflector.h:311
void reflectComplex(T &member)
Type B1/B2: for complex types.
Definition: RecursiveMemberReflector.h:540
Type trait that indicates whether a type is a collection.
Definition: IsCollection.h:63
void member(const char *name, T &member, const char *comment, const T &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:907
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:895
static void registerClass()
Registers a new polymorphic class at the PolymorphPointerReflector.
Definition: RecursiveMemberReflector.h:429
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:953
Definition: IsTransparentSerializable.h:84
Accessor< Getter, Setter > makeAccessor(const Getter &getter, const Setter &setter)
Helper method that creates an accessor from a different combination of either direct access to a vari...
Definition: Accessor.h:300
void reflectPointerNormal(T *&member)
Type C1: for members that are pointers to normal classes.
Definition: RecursiveMemberReflector.h:577
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
Definition: RecursiveMemberReflector.h:102
For internal use by RecursiveMemberReflector.h!
void atomic(T &member)
Is called if the member is an atomic type (int, float, etc).
Definition: RecursiveMemberReflector.h:268
void reflectArray(T &member)
Type A3: for arrays.
Definition: RecursiveMemberReflector.h:526
void reflectAtomic(T &member)
Type A1: for atomic members (float,int,etc.)
Definition: RecursiveMemberReflector.h:510
Definition: LoggingCore.h:77
void invokeMemberWithDefault(T &member, const ReflectMemberMeta &meta, const serialization::IgnoreMissing &defaultValue)
Delegates to invokeMember() and handles any occurring XMemberNotFound exception by ignoring the excep...
Definition: RecursiveMemberReflector.h:804
virtual int getTypeId() const =0
Return unique id for the class.