MIRA
|
This is the public interface of all reflectors that are able to visit a class' reflect() method. More...
#include <serialization/ReflectorInterface.h>
Classes | |
struct | ReflectState |
If 'reflect barriers' are used, each separated reflection block within an object has a separate state (defined by the Reflector). More... | |
struct | Tag |
Public Types | |
typedef boost::mpl::bool_< true > | isReadOnly |
Specifies, if the Reflector is read-only (true) or write-only (false). More... | |
typedef boost::mpl::bool_< true > | useHumanReadableIDs |
Specifies, if the Reflector supports human readable IDs. More... | |
typedef boost::mpl::bool_< false > | requireReflectBarriers |
Specifies whether the Reflector uses so-called 'reflect barriers' to allow maintaining separate states for individual blocks of reflected data. More... | |
Public Member Functions | |
template<typename Base > | |
void | reflectBase (Base &base) |
Method that can be called to reflect the base class easily. More... | |
ReflectState | preReflect (const char *context="") |
If a reflector requires reflection barriers, preReflect() and postReflect() should be called before/after calling an external method within reflect(), to declare these barriers (such a 'barrier' is just a declaration to the reflector, in fact). More... | |
void | postReflect (const ReflectState &) |
See preReflect for documentation. More... | |
Methods for reflecting members | |
These visiting methods are supported by the RecursiveMemberReflector. | |
template<typename T > | |
void | member (const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE) |
Specifies a class member for reflection/serialization. More... | |
template<typename T > | |
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. More... | |
template<typename T > | |
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. More... | |
template<typename T > | |
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. More... | |
template<typename T , typename U > | |
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 the data source. More... | |
template<typename T , typename U > | |
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 the data source. More... | |
template<typename T , typename U > | |
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 the data source. More... | |
template<typename T > | |
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 at runtime. More... | |
template<typename T > | |
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. More... | |
template<typename T > | |
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 at runtime. More... | |
template<typename T > | |
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 at runtime. More... | |
template<typename T , typename U > | |
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 at runtime. More... | |
template<typename T , typename U > | |
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 at runtime. More... | |
template<typename T , typename U > | |
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 at runtime. More... | |
template<typename T > | |
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. More... | |
template<typename T > | |
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. More... | |
template<typename T > | |
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. More... | |
void | itemName (const std::string &name) |
If the currently reflected object is an item within a collection, this allows to specify an explicit name for that item. More... | |
template<typename T > | |
void | delegate (T &member, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE) |
Delegates the serialization/reflection of a member directly to the member. More... | |
template<typename T > | |
void | delegate (const T &member, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE) |
Delegates the serialization/reflection of a member directly to the member. More... | |
template<typename T > | |
void | delegate (Getter< T > getter, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE) |
Delegates the serialization/reflection of a member directly to the member. More... | |
Methods for reflecting RPC (remote procedure call) methods | |
void | interface (const char *name) |
Indicates that the class implements the specified RPC interface. More... | |
template<typename R , typename... Args, typename F , typename... Description> | |
InvalidRPCDescription< R(Args...), Description... > | method (const char *, F &&, Description &&...) |
template<typename F , typename... Description> | |
InvalidRPCDescription< F, Description... > | method (const char *, F &&, Description &&...) |
template<typename R , typename Class , typename... Args, typename... Description> | |
InvalidRPCDescription< R(Class::*)(Args...), Description... > | method (const char *, R(Class::*)(Args...), Class *, Description &&...) |
template<typename R , typename Class , typename... Args, typename... Description> | |
InvalidRPCDescription< R(Class::*)(Args...) const, Description... > | method (const char *, R(Class::*)(Args...) const, Class *, Description &&...) |
template<typename R , typename... Args, typename F , typename... Description> | |
ValidRPCDescription< R(Args...), Description... > | method (const char *, F &&, Description &&...) |
template<typename F , typename... Description> | |
ValidRPCDescription< F, Description... > | method (const char *, F &&, Description &&...) |
template<typename R , typename Class , typename... Args, typename... Description> | |
ValidRPCDescription< R(Class::*)(Args...), Description... > | method (const char *, R(Class::*)(Args...), Class *, Description &&...) |
template<typename R , typename Class , typename... Args, typename... Description> | |
ValidRPCDescription< R(Class::*)(Args...) const, Description... > | method (const char *, R(Class::*)(Args...) const, Class *, Description &&...) |
template<typename R , typename ... Args> | |
void | invalid_method () |
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 function or free function. More... | |
void | method (const char *name, Method method, Class *object, const char *comment, const char *paramName, const char *paramDescription, P paramSampleValue,...) |
Specifies that the class that is reflected provides a service through the specified non-static member function. More... | |
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 function wrapper. More... | |
Controlling the object tracking state. | |
void | pushObjectTrackingStore () |
Push the current object tracking memory to an internal stack (backup). More... | |
void | popObjectTrackingStore () |
Pop the current object tracking memory from internal stack (restore). More... | |
Static Public Member Functions | |
static bool | usesHumanReadableIDs () |
Returns true, if the concrete derived Reflector supports human readable IDs. More... | |
Static Protected Member Functions | |
static int | checkForcedVersion (const std::string &variable) |
Optional Class Versioning. | |
These visiting methods may be supported by different reflectors like the RecursiveMemberReflector and the RPCMethodReflector, etc.
| |
typedef serialization::VersionType | VersionType |
typedef serialization::ClassVersionMap | ClassVersionMap |
typedef serialization::AcceptDesiredVersion | AcceptDesiredVersion |
template<typename T > | |
VersionType | version (VersionType version, const T *caller=NULL) |
Specifies the current class version and returns the version found in the data stream. More... | |
MIRA_DEPRECATED ("Please call as version<MyType>(v) or version(v, this)", VersionType version(VersionType version)) | |
Deprecated 'anonymous' (no type) version(). More... | |
template<typename T > | |
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 version requirement is not met. More... | |
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(). More... | |
template<typename T > | |
void | requireVersion (VersionType version, const T *caller=NULL) |
Specifies the current class version, which is also the minimum (and therefore only) version accepted (therefore, no need to return a version number). More... | |
MIRA_DEPRECATED ("Please call as requireVersion<MyType>(v) or requireVersion(v, this)", VersionType requireVersion(VersionType version)) | |
Deprecated 'anonymous' (no type) requireVersion(). More... | |
void | desireClassVersions (const ClassVersionMap &versions) |
Historically, classes have just been defining their current version themselves during serialization (the case where an object exists and its state is read out and serialized), by calling Reflector::version() with the respective version number parameter. More... | |
template<typename T > | |
VersionType | version (VersionType version, AcceptDesiredVersion, const T *caller=NULL) |
Extension of version() (see above), that additionally signals the reflector that the caller will properly handle a different version than the one it specifies itself. More... | |
template<typename T > | |
VersionType | requireVersion (VersionType version, VersionType minVersion, AcceptDesiredVersion, const T *caller=NULL) |
Extension of requireVersion() (see above), that additionally signals the reflector that the caller will properly handle a different version than the one it specifies itself. More... | |
template<typename T > | |
void | requireVersion (VersionType version, AcceptDesiredVersion, const T *caller=NULL) |
Extension of requireVersion() (see above), that additionally signals the reflector that the caller will properly handle a different version than it one it specifies itself. More... | |
This is the public interface of all reflectors that are able to visit a class' reflect() method.
The reflect-method is used to realize some kind of reflection that is known from other programming languages like C# or Java. Within the reflect method a class or actually a certain instance of a class can specify it's members, properties, methods etc. by calling the visitor-methods of the reflector. All available visiting methods are specified in this ReflectorInterface class.
Concrete derived Reflectors may then implement a subset of these visitor-methods below to process the given information. E.g. a reflector like the RecursiveMemberReflectorBase that collects information about the class members, will implement all "method"-visitor methods.
If new visitors require additional visitor-methods, these methods must be added to this interface with some default behavior to ensure that the existing Reflectors still can be used with all reflect methods (including those that use the new visitor-methods).
You should not derive from this class directly. Use AbstractReflector as base class instead, since it implements many important methods.
typedef boost::mpl::bool_<true> isReadOnly |
Specifies, if the Reflector is read-only (true) or write-only (false).
This type must be set to the proper boost::mpl::bool type by the derived Reflector class. (Default is true)
typedef boost::mpl::bool_<true> useHumanReadableIDs |
Specifies, if the Reflector supports human readable IDs.
This type must be set to the proper boost::mpl::bool type by the derived Reflector class. (Default is true)
typedef boost::mpl::bool_<false> requireReflectBarriers |
Specifies whether the Reflector uses so-called 'reflect barriers' to allow maintaining separate states for individual blocks of reflected data.
A reflect barrier is just a virtual separation line declared by a reflected object. It tells the reflector that certain parts of the reflected data should be considered as independent and can have separate states (if the reflector maintains any states for data). As an example, the BinarySerializer reserves space for a version number for each reflected object. If there is more than one individual block, it reserves space for a version for each of the blocks. If the reflector needs reflect barriers, it defines requireReflectBarriers::type to true in its class scope, and defines methods preReflect() and postReflect() that should be called by reflected objects for separation of independent reflection blocks (where the separation is not already implied by visitors like reflector.member()!) (The default is false). Also see ReflectState and MIRA_REFLECT_CALL.
|
inline |
Specifies the current class version and returns the version found in the data stream.
During serialization (read-only reflector), the specified version usually is stored as class version in the data stream. However, the serialized version can be overridden by setting a specific version for a certain class identifier, using desireClassVersions(). In that case, version() may return a different value than specified, and the class' reflect() method must implement reflection according to that version number. During deserialization (write-only reflector), the reflector reads the version found in the data stream and returns it. Providing the type of the caller enables defining separate version numbers for all base classes of an inherited type. Each class in the inheritance hierarchy can store and retrieve a version number independently of all its bases or sub-classes (assuming reflect() calls the reflect() method of the base class using reflectBase()). The type of the caller is also required to look up whether a specific version is desired (see desireClassVersions()). The sole purpose of the 'caller' parameter is to enable automatic deduction of the template parameter T. It can be omitted when T is given explicitly.
Usage:
|
inline |
Deprecated 'anonymous' (no type) version().
|
inline |
Same as above, but allows to specify a minimum supported version, and throws XIO if the minimum version requirement is not met.
Calls version() internally.
Usage:
|
inline |
Deprecated 'anonymous' (no type) requireVersion().
|
inline |
Specifies the current class version, which is also the minimum (and therefore only) version accepted (therefore, no need to return a version number).
See above.
|
inline |
Deprecated 'anonymous' (no type) requireVersion().
|
inline |
Historically, classes have just been defining their current version themselves during serialization (the case where an object exists and its state is read out and serialized), by calling Reflector::version() with the respective version number parameter.
Different versions of a class were only considered during deserialization (i.e. restoring an object state from serialized data). In some cases it may be desirable, however, to serialize a different version (naturally, this can not be a higher version than the class implementation knows, only lower). This is useful e.g. to ensure serializing data that is compatible with a certain other (older) implementation, thus it can be deserialized by another instance.
For such cases, a mechanism is provided to generally enable requesting a specific version for any class from the reflector. This involves providing a map of class types (type names) to version numbers to the reflector. When a class contained in the map calls version() in its reflect() method, the call shall return the version number from the version map instead of the version number indicated by the class implementation itself. The class serialization must then follow that returned version.
A call to this method will always overwrite any previous setting of desired versions, i.e. the map is not cumulative.
|
inline |
Extension of version() (see above), that additionally signals the reflector that the caller will properly handle a different version than the one it specifies itself.
|
inline |
Extension of requireVersion() (see above), that additionally signals the reflector that the caller will properly handle a different version than the one it specifies itself.
|
inline |
Extension of requireVersion() (see above), that additionally signals the reflector that the caller will properly handle a different version than it one it specifies itself.
|
inline |
Specifies a class member for reflection/serialization.
For each member its name (as used in XML files, etc) and a comment that describes the member must be specified.
name | The name of the member (as used in XML files) |
member | The member that should be reflected/serialized |
comment | A comment that describes the member |
flags | Flags for controlling the reflection |
|
inline |
Same as above, with an extra parameter for specifying the id explicitly if it differs from name.
(Used by several adapters to STL-containers, etc.)
|
inline |
Same as above, with a special setter method for reading the member.
|
inline |
Same as above, with a special getter and setter accessing the member.
Since both, getter and setter are specified, the member does not need to be specified itself. The full access is done using the accessor methods.
|
inline |
Same as above, where a default value can be specified that is used, if the value is not available in the data source.
|
inline |
Same as above, where a default value can be specified that is used, if the value is not available in the data source.
|
inline |
Same as above, where a default value can be specified that is used, if the value is not available in the data source.
|
inline |
Same as the corresponding member-method, to indicate that the member is a property and can be altered at runtime.
Using the last optional parameter certain "property hints" can be specified
|
inline |
Same as above, with an extra parameter for specifying the id explicitly if it differs from name.
(Used by several adapters to STL-containers, etc.)
|
inline |
Same as the corresponding member-method, to indicate that the member is a property and can be altered at runtime.
|
inline |
Same as the corresponding member-method, to indicate that the member is a property and can be altered at runtime.
|
inline |
Same as the corresponding member-method, to indicate that the member is a property and can be altered at runtime.
|
inline |
Same as the corresponding member-method, to indicate that the member is a property and can be altered at runtime.
|
inline |
Same as the corresponding member-method, to indicate that the member is a property and can be altered at runtime.
|
inline |
A property that just reflects a runtime state of the object and can be displayed but not altered.
|
inline |
Same as above, with an extra parameter for specifying the id explicitly if it differs from name.
|
inline |
Same as above, with a special getter method for reading the member.
|
inline |
If the currently reflected object is an item within a collection, this allows to specify an explicit name for that item.
This currently is interpreted by the PropertySerializer only.
|
inline |
Delegates the serialization/reflection of a member directly to the member.
Must be used with IsTransparentSerializable and is for most advanced users only.
|
inline |
Delegates the serialization/reflection of a member directly to the member.
Must be used with IsTransparentSerializable and is for most advanced users only.
|
inline |
Delegates the serialization/reflection of a member directly to the member.
Must be used with IsTransparentSerializable and is for most advanced users only.
|
inline |
Indicates that the class implements the specified RPC interface.
If you indicate that your class implements the specified interface by calling this method in your reflect method, there is an implicit contract that your class provides all methods that are defined by that interface.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
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 function or free function.
The method will then be available for RPC calls. For each method its name (used to identify the method in RPC calls) and a comment that describes the method must be specified.
name | The name of the method (used for calling it) |
method | The static member function (or free function) that implements the method |
comment | A comment that describes the method |
paramName | Optional additional argument(s) for the names of the method's parameters |
paramDescription | Optional additional argument(s) for the descriptions of the method's parameters. |
paramSampleValue | Optional additional argument(s) providing a sample value for each parameter. These are not default values, they are only used for documentation purpose, and should mainly serve to illustrate notation. |
The optional parameter documentation arguments must be either a sequence of pairs of const char* values or a sequence of triplets, where each third value is a value of the respective method parameter's type. (name and description must both be provided, for all parameters or for none, and if sample values are to be added, they also need to be added for all parameters).
Examples:
void method | ( | const char * | name, |
Method | method, | ||
Class * | object, | ||
const char * | comment, | ||
const char * | paramName, | ||
const char * | paramDescription, | ||
P | paramSampleValue, | ||
... | |||
) |
Specifies that the class that is reflected provides a service through the specified non-static member function.
The method will then be available for RPC calls. For each method its name (used to identify the method in RPC calls) and a comment that describes the method must be specified.
name | The name of the method (used for calling it) |
method | The non-static member function (const or non-const) that implements the method |
object | A pointer to the object on which the function is called (usually "this") |
comment | A comment that describes the method |
paramName | Optional additional argument(s) for the names of the method's parameters |
paramDescription | Optional additional argument(s) for the descriptions of the method's parameters. |
paramSampleValue | Optional additional argument(s) providing a sample value for each parameter. |
See above for documentation of optional parameter documentation arguments.
Example:
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 function wrapper.
The method will then be available for RPC calls. For each method its name (used to identify the method in RPC calls) and a comment that describes the method must be specified.
name | The name of the method (used for calling it) |
method | The function wrapper object that implements the method, e.g. created using boost::bind |
comment | A comment that describes the method |
paramName | Optional additional argument(s) for the names of the method's parameters |
paramDescription | Optional additional argument(s) for the descriptions of the method's parameters. |
paramSampleValue | Optional additional argument(s) providing a sample value for each parameter. |
See above for documentation of optional parameter documentation arguments.
Example:
|
inline |
Push the current object tracking memory to an internal stack (backup).
|
inline |
Pop the current object tracking memory from internal stack (restore).
|
inline |
Method that can be called to reflect the base class easily.
Usage:
You can use the MIRA_REFLECT_BASE macro:
or either call
or use
The method can also be used in non-intrusive reflection:
|
inlinestatic |
Returns true, if the concrete derived Reflector supports human readable IDs.
The return value of this method is known at compile time and hence the compiler is able to optimize the code depending on that value.
|
inline |
If a reflector requires reflection barriers, preReflect() and postReflect() should be called before/after calling an external method within reflect(), to declare these barriers (such a 'barrier' is just a declaration to the reflector, in fact).
The base implementation is empty and should not actually be called (if a reflector needs these methods, it must provide own definitions).
context | Can be used to provide context, e.g. name of the reflected class or function that is called. How this is used depends on the reflector implementation, e.g. MetaSerializer uses it to generate comments on data elements implicitly defined by preReflect. |
The complete process of calling these methods is wrapped by MIRA_REFLECT_CALL. That macro should be used to simplify handling.
See requireReflectBarriers and ReflectState.
|
inline |
See preReflect for documentation.
|
inlinestaticprotected |