MIRA
Namespaces | Macros | Typedefs | Functions
ReflectorMacros.h File Reference

Macros for use with reflectors. More...

#include <utility>
Include dependency graph for ReflectorMacros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 mira
 specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
 
 mira::serialization::barrier
 

Macros

#define MIRA_REFLECT_CALL(ReflectorType, reflector, context, COMMAND)
 Whenever a reflection function calls another function that is independently maintained, the call should be marked to the reflector. More...
 

Typedefs

template<typename Reflector >
using State = typename Reflector::ReflectState
 

Functions

template<typename Reflector >
auto preCommand (Reflector &r, const char *context) -> State< Reflector >
 
template<typename Reflector >
void postCommand (Reflector &r, State< Reflector > &&state)
 

Detailed Description

Macros for use with reflectors.

Author
Christof Schröter
Date
2019/01/11

Macro Definition Documentation

◆ MIRA_REFLECT_CALL

#define MIRA_REFLECT_CALL (   ReflectorType,
  reflector,
  context,
  COMMAND 
)
Value:
{ \
auto state = serialization::barrier::preCommand(reflector, context); \
COMMAND; \
serialization::barrier::postCommand(reflector, std::move(state)); \
}
void postCommand(Reflector &r, State< Reflector > &&state)
Definition: ReflectorMacros.h:73
auto preCommand(Reflector &r, const char *context) -> State< Reflector >
Definition: ReflectorMacros.h:62

Whenever a reflection function calls another function that is independently maintained, the call should be marked to the reflector.

The reflector will then regard these as separate reflection blocks and keep a separate state for them. E.g. the BinarySerializer can allow these blocks to have separate reflection versions and will make sure these version numbers are correctly serialized (and deserialized later). Without making the reflector aware, it might know only one state for these different blocks, e.g. the BinarySerializer would potentially assume a version is reported twice for the same object (possibly with different version numbers!), and throw an exception. MIRA_REFLECT_CALL is used to insert the code required to mark the start and end of a call to a separate reflection function to the reflector. It can thus be seen as a generalization of the concept of using reflectBase()/MIRA_REFLECT_BASE instead of calling Base::reflect() directly.

template<typename Reflector>
void reflectMyStruct(Reflector& r, MyStruct& c) {
{
MIRA_REFLECT_CALL(Reflector, r, "MyStruct someReflectMethod", (someReflectMethod(r, c)));
}

context must be a const char* that must persist until after postCommand (e.g. use a string literal or create a static const string).