MIRA
|
If 'reflect barriers' are used, each separated reflection block within an object has a separate state (defined by the Reflector). More...
#include <serialization/ReflectorInterface.h>
If 'reflect barriers' are used, each separated reflection block within an object has a separate state (defined by the Reflector).
When reflection of one block is interrupted to reflect a member block or call a helper subroutine, the state information refering to the parent block is pushed to a stack, then popped and restored when the flow of reflection returns to the parent, ensuring the current state held by the reflector always corresponds to the block just being reflected. This stack keeping is done internally for cases where the reflector is made aware of the transit from one block to the other by member() etc. If the change results from the reflecting method directly calling another method, it should call reflector.preReflect() before and keep the returned state locally, then (after the member/subroutine is finished), give back the state to reflector.postReflect(), thus emulating a stack in a single local variable kept on the program stack automatically with each subroutine call (more efficient than a true stack held internally). The type of the stacked state is defined by the Reflector. The default state type is an empty struct. The MIRA_REFLECT_CALL macro encapsulates the use of preReflect()/postReflect() for stack-keeping and makes it simple to use this in class reflection.
Example: BinarySerializer keeps a version placeholder (buffer position) for each reflection block, and tracks access to make sure a block does not write to it more than once during serialization. The state for a block therefore consists of a size_t (position in buffer) and a bool (version was written). BinaryDeserializer just keeps as state the int version read from the buffer and a flag to ensure it is read at least once. Both contain an additional context string for error analysis.