DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Friends | List of all members
dueca::ElementWriter Class Reference

ElementWriter. More...

#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.
 
ElementWriteroperator= (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.
 

Detailed Description

ElementWriter.

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.

Constructor & Destructor Documentation

◆ ElementWriter()

dueca::ElementWriter::ElementWriter ( )
inline

Constructor.

After this, the placement new operator must be used to initialize the WriteElementBase/WriteElement object.

Member Function Documentation

◆ write() [1/2]

void dueca::ElementWriter::write ( const boost::any & a,
unsigned idx )
inline

write data.

Only for fixed length arrays.

Parameters
aData to be written
idxIndex into the array

◆ write() [2/2]

void dueca::ElementWriter::write ( const boost::any & a,
const boost::any & key = boost::any() )
inline

write data.

If the entry is of a "mapped" type, the key must also be provided.

Parameters
aData to be written
keyKey, only used for mapped data (e.g. std::map)

◆ recurse() [1/2]

CommObjectWriter dueca::ElementWriter::recurse ( const boost::any & key = boost::any())
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.

Parameters
keyKey, if applicable, only for mapped data.
Returns
A new CommObjectWriter, which can be recursively written.

◆ recurse() [2/2]

CommObjectWriter dueca::ElementWriter::recurse ( unsigned idx)
inline

Recursively access a fixed length iterable object (fixed-length vector.

Parameters
idxIndex into the fixed-length array
Returns
A new CommObjectWriter, which can be recursively written.

◆ isNested()

bool dueca::ElementWriter::isNested ( ) const
inline

Whether the object can be recursed or not.

Returns
true if nested, in that case the recurse method can be used.

◆ getArity()

MemberArity dueca::ElementWriter::getArity ( ) const
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

Returns
A MemberArity enum indicating indexing

◆ operator=()

ElementWriter & dueca::ElementWriter::operator= ( const ElementWriter & o)
inline

Assignment.

Copy the hidden object in stretch


The documentation for this class was generated from the following file: