RTI Connext Modern C++ API  Version 6.1.0
rti::flat::MutableArrayBuilder< ElementBuilder, N > Class Template Reference

Builds an array member of variable-size elements. More...

#include <SequenceBuilders.hpp>

Inheritance diagram for rti::flat::MutableArrayBuilder< ElementBuilder, N >:
rti::flat::AbstractListBuilder rti::flat::AbstractBuilder

Public Types

typedef MutableArrayOffset< typename ElementBuilder::Offset, N > Offset
 The related Offset type. More...
 

Public Member Functions

ElementBuilder build_next ()
 Begins building the next element. More...
 
Offset finish ()
 Finishes building the array. More...
 
- Public Member Functions inherited from rti::flat::AbstractBuilder
void discard ()
 Discards a member in process of being built. More...
 
bool is_nested () const
 Returns whether this is a member Builder. More...
 
bool is_valid () const
 Whether this Builder is valid. More...
 
rti::xcdr::length_t capacity () const
 Returns the total capacity in bytes. More...
 

Additional Inherited Members

- Protected Member Functions inherited from rti::flat::AbstractListBuilder
unsigned int element_count () const
 Returns the current number of elements that have been added. More...
 
- Protected Member Functions inherited from rti::flat::AbstractBuilder
virtual ~AbstractBuilder ()
 If this is a member Builder, it calls finish(). More...
 

Detailed Description

template<typename ElementBuilder, unsigned int N>
class rti::flat::MutableArrayBuilder< ElementBuilder, N >

Builds an array member of variable-size elements.

Template Parameters
ElementBuilderThe Builder type for the elements of the array
NThe array bound; the exact number of elements this array builder must build. For multidimensional arrays, N is the product of each dimension bound.

Each element of this array needs to be built using the ElementBuilder returned by build_next(). N elements exactly must be built. Unlike a sequence Builder, it is not possible to finish an array with less than N elements.

This example shows how to use a MutableArrayBuilder to build an array member of MyFlatMutableBuilder:

auto array_builder = builder.build_my_mutable_array();
for (int i = 0; i < 10; i++) {
FlatMutableBarBuilder element_builder = array_builder.build_next();
// ... build element
element_builder.finish();
}
array_builder.finish();

Note that Builder types are not necessary for arrays of fixed-size elements, since they are added at once (see MyFlatMutableBuilder::add_my_final_array()).

Member Typedef Documentation

◆ Offset

template<typename ElementBuilder, unsigned int N>
typedef MutableArrayOffset<typename ElementBuilder::Offset, N> rti::flat::MutableArrayBuilder< ElementBuilder, N >::Offset

The related Offset type.

Member Function Documentation

◆ build_next()

template<typename ElementBuilder, unsigned int N>
ElementBuilder rti::flat::MutableArrayBuilder< ElementBuilder, N >::build_next ( )
inline

Begins building the next element.

Before calling build_next() to create a new element, the element Builder returned by a previous call to build_next must have been finished.

References rti::flat::AbstractListBuilder::element_count().

◆ finish()

template<typename ElementBuilder, unsigned int N>
Offset rti::flat::MutableArrayBuilder< ElementBuilder, N >::finish ( )
inline

Finishes building the array.

Precondition
build_next() must have been succesfully called N times exactly.
Returns
The Offset to the member that has been built.
See also
discard()

References rti::flat::AbstractListBuilder::element_count().