RTI Connext Modern C++ API  Version 7.0.0
dds::core::xtypes::DynamicData Class Reference

<<value-type>> A data sample of any complex data type, which can be inspected and manipulated reflectively. More...

#include <dds/core/xtypes/DynamicData.hpp>

Public Member Functions

 DynamicData (const dds::core::xtypes::DynamicType &type)
 Creates a DynamicData instance for a type. More...
 
 DynamicData (const dds::core::xtypes::DynamicType &type, const DynamicDataProperty &property)
 Creates a DynamicData instance for a type with specific memory-management. More...
 
template<typename T >
void value (const std::string &name, const T &v)
 Sets the value of a member by member name. More...
 
template<typename T >
void value (uint32_t index, const T &v)
 Sets the value of a member by member index. More...
 
template<typename T >
value (const std::string &name) const
 Gets the value of a member by member name. More...
 
template<typename T >
value (uint32_t index) const
 Gets the value of a member by member index. More...
 
template<typename T >
void get_values (const std::string &name, std::vector< T > &out_array) const
 Obtains the values of an array or sequence member by member name. More...
 
template<typename T >
void get_values (uint32_t index, std::vector< T > &out_array) const
 Obtains the values of an array or sequence member by member index. More...
 
template<typename T >
std::vector< T > get_values (uint32_t index) const
 Obtains the values of an array or sequence member by member index. More...
 
template<typename T >
std::vector< T > get_values (const std::string &name) const
 Obtains the values of an array or sequence member by member name. More...
 
template<typename T >
void set_values (uint32_t index, const std::vector< T > &v)
 Sets the values of an array or sequence member by member index. More...
 
template<typename T >
void set_values (const std::string &name, const std::vector< T > &v)
 Sets the values of an array or sequence member by member name. More...
 
LoanedDynamicData loan_value (const std::string &name)
 Gets a view of a complex member. More...
 
LoanedDynamicData loan_value (uint32_t index)
 Gets a view of a complex member. More...
 
LoanedDynamicData & loan_value (LoanedDynamicData &data, const std::string &name)
 Gets a view of a complex member. More...
 
LoanedDynamicData & loan_value (LoanedDynamicData &data, uint32_t mid)
 Gets a view of a complex member. More...
 
uint32_t discriminator_value () const
 Obtains the value of the union discriminator (UnionType only) More...
 
void clear_all_members ()
 Clear the contents of all data members of this object, including key members. More...
 
void clear_optional_member (const std::string &name)
 Clear the contents of a single optional data member of this object. More...
 
void clear_optional_member (uint32_t index)
 Clear the contents of a single optional data member of this object. More...
 
void clear_member (const std::string &name)
 Clear the contents of a single data member of this object. More...
 
void clear_member (uint32_t index)
 Clear the contents of a single data member of this object. More...
 
const dds::core::xtypes::DynamicTypetype () const
 Gets the data type of this DynamicData. More...
 
dds::core::xtypes::TypeKind type_kind () const
 Gets the data type kind of this DynamicData. More...
 
uint32_t member_count () const
 Get the number of members in this sample. More...
 
bool member_exists (const std::string &name) const
 Indicates whether a member exists in this sample. More...
 
bool member_exists (uint32_t index) const
 Indicates whether a member exists in this sample. More...
 
bool member_exists_in_type (const std::string &name) const
 Indicates whether a member with a particular name exists in type() More...
 
bool member_exists_in_type (uint32_t index) const
 Indicates whether a member of a particular index exists in type() More...
 
DynamicDataInfo info () const
 Returns information about this sample. More...
 
rti::core::xtypes::DynamicDataMemberInfo member_info (const std::string &name) const
 Returns information about a member. More...
 
rti::core::xtypes::DynamicDataMemberInfo member_info (uint32_t index) const
 Returns information about a member. More...
 
uint32_t member_index (const std::string &name) const
 Translates from member name to member index. More...
 
bool is_member_key (const std::string &name) const
 Returns whether a member is a key. More...
 
bool is_member_key (uint32_t index) const
 Returns whether a member is a key. More...
 

Related Functions

(Note that these are not member functions.)

std::vector< char > & to_cdr_buffer (std::vector< char > &buffer, const DynamicData &sample, dds::core::policy::DataRepresentationId representation_id=dds::core::policy::DataRepresentation::auto_id())
 <<extension>> Serializes a DynamicData sample into CDR format More...
 
DynamicDatafrom_cdr_buffer (DynamicData &sample, const std::vector< char > &buffer)
 <<extension>> Creates a DynamicData sample by deserializing a CDR buffer' More...
 
template<typename TopicType >
TopicType convert (const DynamicData &sample)
 <<extension>> Creates a typed sample from a DynamicData sample. More...
 
template<typename TopicType >
DynamicData convert (const TopicType &sample)
 <<extension>> Creates a DynamicData sample from a typed sample More...
 
template<typename TopicType >
bool can_convert (const DynamicData &sample)
 <<extension>> Determines if the DynamicType of this sample is equal to the DynamicType of TopicType More...
 
template<typename... Types>
std::tuple< Types... > get_tuple (const dds::core::xtypes::DynamicData &data)
 <<C++11>> <<experimental>> <<extension>> Retrieves all the values of a DynamicData object into an std::tuple at once More...
 
template<typename... Types>
void set_tuple (dds::core::xtypes::DynamicData &data, const std::tuple< Types... > &value)
 <<C++11>> <<experimental>> <<extension>> Assigns the values of a std::tuple to a DynamicData object at once More...
 

Detailed Description

<<value-type>> A data sample of any complex data type, which can be inspected and manipulated reflectively.

DynamicData allows manipulating a data sample whose type is unknown at compilation time. A DynamicData object is created by passing its DynamicType, which can be a StructType, a UnionType, ArrayType, SequenceType or AliasType. DynamicData is a valid topic-type, so you can instantiate a Topic<DynamicData> (using the constructor that receives a DynamicType), and then a DataReader<DynamicData> or a DataWriter<DynamicData>.

Several overloaded versions of the function value() allow reading or writing the value of a member by name or index. Another set of functions, loan_value(), can access a non-primitive member (for reading and writing) without making a copy. For primitive arrays and sequences DynamicData also provides a way to get or set all the values at once, using set_values() and get_values().

A number of other functions allow querying information about the sample and its type.

Applications that use both statically typed data and DynamicData can benefit from the conversion between them, using rti::core::xtypes::convert().

For examples on how to use DynamicData, see Using DynamicData.

Member Names and Indexes

As mentioned before, to access a member you need to specify its name or its index. Depending on the DynamicType of the DynamicData sample, the name may apply or not and the index can mean different things. This table summarizes that:

DynamicType of the sample Can access by name?What does index mean?
StructType Yes The position of the member in the type (starting at 1)
UnionType Yes The value of the label that selects a member, see discriminator_value()
ArrayType No The position of the element in the array (1 to ArrayType::total_element_count())
SequenceType No The position of the element in the sequence (1 to member_count()) or past member_count() to increase the length of the sequence.
Any other type N/A N/A

For example, given the following IDL description of a type:

struct Foo {
long x;
long y;
};

If we have a DynamicData sample representing data of that type, we can access the member y in two different ways:

sample.value("y", 33); // Set value to 33
sample.value(2, 33); // Same effect

Accessing a member by index can be more efficient, so when accessing a member repeatedly it may be beneficial to obtain its index first:

const uint32_t y_index = sample.member_index("y");
while (...) {
int32_t y_value = sample.value<int32_t>(y_index);
// ...
}

For an example on how to access a union member, see discriminator_value(), and for more examples, including how to access elements in a collection see Using DynamicData.

Hierarchical Member Names

It is possible to refer to a nested member in a type without first having to use the loan_value() API. You can do this by using a hierarchical name. A hierarchical member name is a concatenation of member names separated by the '.' character. The hierarchical name describes the complete path from a top-level type to the nested member. For example, in the following type:

struct MyNestedType {
char theChar;
octet theOctetArray[10];
long long theMultidimensionalArray[4][6][12];
sequence<long> myArrayOfSeq[8];
};
struct MyType {
MyNestedType theNestedType;
};

any DynamicData API that receives a member name will accept "theNestedType.theChar" to refer to the char member in MyNestedType:

char my_char = myDynamicData.value<char>("theNestedType.theChar");

In order to access the value of theChar without using a hierarchical name, you would have to first bind to theNestedType and then get the value:

auto member = myDynamicData.loan_value("theNestedType");
char my_char = member.get().value<char>("theChar");

As you can see, using a hierarchical member name removes the need to call the loan_value() API, and allows for access to nested members at any depth directly from the top-level type.

The member name can also contain indexes to address members in arrays and sequences. For example, to set the third member in the array theOctetArray, you can pass in "theNestedType.theOctetArray[2]" as the member name. The index values when used as part of the member name are 0-based.

For multi-dimensional arrays, the indexes for each dimension should be listed comma-separated in between brackets. For example, to address a member of theMultidimensionalArray, the member name should be something like "theNestedType.theMultidimensionalArray[3,2,5]".

In complex types with arrays and sequences that contain other arrays and sequences, the hierarchical name may include multiple index values, one right after another. For example, in MyNestedType, myArrayOfSeq is an array of sequences. In order to set the third member of the sequence in the fourth member of the array, the member name would be "myNestedType.myArrayOfSeq[3][2]".

Exceptions accessing a member

The different DynamicData functions that access members may throw the following exceptions:

  • dds::core::InvalidArgumentError when attempting to get the value a member that doesn't exist in the type, is optional and is not set, or is part of a union and not currently selected (see discriminator_value). Attempting to set an unset optional member or an unselected union member is legal and will set the optional member or change the active union member.
  • dds::core::IllegalOperationError when attempting to get or set a member of the wrong type–that is, when the DynamicType of that member doesn't match the template type T of the function. For example assumming that my_string_member is a string, the two following statements are illegal:
    data.value("my_string_member", 3);
    int v = data.value<int>("my_string_member");
See also
Using DynamicData

Constructor & Destructor Documentation

◆ DynamicData() [1/2]

dds::core::xtypes::DynamicData::DynamicData ( const dds::core::xtypes::DynamicType type)

Creates a DynamicData instance for a type.

Uses default DynamicDataProperty.

Precondition
!is_primitive(type) – a DynamicData object cannot encapsulate a primitive type.
Parameters
typeThe type of this data sample

◆ DynamicData() [2/2]

dds::core::xtypes::DynamicData::DynamicData ( const dds::core::xtypes::DynamicType type,
const DynamicDataProperty &  property 
)

Creates a DynamicData instance for a type with specific memory-management.

Precondition
!is_primitive(type) – a DynamicData object cannot encapsulate a primitive type.
Parameters
typeThe type of this data sample
propertyMemory-management configuration

Member Function Documentation

◆ value() [1/4]

template<typename T >
void dds::core::xtypes::DynamicData::value ( const std::string &  name,
const T &  v 
)

Sets the value of a member by member name.

Template Parameters
TThe type of the member to set. The possible types are:
Note
If the member type is a collection type, use loan_value for collections of complex types or set_values for collections of primitive types.

For examples on how to set member values, see Publishing data using DynamicData.

If the member is optional and unset, this function will set it. To unset it again, see clear_optional_member().

It is not always possible to rely on inferring the type T based on the argument v. For example, if the member being set is a short, this statement will throw an exception, because T is deduced as int:

sample.value("my_short", 10);

There are two ways to specify that the member is a short:

sample.value<short>("my_short", 10);
sample.value("my_short", (short) 10);
Parameters
nameThe member name, see Member Names and Indexes. This function also allows to access nested members
vThe value to set for that member
Exceptions
SeeExceptions accessing a member
See also
member_exists(const std::string&) const
Publishing data using DynamicData

◆ value() [2/4]

template<typename T >
void dds::core::xtypes::DynamicData::value ( uint32_t  index,
const T &  v 
)

Sets the value of a member by member index.

Parameters
indexThe position of the member in the type, see Member Names and Indexes.
vThe value to set for that member
Exceptions
SeeExceptions accessing a member
See also
value(const std::string&, const T&)
Member Names and Indexes

◆ value() [3/4]

template<typename T >
T dds::core::xtypes::DynamicData::value ( const std::string &  name) const

Gets the value of a member by member name.

Template Parameters
TThe type of the member. See value(const std::string&, const T&)

For examples on how to get member values, see Subscribing to data using DynamicData.

Parameters
nameThe member name, see Member Names and Indexes.
Returns
The value of that member
Exceptions
SeeExceptions accessing a member
See also
value(const std::string&, const T&)
Subscribing to data using DynamicData

◆ value() [4/4]

template<typename T >
T dds::core::xtypes::DynamicData::value ( uint32_t  index) const

Gets the value of a member by member index.

Template Parameters
TThe type of the member. See value(const std::string&, const T&)

For examples on how to get member values, see Subscribing to data using DynamicData.

Parameters
indexThe position of the member in the type, see Member Names and Indexes.
Returns
The value of that member
Exceptions
SeeExceptions accessing a member
See also
value(const std::string&, const T&)
Member Names and Indexes

◆ get_values() [1/4]

template<typename T >
void dds::core::xtypes::DynamicData::get_values ( const std::string &  name,
std::vector< T > &  out_array 
) const

Obtains the values of an array or sequence member by member name.

This function reuses an existing vector

Template Parameters
TThe element type of the array or sequence. These are the possible types:
  • The primitive types char, (u)int8_t, (u)int16_t, DDS_Long, DDS_UnsignedLong, DDS_LongLong, DDS_UnsignedLongLong, float, double. The types int and unsigned int may be used instead of DDS_Long and DDS_UnsignedLong except in some platforms (VxWorks).
  • If the element type is an enumeration, use int32_t.
  • If the element type is bool, use uint8_t.
Parameters
nameThe member name, see Member Names and Indexes.
out_arrayA vector containing the values of that array or sequence. The vector will be resized accordingly.

◆ get_values() [2/4]

template<typename T >
void dds::core::xtypes::DynamicData::get_values ( uint32_t  index,
std::vector< T > &  out_array 
) const

Obtains the values of an array or sequence member by member index.

This function reuses an existing vector

Template Parameters
TThe element type of the array or sequence. (See get_values(const std::string&, std::vector<T>&) const)
Parameters
indexThe position of the array or sequence member in the type, see Member Names and Indexes.
out_arrayA vector containing the values of that array or sequence. The vector will be resized accordingly.
See also
Member Names and Indexes
get_values(const std::string& name, std::vector<T>& out_array) const

◆ get_values() [3/4]

template<typename T >
std::vector<T> dds::core::xtypes::DynamicData::get_values ( uint32_t  index) const

Obtains the values of an array or sequence member by member index.

This function returns a new vector.

Template Parameters
TThe element type of the array or sequence. (See get_values(const std::string&, std::vector<T>&) const)
Parameters
indexThe position of the array or sequence member in the type
Returns
A vector containing the values of that array or sequence.
See also
Member Names and Indexes
get_values(const std::string& name, std::vector<T>& out_array) const

◆ get_values() [4/4]

template<typename T >
std::vector<T> dds::core::xtypes::DynamicData::get_values ( const std::string &  name) const

Obtains the values of an array or sequence member by member name.

This function returns a new vector.

Template Parameters
TThe element type of the array or sequence. (See get_values(const std::string&, std::vector<T>&) const)
Parameters
nameThe member name, see Member Names and Indexes.
Returns
A vector containing the values of that array or sequence.
See also
get_values(const std::string& name, std::vector<T>& out_array) const

◆ set_values() [1/2]

template<typename T >
void dds::core::xtypes::DynamicData::set_values ( uint32_t  index,
const std::vector< T > &  v 
)

Sets the values of an array or sequence member by member index.

Template Parameters
TThe element type of the array or sequence. (See get_values(const std::string&, std::vector<T>&) const)
Parameters
indexThe position of the array or sequence member in the type
vA vector containing the values to be set for that array or sequence.
See also
Member Names and Indexes
get_values(const std::string& name, std::vector<T>& out_array) const

◆ set_values() [2/2]

template<typename T >
void dds::core::xtypes::DynamicData::set_values ( const std::string &  name,
const std::vector< T > &  v 
)

Sets the values of an array or sequence member by member name.

Template Parameters
TThe element type of the array or sequence. (See get_values(const std::string&, std::vector<T>&) const)
Parameters
nameThe member name, see Member Names and Indexes.
vA vector containing the values to be set for that array or sequence.
See also
get_values(const std::string& name, std::vector<T>& out_array) const

◆ loan_value() [1/4]

LoanedDynamicData dds::core::xtypes::DynamicData::loan_value ( const std::string &  name)

Gets a view of a complex member.

This function returns a new LoanedDynamicData instance.

Only a single member of a given DynamicData object may be loaned at a time. However, members of members may be recursively loaned to any depth. Furthermore, while the outer object has a bound member, it may only be modified through that bound member. That is, after loaning this member, the outer object disables all calls to set value() until the loan is returned.

This method, as opposed to value<DynamicData>() doesn't make a copy; it provides a view of the member so changes to the loaned member change the outer object.

Parameters
nameThe member name, see Member Names and Indexes.
Returns
The object to access the complex member
See also
rti::core::xtypes::LoanedDynamicData
Using DynamicData.

◆ loan_value() [2/4]

LoanedDynamicData dds::core::xtypes::DynamicData::loan_value ( uint32_t  index)

Gets a view of a complex member.

This function returns a new LoanedDynamicData instance.

Parameters
indexThe position of the member in the type, see Member Names and Indexes.
Returns
The object to access the complex member
See also
loan_value(const std::string&)
rti::core::xtypes::LoanedDynamicData
Member Names and Indexes

◆ loan_value() [3/4]

LoanedDynamicData& dds::core::xtypes::DynamicData::loan_value ( LoanedDynamicData &  data,
const std::string &  name 
)

Gets a view of a complex member.

This function reuses a LoanedDynamicData instance, returning its previous loan.

Parameters
dataThe object to access the complex member
nameThe member name, see Member Names and Indexes.
See also
loan_value(const std::string&)
rti::core::xtypes::LoanedDynamicData

◆ loan_value() [4/4]

LoanedDynamicData& dds::core::xtypes::DynamicData::loan_value ( LoanedDynamicData &  data,
uint32_t  mid 
)

Gets a view of a complex member.

This function reuses a LoanedDynamicData instance, returning its previous loan.

Parameters
dataThe object to access the complex member
midThe position of the member in the type, see Member Names and Indexes.
See also
loan_value(const std::string&)
rti::core::xtypes::LoanedDynamicData

◆ discriminator_value()

uint32_t dds::core::xtypes::DynamicData::discriminator_value ( ) const

Obtains the value of the union discriminator (UnionType only)

Use the value that this function returns in any function expecting a member index to access the active member in this union.

For example, given the following IDL Union:

union Foo switch (short) {
case 1:
long x;
case 2:
case 3:
string y;
};

If we have a DynamicData sample of that type whose active member is "y", we can access it as follows:

std::string y_value = sample.value<std::string>(sample.discriminator_value());
y_value = sample.value<std::string>("y"); // Same effect
y_value = sample.value<std::string>(3); // Same effect

If you set a different member, the discriminator value automatically changes:

sample.value("x", 10);
assert (sample.discriminator_value() == 1);
Precondition
type().kind() == TypeKind::UNION_TYPE – Only applies to samples of a UnionType.
Returns
The value of this sample's discriminator.

◆ clear_all_members()

void dds::core::xtypes::DynamicData::clear_all_members ( )

Clear the contents of all data members of this object, including key members.

MT Safety:
UNSAFE.
Exceptions
Oneof the Standard Exceptions
See also
dds::core::xtypes::DynamicData::clear_optional_member

◆ clear_optional_member() [1/2]

void dds::core::xtypes::DynamicData::clear_optional_member ( const std::string &  name)

Clear the contents of a single optional data member of this object.

Parameters
nameThe member name, see Member Names and Indexes.

◆ clear_optional_member() [2/2]

void dds::core::xtypes::DynamicData::clear_optional_member ( uint32_t  index)

Clear the contents of a single optional data member of this object.

Parameters
indexThe position of the member in the type, see Member Names and Indexes.

◆ clear_member() [1/2]

void dds::core::xtypes::DynamicData::clear_member ( const std::string &  name)

Clear the contents of a single data member of this object.

Parameters
nameThe member name, see Member Names and Indexes.

◆ clear_member() [2/2]

void dds::core::xtypes::DynamicData::clear_member ( uint32_t  index)

Clear the contents of a single data member of this object.

Parameters
indexThe position of the member in the type, see Member Names and Indexes.

◆ type()

const dds::core::xtypes::DynamicType& dds::core::xtypes::DynamicData::type ( ) const

Gets the data type of this DynamicData.

◆ type_kind()

dds::core::xtypes::TypeKind dds::core::xtypes::DynamicData::type_kind ( ) const

Gets the data type kind of this DynamicData.

Returns
this->type().kind().

◆ member_count()

uint32_t dds::core::xtypes::DynamicData::member_count ( ) const

Get the number of members in this sample.

For objects of type ArrayType or SequenceType, this method returns the number of elements in the collection.

For objects of type kind StructType, it returns the number of fields in the sample, which will always be the same as the number of fields in the type.

◆ member_exists() [1/2]

bool dds::core::xtypes::DynamicData::member_exists ( const std::string &  name) const

Indicates whether a member exists in this sample.

If the member doesn't exist in the type, this function returns false. In all other cases, it provides the same result as rti::core::xtypes::DynamicDataMemberInfo::member_exists(), which is retrieved with member_info()).

Parameters
nameThe member name, see Member Names and Indexes.

◆ member_exists() [2/2]

bool dds::core::xtypes::DynamicData::member_exists ( uint32_t  index) const

Indicates whether a member exists in this sample.

If the member doesn't exist in the type, this function returns false. In all other cases, it provides the same result as rti::core::xtypes::DynamicDataMemberInfo::member_exists(), which is retrieved with member_info()).

Parameters
indexThe member index, see Member Names and Indexes.

◆ member_exists_in_type() [1/2]

bool dds::core::xtypes::DynamicData::member_exists_in_type ( const std::string &  name) const

Indicates whether a member with a particular name exists in type()

◆ member_exists_in_type() [2/2]

bool dds::core::xtypes::DynamicData::member_exists_in_type ( uint32_t  index) const

Indicates whether a member of a particular index exists in type()

◆ info()

DynamicDataInfo dds::core::xtypes::DynamicData::info ( ) const

Returns information about this sample.

◆ member_info() [1/2]

rti::core::xtypes::DynamicDataMemberInfo dds::core::xtypes::DynamicData::member_info ( const std::string &  name) const

Returns information about a member.

Precondition
this->type_kind() must be dds::core::xtypes::TypeKind_def::ARRAY_TYPE, dds::core::xtypes::TypeKind_def::SEQUENCE_TYPE, dds::core::xtypes::TypeKind_def::STRUCTURE_TYPE, or dds::core::xtypes::TypeKind_def::UNION_TYPE

When name identifies a field in a struct or union:

When name identifies a sequence element, such as "my_sequence[i]":

When name identifies an array element, such as "my_array[i], this function either throws when the i is out of bounds or else returns an object with rti::core::xtypes::DynamicDataMemberInfo::member_exists() set to true.

Parameters
nameThe member name, see Member Names and Indexes.
Returns
Information about the member.
Exceptions
dds::core::InvalidArgumentErrorif the member doesn't exist in the type, or Standard Exceptions.

◆ member_info() [2/2]

rti::core::xtypes::DynamicDataMemberInfo dds::core::xtypes::DynamicData::member_info ( uint32_t  index) const

Returns information about a member.

Precondition
this->type_kind() must be dds::core::xtypes::TypeKind_def::ARRAY_TYPE, dds::core::xtypes::TypeKind_def::SEQUENCE_TYPE, or dds::core::xtypes::TypeKind_def::STRUCTURE_TYPE, dds::core::xtypes::TypeKind_def::UNION_TYPE

When this sample represents a struct and index is the position of the member in the type definition, or when the sample represents a union and index is the discriminator value:

When this sample represents a sequence and index is the 1-based element index:

When this sample represents an array this function either throws dds::core::InvalidArgumentError when the index is out of bounds or else returns an object with rti::core::xtypes::DynamicDataMemberInfo::member_exists() set to true.

Parameters
indexThe member index, see Member Names and Indexes.
Returns
DynamicDataMemberInfo Information about the member.
Exceptions
dds::core::InvalidArgumentErrorif the member doesn't exist in the type or the element with this index doesn't exist in this sequence. See also Standard Exceptions.

◆ member_index()

uint32_t dds::core::xtypes::DynamicData::member_index ( const std::string &  name) const

Translates from member name to member index.

Parameters
nameThe member name, see Member Names and Indexes.
Returns
The member index for the member with that name
Exceptions
SeeExceptions accessing a member

◆ is_member_key() [1/2]

bool dds::core::xtypes::DynamicData::is_member_key ( const std::string &  name) const

Returns whether a member is a key.

Parameters
nameThe member name, see Member Names and Indexes.
Exceptions
SeeExceptions accessing a member

◆ is_member_key() [2/2]

bool dds::core::xtypes::DynamicData::is_member_key ( uint32_t  index) const

Returns whether a member is a key.

Parameters
indexThe member index, see Member Names and Indexes.
Exceptions
SeeExceptions accessing a member

Friends And Related Function Documentation

◆ to_cdr_buffer()

std::vector< char > & to_cdr_buffer ( std::vector< char > &  buffer,
const DynamicData sample,
dds::core::policy::DataRepresentationId  representation_id = dds::core::policy::DataRepresentation::auto_id() 
)
related

<<extension>> Serializes a DynamicData sample into CDR format

Parameters
bufferThe output buffer, which will be resized to the correct size
sampleThe sample to serialize
representation_idThe data representation used to serialize the data
Returns
A reference to buffer

◆ from_cdr_buffer()

DynamicData & from_cdr_buffer ( DynamicData sample,
const std::vector< char > &  buffer 
)
related

<<extension>> Creates a DynamicData sample by deserializing a CDR buffer'

Parameters
sampleThe sample to deserialize.
bufferThe buffer containing the CDR data
Returns
A reference to sample

◆ convert() [1/2]

template<typename TopicType >
TopicType convert ( const DynamicData sample)
related

<<extension>> Creates a typed sample from a DynamicData sample.

This function is useful when an application uses DynamicData and regular typed Topics at the same time.

For example, given this IDL type:

struct Foo {
long x;
};

We can convert from Foo and DynamicData:

// Receive a DynamicData sample
assert (samples.size() > 0);
// Create a Foo sample
const DynamicData& dynamic_data = samples[0].data();
assert (can_convert<Foo>(dynamic_data));
Foo typed_data = convert<Foo>(dynamic_data);
assert (typed_data.x() == dynamic_data.value<int32_t>("x"));
Precondition
can_convert<TopicType>(sample), otherwise the behavior is undefined.
Template Parameters
TopicTypeAn IDL topic-type
Parameters
sampleThe DynamicData sample to convert to type TopicType
Returns
An instance of TopicType containing the data in sample.

◆ convert() [2/2]

template<typename TopicType >
DynamicData convert ( const TopicType &  sample)
related

<<extension>> Creates a DynamicData sample from a typed sample

Template Parameters
TopicTypeAn IDL topic-type
Parameters
sampleThe typed sample to convert to DynamicData
Returns
A new DynamicData object whose type is rti::topic::dynamic_type<TopicType> and contains the data from sample

◆ can_convert()

template<typename TopicType >
bool can_convert ( const DynamicData sample)
related

<<extension>> Determines if the DynamicType of this sample is equal to the DynamicType of TopicType

Template Parameters
TopicTypeAn IDL topic-type
Returns
True if the DynamicType of TopicType is the same as this sample's and therefore it is possible to create an instance of TopicType from this DynamicData object.
See also
convert()

◆ get_tuple()

template<typename... Types>
std::tuple< Types... > get_tuple ( const dds::core::xtypes::DynamicData data)
related

<<C++11>> <<experimental>> <<extension>> Retrieves all the values of a DynamicData object into an std::tuple at once

See also
Manipulating data reflectively using C++ tuples

◆ set_tuple()

template<typename... Types>
void set_tuple ( dds::core::xtypes::DynamicData data,
const std::tuple< Types... > &  value 
)
related

<<C++11>> <<experimental>> <<extension>> Assigns the values of a std::tuple to a DynamicData object at once

See also
Manipulating data reflectively using C++ tuples