47 #ifndef _MIRA_REFLECTORINTERFACE_H_
48 #define _MIRA_REFLECTORINTERFACE_H_
51 #include <unordered_map>
54 #include <boost/preprocessor/repetition.hpp>
55 #include <boost/mpl/bool.hpp>
56 #include <boost/type_traits/integral_constant.hpp>
71 namespace serialization {
110 template <
typename Derived>
241 template <
typename T>
275 template <
typename T>
280 MIRA_DEPRECATED(
"Please call as requireVersion<MyType>(v, minV) or requireVersion(v, minV, this)",
287 template <
typename T>
291 MIRA_DEPRECATED(
"Please call as requireVersion<MyType>(v) or requireVersion(v, this)",
336 template <
typename T>
346 template <
typename T>
354 template <
typename T>
413 template<
typename T,
typename U>
422 template<
typename T,
typename U>
424 const char* comment,
const U& defaultValue,
432 template<
typename T,
typename U>
434 const char* comment,
const U& defaultValue,
455 void property(
const char* name,
const std::string&
id, T& member,
483 template<
typename T,
typename U>
484 void property(
const char* name, T& member,
const char* comment,
492 template<
typename T,
typename U>
494 const char* comment,
const U& defaultValue,
502 template<
typename T,
typename U>
504 const char* comment,
const U& defaultValue,
523 void roproperty(
const char* name,
const std::string&
id,
const T& member,
583 #define RPC_METHODS_MAX_PARAMS 8
586 #define RPCGEN_METHODS(z,n,_) \
587 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
588 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), const char* comment) {} \
590 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
591 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class*, const char* comment) {} \
593 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
594 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class*, const char* comment) {} \
596 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
597 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))>, const char* comment) {} \
600 #undef RPCGEN_METHODS
603 #define RPCGEN_METHODS_PARAMDESC(z,n,_) \
604 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
605 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), \
606 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) {} \
608 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
609 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class*, \
610 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) {} \
612 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
613 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class*, \
614 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) {} \
616 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
617 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))>, \
618 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) {} \
622 #undef RPCGEN_METHODS_PARAMDESC
625 #define RPCGEN_METHODS_PARAMDESCSAMPLE(z,n,_) \
626 template<typename R, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \
627 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), \
628 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) {} \
630 template<typename R, typename Class, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \
631 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class*, \
632 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) {} \
634 template<typename R, typename Class, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \
635 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class*, \
636 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) {} \
638 template<typename R, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \
639 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))>, \
640 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) {} \
644 #undef RPCGEN_METHODS_PARAMDESCSAMPLE
645 #undef RPCGEN_METHODS_CONSTCHARPTR_NAME_DESC_SAMPLE
654 #define RPCGEN_METHODS_WRONG_ARGUMENT_NUMBER(z,n,_) \
655 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \
656 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), \
657 const char* comment, Args...) {} \
659 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \
660 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class* This, \
661 const char* comment, Args...) {} \
663 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \
664 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class* This, \
665 const char* comment, Args...) {} \
667 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \
668 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))> fn, \
669 const char* comment, Args...) {} \
672 #undef RPCGEN_METHODS_WRONG_ARGUMENT_NUMBER
676 #define RPCGEN_METHODS_INVALID(z,n,_) \
677 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \
678 void invalid_method() \
680 static_assert(sizeof(R*)==0, \
681 "_____________NUMBER OR TYPES OF NAMES/DESCRIPTIONS/SAMPLEVALUES FOR PARAMETERS " \
682 "IN CALL TO Reflector::method() DO NOT MATCH THE PROVIDED FUNCTION'S SIGNATURE. " \
683 "PLEASE PROVIDE const char* NAME AND DESCRIPTION FOR EACH RPC METHOD PARAMETER, " \
684 "OR NAME, DESCRIPTION AND A CORRECTLY TYPED SAMPLE VALUE FOR EACH PARAMETER._____________"); \
688 #undef RPCGEN_METHODS_INVALID
725 void method(
const char* name, Method
method,
const char* comment,
726 const char* paramName,
const char* paramDescription, P paramSampleValue, ...);
751 void method(
const char* name, Method
method, Class*
object,
const char* comment,
752 const char* paramName,
const char* paramDescription, P paramSampleValue, ...);
777 void method(
const char* name, Method
method,
const char* comment,
778 const char* paramName,
const char* paramDescription, P paramSampleValue, ...);
835 template <
typename Base>
846 return Derived::useHumanReadableIDs::value;
869 typeName<Derived>() <<
"::requireReflectBarriers == true, but " <<
870 typeName<Derived>() <<
"::preReflect() not implemented!");
872 return ReflectState();
879 typeName<Derived>() <<
"::requireReflectBarriers == true, but " <<
880 typeName<Derived>() <<
"::postReflect() not implemented!");
888 std::stringstream ss;
894 catch(XInvalidConfig&) {}
918 #define MIRA_REFLECT_VERSION(reflector, versionNumber) reflector.version(versionNumber, this)
937 #define MIRA_REFLECT_REQUIRE_VERSION(reflector, versionNumber) reflector.requireVersion(versionNumber, this)
956 #define MIRA_REFLECT_BASE(reflector, BaseClass) reflector.template reflectBase<BaseClass>(*this)
975 #define MIRA_REFLECT_BASE_NONINTRUSIVE(reflector, BaseClass, object) reflector.template reflectBase<BaseClass>(object)
1014 #define MIRA_REFLECT_BASE_IF_VERSION_ATLEAST(reflector, BaseClass, versionvar, minversion) \
1015 if (versionvar < minversion) \
1016 BaseClass::reflect(reflector); \
1018 reflector.template reflectBase<BaseClass>(*this); \
1029 #define MIRA_REFLECT_BASE_NONINTRUSIVE_IF_VERSION_ATLEAST(reflector, BaseClass, object, versionvar, minversion) \
1030 if (versionvar < minversion) \
1031 reflect(reflector, (BaseClass&)object); \
1033 reflector.template reflectBase<BaseClass>(object); \
1047 #define MIRA_MEMBER_WITH_ID(reflector, name, id, var, ...) \
1048 if(reflector.usesHumanReadableIDs()) \
1049 reflector.member(name, id, var, __VA_ARGS__); \
1051 reflector.member(name, var, __VA_ARGS__);
1053 #define MIRA_PROPERTY_WITH_ID(reflector, name, id, var, ...) \
1054 if(reflector.usesHumanReadableIDs()) \
1055 reflector.property(name, id, var, __VA_ARGS__); \
1057 reflector.property(name, var, __VA_ARGS__);
static int checkForcedVersion(const std::string &variable)
Definition: ReflectorInterface.h:885
std::unordered_map< Typename, VersionType > ClassVersionMap
Definition: ReflectorInterface.h:73
void popObjectTrackingStore()
Pop the current object tracking memory from internal stack (restore).
Definition: ReflectorInterface.h:793
#define RPC_METHODS_MAX_PARAMS
Definition: ReflectorInterface.h:583
void property(const char *name, T &member, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as the corresponding member-method, to indicate that the member is a property and can be altered...
Definition: ReflectorInterface.h:484
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 member(const char *name, const T &member, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, with a special setter method for reading the member.
Definition: ReflectorInterface.h:392
serialization::ClassVersionMap ClassVersionMap
Definition: ReflectorInterface.h:294
#define RPCGEN_METHODS(z, n, _)
Definition: ReflectorInterface.h:586
void delegate(Getter< T > getter, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Delegates the serialization/reflection of a member directly to the member.
Definition: ReflectorInterface.h:567
void member(const char *name, const std::string &id, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, with an extra parameter for specifying the id explicitly if it differs from name...
Definition: ReflectorInterface.h:384
void itemName(const std::string &name)
If the currently reflected object is an item within a collection, this allows to specify an explicit ...
Definition: ReflectorInterface.h:541
If 'reflect barriers' are used, each separated reflection block within an object has a separate state...
Definition: ReflectorInterface.h:179
boost::mpl::bool_< false > requireReflectBarriers
Specifies whether the Reflector uses so-called 'reflect barriers' to allow maintaining separate state...
Definition: ReflectorInterface.h:148
Provides property hints and attributes.
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
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, with a special getter and setter accessing the member.
Definition: ReflectorInterface.h:402
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
VersionType requireVersion(VersionType version, VersionType minVersion, const T *caller=NULL)
Same as above, but allows to specify a minimum supported version, and throws XIO if the minimum versi...
Definition: ReflectorInterface.h:276
Get compiler and platform independent typenames.
void desireClassVersions(const ClassVersionMap &versions)
Historically, classes have just been defining their current version themselves during serialization (...
Definition: ReflectorInterface.h:328
uint8 VersionType
Definition: ReflectorInterface.h:72
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:91
void roproperty(const char *name, const T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
A property that just reflects a runtime state of the object and can be displayed but not altered...
Definition: ReflectorInterface.h:514
This is the public interface of all reflectors that are able to visit a class' reflect() method...
Definition: ReflectorInterface.h:111
A property hint gives optional instructions to the property editor, i.e.
Definition: PropertyHint.h:82
void roproperty(const char *name, Getter< T > getter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, with a special getter method for reading the member.
Definition: ReflectorInterface.h:532
#define RPCGEN_METHODS_PARAMDESC(z, n, _)
Definition: ReflectorInterface.h:603
Flags controlling reflector behaviour.
boost::mpl::bool_< true > isReadOnly
Specifies, if the Reflector is read-only (true) or write-only (false).
Definition: ReflectorInterface.h:121
static bool usesHumanReadableIDs()
Returns true, if the concrete derived Reflector supports human readable IDs.
Definition: ReflectorInterface.h:845
MIRA_DEPRECATED("Please call as requireVersion<MyType>(v) or requireVersion(v, this)", VersionType requireVersion(VersionType version))
Deprecated 'anonymous' (no type) requireVersion().
Definition: ReflectorInterface.h:291
void pushObjectTrackingStore()
Push the current object tracking memory to an internal stack (backup).
Definition: ReflectorInterface.h:790
void reflectBase(Base &base)
Method that can be called to reflect the base class easily.
Definition: ReflectorInterface.h:836
MIRA_BASE_EXPORT std::string resolveEnvironmentVariable(const std::string &envVar)
Resolves an environmental variable.
No flags.
Definition: ReflectControlFlags.h:65
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, where a default value can be specified that is used, if the value is not available in ...
Definition: ReflectorInterface.h:433
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as the corresponding member-method, to indicate that the member is a property and can be altered...
Definition: ReflectorInterface.h:473
MIRA_DEPRECATED("Please call as version<MyType>(v) or version(v, this)", VersionType version(VersionType version))
Deprecated 'anonymous' (no type) version().
Definition: ReflectorInterface.h:248
Tag class used as parameter to ReflectorInterface::version() etc.
Definition: ReflectorInterface.h:80
VersionType version(VersionType version, AcceptDesiredVersion, const T *caller=NULL)
Extension of version() (see above), that additionally signals the reflector that the caller will prop...
Definition: ReflectorInterface.h:337
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)
Same as the corresponding member-method, to indicate that the member is a property and can be altered...
Definition: ReflectorInterface.h:493
Getter< T > getter(T(*f)())
Creates a Getter for global or static class methods returning the result by value.
Definition: GetterSetter.h:136
void delegate(const T &member, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Delegates the serialization/reflection of a member directly to the member.
Definition: ReflectorInterface.h:558
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)
Same as the corresponding member-method, to indicate that the member is a property and can be altered...
Definition: ReflectorInterface.h:503
#define RPCGEN_METHODS_PARAMDESCSAMPLE(z, n, _)
Definition: ReflectorInterface.h:625
void delegate(T &member, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Delegates the serialization/reflection of a member directly to the member.
Definition: ReflectorInterface.h:549
Utility macros used in generating RPC method definitions with BOOST_PP.
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
void method(const char *name, Method method, const char *comment, const char *paramName, const char *paramDescription, P paramSampleValue,...)
Specifies that the class that is reflected provides a service through the specified static member fun...
void member(const char *name, T &member, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, where a default value can be specified that is used, if the value is not available in ...
Definition: ReflectorInterface.h:414
void roproperty(const char *name, const std::string &id, const T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, with an extra parameter for specifying the id explicitly if it differs from name...
Definition: ReflectorInterface.h:523
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as the corresponding member-method, to indicate that the member is a property and can be altered...
Definition: ReflectorInterface.h:445
serialization::VersionType VersionType
Definition: ReflectorInterface.h:194
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
#define RPCGEN_METHODS_INVALID(z, n, _)
Definition: ReflectorInterface.h:676
void property(const char *name, const std::string &id, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, with an extra parameter for specifying the id explicitly if it differs from name...
Definition: ReflectorInterface.h:455
Functions for platform independent resolving of environment variables.
VersionType requireVersion(VersionType version, VersionType minVersion, AcceptDesiredVersion, const T *caller=NULL)
Extension of requireVersion() (see above), that additionally signals the reflector that the caller wi...
Definition: ReflectorInterface.h:347
ReflectCtrlFlags
Control Flags that can modify the behavior of certain reflectors.
Definition: ReflectControlFlags.h:63
serialization::AcceptDesiredVersion AcceptDesiredVersion
Definition: ReflectorInterface.h:330
void requireVersion(VersionType version, AcceptDesiredVersion, const T *caller=NULL)
Extension of requireVersion() (see above), that additionally signals the reflector that the caller wi...
Definition: ReflectorInterface.h:355
void property(const char *name, const T &member, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as the corresponding member-method, to indicate that the member is a property and can be altered...
Definition: ReflectorInterface.h:464
ReflectState preReflect(const char *context="")
If a reflector requires reflection barriers, preReflect() and postReflect() should be called before/a...
Definition: ReflectorInterface.h:866
boost::mpl::bool_< true > useHumanReadableIDs
Specifies, if the Reflector supports human readable IDs.
Definition: ReflectorInterface.h:128
#define RPCGEN_METHODS_WRONG_ARGUMENT_NUMBER(z, n, _)
Definition: ReflectorInterface.h:654
MIRA_DEPRECATED("Please call as requireVersion<MyType>(v, minV) or requireVersion(v, minV, this)", VersionType requireVersion(VersionType version, VersionType minVersion))
Deprecated 'anonymous' (no type) requireVersion().
Definition: ReflectorInterface.h:280
Provides definition for getters and setters that are used with the serialization framework.
void member(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Same as above, where a default value can be specified that is used, if the value is not available in ...
Definition: ReflectorInterface.h:423
Definition: ReflectorInterface.h:114
void requireVersion(VersionType version, const T *caller=NULL)
Specifies the current class version, which is also the minimum (and therefore only) version accepted ...
Definition: ReflectorInterface.h:288
void interface(const char *name)
Indicates that the class implements the specified RPC interface.
Definition: ReflectorInterface.h:581
void postReflect(const ReflectState &)
See preReflect for documentation.
Definition: ReflectorInterface.h:876