DUECA/DUSIME
|
#include <CommObjectElementWriter.hxx>
Public Member Functions | |
ElementWriter () | |
Constructor. | |
void | write (const boost::any &a, unsigned idx) |
write data. | |
void | write (const boost::any &a, const boost::any &key=boost::any()) |
write data. | |
void | skip () |
Skip writing, only relevant for fixed-length iterables, counts to the next element. | |
void | setFirstValue () |
Select the first value, for enum(-like) objects. | |
bool | setNextValue () |
Select the next value, for enum(-like) objects. | |
CommObjectWriter | recurse (const boost::any &key=boost::any()) |
Recursively access a nested object. | |
CommObjectWriter | recurse (unsigned idx) |
Recursively access a fixed length iterable object (fixed-length vector. | |
bool | isEnd () |
returns true if the last value has been written. | |
bool | isNested () const |
Whether the object can be recursed or not. | |
MemberArity | getArity () const |
returns what type of "Arity" the object has; either a single object, an iterable object, or a mapped object, i.e. | |
typeindex_t | getTypeIndex () const |
Returns the typeindex_t of the class type. | |
typeindex_t | getKeyTypeIndex () const |
Returns the typeindex_t of the key type, if applicable. | |
bool | arrayIsComplete () const |
Returns true if a complete fixed-length array has been written. | |
ElementWriter & | operator= (const ElementWriter &o) |
Assignment. | |
Static Public Attributes | |
static const size_t | RESERVE = 3*sizeof(void*) |
To keep the required data light-weight and on the stack, this defines space for the parent's pointers/indices. | |
Friends | |
template<typename C , typename T > | |
class | CommObjectMemberAccess |
Make this (templated class) a friend, for constructor and placement of the internal WriteElement object. | |
An object to write members of DCO objects
The ElementWriter enables a generic level (based on boost::any) interaction with a member of a DCO object. Generally, the ElementWriter will be generated by a CommObjectWriter, which in turn may be the parent of a DCOWriter, that takes a channel access token to obtain access to a channel entry.
This is for generic access. In most cases, it is more efficient, easier and safer to reference the DCO in the comm-objects.lst for your modules, and use a DataWriter. However, if you want to create for example a generic logger that can handle any data type, this might be useful.
If the member is iterable, it may be written to multiple times; each write enters the next value. The member arity/multiplicity can be tested with getArity(). Note that a member that returns FixedIterable has a fixed size, and will fail with an IndexExceeded exception when you exceed the vector size.
Mapped containers (e.g. std::map), require a key to be defined for writing. This interface is used for simply filling the container, not using it.
In addition, a fixed length array, identified as a FixedIterable type, can be written to with an integer index.
If the member is nested, the recurse method can be used to get a new CommObjectWriter that can be used to write elements of the nested member. For iterables (arrays, lists) of nested members this can be done repeatedly.
|
inline |
Constructor.
After this, the placement new operator must be used to initialize the WriteElementBase/WriteElement object.
write data.
Only for fixed length arrays.
a | Data to be written |
idx | Index into the array |
|
inline |
write data.
If the entry is of a "mapped" type, the key must also be provided.
a | Data to be written |
key | Key, only used for mapped data (e.g. std::map) |
|
inline |
Recursively access a nested object.
k provides the key if needed. If the object is iterable (list, vector-like), repeated calls write the next element.
key | Key, if applicable, only for mapped data. |
|
inline |
Recursively access a fixed length iterable object (fixed-length vector.
idx | Index into the fixed-length array |
|
inline |
Whether the object can be recursed or not.
|
inline |
returns what type of "Arity" the object has; either a single object, an iterable object, or a mapped object, i.e.
iterable with key
|
inline |
Assignment.
Copy the hidden object in stretch