RTI Connext Modern C++ API  Version 5.3.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dds::core::xtypes::DynamicType Class Reference

<<value-type>> Represents a runtime type. More...

#include "dds/core/xtypes/DynamicType.hpp"

Inheritance diagram for dds::core::xtypes::DynamicType:
dds::core::xtypes::AbstractConstructedType< EnunMember > dds::core::xtypes::AbstractConstructedType< Member > dds::core::xtypes::AbstractConstructedType< UnionMember > dds::core::xtypes::AbstractConstructedType< MemberType > dds::core::xtypes::AliasType dds::core::xtypes::CollectionType dds::core::xtypes::PrimitiveType dds::core::xtypes::EnumType dds::core::xtypes::StructType dds::core::xtypes::UnionType dds::core::xtypes::ArrayType dds::core::xtypes::UnidimensionalCollectionType dds::core::xtypes::SequenceType dds::core::xtypes::StringType dds::core::xtypes::WStringType

Public Member Functions

dds::core::xtypes::TypeKind kind () const
 Gets the type kind.
 
std::string name () const
 Gets the name.
 

Related Functions

(Note that these are not member functions.)

bool is_primitive_type (const DynamicType &t)
 Determines if a DynamicType is a PrimitiveType.
 
bool is_constructed_type (const DynamicType &t)
 Determines if a DynamicType is a constructed type.
 
bool is_collection_type (const DynamicType &t)
 Determines if a DynamicType is a CollectionType.
 
bool is_aggregation_type (const DynamicType &t)
 Determines if a DynamicType is an aggregation type.
 
void print_idl (const DynamicType &type, unsigned int indent=0)
 <<extension>> Prints the IDL representation of this type to the standard output
 

Detailed Description

<<value-type>> Represents a runtime type.

A DynamicType is a mechanism for representing a type at runtime. DynamicTypes allow the reflective manipulation of data (DynamicData) and the inspection of the type information about discovered readers and writers.

You can obtain a DynamicType in a few different ways:

  1. Creating one by instantiating a subclass of dds::core::xtypes::DynamicType instance, such as dds::core::xtypes::StructType and adding members to it. For example:
    using namespace dds::core::xtypes;
    StructType point_type("Point");
    point_type.add_member(Member("x", PrimitiveType<double>()));
    point_type.add_member(Member("y", PrimitiveType<double>()));
  2. From an IDL-generated type, using the rti::topic::dynamic_type trait type. <<extension>>
  3. From an XML description, using dds::core::QosProvider::type().
  4. Constructing it using tuples. <<C++11>> <<experimental>> <<extension>>
  5. From a discovered DataReader or DataWriter, using the built-in topics.

For examples, see DynamicType and DynamicData Use Cases

This an abstract base class of all the types. This class contains all of the internal state—derived classes don't add any new state. That means that it is safe to copy a DynamicType without slicing.

To downcast a DynamicType into a concrete class, you can check its kind() and then apply a static_cast to the appropriate class.

For example, let's assume we have the following IDL type:

struct Bar {
long x;
};
struct Foo {
Bar bar;
long y;
};

We obtain the type of Foo and want to know the type of its member bar:

// Get the DynamicType of the IDL-generated type Foo
const StructType& foo_type = rti::topic::dynamic_type<Foo>::get();
// Get the type of its member bar
const DynamicType& bar_type = foo_type.member("bar").type();
// Check type kind and downcast
if (bar_type.kind() == TypeKind::STRUCTURE_TYPE) {
const StructType& bar_struct = static_cast<const StructType&>(bar_type);
}
See Also
dds::core::xtypes::DynamicData, the class that represents data samples for a DynamicType
dds::topic::SubscriptionBuiltinTopicData::type() and dds::topic::PublicationBuiltinTopicData::type() to obtain the type of a remote subscription or publication
rti::topic::dynamic_type to obtain the equivalent DynamicType of an IDL-generated type
DynamicType and DynamicData Use Cases

Member Function Documentation

dds::core::xtypes::TypeKind dds::core::xtypes::DynamicType::kind ( ) const

Gets the type kind.

std::string dds::core::xtypes::DynamicType::name ( ) const

Gets the name.

Friends And Related Function Documentation

bool is_primitive_type ( const DynamicType t)
related

Determines if a DynamicType is a PrimitiveType.

bool is_constructed_type ( const DynamicType t)
related

Determines if a DynamicType is a constructed type.

This includes EnumType, AliasType, collection types and aggregation types.

See Also
is_collection_type
is_aggregation_type
bool is_collection_type ( const DynamicType t)
related

Determines if a DynamicType is a CollectionType.

This includes ArrayType, SequenceType, StringType, and WStringType.

bool is_aggregation_type ( const DynamicType t)
related

Determines if a DynamicType is an aggregation type.

This includes StructType and UnionType.

void print_idl ( const DynamicType type,
unsigned int  indent = 0 
)
related

<<extension>> Prints the IDL representation of this type to the standard output


RTI Connext Modern C++ API Version 5.3.1 Copyright © Mon Feb 19 2018 Real-Time Innovations, Inc