From 2d178cda978b8a8be157ab74a195fe072f3fd6eb Mon Sep 17 00:00:00 2001 From: adriancampo Date: Sun, 17 Mar 2024 10:26:18 +0100 Subject: [PATCH] Refs #20359: Updated xtypes doc. Signed-off-by: adriancampo --- code/CodeTester.cpp | 718 --------------- code/DDSCodeTester.cpp | 821 ++++++++++++++++- code/DynamicTypesIDLExamples.idl | 219 +++++ code/XMLTester.xml | 197 +++-- docs/03-exports/aliases-api.include | 37 +- docs/03-exports/aliases.include | 56 +- .../fastdds/api_reference/dds_pim/dds_pim.rst | 1 + .../dds_pim/xtypes/annotationdescriptor.rst | 10 + .../dds_pim/xtypes/dynamic_types.rst | 32 + .../dds_pim/xtypes/dynamicdata.rst | 10 + .../dds_pim/xtypes/dynamicdatafactory.rst | 10 + .../dds_pim/xtypes/dynamicpubsubtype.rst | 10 + .../dds_pim/xtypes/dynamictype.rst | 10 + .../dds_pim/xtypes/dynamictypebuilder.rst | 10 + .../xtypes/dynamictypebuilderfactory.rst | 10 + .../dds_pim/xtypes/dynamictypemember.rst | 10 + .../dds_pim/xtypes/exception.rst | 10 + .../dds_pim/xtypes/memberdescriptor.rst | 10 + .../dds_pim/xtypes/type_representation.rst | 7 + .../dds_pim/xtypes/typedescriptor.rst | 10 + .../dds_pim/xtypes/typeobjectregistry.rst | 10 + .../dds_pim/xtypes/typeobjectutils.rst | 10 + .../dds_pim/xtypes/verbatimtextdescriptor.rst | 10 + .../api_reference/dds_pim/xtypes/xtypes.rst | 8 + docs/fastdds/dynamic_types/annotations.rst | 63 -- docs/fastdds/dynamic_types/complex_types.rst | 85 -- docs/fastdds/dynamic_types/concepts.rst | 188 ---- docs/fastdds/dynamic_types/discovery.rst | 133 --- .../dynamic_types/discovery_matching.rst | 66 ++ docs/fastdds/dynamic_types/dynamic_types.rst | 17 +- docs/fastdds/dynamic_types/examples.rst | 50 -- .../dynamic_types/language_binding.rst | 827 ++++++++++++++++++ .../dynamic_types/memory_management.rst | 34 - docs/fastdds/dynamic_types/serialization.rst | 16 - .../fastdds/dynamic_types/supported_types.rst | 321 ------- docs/fastdds/dynamic_types/xml_profiles.rst | 17 - .../xml_configuration/dynamic_types.rst | 353 ++++++-- docs/fastddsgen/dataTypes/dataTypes.rst | 14 +- docs/notes/previous_versions/v2.4.2.rst | 2 +- 39 files changed, 2575 insertions(+), 1847 deletions(-) create mode 100644 code/DynamicTypesIDLExamples.idl create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/annotationdescriptor.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamic_types.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamicdata.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamicdatafactory.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamicpubsubtype.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamictype.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilder.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilderfactory.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/dynamictypemember.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/exception.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/memberdescriptor.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/type_representation.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/typedescriptor.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/typeobjectregistry.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/typeobjectutils.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/verbatimtextdescriptor.rst create mode 100644 docs/fastdds/api_reference/dds_pim/xtypes/xtypes.rst delete mode 100644 docs/fastdds/dynamic_types/annotations.rst delete mode 100644 docs/fastdds/dynamic_types/complex_types.rst delete mode 100644 docs/fastdds/dynamic_types/concepts.rst delete mode 100644 docs/fastdds/dynamic_types/discovery.rst create mode 100644 docs/fastdds/dynamic_types/discovery_matching.rst delete mode 100644 docs/fastdds/dynamic_types/examples.rst create mode 100644 docs/fastdds/dynamic_types/language_binding.rst delete mode 100644 docs/fastdds/dynamic_types/memory_management.rst delete mode 100644 docs/fastdds/dynamic_types/serialization.rst delete mode 100644 docs/fastdds/dynamic_types/supported_types.rst delete mode 100644 docs/fastdds/dynamic_types/xml_profiles.rst diff --git a/code/CodeTester.cpp b/code/CodeTester.cpp index dbb3be40f..10513a2ae 100644 --- a/code/CodeTester.cpp +++ b/code/CodeTester.cpp @@ -10,9 +10,6 @@ #include #include #include -#include -#include -#include #include #include @@ -20,7 +17,6 @@ using namespace eprosima::fastrtps; using namespace ::rtps; using namespace ::security; -using namespace ::types; class HelloWorld { @@ -294,720 +290,6 @@ void rtps_api_example_conf() //!-- } -void xml_dyn_examples_check() -{ - //XML-DYN-ENUM - eprosima::fastrtps::types::DynamicTypeBuilder_ptr enum_builder = - DynamicTypeBuilderFactory::get_instance()->create_enum_builder(); - enum_builder->set_name("MyEnum"); - enum_builder->add_empty_member(0, "A"); - enum_builder->add_empty_member(1, "B"); - enum_builder->add_empty_member(2, "C"); - DynamicType_ptr enum_type = DynamicTypeBuilderFactory::get_instance()->create_type(enum_builder.get()); - //!-- - //XML-TYPEDEF - eprosima::fastrtps::types::DynamicTypeBuilder_ptr alias1_builder = - DynamicTypeBuilderFactory::get_instance()->create_alias_builder( - enum_builder.get(), "MyAlias1"); - DynamicType_ptr alias1_type = DynamicTypeBuilderFactory::get_instance()->create_type(alias1_builder.get()); - - std::vector sequence_lengths = { 2, 2 }; - eprosima::fastrtps::types::DynamicTypeBuilder_ptr int_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr array_builder = - DynamicTypeBuilderFactory::get_instance()->create_array_builder( - int_builder.get(), sequence_lengths); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr alias2_builder = - DynamicTypeBuilderFactory::get_instance()->create_alias_builder( - array_builder.get(), "MyAlias2"); - DynamicType_ptr alias2_type = DynamicTypeBuilderFactory::get_instance()->create_type(alias2_builder.get()); - //!-- - { - //XML-STRUCT - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int64_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - - struct_builder->set_name("MyStruct"); - struct_builder->add_member(0, "first", long_builder.get()); - struct_builder->add_member(1, "second", long_long_builder.get()); - DynamicType_ptr struct_type = DynamicTypeBuilderFactory::get_instance()->create_type(struct_builder.get()); - //!-- - } - { - //XML-STRUCT-INHERIT - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int64_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - - struct_builder->set_name("ParentStruct"); - struct_builder->add_member(0, "first", long_builder.get()); - struct_builder->add_member(1, "second", long_long_builder.get()); - DynamicType_ptr struct_type = DynamicTypeBuilderFactory::get_instance()->create_type(struct_builder.get()); - - eprosima::fastrtps::types::DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance()->create_child_struct_builder(struct_builder.get()); - - child_builder->set_name("ChildStruct"); - child_builder->add_member(0, "third", long_builder.get()); - child_builder->add_member(1, "fourth", long_long_builder.get()); - DynamicType_ptr child_struct_type = DynamicTypeBuilderFactory::get_instance()->create_type(child_builder.get()); - //!-- - } - { - //XML-UNION - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int64_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr octet_builder = - DynamicTypeBuilderFactory::get_instance()->create_byte_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr union_builder = - DynamicTypeBuilderFactory::get_instance()->create_union_builder( - octet_builder.get()); - - union_builder->set_name("MyUnion"); - union_builder->add_member(0, "first", long_builder.get(), "", { 0, 1 }, false); - union_builder->add_member(1, "second", struct_builder.get(), "", { 2 }, false); - union_builder->add_member(2, "third", long_long_builder.get(), "", { }, true); - DynamicType_ptr union_type = DynamicTypeBuilderFactory::get_instance()->create_type(union_builder.get()); - //!-- - } - { - //XML-GENERIC - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int64_builder(); - long_long_builder->set_name("my_long"); - DynamicType_ptr long_long_type = - DynamicTypeBuilderFactory::get_instance()->create_type(long_long_builder.get()); - //!-- - } - { - //XML-BOUNDEDSTRINGS - eprosima::fastrtps::types::DynamicTypeBuilder_ptr string_builder = - DynamicTypeBuilderFactory::get_instance()->create_string_builder(41925); - string_builder->set_name("my_large_string"); - DynamicType_ptr string_type = DynamicTypeBuilderFactory::get_instance()->create_type(string_builder.get()); - - eprosima::fastrtps::types::DynamicTypeBuilder_ptr wstring_builder = - DynamicTypeBuilderFactory::get_instance()->create_wstring_builder(20925); - wstring_builder->set_name("my_large_wstring"); - DynamicType_ptr wstring_type = DynamicTypeBuilderFactory::get_instance()->create_type(wstring_builder.get()); - //!-- - } - { - //XML-ARRAYS - std::vector lengths = { 2, 3, 4 }; - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr array_builder = - DynamicTypeBuilderFactory::get_instance()->create_array_builder( - long_builder.get(), lengths); - array_builder->set_name("long_array"); - DynamicType_ptr array_type = DynamicTypeBuilderFactory::get_instance()->create_type(array_builder.get()); - //!-- - } - { - //XML-SEQUENCES - uint32_t child_len = 2; - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr seq_builder = - DynamicTypeBuilderFactory::get_instance()->create_sequence_builder( - long_builder.get(), - child_len); - uint32_t length = 3; - eprosima::fastrtps::types::DynamicTypeBuilder_ptr seq_seq_builder = - DynamicTypeBuilderFactory::get_instance()->create_sequence_builder( - seq_builder.get(), length); - seq_seq_builder->set_name("my_sequence_sequence"); - DynamicType_ptr seq_type = DynamicTypeBuilderFactory::get_instance()->create_type(seq_seq_builder.get()); - //!-- - } - { - //XML-MAPS - uint32_t length = 2; - eprosima::fastrtps::types::DynamicTypeBuilder_ptr long_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr map_builder = - DynamicTypeBuilderFactory::get_instance()->create_map_builder( - long_builder.get(), - long_builder.get(), length); - - eprosima::fastrtps::types::DynamicTypeBuilder_ptr map_map_builder = - DynamicTypeBuilderFactory::get_instance()->create_map_builder( - long_builder.get(), - map_builder.get(), length); - map_map_builder->set_name("my_map_map"); - DynamicType_ptr map_type = DynamicTypeBuilderFactory::get_instance()->create_type(map_map_builder.get()); - //!-- - } - { - //XML-BITSET - DynamicTypeBuilderFactory* m_factory = DynamicTypeBuilderFactory::get_instance(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder_ptr = m_factory->create_bitset_builder(); - builder_ptr->add_member(0, "a", m_factory->create_byte_builder()->build()); - builder_ptr->add_member(1, "b", m_factory->create_bool_builder()->build()); - builder_ptr->add_member(3, "c", m_factory->create_uint16_builder()->build()); - builder_ptr->add_member(4, "d", m_factory->create_int16_builder()->build()); - builder_ptr->apply_annotation_to_member(0, ANNOTATION_BIT_BOUND_ID, "value", "3"); - builder_ptr->apply_annotation_to_member(0, ANNOTATION_POSITION_ID, "value", "0"); - builder_ptr->apply_annotation_to_member(1, ANNOTATION_BIT_BOUND_ID, "value", "1"); - builder_ptr->apply_annotation_to_member(1, ANNOTATION_POSITION_ID, "value", "3"); - builder_ptr->apply_annotation_to_member(3, ANNOTATION_BIT_BOUND_ID, "value", "10"); - builder_ptr->apply_annotation_to_member(3, ANNOTATION_POSITION_ID, "value", "8"); // 4 empty - builder_ptr->apply_annotation_to_member(4, ANNOTATION_BIT_BOUND_ID, "value", "12"); - builder_ptr->apply_annotation_to_member(4, ANNOTATION_POSITION_ID, "value", "18"); - builder_ptr->set_name("MyBitSet"); - //!-- - } - { - //XML-BITMASK - DynamicTypeBuilderFactory* m_factory = DynamicTypeBuilderFactory::get_instance(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder_ptr = m_factory->create_bitmask_builder(8); - builder_ptr->add_empty_member(0, "flag0"); - builder_ptr->add_empty_member(1, "flag1"); - builder_ptr->add_empty_member(2, "flag2"); - builder_ptr->add_empty_member(5, "flag5"); - builder_ptr->set_name("MyBitMask"); - //!-- - } - { - //XML-BITSET-INHERIT - DynamicTypeBuilderFactory* m_factory = DynamicTypeBuilderFactory::get_instance(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder_ptr = m_factory->create_bitset_builder(); - builder_ptr->add_member(0, "a", m_factory->create_byte_builder()->build()); - builder_ptr->add_member(1, "b", m_factory->create_bool_builder()->build()); - builder_ptr->apply_annotation_to_member(0, ANNOTATION_BIT_BOUND_ID, "value", "3"); - builder_ptr->apply_annotation_to_member(0, ANNOTATION_POSITION_ID, "value", "0"); - builder_ptr->apply_annotation_to_member(1, ANNOTATION_BIT_BOUND_ID, "value", "1"); - builder_ptr->apply_annotation_to_member(1, ANNOTATION_POSITION_ID, "value", "3"); - builder_ptr->set_name("ParentBitSet"); - - eprosima::fastrtps::types::DynamicTypeBuilder_ptr child_ptr = m_factory->create_child_struct_builder( - builder_ptr.get()); - child_ptr->add_member(3, "c", m_factory->create_uint16_builder()->build()); - child_ptr->add_member(4, "d", m_factory->create_int16_builder()->build()); - child_ptr->apply_annotation_to_member(3, ANNOTATION_BIT_BOUND_ID, "value", "10"); - child_ptr->apply_annotation_to_member(3, ANNOTATION_POSITION_ID, "value", "8"); // 4 empty - child_ptr->apply_annotation_to_member(4, ANNOTATION_BIT_BOUND_ID, "value", "12"); - child_ptr->apply_annotation_to_member(4, ANNOTATION_POSITION_ID, "value", "18"); - child_ptr->set_name("ChildBitSet"); - //!-- - } -} - -void dynamictypes_configuration() -{ - { - //DYNAMIC_TYPES_QUICK_EXAMPLE - // Create a builder for a specific type - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_enum_builder(); - - // Use the builder to configure the type - builder->add_empty_member(0, "DEFAULT"); - builder->add_empty_member(1, "FIRST"); - builder->add_empty_member(2, "SECOND"); - - // Create the data type using the builder - // The builder will internally use the DynamicTypeBuilderFactory to create the type - DynamicType_ptr type = builder->build(); - - // Create a new data instance of the create data type - DynamicData_ptr data (DynamicDataFactory::get_instance()->create_data(type)); - - // Now we can set or read data values - data->set_int32_value(1); - - // No need of deleting the objects, since we used the - // automanaged smart pointers - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_PRIMITIVES - // Using Builders - eprosima::fastrtps::types::DynamicTypeBuilder_ptr created_builder = - DynamicTypeBuilderFactory::get_instance()->create_int32_builder(); - DynamicType_ptr created_type = DynamicTypeBuilderFactory::get_instance()->create_type(created_builder.get()); - DynamicData* data = DynamicDataFactory::get_instance()->create_data(created_type); - data->set_int32_value(1); - - // Creating directly the Dynamic Type - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - DynamicData* data2 = DynamicDataFactory::get_instance()->create_data(pType); - data2->set_int32_value(1); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_STRINGS - // Using Builders - eprosima::fastrtps::types::DynamicTypeBuilder_ptr created_builder = - DynamicTypeBuilderFactory::get_instance()->create_string_builder(100); - DynamicType_ptr created_type = DynamicTypeBuilderFactory::get_instance()->create_type(created_builder.get()); - DynamicData* data = DynamicDataFactory::get_instance()->create_data(created_type); - data->set_string_value("Dynamic String"); - - // Creating directly the Dynamic Type - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance()->create_string_type(100); - DynamicData* data2 = DynamicDataFactory::get_instance()->create_data(pType); - data2->set_string_value("Dynamic String"); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_ALIAS - // Create the base type - eprosima::fastrtps::types::DynamicTypeBuilder_ptr base_builder = - DynamicTypeBuilderFactory::get_instance()->create_string_builder(100); - DynamicType_ptr base_type = DynamicTypeBuilderFactory::get_instance()->create_type(base_builder.get()); - - // Create alias using Builders - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_alias_builder(base_type, - "alias"); - DynamicData* data = DynamicDataFactory::get_instance()->create_data(builder.get()); - data->set_string_value("Dynamic Alias String"); - - // Create alias type directly - DynamicType_ptr pAliasType = DynamicTypeBuilderFactory::get_instance()->create_alias_type(base_type, "alias"); - DynamicData* data2 = DynamicDataFactory::get_instance()->create_data(pAliasType); - data2->set_string_value("Dynamic Alias String"); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_ENUMERATIONS - // Add enumeration values using the DynamicTypeBuilder - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_enum_builder(); - builder->add_empty_member(0, "DEFAULT"); - builder->add_empty_member(1, "FIRST"); - builder->add_empty_member(2, "SECOND"); - - // Create the data instance - DynamicData* data = DynamicDataFactory::get_instance()->create_data(builder.get()); - - // Access value using the name - std::string sValue = "SECOND"; - data->set_enum_value(sValue); - std::string sStoredValue; - data->get_enum_value(sStoredValue, MEMBER_ID_INVALID); - - // Access value using the index - uint32_t uValue = 2; - data->set_enum_value(uValue); - uint32_t uStoredValue; - data->get_enum_value(uStoredValue, MEMBER_ID_INVALID); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_BITSETS - // Create bitfields with the appropriate type for their size - eprosima::fastrtps::types::DynamicTypeBuilder_ptr base_type_byte_builder = - DynamicTypeBuilderFactory::get_instance()->create_byte_builder(); - auto base_type_byte = base_type_byte_builder->build(); - - eprosima::fastrtps::types::DynamicTypeBuilder_ptr base_type_uint32_builder = - DynamicTypeBuilderFactory::get_instance()->create_uint32_builder(); - auto base_type_uint32 = base_type_uint32_builder->build(); - - // Create the bitset with two bitfields - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_bitset_builder(); - builder->add_member(0, "byte", base_type_byte); - builder->add_member(1, "uint32", base_type_uint32); - - // Apply members' annotations - builder->apply_annotation_to_member(0, ANNOTATION_POSITION_ID, "value", "0"); // "byte" starts at position 0 - builder->apply_annotation_to_member(0, ANNOTATION_BIT_BOUND_ID, "value", "2"); // "byte" is 2 bit length - builder->apply_annotation_to_member(1, ANNOTATION_POSITION_ID, "value", "10"); // "uint32" starts at position 10 (8 bits empty) - builder->apply_annotation_to_member(1, ANNOTATION_BIT_BOUND_ID, "value", "20"); // "uint32" is 20 bits length - - // Create the data instance - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(builder.get())); - - // Access values - data->set_byte_value(234, 0); - data->set_uint32_value(2340, 1); - octet bValue; - uint32_t uValue; - data->get_byte_value(bValue, 0); - data->get_uint32_value(uValue, 1); - //!-- - //DYNAMIC_TYPES_CREATE_BITSETS-INHERIT - eprosima::fastrtps::types::DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance()->create_child_struct_builder(builder.get()); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_BITMASKS - uint32_t limit = 5; // Stores as "octet" - - // Add bitmask flags using the DynamicTypeBuilder - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_bitmask_builder(limit); - builder->add_empty_member(0, "FIRST"); - builder->add_empty_member(1, "SECOND"); - - // Create the data instance - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(builder.get())); - - // Access the mask values using the name - data->set_bool_value(true, "FIRST"); // Set the "FIRST" bit - bool bSecondValue = data->get_bool_value("SECOND"); // Get the "SECOND" bit - - // Access the mask values using the index - data->set_bool_value(true, 1); // Set the "SECOND" bit - bool bFirstValue = data->get_bool_value(0); // Get the "FIRST" bit - - // Get the complete bitmask as integer - uint64_t fullValue; - data->get_bitmask_value(fullValue); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_STRUCTS - // Build a structure with two fields ("first" as int32, "other" as uint64) using DynamicTypeBuilder - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - builder->add_member(0, "first", DynamicTypeBuilderFactory::get_instance()->create_int32_type()); - builder->add_member(1, "other", DynamicTypeBuilderFactory::get_instance()->create_uint64_type()); - DynamicType_ptr struct_type(builder->build()); - - // Create the data instance - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(struct_type)); - - // Access struct members - data->set_int32_value(5, 0); - data->set_uint64_value(13, 1); - //!-- - //DYNAMIC_TYPES_CREATE_STRUCTS-INHERIT - eprosima::fastrtps::types::DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance()->create_child_struct_builder(builder.get()); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_UNIONS - // Create the union DynamicTypeBuilder with an int32 discriminator - DynamicType_ptr discriminator = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_union_builder(discriminator); - - // Add the union members. "firts" will be the default value - builder->add_member(0, "first", DynamicTypeBuilderFactory::get_instance()->create_int32_type(), "", { 0 }, - true); - builder->add_member(0, "second", DynamicTypeBuilderFactory::get_instance()->create_int64_type(), "", { 1 }, - false); - - // Create the data instance - DynamicType_ptr union_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(union_type)); - - // Access the values using the member index - data->set_int32_value(9, 0); - data->set_int64_value(13, 1); - - // Get the label of the currently selected member - uint64_t unionLabel; - data->get_union_label(unionLabel); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_SEQUENCES - // Create a DynamicTypeBuilder for a sequence of two elements of type inte32 - uint32_t length = 2; - DynamicType_ptr base_type = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_sequence_builder(base_type, length); - - // Create the data instance - DynamicType_ptr sequence_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(sequence_type)); - - // Insert and remove elements - MemberId newId, newId2; - data->insert_int32_value(10, newId); - data->insert_int32_value(12, newId2); - data->remove_sequence_data(newId); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_ARRAYS - // Create an array DynamicTypeBuilder for a 2x2 elements of type int32 - std::vector lengths = { 2, 2 }; - DynamicType_ptr base_type = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_array_builder(base_type, lengths); - - // Create the data instance - DynamicType_ptr array_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(array_type)); - - // Access elements in the multidimensional array - MemberId pos = data->get_array_index({1, 0}); - data->set_int32_value(11, pos); - data->set_int32_value(27, pos + 1); - data->clear_array_data(pos); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_MAPS - // Create DynamicTypeBuilder for a map of two pairs of {key:int32, value:int32} - uint32_t length = 2; - DynamicType_ptr base = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_map_builder(base, base, length); - - // Create the data instance - DynamicType_ptr map_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(map_type)); - - // Add a new element to the map with key 1 - DynamicData_ptr key(DynamicDataFactory::get_instance()->create_data(base)); - MemberId keyId; - MemberId valueId; - key->set_int32_value(1); - data->insert_map_data(key.get(), keyId, valueId); - - // Add a new element to the map with key 2 - // insert_map_data creates a copy of the key, so the same instance can be reused - MemberId keyId2; - MemberId valueId2; - key->set_int32_value(2); - data->insert_map_data(key.get(), keyId2, valueId2); - - // Set the value to the element with key 2, using the returned value Id - data->set_int32_value(53, valueId2); - - // Remove elements from the map - data->remove_map_data(keyId); - data->remove_map_data(keyId2); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_NESTED_STRUCTS - // Create a struct type - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - builder->add_member(0, "first", DynamicTypeBuilderFactory::get_instance()->create_int32_type()); - builder->add_member(1, "other", DynamicTypeBuilderFactory::get_instance()->create_uint64_type()); - DynamicType_ptr struct_type = builder->build(); - - // Create a struct type with the previous struct as member - eprosima::fastrtps::types::DynamicTypeBuilder_ptr parent_builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - parent_builder->add_member(0, "child_struct", struct_type); - parent_builder->add_member(1, "second", DynamicTypeBuilderFactory::get_instance()->create_int32_type()); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(parent_builder.get())); - - // Access the child struct with the loan operations - DynamicData* child_data = data->loan_value(0); - child_data->set_int32_value(5, 0); - child_data->set_uint64_value(13, 1); - data->return_loaned_value(child_data); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_INHERITANCE_STRUCTS - // Create a base struct type - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - builder->add_member(0, "first", DynamicTypeBuilderFactory::get_instance()->create_int32_type()); - builder->add_member(1, "other", DynamicTypeBuilderFactory::get_instance()->create_uint64_type()); - - // Create a struct type derived from the previous struct - eprosima::fastrtps::types::DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance()->create_child_struct_builder(builder.get()); - - // Add new members to the derived type - builder->add_member(2, "third", DynamicTypeBuilderFactory::get_instance()->create_uint64_type()); - - // Create the data instance - DynamicType_ptr struct_type = child_builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(struct_type)); - - // The derived type includes the members defined on the base type - data->set_int32_value(5, 0); - data->set_uint64_value(13, 1); - data->set_uint64_value(47, 2); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_NESTED_ALIAS - // Using Builders - eprosima::fastrtps::types::DynamicTypeBuilder_ptr created_builder = - DynamicTypeBuilderFactory::get_instance()->create_string_builder(100); - DynamicType_ptr created_type = DynamicTypeBuilderFactory::get_instance()->create_type(created_builder.get()); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_alias_builder( - created_builder.get(), "alias"); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder2 = - DynamicTypeBuilderFactory::get_instance()->create_alias_builder( - builder.get(), "alias2"); - DynamicData* data(DynamicDataFactory::get_instance()->create_data(builder2->build())); - data->set_string_value("Dynamic Alias 2 String"); - - // Creating directly the Dynamic Type - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance()->create_string_type(100); - DynamicType_ptr pAliasType = DynamicTypeBuilderFactory::get_instance()->create_alias_type(pType, "alias"); - DynamicType_ptr pAliasType2 = - DynamicTypeBuilderFactory::get_instance()->create_alias_type(pAliasType, "alias2"); - DynamicData* data2(DynamicDataFactory::get_instance()->create_data(pAliasType)); - data2->set_string_value("Dynamic Alias 2 String"); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_NESTED_UNIONS - // Create a union DynamicTypeBuilder - DynamicType_ptr discriminator = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_union_builder(discriminator); - - // Add a int32 to the union - builder->add_member(0, "first", DynamicTypeBuilderFactory::get_instance()->create_int32_type(), "", { 0 }, - true); - - // Create a struct type and add it to the union - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - struct_builder->add_member(0, "first", DynamicTypeBuilderFactory::get_instance()->create_int32_type()); - struct_builder->add_member(1, "other", DynamicTypeBuilderFactory::get_instance()->create_uint64_type()); - builder->add_member(1, "first", struct_builder.get(), "", { 1 }, false); - - // Create the union data instance - DynamicType_ptr union_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(union_type)); - - // Access the struct member using the loan operations - DynamicData* child_data = data->loan_value(1); - child_data->set_int32_value(9, 0); - child_data->set_int64_value(13, 1); - data->return_loaned_value(child_data); - //!-- - } - - { - //DYNAMIC_TYPES_CREATE_ANNOTATION - // Apply the annotation - eprosima::fastrtps::types::DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance()->create_struct_builder(); - //... - builder->apply_annotation("MyAnnotation", "value", "5"); - builder->apply_annotation("MyAnnotation", "name", "length"); - //!-- - } - - { - //DYNAMIC_TYPES_SERIALIZATION - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - DynamicPubSubType pubsubType(pType); - - // SERIALIZATION EXAMPLE - DynamicData* pData = DynamicDataFactory::get_instance()->create_data(pType); - uint32_t payloadSize = static_cast(pubsubType.getSerializedSizeProvider(pData)()); - SerializedPayload_t payload(payloadSize); - pubsubType.serialize(pData, &payload); - - // DESERIALIZATION EXAMPLE - types::DynamicData* data2 = DynamicDataFactory::get_instance()->create_data(pType); - pubsubType.deserialize(&payload, data2); - //!-- - } - - { - //DYNAMIC_TYPES_NOTES_1 - DynamicTypeBuilder* pBuilder = DynamicTypeBuilderFactory::get_instance()->create_uint32_builder(); - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - DynamicData* pData = DynamicDataFactory::get_instance()->create_data(pType); - - DynamicTypeBuilderFactory::get_instance()->delete_builder(pBuilder); - DynamicDataFactory::get_instance()->delete_data(pData); - //!-- - } - - { - //DYNAMIC_TYPES_NOTES_2 - eprosima::fastrtps::types::DynamicTypeBuilder_ptr pBuilder = - DynamicTypeBuilderFactory::get_instance()->create_uint32_builder(); - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance()->create_int32_type(); - DynamicData_ptr pData(DynamicDataFactory::get_instance()->create_data(pType)); - //!-- - } - - { - //DYNAMIC_HELLO_WORLD_API - // In HelloWorldPublisher.h - // Dynamic Types - eprosima::fastrtps::types::DynamicData* m_DynHello; - eprosima::fastrtps::types::DynamicPubSubType m_DynType; - - // In HelloWorldPublisher.cpp - // Create basic builders - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_type_builder(DynamicTypeBuilderFactory::get_instance() - ->create_struct_builder()); - - // Add members to the struct. - struct_type_builder->add_member(0, "index", DynamicTypeBuilderFactory::get_instance()->create_uint32_type()); - struct_type_builder->add_member(1, "message", DynamicTypeBuilderFactory::get_instance()->create_string_type()); - struct_type_builder->set_name("HelloWorld"); - - DynamicType_ptr dynType = struct_type_builder->build(); - m_DynType.SetDynamicType(dynType); - m_DynHello = DynamicDataFactory::get_instance()->create_data(dynType); - m_DynHello->set_uint32_value(0, 0); - m_DynHello->set_string_value("HelloWorld", 1); - //!-- - } - - { - //DYNAMIC_HELLO_WORLD_API - // In HelloWorldPublisher.h - // Dynamic Types - eprosima::fastrtps::types::DynamicData* m_DynHello; - eprosima::fastrtps::types::DynamicPubSubType m_DynType; - - // In HelloWorldPublisher.cpp - // Create basic builders - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_type_builder(DynamicTypeBuilderFactory::get_instance() - ->create_struct_builder()); - - // Add members to the struct. - struct_type_builder->add_member(0, "index", DynamicTypeBuilderFactory::get_instance()->create_uint32_type()); - struct_type_builder->add_member(1, "message", DynamicTypeBuilderFactory::get_instance()->create_string_type()); - struct_type_builder->set_name("HelloWorld"); - - DynamicType_ptr dynType = struct_type_builder->build(); - m_DynType.SetDynamicType(dynType); - m_DynHello = DynamicDataFactory::get_instance()->create_data(dynType); - m_DynHello->set_uint32_value(0, 0); - m_DynHello->set_string_value("HelloWorld", 1); - //!-- - } - -} - bool permissions_test( std::string main_ca_file, std::string appcert_file, diff --git a/code/DDSCodeTester.cpp b/code/DDSCodeTester.cpp index 42263b27c..c9bea793f 100644 --- a/code/DDSCodeTester.cpp +++ b/code/DDSCodeTester.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -47,13 +48,8 @@ #include #include #include -#include -#include -#include -#include #include - using namespace eprosima::fastdds::dds; class CustomChainingTransportDescriptor : public eprosima::fastdds::rtps::ChainingTransportDescriptor @@ -1700,9 +1696,13 @@ void dds_topic_examples() // Load the XML file with the type description DomainParticipantFactory::get_instance()->load_XML_profiles_file("example_type.xml"); - // Retrieve the an instance of the desired type and register it - traits::ref_type dyn_type; - eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName(dyn_type, "DynamicType"); + // Retrieve the an instance of the desired type + DynamicTypeBuilder::_ref_type type_builder; + //TODO xtypes use the correct public method to get the type builder + //DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name("DynamicType", type_builder); + + // Build and register it + DynamicType::_ref_type dyn_type = type_builder->build(); TypeSupport dyn_type_support(new DynamicPubSubType(dyn_type)); dyn_type_support.register_type(participant, nullptr); @@ -4392,6 +4392,767 @@ void log_examples() } +void dynamictypes_examples() +{ + { + //!--CPP_PRIMITIVES + // Define a struct type with various primitive members + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("PrimitivesStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define and add primitive members to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + + member_descriptor->name("my_bool"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_char"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_wchar"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_octet"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BYTE)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_int8"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT8)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_uint8"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT8)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_short"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_ushort"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT16)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_long"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_ulong"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_longlong"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_ulonglong"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT64)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_float"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT32)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_double"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT64)); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_longdouble"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT128)); + struct_builder->add_member(member_descriptor); + + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for a member of type int32_t + int32_t in_value = 2; + int32_t out_value = 0; + data->set_int32_value(data->get_member_id_by_name(ObjectName("my_long")), in_value); + data->get_int32_value(out_value, data->get_member_id_by_name(ObjectName("my_long"))); + //!-- + } + { + //!--CPP_STRINGS + // Define a struct type to contain the strings + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("StringsStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define and add string members to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + + member_descriptor->name("my_string"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_string_type(LENGTH_UNLIMITED)->build()); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_wstring"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_wstring_type(LENGTH_UNLIMITED)->build()); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_bounded_string"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_string_type(41925)->build()); + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_bounded_wstring"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_wstring_type(20925)->build()); + struct_builder->add_member(member_descriptor); + + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for a string member + std::string in_value = "helloworld"; + std::string out_value; + data->set_string_value(data->get_member_id_by_name(ObjectName("my_string")), in_value); + data->get_string_value(out_value, data->get_member_id_by_name(ObjectName("my_string"))); + //!-- + } + { + //!--CPP_ENUM + // Define a struct type to contain an enum + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("EnumStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define the enum type + TypeDescriptor::_ref_type enum_type_descriptor {traits::make_shared()}; + enum_type_descriptor->kind(TK_ENUM); + enum_type_descriptor->name("MyEnum"); + DynamicTypeBuilder::_ref_type enum_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(enum_type_descriptor)}; + // Add enum members to the enum type + MemberDescriptor::_ref_type union_member_descriptor {traits::make_shared()}; + union_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + union_member_descriptor->name("A"); + enum_builder->add_member(union_member_descriptor); + union_member_descriptor = traits::make_shared(); + union_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + union_member_descriptor->name("B"); + enum_builder->add_member(union_member_descriptor); + union_member_descriptor = traits::make_shared(); + union_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + union_member_descriptor->name("C"); + enum_builder->add_member(union_member_descriptor); + // Build the enum type + DynamicType::_ref_type enum_type = enum_builder->build(); + + // Add an enum member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_enum"); + member_descriptor->type(enum_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for an enum member + int32_t in_value = 2; + int32_t out_value = 0; + data->set_int32_value(data->get_member_id_by_name(ObjectName("my_enum")), in_value); + data->get_int32_value(out_value, data->get_member_id_by_name(ObjectName("my_enum"))); + //!-- + } + { + //!--CPP_BITMASK + // Define a struct type to contain a bitmask + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("BitmaskStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define the bitmask type + TypeDescriptor::_ref_type bitmask_type_descriptor {traits::make_shared()}; + bitmask_type_descriptor->kind(TK_BITMASK); + bitmask_type_descriptor->name("MyBitMask"); + bitmask_type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_BOOLEAN)); + bitmask_type_descriptor->bound().push_back(8); + DynamicTypeBuilder::_ref_type bitmask_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + bitmask_type_descriptor)}; + // Add bitfield members to the bitmask type + MemberDescriptor::_ref_type bitfield_member_descriptor {traits::make_shared()}; + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag0"); + bitfield_member_descriptor->id(0); + bitmask_builder->add_member(bitfield_member_descriptor); + bitfield_member_descriptor = traits::make_shared(); + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag1"); + bitfield_member_descriptor->id(1); + bitmask_builder->add_member(bitfield_member_descriptor); + bitfield_member_descriptor = traits::make_shared(); + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag2"); + bitfield_member_descriptor->id(2); + bitmask_builder->add_member(bitfield_member_descriptor); + bitfield_member_descriptor = traits::make_shared(); + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag5"); + bitfield_member_descriptor->id(5); + bitmask_builder->add_member(bitfield_member_descriptor); + // Build the bitmask type + DynamicType::_ref_type bitmask_type = bitmask_builder->build(); + + // Add a bitmask member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_bitmask"); + member_descriptor->type(bitmask_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for a bitmask member + bool in_value = 2; + bool out_value = 0; + data->set_boolean_value(data->get_member_id_by_name(ObjectName("my_bitmask")), in_value); + data->get_boolean_value(out_value, data->get_member_id_by_name(ObjectName("my_bitmask"))); + //!-- + } + { + DynamicType::_ref_type enum_type; + //!--CPP_TYPEDEF + // Define a struct type to contain the alias + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("AliasStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define an alias type for the enum + TypeDescriptor::_ref_type aliasenum_type_descriptor {traits::make_shared()}; + aliasenum_type_descriptor->kind(TK_ALIAS); + aliasenum_type_descriptor->name("MyAliasEnum"); + aliasenum_type_descriptor->base_type(enum_type); + DynamicTypeBuilder::_ref_type aliasenum_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(aliasenum_type_descriptor)}; + // Build the alias type + DynamicType::_ref_type aliasenum_type = aliasenum_builder->build(); + + // Define an alias type for an array + TypeDescriptor::_ref_type aliasarray_type_descriptor {traits::make_shared()}; + aliasarray_type_descriptor->kind(TK_ALIAS); + aliasarray_type_descriptor->name("MyAliasArray"); + BoundSeq array_bounds = { 2, 2 }; + aliasarray_type_descriptor->base_type(DynamicTypeBuilderFactory::get_instance()-> + create_array_type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_INT32), array_bounds)->build()); + DynamicTypeBuilder::_ref_type aliasarray_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(aliasarray_type_descriptor)}; + // Build the alias type for the array + DynamicType::_ref_type aliasarray_type = aliasarray_builder->build(); + + // Add alias enum member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_alias_enum"); + member_descriptor->type(aliasenum_type); + struct_builder->add_member(member_descriptor); + // Add alias array member to the struct + member_descriptor = traits::make_shared(); + member_descriptor->name("my_alias_array"); + member_descriptor->type(aliasarray_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the alias enum member + int32_t in_value = 2; + int32_t out_value = 0; + data->set_int32_value(data->get_member_id_by_name(ObjectName("my_alias_enum")), in_value); + data->get_int32_value(out_value, data->get_member_id_by_name(ObjectName("my_alias_enum"))); + //!-- + } + { + //!--CPP_RECURSIVE_TYPEDEF + // Define a struct type to contain the alias + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("RecursiveAliasStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define an alias type for base type + type_descriptor = traits::make_shared(); + type_descriptor->kind(eprosima::fastdds::dds::TK_ALIAS); + type_descriptor->name(ObjectName("RecursiveAlias")); + type_descriptor->base_type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_UINT32)); + DynamicTypeBuilder::_ref_type builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Build the alias type for the base type + DynamicType::_ref_type rec_type {builder->build()}; + + type_descriptor = traits::make_shared(); + type_descriptor->kind(eprosima::fastdds::dds::TK_ALIAS); + type_descriptor->name(ObjectName("MyAlias")); + type_descriptor->base_type(rec_type); + builder = DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor); + // Build the alias type for other alias + DynamicType::_ref_type alias_type {builder->build()}; + + // Add alias member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_alias"); + member_descriptor->type(alias_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the alias member + int32_t in_value = 2; + int32_t out_value = 0; + data->set_int32_value(data->get_member_id_by_name(ObjectName("my_alias")), in_value); + data->get_int32_value(out_value, data->get_member_id_by_name(ObjectName("my_alias"))); + //!-- + } + { + //!--CPP_ARRAYS + // Define a struct type to contain the array + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("ArrayStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define a member for the array + MemberDescriptor::_ref_type array_member_descriptor {traits::make_shared()}; + array_member_descriptor->name("long_array"); + array_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_array_type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32), { 2, 3, 4 })->build()); + + // Add the array member to the struct + struct_builder->add_member(array_member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the array member + Int32Seq in_value = {1, 2}; + Int32Seq out_value; + data->set_int32_values(data->get_member_id_by_name(ObjectName("long_array")), in_value); + data->get_int32_values(out_value, data->get_member_id_by_name(ObjectName("long_array"))); + //!-- + } + { + //!--CPP_SEQUENCES + // Define a struct type to contain the sequence + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("SequenceStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define a member for the sequence + MemberDescriptor::_ref_type sequence_member_descriptor {traits::make_shared()}; + sequence_member_descriptor->name("short_sequence"); + sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_sequence_type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16), 5)->build()); + // Add the sequence member to the struct + struct_builder->add_member(sequence_member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the sequence member + Int16Seq in_value = {1, 2}; + Int16Seq out_value; + data->set_int16_values(data->get_member_id_by_name(ObjectName("short_sequence")), in_value); + data->get_int16_values(out_value, data->get_member_id_by_name(ObjectName("short_sequence"))); + //!-- + } + { + //!--CPP_MAPS + // Define a struct type to contain the map + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(ObjectName("MapStruct")); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define a member for the map + MemberDescriptor::_ref_type map_member_descriptor {traits::make_shared()}; + map_member_descriptor->name("long_long_map"); + map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_map_type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32), + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32), 2)->build()); + // Add the map member to the struct + struct_builder->add_member(map_member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Get the data loan of the map member + DynamicData::_ref_type map_data = data->loan_value(data->get_member_id_by_name("long_long_map")); + + // Set and retrieve values for the map member + int32_t key = 1; + int32_t in_value = 2; + int32_t out_value; + map_data->set_int32_value(map_data->get_member_id_by_name(std::to_string(key)), in_value); + map_data->get_int32_value(out_value, map_data->get_member_id_by_name(std::to_string(key))); + + // Return de data loan of the map member + data->return_loaned_value(map_data); + //!-- + } + { + //!--CPP_STRUCT + // Define a struct type + TypeDescriptor::_ref_type struct_type_descriptor {traits::make_shared()}; + struct_type_descriptor->kind(TK_STRUCTURE); + struct_type_descriptor->name("MyStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + struct_type_descriptor)}; + // Add members to the struct + MemberDescriptor::_ref_type struct_member {traits::make_shared()}; + struct_member->name("first"); + struct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + struct_builder->add_member(struct_member); + struct_member = traits::make_shared(); + struct_member->name("second"); + struct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + struct_builder->add_member(struct_member); + + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the member + const int32_t value1 = 2; + int32_t value2 = 0; + data->set_int32_value(data->get_member_id_by_name(ObjectName("first")), value1); + data->get_int32_value(value2, data->get_member_id_by_name(ObjectName("first"))); + //!-- + } + { + DynamicType::_ref_type mystruct_type; + //!--CPP_UNION + // Define a struct type to contain the union + TypeDescriptor::_ref_type struct_type_descriptor {traits::make_shared()}; + struct_type_descriptor->kind(TK_STRUCTURE); + struct_type_descriptor->name("UnionStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + struct_type_descriptor)}; + // Define a type for union + TypeDescriptor::_ref_type union_type_descriptor = traits::make_shared(); + union_type_descriptor->kind(TK_UNION); + union_type_descriptor->name("MyUnion"); + union_type_descriptor->discriminator_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT16)); + DynamicTypeBuilder::_ref_type union_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + union_type_descriptor)}; + // Add members to the union type + MemberDescriptor::_ref_type union_member_descriptor {traits::make_shared()}; + union_member_descriptor->name("first"); + union_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + union_member_descriptor->label({0, 1}); + union_builder->add_member(union_member_descriptor); + union_member_descriptor = traits::make_shared(); + union_member_descriptor->name("second"); + union_member_descriptor->type(mystruct_type); + union_member_descriptor->label({2}); + union_builder->add_member(union_member_descriptor); + union_member_descriptor = traits::make_shared(); + union_member_descriptor->name("third"); + union_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + union_member_descriptor->is_default_label(true); + union_builder->add_member(union_member_descriptor); + // Build the union type + DynamicType::_ref_type union_type = union_builder->build(); + + // Add the union member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_union"); + member_descriptor->type(union_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + // Set and retrieve values for the member + DynamicData::_ref_type union_data = data->loan_value(data->get_member_id_by_name("my_union")); + + // Set and retrieve values for the member + int32_t in_value = 2; + int32_t out_value; + union_data->set_int32_value(union_data->get_member_id_by_name("first"), in_value); + union_data->get_int32_value(out_value, union_data->get_member_id_by_name("first")); + // Return de data loan of the member + data->return_loaned_value(union_data); + //!-- + } + { + //!--CPP_BITSET + // Define a struct type to contain the bitset + TypeDescriptor::_ref_type struct_type_descriptor {traits::make_shared()}; + struct_type_descriptor->kind(TK_STRUCTURE); + struct_type_descriptor->name("BitsetStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + struct_type_descriptor)}; + // Define a type for bitset + TypeDescriptor::_ref_type bitset_type_descriptor {traits::make_shared()}; + bitset_type_descriptor->kind(TK_BITSET); + bitset_type_descriptor->name("MyBitset"); + bitset_type_descriptor->bound({3, 1, 4, 10, 12}); + DynamicTypeBuilder::_ref_type bitset_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + bitset_type_descriptor)}; + // Add members to the bitset type + MemberDescriptor::_ref_type bitset_member_descriptor {traits::make_shared()}; + bitset_member_descriptor->name("a"); + bitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + bitset_member_descriptor->id(0); + bitset_builder->add_member(bitset_member_descriptor); + bitset_member_descriptor = traits::make_shared(); + bitset_member_descriptor->name("b"); + bitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitset_member_descriptor->id(3); + bitset_builder->add_member(bitset_member_descriptor); + bitset_member_descriptor = traits::make_shared(); + bitset_member_descriptor->name("c"); + bitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT16)); + bitset_member_descriptor->id(8); + bitset_builder->add_member(bitset_member_descriptor); + bitset_member_descriptor = traits::make_shared(); + bitset_member_descriptor->name("d"); + bitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + bitset_member_descriptor->id(18); + bitset_builder->add_member(bitset_member_descriptor); + // Build the bitset type + DynamicType::_ref_type bitset_type = bitset_builder->build(); + + // Add the bitset member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_bitset"); + member_descriptor->type(bitset_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + // Set and retrieve values for the map member + DynamicData::_ref_type bitset_data = data->loan_value(data->get_member_id_by_name("my_bitset")); + + // Set and retrieve values for the member + int16_t in_value = 2; + int16_t out_value; + bitset_data->set_int16_value(bitset_data->get_member_id_by_name("d"), in_value); + bitset_data->get_int16_value(out_value, bitset_data->get_member_id_by_name("d")); + // Return de data loan of the member + data->return_loaned_value(bitset_data); + //!-- + } + { + //!--CPP_BITSET_INHERITANCE + // Create a parent bitset type + TypeDescriptor::_ref_type parentbitset_type_descriptor {traits::make_shared()}; + parentbitset_type_descriptor->kind(TK_BITSET); + parentbitset_type_descriptor->name("ParentBitSet"); + parentbitset_type_descriptor->bound({3, 1}); + DynamicTypeBuilder::_ref_type parentbitset_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + parentbitset_type_descriptor)}; + // Add members to the parent bitset type + MemberDescriptor::_ref_type parentbitset_member_descriptor {traits::make_shared()}; + parentbitset_member_descriptor->name("a"); + parentbitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_CHAR8)); + parentbitset_member_descriptor->id(0); + parentbitset_builder->add_member(parentbitset_member_descriptor); + parentbitset_member_descriptor = traits::make_shared(); + parentbitset_member_descriptor->name("b"); + parentbitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_BOOLEAN)); + parentbitset_member_descriptor->id(3); + parentbitset_builder->add_member(parentbitset_member_descriptor); + // Build the parent bitset type + DynamicType::_ref_type parentbitset_type = parentbitset_builder->build(); + + // Create child bitset type + TypeDescriptor::_ref_type childbitset_type_descriptor {traits::make_shared()}; + childbitset_type_descriptor->kind(TK_BITSET); + childbitset_type_descriptor->name("ChildBitSet"); + childbitset_type_descriptor->base_type(parentbitset_type); + childbitset_type_descriptor->bound({10, 12}); + DynamicTypeBuilder::_ref_type childbitset_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + childbitset_type_descriptor)}; + // Add members to the child bitset type + MemberDescriptor::_ref_type childbitset_member_descriptor {traits::make_shared()}; + childbitset_member_descriptor->name("c"); + childbitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT16)); + childbitset_member_descriptor->id(0); + childbitset_builder->add_member(childbitset_member_descriptor); + childbitset_member_descriptor = traits::make_shared(); + childbitset_member_descriptor->name("d"); + childbitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + childbitset_member_descriptor->id(10); + childbitset_builder->add_member(childbitset_member_descriptor); + // Build the child bitset type + DynamicType::_ref_type childbitset_type = childbitset_builder->build(); + //!-- + } + { + //!--CPP_STRUCT_INHERITANCE + // Create a parent struct type + TypeDescriptor::_ref_type parentstruct_type_descriptor {traits::make_shared()}; + parentstruct_type_descriptor->kind(TK_STRUCTURE); + parentstruct_type_descriptor->name("ParentStruct"); + DynamicTypeBuilder::_ref_type parentstruct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(parentstruct_type_descriptor)}; + // Add members to the parent struct type + MemberDescriptor::_ref_type parentstruct_member {traits::make_shared()}; + parentstruct_member->name("first"); + parentstruct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + parentstruct_builder->add_member(parentstruct_member); + parentstruct_member = traits::make_shared(); + parentstruct_member->name("second"); + parentstruct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + parentstruct_builder->add_member(parentstruct_member); + // Build the parent struct type + DynamicType::_ref_type parentstruct_type = parentstruct_builder->build(); + + // Create child struct type + TypeDescriptor::_ref_type childstruct_type_descriptor {traits::make_shared()}; + childstruct_type_descriptor->kind(TK_STRUCTURE); + childstruct_type_descriptor->name("ChildStruct"); + childstruct_type_descriptor->base_type(parentstruct_type); + DynamicTypeBuilder::_ref_type childstruct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(childstruct_type_descriptor)}; + // Add members to the child struct type + MemberDescriptor::_ref_type childstruct_member {traits::make_shared()}; + childstruct_member->name("third"); + childstruct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + childstruct_builder->add_member(childstruct_member); + childstruct_member = traits::make_shared(); + childstruct_member->name("fourth"); + childstruct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + childstruct_builder->add_member(childstruct_member); + // Build the child struct type + DynamicType::_ref_type childstruct_type = childstruct_builder->build(); + //!-- + } + { + //!--CPP_COMPLEX_STRUCTS + // Create a inner struct type + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(eprosima::fastdds::dds::TK_STRUCTURE); + type_descriptor->name("InnerStruct"); + DynamicTypeBuilder::_ref_type builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + // Add members to the inner struct type + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT32)); + member_descriptor->name("first"); + member_descriptor->id(0); + builder->add_member(member_descriptor); + // Build the inner struct type + DynamicType::_ref_type inner_struct_type {builder->build()}; + + // Create a complex struct type + type_descriptor = traits::make_shared(); + type_descriptor->kind(eprosima::fastdds::dds::TK_STRUCTURE); + type_descriptor->name("ComplexStruct"); + builder = DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor); + // Add members to the complex struct type + member_descriptor = traits::make_shared(); + member_descriptor->type(inner_struct_type); + member_descriptor->name("complex_member"); + member_descriptor->id(0); + builder->add_member(member_descriptor); + // Build the complex struct type + DynamicType::_ref_type struct_type {builder->build()}; + //!-- + } + { + //!--CPP_COMPLEX_UNIONS + // Create the inner union + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(eprosima::fastdds::dds::TK_UNION); + type_descriptor->name("InnerUnion"); + type_descriptor->discriminator_type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT32)); + DynamicTypeBuilder::_ref_type builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Add members to the inner union type + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT64)); + member_descriptor->name("first"); + member_descriptor->id(1); + member_descriptor->label({0}); + builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT64)); + member_descriptor->name("second"); + member_descriptor->id(2); + member_descriptor->label({1}); + member_descriptor->is_default_label(true); + builder->add_member(member_descriptor); + // Build the inner union type + DynamicType::_ref_type inner_union_type {builder->build()}; + + // Create a complex union type + type_descriptor = traits::make_shared(); + type_descriptor->kind(eprosima::fastdds::dds::TK_UNION); + type_descriptor->name("ComplexUnion"); + type_descriptor->discriminator_type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT32)); + builder = DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor); + // Add members to the complex union type + member_descriptor = traits::make_shared(); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT32)); + member_descriptor->name("third"); + member_descriptor->id(1); + member_descriptor->label({0}); + builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->type(inner_union_type); + member_descriptor->name("fourth"); + member_descriptor->id(2); + member_descriptor->label({1}); + builder->add_member(member_descriptor); + // Build the complex union type + DynamicType::_ref_type union_type {builder->build()}; + //!-- + } + { + //!--CPP_CUSTOM_ANNOTATION + // Create the structure to annotate + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("AnnotatedStruct"); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Create the annotation type + AnnotationDescriptor::_ref_type annotation_descriptor {traits::make_shared()}; + TypeDescriptor::_ref_type annotation_type {traits::make_shared()}; + annotation_type->kind(TK_ANNOTATION); + annotation_type->name("MyAnnotation"); + DynamicTypeBuilder::_ref_type annotation_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(annotation_type)}; + + // Add members to the annotation type + MemberDescriptor::_ref_type annotation_parameter {traits::make_shared()}; + annotation_parameter->name("length"); + annotation_parameter->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + annotation_builder->add_member(annotation_parameter); + // Set the annotation type using the annotation descriptor + annotation_descriptor->type(annotation_builder->build()); + // Set the value of the annotation + annotation_descriptor->set_value("length", std::to_string(5)); + // Apply the annotation to the structure + type_builder->apply_annotation(annotation_descriptor); + //!-- + } +} + void xml_profiles_examples() { { @@ -4451,10 +5212,13 @@ void xml_profiles_examples() if (RETCODE_OK == DomainParticipantFactory::get_instance()->load_XML_profiles_file("my_profiles.xml")) { - // Retrieve the an instance of MyStruct type - traits::ref_type my_struct_type; - eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName(my_struct_type, "MyStruct"); + // Retrieve the an instance of the desired type + DynamicTypeBuilder::_ref_type my_struct_builder; + //TODO xtypes use the correct public method to get the type builder + //DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name("MyStruct", my_struct_builder); + // Register MyStruct type + DynamicType::_ref_type my_struct_type = my_struct_builder->build(); TypeSupport my_struct_type_support(new DynamicPubSubType(my_struct_type)); my_struct_type_support.register_type(participant, nullptr); } @@ -4754,7 +5518,8 @@ void dds_transport_examples () DomainParticipantQos qos; // Create a descriptor for the new transport. - std::shared_ptr shm_transport = std::make_shared(); + std::shared_ptr shm_transport = + std::make_shared(); // [OPTIONAL] ThreadSettings configuration shm_transport->default_reception_threads(eprosima::fastdds::rtps::ThreadSettings{-1, 0, 0, -1}); @@ -4771,7 +5536,8 @@ void dds_transport_examples () DomainParticipantQos qos; // Create a descriptor for the new transport. - std::shared_ptr shm_transport = std::make_shared(); + std::shared_ptr shm_transport = + std::make_shared(); // Link the Transport Layer to the Participant. qos.transport().user_transports.push_back(shm_transport); @@ -5254,7 +6020,7 @@ void dds_usecase_examples() //CONF_QOS_TUNING_RELIABLE_WRITER DataWriterQos qos; qos.reliable_writer_qos().times.heartbeatPeriod.seconds = 0; - qos.reliable_writer_qos().times.heartbeatPeriod.nanosec = 500000000; //500 ms + qos.reliable_writer_qos().times.heartbeatPeriod.nanosec = 500000000; //500 ms //!-- } @@ -5871,7 +6637,8 @@ void dds_request_reply_example_client() eprosima::fastdds::dds::DomainParticipantQos participant_qos; eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->get_default_participant_qos(participant_qos); - DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0, participant_qos); + DomainParticipant* participant = + DomainParticipantFactory::get_instance()->create_participant(0, participant_qos); TypeSupport request_type; TypeSupport reply_type; @@ -5886,7 +6653,8 @@ void dds_request_reply_example_client() Topic* request_topic = participant->create_topic("CalculatorRequest", request_type.get_type_name(), TOPIC_QOS_DEFAULT); - Topic* reply_topic = participant->create_topic("CalculatorReply", reply_type.get_type_name(), TOPIC_QOS_DEFAULT); + Topic* reply_topic = + participant->create_topic("CalculatorReply", reply_type.get_type_name(), TOPIC_QOS_DEFAULT); DataWriter* request_writer = publisher->create_datawriter(request_topic, DATAWRITER_QOS_DEFAULT); @@ -5937,7 +6705,8 @@ void dds_request_reply_example_server() eprosima::fastdds::dds::DomainParticipantQos participant_qos; eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->get_default_participant_qos(participant_qos); - DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0, participant_qos); + DomainParticipant* participant = + DomainParticipantFactory::get_instance()->create_participant(0, participant_qos); TypeSupport request_type; TypeSupport reply_type; @@ -5953,7 +6722,8 @@ void dds_request_reply_example_server() Topic* request_topic = participant->create_topic("CalculatorRequest", request_type.get_type_name(), TOPIC_QOS_DEFAULT); - Topic* reply_topic = participant->create_topic("CalculatorReply", reply_type.get_type_name(), TOPIC_QOS_DEFAULT); + Topic* reply_topic = + participant->create_topic("CalculatorReply", reply_type.get_type_name(), TOPIC_QOS_DEFAULT); DataWriter* reply_writer = publisher->create_datawriter(reply_topic, DATAWRITER_QOS_DEFAULT); @@ -6018,7 +6788,8 @@ void dds_waitset_example() // Process status. Liveliness changed and data available are depicted as an example if (changed_statuses.is_active(StatusMask::liveliness_changed())) { - std::cout << "Liveliness changed reported for entity " << entity->get_instance_handle() << + std::cout << "Liveliness changed reported for entity " << + entity->get_instance_handle() << std::endl; } @@ -6039,7 +6810,8 @@ void dds_waitset_example() for (FooSeq::size_type n = 0; n < info_seq.length(); ++n) { // Only samples with valid data should be accessed - if (info_seq[n].valid_data && reader->is_sample_valid(&data_seq[n], &info_seq[n])) + if (info_seq[n].valid_data && + reader->is_sample_valid(&data_seq[n], &info_seq[n])) { // Process sample on data_seq[n] } @@ -6315,9 +7087,9 @@ void pubsub_api_example_create_entities() //!-- //PUBSUB_API_WRITE_SAMPLE - HelloWorld sample; //Auto-generated container class for topic data from Fast DDS-Gen - sample.msg("Hello there!"); // Add contents to the message - data_writer->write(&sample); //Publish + HelloWorld sample; //Auto-generated container class for topic data from Fast DDS-Gen + sample.msg("Hello there!"); // Add contents to the message + data_writer->write(&sample); //Publish //!-- //PUBSUB_API_CREATE_SUBSCRIBER @@ -6375,8 +7147,7 @@ int main( } else { - if (ReturnCode_t::RETCODE_OK != - DomainParticipantFactory::get_instance()->load_XML_profiles_file(argv[1])) + if (RETCODE_OK != DomainParticipantFactory::get_instance()->load_XML_profiles_file(argv[1])) { printf("Error parsing xml file %s\n", argv[1]); exit_code = -1; diff --git a/code/DynamicTypesIDLExamples.idl b/code/DynamicTypesIDLExamples.idl new file mode 100644 index 000000000..5807c7a1c --- /dev/null +++ b/code/DynamicTypesIDLExamples.idl @@ -0,0 +1,219 @@ +//!--IDL_PRIMITIVES +struct PrimitivesStruct +{ + boolean my_bool; + char my_char; + wchar my_wchar; + octet my_octet; + int8 my_int8; + uint8 my_uint8; + int16 my_short; + uint16 my_ushort; + int32 my_long; + uint32 my_unlong; + int64 my_longlong; + uint64 my_ulonglong; + float my_float; + double my_double; + long double my_longdouble; +}; +//!-- + +//!--IDL_STRINGS +struct StringsStruct +{ + string my_string; + wstring my_wstring; + string<41925> my_bounded_string; + wstring<20925> my_bounded_wstring; +}; +//!-- + +//!--IDL_ARRAYS +struct ArrayStruct +{ + int32 long_array[2][3][4]; +}; +//!-- + +//!--IDL_SEQUENCES +struct SequenceStruct +{ + sequence short_sequence; +}; +//!-- + +//!--IDL_MAPS +struct MapStruct +{ + map long_long_map; +}; +//!-- + +//!--IDL_ENUM +enum MyEnum +{ + A, + B, + C +}; +struct EnumStruct +{ + MyEnum my_enum; +}; +//!-- + +//!--IDL_BITMASK +@bit_bound(8) +bitmask MyBitMask +{ + @position(0) flag0, + @position(1) flag1, + @position(2) flag2, + @position(5) flag5 +}; +struct BitmaskStruct +{ + MyBitMask my_bitmask; +}; +//!-- + +//!--IDL_TYPEDEF +typedef MyEnum MyAliasEnum; +typedef int32 MyAliasArray[2][2]; +struct AliasStruct +{ + MyAliasEnum my_alias_enum; + MyAliasArray my_alias_array; +}; +//!-- + +//!--IDL_RECURSIVE_TYPEDEF +typedef uint32 RecursiveAlias; +typedef RecursiveAlias MyAlias; +struct RecursiveAliasStruct +{ + MyAlias my_alias; +}; +//!-- + +//!--IDL_STRUCT +struct MyStruct +{ + int32 first; + int64 second; +}; +//!-- + +//!--IDL_UNION +union MyUnion switch (int16) +{ + case 0: + case 1: + int32 first; + case 2: + MyStruct second; + default: + int64 third; +}; +struct UnionStruct +{ + MyUnion my_union; +};//!-- + +//!--IDL_BITSET +bitset MyBitset +{ + bitfield<3> a; + bitfield<1> b; + bitfield<4>; + bitfield<10> c; + bitfield<12, short> d; +}; +struct BitsetStruct +{ + MyBitset my_bitset; +}; +//!-- + +//!--IDL_BITSET_INHERITANCE +bitset ParentBitSet +{ + bitfield<3> a; + bitfield<1> b; +}; + +bitset ChildBitSet : ParentBitSet +{ + bitfield<10> c; + bitfield<12, short> d; +}; +//!-- + +//!--IDL_STRUCT_INHERITANCE +struct ParentStruct +{ + int32 first; + int64 second; +}; + +struct ChildStruct : ParentStruct +{ + int32 third; + int63 fourth; +}; +//!-- + +//!--CPP_COMPLEX_STRUCTS +struct InnerStruct +{ + int32 first; +}; + +struct ComplexStruct +{ + InnerStruct complex_member; +}; +//!-- + +//!--IDL_COMPLEX_STRUCTS +struct InnerStruct +{ + int32 first; +}; + +struct ComplexStruct +{ + InnerStruct complex_member; +}; +//!-- + +//!--IDL_COMPLEX_UNIONS +union InnerUnion switch (int32) +{ + case 0: + int64 first; + case 1: + int64 second; +}; + +union ComplexUnion switch (int32) +{ + case 0: + int32 third; + case 1: + InnerUnion fourth; +}; +//!-- + +//!--IDL_CUSTOM_ANNOTATION +@annotation MyAnnotation +{ + short length; +}; + +@MyAnnotation(length = 5) +struct AnnotatedStruct +{ +}; +//!-- diff --git a/code/XMLTester.xml b/code/XMLTester.xml index b6a6da4db..946b0e548 100644 --- a/code/XMLTester.xml +++ b/code/XMLTester.xml @@ -4153,39 +4153,97 @@ -XML-DYN-ENUM<--> + + + + +XML_PRIMITIVES<--> + + + + + + + + + + + + + + + + + +<--> +XML_STRINGS<--> + + + + + + +<--> +XML_ARRAYS<--> + + + +<--> +XML_SEQUENCES<--> + + + +<--> +XML_MAPS<--> + + + +<--> +XML_ENUM<--> + + + <--> - -XML-TYPEDEF<--> +XML_BITMASK<--> + + + + + + + + + +<--> +XML_TYPEDEF<--> - - - - + + + - - - - +<--> +XML_RECURSIVE_TYPEDEF<--> + + + + <--> - -XML-STRUCT<--> +XML_STRUCT<--> <--> - -XML-UNION<--> +XML_UNION<--> - + @@ -4200,81 +4258,33 @@ -<--> - -XML-GENERIC<--> - - - - - - - - - - - - - - - - - - - - -<--> - -XML-BOUNDEDSTRINGS<--> - - -<--> -XML-SEQUENCES<--> - -<--> -XML-ARRAYS<--> - -<--> -XML-MAPS<--> - -<--> - - -XML-COMPLEX<--> - - + + <--> - -XML-BITSET<--> - +XML_BITSET<--> + + + + <--> -XML-BITMASK<--> - - - - - - -<--> -XML-BITSET-INHERIT<--> +XML_BITSET_INHERITANCE<--> - - + + - - - + + <--> -XML-STRUCT-INHERIT<--> +XML_STRUCT_INHERITANCE<--> @@ -4284,6 +4294,39 @@ <--> +XML_COMPLEX_STRUCTS<--> + + + + + + +<--> +XML_COMPLEX_UNIONS<--> + + + + + + + + + + + + + + + + + + + + + + +<--> + diff --git a/docs/03-exports/aliases-api.include b/docs/03-exports/aliases-api.include index 5acacac25..77f551ff9 100644 --- a/docs/03-exports/aliases-api.include +++ b/docs/03-exports/aliases-api.include @@ -940,10 +940,39 @@ .. |EDPStatic| replace:: :cpp:class:`EDPStatic ` -.. |DynamicPubSubType-api| replace:: :cpp:class:`DynamicPubSubType ` -.. |DynamicPubSubTypes-api| replace:: :cpp:class:`DynamicPubSubTypes ` -.. |DynamicType-api| replace:: :cpp:class:`DynamicType ` -.. |DynamicTypes-api| replace:: :cpp:class:`DynamicTypes ` +.. |AnnotationDescriptor-api| replace:: :cpp:class:`AnnotationDescriptor ` +.. |DynamicData-api| replace:: :cpp:class:`DynamicData ` +.. |DynamicData::loan_value| replace:: :cpp:func:`DynamicData::loan_value ` +.. |DynamicData::return_loaned_value| replace:: :cpp:func:`DynamicData::return_loaned_value ` +.. |DynamicDataFactory-api| replace:: :cpp:class:`DynamicDataFactory ` +.. |DynamicPubSubType-api| replace:: :cpp:class:`DynamicPubSubType ` +.. |DynamicType-api| replace:: :cpp:class:`DynamicType ` +.. |DynamicTypeBuilder-api| replace:: :cpp:class:`DynamicTypeBuilder ` +.. |DynamicTypeBuilder::add_member| replace:: :cpp:func:`DynamicTypeBuilder::add_member ` +.. |DynamicTypeBuilder::apply_annotation| replace:: :cpp:func:`DynamicTypeBuilder::apply_annotation ` +.. |DynamicTypeBuilder::apply_annotation_to_member| replace:: :cpp:func:`DynamicTypeBuilder::apply_annotation_to_member ` +.. |DynamicTypeBuilderFactory-api| replace:: :cpp:class:`DynamicTypeBuilderFactory ` +.. |DynamicTypeBuilderFactory::get_primitive_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::get_primitive_type ` +.. |DynamicTypeBuilderFactory::create_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_type ` +.. |DynamicTypeBuilderFactory::create_string_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_string_type ` +.. |DynamicTypeBuilderFactory::create_wstring_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_wstring_type ` +.. |DynamicTypeBuilderFactory::create_sequence_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_sequence_type ` +.. |DynamicTypeBuilderFactory::create_array_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_array_type ` +.. |DynamicTypeBuilderFactory::create_map_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_map_type ` +.. |DynamicTypeBuilderFactory::create_bitmask_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_bitmask_type ` +.. |DynamicTypeMember-api| replace:: :cpp:class:`DynamicTypeMember ` +.. |MemberDescriptor-api| replace:: :cpp:class:`MemberDescriptor ` +.. |MemberDescriptor::label| replace:: :cpp:func:`MemberDescriptor::label ` +.. |MemberDescriptor::is_key| replace:: :cpp:func:`MemberDescriptor::is_key ` +.. |MemberDescriptor::is_default_label| replace:: :cpp:func:`MemberDescriptor::is_default_label ` +.. |TypeDescriptor-api| replace:: :cpp:class:`TypeDescriptor ` +.. |TypeDescriptor::extensibility_kind| replace:: :cpp:func:`TypeDescriptor::extensibility_kind ` +.. |TypeDescriptor::base_type| replace:: :cpp:func:`TypeDescriptor::base_type ` +.. |TypeDescriptor::discriminator_type| replace:: :cpp:func:`TypeDescriptor::discriminator_type ` +.. |VerbatimTextDescriptor-api| replace:: :cpp:class:`VerbatimTextDescriptor ` + +.. |ITypeObjectRegistry-api| replace:: :cpp:class:`ITypeObjectRegistry ` +.. |TypeObjectUtils-api| replace:: :cpp:class:`TypeObjectUtils ` .. |TypeObjectV1-api| replace:: :cpp:class:`TypeObject` .. |TypeIdV1-api| replace:: :cpp:class:`TypeIdentifier` diff --git a/docs/03-exports/aliases.include b/docs/03-exports/aliases.include index b2d6b5838..3622f77a5 100644 --- a/docs/03-exports/aliases.include +++ b/docs/03-exports/aliases.include @@ -82,42 +82,28 @@ .. |whitelist| replace:: :ref:`Whitelist ` .. |MemoryManagementPolicy| replace:: :ref:`MemoryManagementPolicy` -.. |DynamicType| replace:: :ref:`dynamictypes_overview_dynamictype` -.. |DynamicTypes| replace:: :ref:`dynamictypes_overview_dynamictype` -.. |DynamicTypeBuilderFactory| replace:: :ref:`dynamictypes_overview_dynamictypebuilderfactory` -.. |DynamicTypeBuilder| replace:: :ref:`dynamictypes_overview_dynamictypebuilder` -.. |TypeDescriptor| replace:: :ref:`dynamictypes_overview_typedescriptor` -.. |DynamicTypeMember| replace:: :ref:`dynamictypes_overview_dynamictypemember` -.. |MemberDescriptor| replace:: :ref:`dynamictypes_overview_memberdescriptor` -.. |DynamicData| replace:: :ref:`dynamictypes_overview_dynamicdata` -.. |DynamicDataFactory| replace:: :ref:`dynamictypes_overview_dynamicdatafactory` -.. |DynamicPubSubType| replace:: :ref:`dynamictypes_overview_dynamicpubsubtype` +.. |DynamicTypes| replace:: :ref:`DynamicTypes` +.. |Supported Types| replace:: :ref:`Supported Types` +.. |Primitive Types| replace:: :ref:`Primitive Types` +.. |String and WString| replace:: :ref:`String and WString` +.. |Alias| replace:: :ref:`Alias` +.. |Alias of an alias| replace:: :ref:`Alias of an alias` +.. |Enumeration| replace:: :ref:`Enumeration` +.. |Bitmask| replace:: :ref:`Bitmask` +.. |Structure| replace:: :ref:`Structure` +.. |Bitset| replace:: :ref:`Bitset` +.. |Union| replace:: :ref:`Union` +.. |Sequence| replace:: :ref:`Sequence` +.. |Array| replace:: :ref:`Array` +.. |Map| replace:: :ref:`Map` +.. |Complex Types| replace:: :ref:`Complex Types` +.. |Structure inheritance| replace:: :ref:`Structure inheritance` +.. |Bitset inheritance| replace:: :ref:`Bitset inheritance` +.. |Nested Structures| replace:: :ref:`Nested Structures` +.. |Nested Unions| replace:: :ref:`Nested Unions` -.. |Supported Types| replace:: :ref:`dynamictypes_supportedtypes` -.. |Primitive Types| replace:: :ref:`dynamictypes_supportedtypes_primitive` -.. |String and WString| replace:: :ref:`dynamictypes_supportedtypes_string` -.. |Alias| replace:: :ref:`dynamictypes_supportedtypes_alias` -.. |Enumeration| replace:: :ref:`dynamictypes_supportedtypes_enumeration` -.. |Bitmask| replace:: :ref:`dynamictypes_supportedtypes_bitmask` -.. |Structure| replace:: :ref:`dynamictypes_supportedtypes_structure` -.. |Bitset| replace:: :ref:`dynamictypes_supportedtypes_bitset` -.. |Union| replace:: :ref:`dynamictypes_supportedtypes_union` -.. |Sequence| replace:: :ref:`dynamictypes_supportedtypes_sequence` -.. |Array| replace:: :ref:`dynamictypes_supportedtypes_array` -.. |Map| replace:: :ref:`dynamictypes_supportedtypes_map` - -.. |Memory management| replace:: :ref:`dynamictypes_memorymanagement` - -.. |Complex Types| replace:: :ref:`dynamictypes_complextypes` - -.. |Nested structures| replace:: :ref:`dynamictypes_complextypes_nestedstructures` -.. |Structure inheritance| replace:: :ref:`dynamictypes_complextypes_inheritance` -.. |Alias of an alias| replace:: :ref:`dynamictypes_complextypes_aliasalias` -.. |Unions with complex types| replace:: :ref:`dynamictypes_complextypes_complexunions` - -.. |TypeObject| replace:: :ref:`dynamictypes_discovery_typeobject` -.. |TypeInformation| replace:: :ref:`dynamictypes_discovery_typeinformation` -.. |TypeIdentifier| replace:: :ref:`dynamictypes_discovery_typeidentifier` +.. |TypeObject| replace:: :ref:`TypeObject` +.. |TypeInformation| replace:: :ref:`TypeInformation` .. |TopicDataType| replace:: :ref:`TopicDataType` .. |TopicDataTypes| replace:: :ref:`TopicDataTypes` diff --git a/docs/fastdds/api_reference/dds_pim/dds_pim.rst b/docs/fastdds/api_reference/dds_pim/dds_pim.rst index a2aab192f..d5c54eaa5 100644 --- a/docs/fastdds/api_reference/dds_pim/dds_pim.rst +++ b/docs/fastdds/api_reference/dds_pim/dds_pim.rst @@ -12,3 +12,4 @@ Data Distribution Service (DDS) Data-Centric Publish-Subscribe (DCPS) Platform I /fastdds/api_reference/dds_pim/publisher/publisher.rst /fastdds/api_reference/dds_pim/subscriber/subscriber.rst /fastdds/api_reference/dds_pim/topic/topic.rst + /fastdds/api_reference/dds_pim/xtypes/xtypes.rst diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/annotationdescriptor.rst b/docs/fastdds/api_reference/dds_pim/xtypes/annotationdescriptor.rst new file mode 100644 index 000000000..64f66e71f --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/annotationdescriptor.rst @@ -0,0 +1,10 @@ +.. _api_pim_annotationdescriptor: + +.. rst-class:: api-ref + +AnnotationDescriptor +-------------------- + +.. doxygenclass:: eprosima::fastdds::dds::AnnotationDescriptor + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamic_types.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamic_types.rst new file mode 100644 index 000000000..bffd71c64 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamic_types.rst @@ -0,0 +1,32 @@ +Dynamic Types +============= + +.. toctree:: + + /fastdds/api_reference/dds_pim/xtypes/annotationdescriptor.rst + /fastdds/api_reference/dds_pim/xtypes/dynamicdata.rst + /fastdds/api_reference/dds_pim/xtypes/dynamicdatafactory.rst + /fastdds/api_reference/dds_pim/xtypes/dynamicpubsubtype.rst + /fastdds/api_reference/dds_pim/xtypes/dynamictype.rst + /fastdds/api_reference/dds_pim/xtypes/dynamictypebuilder.rst + /fastdds/api_reference/dds_pim/xtypes/dynamictypebuilderfactory.rst + /fastdds/api_reference/dds_pim/xtypes/dynamictypemember.rst + /fastdds/api_reference/dds_pim/xtypes/memberdescriptor.rst + /fastdds/api_reference/dds_pim/xtypes/typedescriptor.rst + /fastdds/api_reference/dds_pim/xtypes/verbatimtextdescriptor.rst + + + + + + + + + + + + + + + + diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamicdata.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamicdata.rst new file mode 100644 index 000000000..64d3d702c --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamicdata.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamicdata: + +.. rst-class:: api-ref + +DynamicData +----------- + +.. doxygenclass:: eprosima::fastdds::dds::DynamicData + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamicdatafactory.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamicdatafactory.rst new file mode 100644 index 000000000..e0408be62 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamicdatafactory.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamicdatafactory: + +.. rst-class:: api-ref + +DynamicDataFactory +------------------ + +.. doxygenclass:: eprosima::fastdds::dds::DynamicDataFactory + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamicpubsubtype.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamicpubsubtype.rst new file mode 100644 index 000000000..5ebf38037 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamicpubsubtype.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamicpubsubtype: + +.. rst-class:: api-ref + +DynamicPubSubType +----------------- + +.. doxygenclass:: eprosima::fastdds::dds::DynamicPubSubType + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamictype.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictype.rst new file mode 100644 index 000000000..e3d2372fe --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictype.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamictype: + +.. rst-class:: api-ref + +DynamicType +----------- + +.. doxygenclass:: eprosima::fastdds::dds::DynamicType + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilder.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilder.rst new file mode 100644 index 000000000..15a1e81f8 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilder.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamictypebuilder: + +.. rst-class:: api-ref + +DynamicTypeBuilder +------------------ + +.. doxygenclass:: eprosima::fastdds::dds::DynamicTypeBuilder + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilderfactory.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilderfactory.rst new file mode 100644 index 000000000..6154157ab --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypebuilderfactory.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamictypebuilderfactory: + +.. rst-class:: api-ref + +DynamicTypeBuilderFactory +------------------------- + +.. doxygenclass:: eprosima::fastdds::dds::DynamicTypeBuilderFactory + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypemember.rst b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypemember.rst new file mode 100644 index 000000000..8420d99d4 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/dynamictypemember.rst @@ -0,0 +1,10 @@ +.. _api_pim_dynamictypemember: + +.. rst-class:: api-ref + +DynamicTypeMember +----------------- + +.. doxygenclass:: eprosima::fastdds::dds::DynamicTypeMember + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/exception.rst b/docs/fastdds/api_reference/dds_pim/xtypes/exception.rst new file mode 100644 index 000000000..ff462282a --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/exception.rst @@ -0,0 +1,10 @@ +.. _api_pim_invalidargumenterror: + +.. rst-class:: api-ref + +InvalidArgumentError +-------------------- + +.. doxygenclass:: eprosima::fastdds::dds::xtypes::InvalidArgumentError + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/memberdescriptor.rst b/docs/fastdds/api_reference/dds_pim/xtypes/memberdescriptor.rst new file mode 100644 index 000000000..fb3f00386 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/memberdescriptor.rst @@ -0,0 +1,10 @@ +.. _api_pim_memberdescriptor: + +.. rst-class:: api-ref + +MemberDescriptor +---------------- + +.. doxygenclass:: eprosima::fastdds::dds::MemberDescriptor + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/type_representation.rst b/docs/fastdds/api_reference/dds_pim/xtypes/type_representation.rst new file mode 100644 index 000000000..18299eaf9 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/type_representation.rst @@ -0,0 +1,7 @@ +Type Representation +=================== + +.. toctree:: + + /fastdds/api_reference/dds_pim/xtypes/typeobjectregistry.rst + /fastdds/api_reference/dds_pim/xtypes/typeobjectutils.rst diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/typedescriptor.rst b/docs/fastdds/api_reference/dds_pim/xtypes/typedescriptor.rst new file mode 100644 index 000000000..f50a520b5 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/typedescriptor.rst @@ -0,0 +1,10 @@ +.. _api_pim_typedescriptor: + +.. rst-class:: api-ref + +TypeDescriptor +-------------- + +.. doxygenclass:: eprosima::fastdds::dds::TypeDescriptor + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/typeobjectregistry.rst b/docs/fastdds/api_reference/dds_pim/xtypes/typeobjectregistry.rst new file mode 100644 index 000000000..dd1524712 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/typeobjectregistry.rst @@ -0,0 +1,10 @@ +.. _api_pim_typeobjectregistry: + +.. rst-class:: api-ref + +TypeObjectRegistry +------------------ + +.. doxygenclass:: eprosima::fastdds::dds::xtypes::ITypeObjectRegistry + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/typeobjectutils.rst b/docs/fastdds/api_reference/dds_pim/xtypes/typeobjectutils.rst new file mode 100644 index 000000000..abae4cbe1 --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/typeobjectutils.rst @@ -0,0 +1,10 @@ +.. _api_pim_typeobjectutils: + +.. rst-class:: api-ref + +TypeObjectUtils +--------------- + +.. doxygenclass:: eprosima::fastdds::dds::xtypes::TypeObjectUtils + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/verbatimtextdescriptor.rst b/docs/fastdds/api_reference/dds_pim/xtypes/verbatimtextdescriptor.rst new file mode 100644 index 000000000..711a590bd --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/verbatimtextdescriptor.rst @@ -0,0 +1,10 @@ +.. _api_pim_verbatimtextdescriptor: + +.. rst-class:: api-ref + +VerbatimTextDescriptor +---------------------- + +.. doxygenclass:: eprosima::fastdds::dds::VerbatimTextDescriptor + :project: FastDDS + :members: diff --git a/docs/fastdds/api_reference/dds_pim/xtypes/xtypes.rst b/docs/fastdds/api_reference/dds_pim/xtypes/xtypes.rst new file mode 100644 index 000000000..60a0b16ad --- /dev/null +++ b/docs/fastdds/api_reference/dds_pim/xtypes/xtypes.rst @@ -0,0 +1,8 @@ +XTypes +====== + +.. toctree:: + + /fastdds/api_reference/dds_pim/xtypes/dynamic_types.rst + /fastdds/api_reference/dds_pim/xtypes/exception.rst + /fastdds/api_reference/dds_pim/xtypes/type_representation.rst diff --git a/docs/fastdds/dynamic_types/annotations.rst b/docs/fastdds/dynamic_types/annotations.rst deleted file mode 100644 index bbd4f7660..000000000 --- a/docs/fastdds/dynamic_types/annotations.rst +++ /dev/null @@ -1,63 +0,0 @@ -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_annotations: - -Annotations -=========== - - -|DynamicTypeBuilder| allows applying an annotation -to both current type and inner members with the functions: - -- :func:`apply_annotation` - -- :func:`apply_annotation_to_member` - -Both functions take the name, the key and the value of the annotation. -:func:`apply_annotation_to_member` additionally receives the ``MemberId`` of the inner member. - -For example, if we define an annotation like: - -.. code-block:: omg-idl - - @annotation MyAnnotation - { - long value; - string name; - }; - -And then we apply it through IDL to a struct: - -.. code-block:: omg-idl - - @MyAnnotation(5, "length") - struct MyStruct - { - // ... - } - -The equivalent code using |DynamicTypes| will be: - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_ANNOTATION - :end-before: //!-- - :dedent: 8 - -Builtin annotations -------------------- - -The following annotations modifies the behavior of DynamicTypes: - -- | ``@position``: When applied to |Bitmask|, sets the position of the flag, - | as expected in the IDL annotation. - | If applied to |Bitset|, sets the base position of the bitfield, - | useful to identify unassigned bits. - -- | ``@bit_bound``: Applies to |Bitset|. Sets the size in bits of the bitfield. - -- | ``@key``: Alias for ``@Key``. See :ref:`dds_layer_topic_keyed_data_types` section for more details. - -- | ``@default``: Sets a default value for the member. - -- | ``@non_serialized``: Excludes a member from being serialized. diff --git a/docs/fastdds/dynamic_types/complex_types.rst b/docs/fastdds/dynamic_types/complex_types.rst deleted file mode 100644 index ea33bbca2..000000000 --- a/docs/fastdds/dynamic_types/complex_types.rst +++ /dev/null @@ -1,85 +0,0 @@ -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_complextypes: - -Complex Types -============= - -If the application's data model is complex, it is possible to combine the -:ref:`basic types` to create complex types, -including nested composed types (structures within structures within unions). -Types can also be extended using inheritance, improving the flexibility of the definition -of the data types to fit the model. - -The following subsections describe these *complex types* and their use. - -.. contents:: - :local: - :backlinks: none - :depth: 2 - - -.. _dynamictypes_complextypes_nestedstructures: - -Nested structures ------------------ - -Structures can contain other structures as members. -The access to these compound members is restricted and managed by the |DynamicData| instance. -Users must request access calling ``loan_value`` before using them, and release -them with ``return_loaned_value`` once they finished. -The loan operation will fail if the member is already loaned and has not been released yet. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_NESTED_STRUCTS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_complextypes_inheritance: - -Structure inheritance ---------------------- - -To inherit a structure from another one, use the ``create_child_struct_type`` function from -|DynamicTypeBuilderFactory|. -The resultant type contains all members from the base class and the new ones added to the child. - -Structures support several levels of inheritance, so the base class can be another derived type itself. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_INHERITANCE_STRUCTS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_complextypes_aliasalias: - -Alias of an alias ------------------ - -Alias types support recursion, simply use an alias name as base type for :func:`create_alias_type`. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_NESTED_ALIAS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_complextypes_complexunions: - -Unions with complex types -------------------------- - -Unions support complex type fields. -The access to these complex type fields is restricted and managed by the |DynamicData| instance. -Users must request access calling ``loan_value`` before using them, and release -them with ``return_loaned_value`` once they finished. -The loan operation will fail if the fields is already loaned and has not been released yet. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_NESTED_UNIONS - :end-before: //!-- - :dedent: 8 - diff --git a/docs/fastdds/dynamic_types/concepts.rst b/docs/fastdds/dynamic_types/concepts.rst deleted file mode 100644 index ca3790967..000000000 --- a/docs/fastdds/dynamic_types/concepts.rst +++ /dev/null @@ -1,188 +0,0 @@ -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_overview: - -Overview of Dynamic Types -========================= - -This section describes the classes related to dynamic types that are used through the rest of the documentation. -At the bottom of the section you can also find a short example using the functionality. - -Involved classes ----------------- - -The following class diagram describes the relationship among the classes related to dynamic types. -Please, refer to the description of each class to find its purpose and the nature of the relationship -with the rest of the classes. - -.. figure:: /01-figures/dynamic_types_class_diagram.svg - :align: center - - Dynamic types class diagram - -.. contents:: - :local: - :backlinks: none - :depth: 2 - -.. _dynamictypes_overview_dynamictype: - -DynamicType -^^^^^^^^^^^^ - -Base class of all types declared dynamically. -It represents a dynamic data type that can be used to create -|DynamicData| values. -By design, the structure of a dynamic type (its member fields) cannot -be modified once the type is created. - - -.. _dynamictypes_overview_dynamictypebuilderfactory: - -DynamicTypeBuilderFactory -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -*Singleton* class that is in charge of the creation and the management of every -DynamicType and |DynamicTypeBuilder|. -It declares functions to create builders for each kind of supported types. -Given a builder for a specific type, it can also create the corresponding -DynamicType. -Some simpler types can be created directly, avoiding the step of creating a -DynamicTypeBuilder. -Please, refer to the |Supported Types| documentation for details about -which ones support this option. - -Every object created by the factory must be deleted to avoid memory leaking. -Refer to the |Memory management| section for details. - - -.. _dynamictypes_overview_dynamictypebuilder: - -DynamicTypeBuilder -^^^^^^^^^^^^^^^^^^^^ - -Intermediate class used to configure a DynamicType -before it is created. -By design, the structure of a DynamicType (its member fields) cannot -be modified once the object is created. -Therefore, all its structure must be defined prior to its creation. -The builder is the object used to set up this structure. - -Once defined, the DynamicTypeBuilderFactory is used to create -the DynamicType from the information contained in the builder. -As a shortcut, the builder exposes a function :func:`build` that internally uses the -DynamicTypeBuilderFactory to return a fully constructed -DynamicType. -The types created with :func:`build` are still subject to the |Memory management| -restrictions, and must be deleted by the DynamicTypeBuilderFactory. - -Builders can be reused after the creation of a DynamicType, as -the changes applied to the builder do not affect to types created previously. - - -.. _dynamictypes_overview_typedescriptor: - -TypeDescriptor -^^^^^^^^^^^^^^^ - -Stores the information about one type with its relationships and restrictions. -This is the class that describes the inner structure of a -DynamicType. -The DynamicTypeBuilder has an internal instance of -TypeDescriptor that modifies during the type building process. -When the DynamicType is created, the -DynamicTypeBuilderFactory uses the information -of the TypeDescriptor in the builder to create the DynamicType. -During the creation, the TypeDescriptor is copied to the DynamicType, -so that it becomes independent from the DynamicTypeBuilder, -and the builder can be reused for another type. - - -.. _dynamictypes_overview_dynamictypemember: - -DynamicTypeMember -^^^^^^^^^^^^^^^^^^^ - -Represents a data member of a DynamicType that is also a -DynamicType. -Compound types (dynamic types that are composed of other dynamic types) have a -DynamicTypeMember for every child DynamicType added to it. - - -.. _dynamictypes_overview_memberdescriptor: - -MemberDescriptor -^^^^^^^^^^^^^^^^^ - -Just as a TypeDescriptor describes the inner structure of a -DynamicType, -a MemberDescriptor stores all the information needed to manage a -DynamicTypeMember, like their name, their unique ID, or -the default value after the creation. -This information is copied to the |DynamicData| on its creation. - - -.. _dynamictypes_overview_dynamicdata: - -DynamicData -^^^^^^^^^^^^ - -While a DynamicType *describes* a type, -DynamicData represents a data instance of a DynamicType. -It provides functions to access and modify the data values in the instance. - -There are two ways to work with DynamicData: - -* Activating the macro ``DYNAMIC_TYPES_CHECKING``, which creates a variable for - each primitive kind to help the debug process. -* Without this macro, the size of the DynamicData is reduced, using only the minimum needed - internal values, but it makes the code harder to debug. - - -.. _dynamictypes_overview_dynamicdatafactory: - -DynamicDataFactory -^^^^^^^^^^^^^^^^^^^^ - -*Singleton* class that is in charge of the creation and the management of every -DynamicData. -It can take a DynamicType and create an instance of a -corresponding DynamicData. -Every data object created by the factory must be deleted to avoid memory leaking. -Refer to the |Memory management| section for details. - -It also allows to create a :class:`TypeIdentifier` and a (Minimal and Complete) :class:`TypeObject` from a -:class:`TypeDescriptor`. - - -.. _dynamictypes_overview_dynamicpubsubtype: - -DynamicPubSubType -^^^^^^^^^^^^^^^^^^ - -This class is an adapter that allows using DynamicData on Fast DDS. -It inherits from ``TopicDataType`` and implements the functions needed to communicate the -DynamicData between Publishers and Subscribers. - - -.. _dynamictypes_overview_example: - -Minimum example ---------------- - -This is a short example to illustrate the use of the dynamic types and how the classes describe above interact -with each other. -While the code snippet can be used as a quick reference for code building, the sequence diagram below provides a -visual interpretation of the actions. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_QUICK_EXAMPLE - :end-before: //! - :dedent: 8 - -.. figure:: /01-figures/dynamic_types_sequence_diagram.svg - :align: center - - Sequence diagram of the code above - diff --git a/docs/fastdds/dynamic_types/discovery.rst b/docs/fastdds/dynamic_types/discovery.rst deleted file mode 100644 index 3b417a9fb..000000000 --- a/docs/fastdds/dynamic_types/discovery.rst +++ /dev/null @@ -1,133 +0,0 @@ -.. include:: ../../03-exports/aliases-api.include -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_discovery: - -Dynamic Types Discovery and Endpoint Matching -============================================= - -.. _DDS-XTypes V1.3: http://www.omg.org/spec/DDS-XTypes/1.3 - -When using |DynamicTypes| support, *Fast DDS* checks the optional |TypeObject| -and |TypeIdentifier| values during endpoint matching. -Currently, the matching only verifies that both endpoints are using the same topic data type, -but will not negotiate about it. - -The process of checking the types is as follows: - -* It checks :class:`CompleteTypeObject` on TypeObject first. -* If one or both endpoints do not define the :class:`CompleteTypeObject`, it tries with :class:`MinimalTypeObject`. -* If one or both endpoints do not define :class:`MinimalTypeObject` either, - it compares the TypeIdentifier. -* If none is defined, then just the type name is checked. - -If one of the endpoints transmits a :class:`CompleteTypeObject`, :ref:`discovery-time-data-typing` can be performed. - -.. _dynamictypes_discovery_typeobject: - -TypeObject ----------- - -|TypeObjectV1-api| fully describes a data type, the same way as the IDL representation does. -There are two kinds of TypeObjects: :class:`CompleteTypeObject` and :class:`MinimalTypeObject` . - - - :class:`CompleteTypeObject` fully describes the type, the same way as the IDL representation does. - - :class:`MinimalTypeObject` is a compact representation of the data type, that contains only the information relevant - for the remote Endpoint to be able to interpret the data. - -TypeObject is an IDL union with both *Minimal* and *Complete* representation. -Both are described in the annexes of `DDS-XTypes V1.3`_ document, -please refer to this document for details. - - -.. _dynamictypes_discovery_typeinformation: - -TypeInformation ---------------- - -|TypeInformation-api| is an extension of *XTypes 1.3* that allow Endpoints to -share information about data types without sending the TypeObject. -Endpoints instead share a TypeInformation containing the -TypeIdentifier of the data type. -Then each Endpoint can request the complete TypeObject for the data -types it is interested in. -This avoids sending the complete data type to Endpoints that may not be interested. - -|TypeInformation-api| is described in the annexes of `DDS-XTypes V1.3`_ document, -please refer to this document for details. - - -.. _dynamictypes_discovery_typeidentifier: - -TypeIdentifier --------------- - -|TypeIdV1-api| provides a unique way to identify each type. -For basic types, the information contained in the TypeIdentifier -completely describes the type, while for complex ones, it serves as a search key to -retrieve the complete TypeObject. - -|TypeIdV1-api| is described in the annexes of `DDS-XTypes V1.3`_ document, -please refer to this document for details. - -Fast DDS-Gen ------------- - -*Fast DDS-Gen* supports the generation of `XXXTypeObjecSupport.h` and `XXXTypeObjecSupport.cxx` files, -taking :class:`XXX` as our IDL type. -These files provide a small Type Factory for the type :class:`XXX`. -Generally, these files are not used directly, as now the type :class:`XXX` will register itself, -making it very easy to use static types with dynamic types. - -.. _discovery-time-data-typing: - -Discovery-Time Data Typing --------------------------- - -Using the Fast DDS API, when a participant discovers a remote endpoint that sends a complete -TypeObject or a simple TypeIdentifier describing a type -that the participant does not know, the participant listener's function -is called with the received TypeObject or TypeIdentifier, -and, when possible, a pointer to a :ref:`dynamictypes_overview_dynamictype` ready to be used. - -Discovery-Time Data Typing allows the discovering of simple DynamicTypes. -A TypeObject that depends on other TypeObjects, cannot be built locally using -Discovery-Time Data Typing and should use :ref:`TypeLookup-Service` instead. - -.. _typelookup-service: - -TypeLookup Service ------------------- - -Using the Fast DDS API, when a participant discovers an endpoint that sends a type information -describing a type that the participant doesn't know, the participant listener's function -is called with the received TypeInformation. -The user can then try to retrieve the full TypeObject hierarchy to build the remote type locally, using the -TypeLookup Service. - -A participant can be enabled to act as a TypeLookup server, client, or both. - -This function takes the name of the type, the type information, and a callback function. -Internally it uses the TypeLookup Service to retrieve the full TypeObject, -and, if successful, it will call the callback. - -This callback has the following signature: - -.. code-block:: c - - void(std::string& type_name, const DynamicType_ptr type) - -* **type_name**: Is the name given to the type - to allow the same callback to be used across different calls. - -* **type**: If unable to build and register a :ref:`dynamictypes_overview_dynamictype`, this parameter contains - a pointer to the type. - Otherwise it contains ``nullptr``. - In the latter case, the user can still try to build the type manually using the factories, but it is very - likely that the build process will fail. - -:ref:`TopicDataType` contains a data member named -|TopicDataType::auto_fill_type_information-api|. -If set to true, the local participant will send the type information to the remote endpoint during discovery. - - diff --git a/docs/fastdds/dynamic_types/discovery_matching.rst b/docs/fastdds/dynamic_types/discovery_matching.rst new file mode 100644 index 000000000..031269029 --- /dev/null +++ b/docs/fastdds/dynamic_types/discovery_matching.rst @@ -0,0 +1,66 @@ +.. include:: ../../03-exports/aliases-api.include +.. include:: ../../03-exports/aliases.include + +.. _dynamictypes_discovery_matching: + +Dynamic Types Discovery and Endpoint Matching +============================================= + +.. _DDS-XTypes V1.3: http://www.omg.org/spec/DDS-XTypes/1.3 + +When using |DynamicTypes| support, *Fast DDS* checks the optional |TypeInformation-api| +value during endpoint matching. + +The process of checking the types is as follows: + +* If the discovered participant has sent |TypeInformation-api|, Fast DDS will check if all required types are known. + If not, it will initiate an automatic process of discovering the necessary types, using |TypeObject-api| + to communicate the information about the types with the other participants. + This process occurs asynchronously, and the matching of the discovered participant will not occur + until all necessary types are known, and they are fully compatible. +* If the discovered participant has not sent |TypeInformation-api|, Fast DDS will utilize a fallback mechanism, + using the type name to check if the type is known. Matching will occur if the type is known. + +.. _dynamictypes_discovery_typeinformation: + +TypeInformation +--------------- + +|TypeInformation-api| is an extension of *XTypes 1.3* that allow Endpoints to share information about data types +without sending the TypeObject. +Endpoints instead share a TypeInformation containing the TypeIdentifier of the data type. +Then each Endpoint can request the TypeObject for the data types it is interested in. +This avoids sending the complete data type to Endpoints that may not be interested. + +|TypeInformation-api| is described in the annexes of `DDS-XTypes V1.3`_ document, +please refer to this document for details. + +.. _dynamictypes_discovery_typeobject: + +TypeObject +---------- + +|TypeObject-api| provides a thorough description of a data type, similar to how it's represented in IDL. +There are two kinds of TypeObjects: :class:`CompleteTypeObject` and :class:`MinimalTypeObject`. + + - :class:`CompleteTypeObject` is representation of a type with the same level of detail and expressiveness as in IDL. + It serves as an alternative representation of types, suitable for programming and tooling purposes. + + - :class:`MinimalTypeObject` is a simplified version of the data type. + It includes only the necessary information for remote Endpoints to interpret the data accurately. + This simplified representation excludes details such as user-defined annotations or member order for types with + extensibility kind MUTABLE, which are irrelevant for type assignability. + By doing so, it reduces the amount of information applications need to transmit over the network. + +TypeObject is an IDL union with both *Minimal* and *Complete* representation. +Both are described in the annexes of `DDS-XTypes V1.3`_ document, please refer to this document for details. + +Fast DDS-Gen +------------ +*Fast DDS-Gen* default behaviour creates the necessary code to work with *Dynamic Types*. +The generated code will include the `XXXTypeObjecSupport.h` and `XXXTypeObjecSupport.cxx` files, +taking :class:`XXX` as our IDL type. +These files provide a Type Factory for the type :class:`XXX`. +Generally, these files are not used directly, as the type :class:`XXX` will register itself. + +*Fast DDS-Gen* usage information can be found on the :ref:`Fast DDS-Gen ` section. diff --git a/docs/fastdds/dynamic_types/dynamic_types.rst b/docs/fastdds/dynamic_types/dynamic_types.rst index 8ac9de4c9..1761a9bea 100644 --- a/docs/fastdds/dynamic_types/dynamic_types.rst +++ b/docs/fastdds/dynamic_types/dynamic_types.rst @@ -1,13 +1,13 @@ .. _dynamic-types: -Dynamic Topic Types -=================== +XTypes 1.3 +========== .. _DDS-XTypes V1.3: http://www.omg.org/spec/DDS-XTypes/1.3 eProsima Fast DDS provides a dynamic way to define and use topic types and topic data. Our implementation follows the *OMG Extensible and Dynamic Topic Types for DDS interface*. -For more information, you can read the specification for `DDS-XTypes V1.3`_. +For more information, For more information, refer to the specification for `DDS-XTypes V1.3`_. The dynamic topic types offer the possibility to work over RTPS without the restrictions related to the IDLs. Using them, the users can declare the different types that they need and manage the information directly, @@ -16,12 +16,5 @@ avoiding the additional step of updating the IDL file and the generation of *C++ .. toctree:: :maxdepth: 3 - /fastdds/dynamic_types/concepts.rst - /fastdds/dynamic_types/supported_types.rst - /fastdds/dynamic_types/complex_types.rst - /fastdds/dynamic_types/annotations.rst - /fastdds/dynamic_types/discovery.rst - /fastdds/dynamic_types/serialization.rst - /fastdds/dynamic_types/xml_profiles.rst - /fastdds/dynamic_types/memory_management.rst - /fastdds/dynamic_types/examples.rst + /fastdds/dynamic_types/discovery_matching.rst + /fastdds/dynamic_types/language_binding.rst diff --git a/docs/fastdds/dynamic_types/examples.rst b/docs/fastdds/dynamic_types/examples.rst deleted file mode 100644 index f97e6075f..000000000 --- a/docs/fastdds/dynamic_types/examples.rst +++ /dev/null @@ -1,50 +0,0 @@ -.. include:: ../../03-exports/aliases.include -.. include:: ../../03-exports/aliases-api.include - -.. _dynamictypes_examples: - -Dynamic HelloWorld Examples -=========================== - -.. _Fast DDS GitHub repository: https://github.com/eProsima/Fast-DDS - -These are complete working examples that make use of dynamic types. -You can explore them to find how this feature connects to the rest of *Fast DDS*, -and learn how to integrate it in your own application. - -DynamicHelloWorldExample ------------------------- - -This example is in folder -`examples/cpp/dds/DynamicHelloWorldExample `_ -of the `Fast DDS GitHub repository`_. -It shows the use of DynamicType generation to provide the |TopicDataType|. -This example is compatible with the classic HelloWorldExample. - -As a quick reference, the following piece of code shows how the HelloWorld type is created using DynamicTypes: - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_HELLO_WORLD_API - :end-before: //!-- - :dedent: 8 - - -DDSDynamicHelloWorldExample ---------------------------- - -This example uses the DDS API, and can be retrieve from folder -`examples/cpp/dds/DynamicHelloWorldExample `_ -of the `Fast DDS GitHub repository`_. -It shows a publisher that loads a type from an XML file, and shares it during discovery. -The subscriber discovers the type using :ref:`discovery-time-data-typing`, and registers the -discovered type on the listener. - -TypeLookupService ------------------ - -This example uses the DDS API, and it is located in folder -`examples/cpp/dds/TypeLookupService `_ -of the `Fast DDS GitHub repository`_. -It is very similar to DDSDynamicHelloWorldExample, but the shared type is complex enough to require the -TypeLookup Service due to the dependency of inner struct types. diff --git a/docs/fastdds/dynamic_types/language_binding.rst b/docs/fastdds/dynamic_types/language_binding.rst new file mode 100644 index 000000000..1f09efa4d --- /dev/null +++ b/docs/fastdds/dynamic_types/language_binding.rst @@ -0,0 +1,827 @@ +.. include:: ../../03-exports/aliases.include +.. include:: ../../03-exports/aliases-api.include +.. include:: ../../03-exports/roles.include + +.. _dynamictypes_language_binding: + +Dynamic Language Binding +======================== + +*eProsima Fast DDS* supports several methods for defining |DynamicTypes|. +Manual creation using |DynamicTypeBuilderFactory-api| and |DynamicTypeBuilder-api| to create the types. + +:ref:`XMLDynamicTypes ` allows *eProsima Fast DDS* to create DynamicTypes directly defining +them through XML. + +:ref:`Fast DDS-Gen ` provides a way to automatically generate the code to define the |DynamicTypes| +from the IDL files. + +This section contains a detailed explanation of how to create |DynamicTypes| using the manual way, as well as the +same examples using XML and IDL files. + +.. _dynamictypes_supportedtypes: + +Supported Types +--------------- + +.. _dynamictypes_supportedtypes_primitive: + +Primitives +^^^^^^^^^^ + +By definition, primitive types are self-described and can be created without configuration parameters. +Therefore, |DynamicTypeBuilderFactory-api| exposes the function |DynamicTypeBuilderFactory::get_primitive_type| +to allow users to create the type avoiding the |DynamicTypeBuilder-api| step. +The |DynamicData-api| class has a specific :func:`get__value` and :func:`set__value` functions for each primitive +type of the list. + +The following table shows the supported primitive types and their corresponding ``TypeKind``. +The ``TypeKind`` is used to identify the type when creating it. + ++------------------+-------------------+ +| Type | TypeKind | ++------------------+-------------------+ +| ``BOOLEAN`` | ``TK_BOOLEAN`` | ++------------------+-------------------+ +| ``CHAR8`` | ``TK_CHAR8`` | ++------------------+-------------------+ +| ``CHAR16`` | ``TK_CHAR16`` | ++------------------+-------------------+ +| ``OCTET`` | ``TK_BYTE`` | ++------------------+-------------------+ +| ``INT8`` | ``TK_INT8`` | ++------------------+-------------------+ +| ``UINT8`` | ``TK_UINT8`` | ++------------------+-------------------+ +| ``INT16`` | ``TK_INT16`` | ++------------------+-------------------+ +| ``UINT16`` | ``TK_UINT16`` | ++------------------+-------------------+ +| ``INT32`` | ``TK_INT32`` | ++------------------+-------------------+ +| ``UINT32`` | ``TK_UINT32`` | ++------------------+-------------------+ +| ``INT64`` | ``TK_INT64`` | ++------------------+-------------------+ +| ``UINT64`` | ``TK_UINT64`` | ++------------------+-------------------+ +| ``FLOAT32`` | ``TK_FLOAT32`` | ++------------------+-------------------+ +| ``FLOAT64`` | ``TK_FLOAT64`` | ++------------------+-------------------+ +| ``FLOAT128`` | ``TK_FLOAT128`` | ++------------------+-------------------+ + +This examples show how to create members of each primitive type using |DynamicTypeBuilderFactory-api|. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_PRIMITIVES + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_PRIMITIVES<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_PRIMITIVES + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Primitives `. + +.. _dynamictypes_supportedtypes_string: + +Strings +^^^^^^^ + +Strings are pretty similar to primitive types, the main difference being that they need to set their size limit. + +|DynamicTypeBuilderFactory-api| exposes the functions |DynamicTypeBuilderFactory::create_string_type| and +|DynamicTypeBuilderFactory::create_wstring_type| to allow users create them directly. +This functions receive a parameter to set the maximum length of the string, using ``LENGTH_UNLIMITED`` +to set it as unlimited. +The |DynamicData-api| class has a specific :func:`get_string_value` and :func:`set_string_value`. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_STRINGS + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_STRINGS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_STRINGS + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Primitives `. + +Constructed Types +^^^^^^^^^^^^^^^^^ + +Enumerated Types +"""""""""""""""" + +.. _dynamictypes_supportedtypes_enumeration: + +Enumerations +************ + +An enumeration contains a set of supported values and a selected value among those supported. +The ``TypeKind`` used to identify Enumerations is ``TK_ENUM``. + +The supported values must be configured using the |DynamicTypeBuilder-api|, using the |DynamicTypeBuilder::add_member| +function for each supported value. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_ENUM + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_ENUM<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_ENUM + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Enumerations `. + +.. _dynamictypes_supportedtypes_bitmask: + +Bitmasks +******** + +Bitmasks are similar to |Enumeration| types, but their members work as bit flags that can be individually turned on and +off. +The ``TypeKind`` used to identify Bitmasks is ``TK_BITMASK``. + +Those flags might use the ``positition`` attribute to set their position in the bitmask. +The ``bit_bound`` attribute specifies the number of bits that the bitmask type will manage. +Bitmasks can be bound to any number of bits up to 64. +The |DynamicTypeBuilderFactory-api| exposes the function |DynamicTypeBuilderFactory::create_bitmask_type| to +facilitate the creation of this type. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_BITMASK + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_BITMASK<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_BITMASK + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Bitmask `. + +.. _dynamictypes_supportedtypes_alias: + +Alias +""""" + +Alias types provide an alternative name to an already existing type. +The ``TypeKind`` used to identify Alias is ``TK_ALIAS``. + +Once the |DynamicData-api| is created, users can access its information as if they were working with the base type. +To create an alias type, users must use the |TypeDescriptor::base_type| function from the |TypeDescriptor-api| with +the existing type they want the alias to represent. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_TYPEDEF + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_TYPEDEF<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_TYPEDEF + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Typedef `. + +.. _dynamictypes_complextypes_aliasalias: + +Alias types support recursion, simply by using an alias as base type for :|TypeDescriptor::base_type|. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_RECURSIVE_TYPEDEF + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_RECURSIVE_TYPEDEF<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_RECURSIVE_TYPEDEF + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Primitives `. + +Collections +""""""""""" + +.. _dynamictypes_supportedtypes_sequence: + +Sequences +********* + +A complex type that manages its members as a list of items allowing users to insert, +remove or access to a member of the list. + +The |DynamicTypeBuilderFactory-api| exposes the function |DynamicTypeBuilderFactory::create_sequence_type| to +facilitate the creation of this type. +To create this type users need to specify the type that it is going to store. +Additionally, the size limit of the list. Users can use ``LENGTH_UNLIMITED`` to create unbounded sequences. + +The |DynamicData-api| class has a specific :func:`get__values` and :func:`set__values` functions for each primitive +type that allow users to work with multiple values at once. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_SEQUENCES + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_SEQUENCES<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_SEQUENCES + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Sequences `. + +.. _dynamictypes_supportedtypes_array: + +Arrays +****** + +Arrays are pretty similar to sequences with two main differences: +They can have multiple dimensions and they do not need their elements to be stored consecutively. + +An array needs to know the number of dimensions it is managing. +For that, users must provide a vector with as many elements as dimensions in the array. +Each element in the vector represents the size of the given dimension. + +The |DynamicTypeBuilderFactory-api| exposes the function |DynamicTypeBuilderFactory::create_array_type| to +facilitate the creation of this type. + +The |DynamicData-api| class has a specific :func:`get__values` and :func:`set___values` functions for each +primitive type that allow users to work with multiple values at once. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_ARRAYS + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_ARRAYS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_ARRAYS + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Arrays `. + +.. _dynamictypes_supportedtypes_map: + +Maps +**** + +Maps contain a list of 'key-value' pair types, allowing users to insert, remove or modify the element types of the map. +The main difference with sequences is that the map works with pairs of elements and creates copies of the key element +to block the access to these elements. + +The |DynamicTypeBuilderFactory-api| exposes the function |DynamicTypeBuilderFactory::create_map_type| to +facilitate the creation of this type. +To create a map, users must set the types of the key and the value elements. +Additionally, the size limit of the map. Users can use ``LENGTH_UNLIMITED`` to create unbounded sequences. + +The |DynamicData-api| class has a specific :func:`get__values` and :func:`set___values` functions for each primitive +type that allow users to work with multiple values at once. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_MAPS + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_MAPS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_MAPS + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Maps `. + +Aggregated Types +"""""""""""""""" + +.. _dynamictypes_supportedtypes_structure: + +Structures +********** + +Structures are the most common complex types, they allow to add any kind of members inside them. +They do not have any value, they are only used to contain other types. + +The function |DynamicTypeBuilderFactory::create_type| is used to create a new structure type. +The ``TypeKind`` used to identify Structures is ``TK_STRUCTURE``. + +To manage the types inside the structure, users can call the :func:`get` and :func:`set` functions according to the +kind of the type inside the structure using their ``ids``. +If the structure contains a complex value, |DynamicData::loan_value| should be used to access it and +|DynamicData::return_loaned_value| to release that loan. +|DynamicData-api| manages the loaned values and users can not loan a value that has been loaned previously +without calling |DynamicData::return_loaned_value| before. + + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_STRUCT + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_STRUCT<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_STRUCT + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Struct `. + +.. _dynamictypes_supportedtypes_union: + +Unions +****** + +Unions are a special kind of structures where only one of the members is active at the same time. +The ``TypeKind`` used to identify Unions is ``TK_UNION``. + +To control these members, users must set the ``discriminator`` type that is going to be used to select the current +member calling the |TypeDescriptor::discriminator_type| function of the union type. +The ``discriminator`` itself is a DynamicType of any primitive type, string type or union type. + +Additionally users can use the function |MemberDescriptor::label| with one or more values to set the labels of each +member of the union, and |MemberDescriptor::is_default_label| to specify the default label of the union. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_UNION + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_UNION<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_UNION + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Union `. + +.. _dynamictypes_supportedtypes_bitset: + +Bitset +****** + +Bitset types are similar to `structure` types, but their members are merely `bitfields`, which are stored optimally. +In the static version of bitsets, each bit uses just one bit in memory (with platform limitations) without alignment +considerations. +A bitfield can be anonymous (cannot be addressed) to skip unused bits within a bitset. + +Each bitfield in a bitset can be modified through their minimal needed primitive representation. + ++--------------------------+--------------------------+ +| Number of bits | Primitive | ++--------------------------+--------------------------+ +| ``1`` | ``BOOLEAN`` | ++--------------------------+--------------------------+ +| ``2-8`` | ``UINT8`` | ++--------------------------+--------------------------+ +| ``9-16`` | ``UINT16`` | ++--------------------------+--------------------------+ +| ``17-32`` | ``UINT32`` | ++--------------------------+--------------------------+ +| ``33-64`` | ``UINT64`` | ++--------------------------+--------------------------+ + +Each bitfield (or member) works like its primitive type with the only difference that the internal storage only +modifies the involved bits instead of the full primitive value. +The ``TypeKind`` used to identify Bitsets is ``TK_BITSET``. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_BITSET + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_BITSET<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_BITSET + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Bitset `. + +.. _dynamictypes_complextypes: + +Complex types +^^^^^^^^^^^^^ + +In complex data models, combinations of basic types :ref:`basic types` +can be used to create intricate structures, including nested compositions such as structures within structures. +Additionally, types can be extended using inheritance to enhance flexibility. + +The following subsections describe these *complex types* and their use. + +Inheritance +""""""""""" + +.. _dynamictypes_structure_inheritance: + +Structures allow inheritance, exactly with the same OOP meaning. +To inherit from another structure, users must create the parent structure calling the +|DynamicTypeBuilderFactory::create_type| normally. +After the parent type is created, use the |TypeDescriptor::base_type| function from the |TypeDescriptor-api| +when creating the child structure, using the parent type as the base type. + +The resultant type contains all members from the base class and the new ones added to the child. +Structures support several levels of inheritance, so the base class can be another derived type itself. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_STRUCT_INHERITANCE + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_STRUCT_INHERITANCE<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_STRUCT_INHERITANCE + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Struct `. + +.. _dynamictypes_bitset_inheritance: + +Bitsets allows inheritance aswell, exactly with the same OOP meaning. +To inherit from another bitset, users must follow the same process as with +:ref:`structures `, but using bitset types. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_BITSET_INHERITANCE + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_BITSET_INHERITANCE<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_BITSET_INHERITANCE + :end-before: //!-- + +For a detailed explanation about the XML definition of this type, +please refer to :ref:`Bitset `. + +Nested Types +"""""""""""" + +.. _dynamictypes_nested_structures: + +Structures can contain other structures as members. +The access to these compound members is restricted and managed by the |DynamicData-api| instance. +Users must request access calling |DynamicData::loan_value| before using them, +and release them with |DynamicData::return_loaned_value| once they finished. +The loan operation will fail if the member is already loaned and has not been released yet. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_COMPLEX_STRUCTS + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_COMPLEX_STRUCTS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_COMPLEX_STRUCTS + :end-before: //!-- + +.. _dynamictypes_nested_unions: + +Unions support complex type fields. +The access to these complex type fields is restricted and managed by the |DynamicData-api| instance. +Users must request access calling |DynamicData::loan_value| before using them, +and release them with |DynamicData::return_loaned_value| once they finished. +The loan operation will fail if the fields is already loaned and has not been released yet. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_COMPLEX_UNIONS + :end-before: //!-- + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_COMPLEX_UNIONS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_COMPLEX_UNIONS + :end-before: //!-- + + +For a detailed explanation about the XML definition of this types, +please refer to :ref:`Complex types `. + +Annotations +^^^^^^^^^^^ + +|DynamicTypeBuilder-api| allows applying an annotation to both current type and inner members with the functions. +To add the annotations to the types, the function |DynamicTypeBuilder::apply_annotation| is used, and +|DynamicTypeBuilder::apply_annotation_to_member| to add them to the members. + +Both functions take the :class:`AnnotationDescriptor` of the annotation to be added, +and |DynamicTypeBuilder::apply_annotation_to_member| additionally receives the ``MemberId`` of the inner member. + + +Custom annotations +"""""""""""""""""" + +|DynamicTypes| allows users to create custom annotations to add extra information to the types. + +:ref:`XMLDynamicTypes ` does not currently support custom annotations. + +.. tabs:: + + .. tab:: IDL + + .. literalinclude:: /../code/DynamicTypesIDLExamples.idl + :language: idl + :start-after: //!--IDL_CUSTOM_ANNOTATION + :end-before: //!-- + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_CUSTOM_ANNOTATION + :end-before: //!-- + + +Builtin annotations +""""""""""""""""""" + +Beside the custom annotations created by the users, there are a number of builtin annotations. + +Currently, |DynamicTypes| supports the following builtin annotations: + ++-------------------------+-------------------------------------------------------------------------------------------+ +| Annotation | Implemented behavior | ++=========================+===========================================================================================+ +| ``@extensibility`` | Applied to any element which is constructed. Allow specifying how the |br| | +| | element is allowed to evolve. More info in :ref:`extensibility`. | ++-------------------------+-------------------------------------------------------------------------------------------+ +| ``@final`` | Shortcut for `@extensibility(FINAL)` | ++-------------------------+-------------------------------------------------------------------------------------------+ +| ``@appendable`` | Shortcut for `@extensibility(APPENDABLE)` | ++-------------------------+-------------------------------------------------------------------------------------------+ +| ``@mutable`` | Shortcut for `@extensibility(MUTABLE)` | ++-------------------------+-------------------------------------------------------------------------------------------+ +| ``@key`` | Alias for eProsima's @Key annotation. Indicate that a data member is part of the key |br| | +| | (please refer to :ref:`dds_layer_topic_instances` for more information). | ++-------------------------+-------------------------------------------------------------------------------------------+ + +To apply the @extensibility annotation (and its shortcuts) the |TypeDescriptor-api| exposes the function +|TypeDescriptor::extensibility_kind|, that recives a :class:`ExtensibilityKind`. + +For the @key annotation the function |MemberDescriptor::is_key| can be fount in |MemberDescriptor-api|. + +Type promotions +--------------- + +|DynamicTypes| supports type promotion, enabling implicit promotion of types during both :func:`get` and :func:`set` +operations. +This means that a smaller type can be implicitly promoted to a larger type, but not the other way around. + +The following promotions are supported: + ++--------------+-------------------------------------------------------------------------------------------+ +| Type | Promotions | ++==============+===========================================================================================+ +| `Int8` | Int16, Int32, Int64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Int16` | Int32, Int64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Int32` | Int64, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Int64` | Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `UInt8` | Int16,Int32, Int64, UInt16, UInt32, UInt64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `UInt16` | Int32, Int64, UInt32, UInt64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `UInt32` | Int64, UInt64, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `UInt64` | Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Float32` | Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Float64` | Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Float128` | (none) | ++--------------+-------------------------------------------------------------------------------------------+ +| `Char8` | Char16, Int16, Int32, Int64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Char16` | Int32, Int64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ +| `Byte` | (any) | ++--------------+-------------------------------------------------------------------------------------------+ +| `Boolean` | Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64, Float128 | ++--------------+-------------------------------------------------------------------------------------------+ diff --git a/docs/fastdds/dynamic_types/memory_management.rst b/docs/fastdds/dynamic_types/memory_management.rst deleted file mode 100644 index bdc6caf64..000000000 --- a/docs/fastdds/dynamic_types/memory_management.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_memorymanagement: - -Memory management -================= - -Memory management is critical for dynamic types since -every dynamic type and dynamic data is managed with pointers. -Every object stored inside of a dynamic object is managed by its owner, and users -must delete every object they create using the factories. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_NOTES_1 - :end-before: //!-- - :dedent: 8 - -To ease this management, the library defines smart pointers (``DynamicTypeBuilder_ptr``, -``DynamicType`` and ``DynamicData_ptr``) that will delete the objects automatically when they are not -needed anymore. -``DynamicType`` will always be returned as ``DynamicType_ptr`` because there is no internal management of its memory. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_NOTES_2 - :end-before: //!-- - :dedent: 8 - -The only case where these smart pointers cannot be used is with functions ``loan_value`` and ``return_loaned_value``. -Raw pointers should be used with these functions, because the returned value should not be deleted, and using -a smart pointer with them will cause a crash. - - diff --git a/docs/fastdds/dynamic_types/serialization.rst b/docs/fastdds/dynamic_types/serialization.rst deleted file mode 100644 index adefa82e6..000000000 --- a/docs/fastdds/dynamic_types/serialization.rst +++ /dev/null @@ -1,16 +0,0 @@ -.. _dynamictypes_serialization: - -Serialization -============= - -Dynamic Types have their own :class:`pubsub` type like any class generated with an IDL, and -their management is pretty similar to them. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_SERIALIZATION - :end-before: //!-- - :dedent: 8 - -A member can be marked to be ignored by serialization with the annotation ``@non_serialized``. - diff --git a/docs/fastdds/dynamic_types/supported_types.rst b/docs/fastdds/dynamic_types/supported_types.rst deleted file mode 100644 index 026a1fdd9..000000000 --- a/docs/fastdds/dynamic_types/supported_types.rst +++ /dev/null @@ -1,321 +0,0 @@ -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_supportedtypes: - -Supported Types -=============== - -In order to provide maximum flexibility and capability to the defined dynamic types, -eProsima Fast DDS supports several member types, ranging from simple primitives to nested structures. - -This section describes the basic (not nested) supported types. For more complex structures and -examples, please, refer to :ref:`dynamictypes_complextypes`. - - -.. contents:: - :local: - :backlinks: none - :depth: 2 - -.. _dynamictypes_supportedtypes_primitive: - -Primitive Types ---------------- - -This section includes every simple kind: - -+--------------------------+--------------------------+ -| ``BOOLEAN`` | ``INT64`` | -+--------------------------+--------------------------+ -| ``BYTE`` | ``UINT16`` | -+--------------------------+--------------------------+ -| ``CHAR8`` | ``UINT32`` | -+--------------------------+--------------------------+ -| ``CHAR16`` | ``UINT64`` | -+--------------------------+--------------------------+ -| ``INT16`` | ``FLOAT32`` | -+--------------------------+--------------------------+ -| ``INT32`` | ``FLOAT64`` | -+--------------------------+--------------------------+ -| ``FLOAT128`` | | -+--------------------------+--------------------------+ - -By definition, primitive types are self-described and can be created without configuration parameters. -Therefore, |DynamicTypeBuilderFactory| exposes several functions to allow users create -the dynamic type avoiding the |DynamicTypeBuilder| step. -The DynamicTypeBuilder can still be used to create dynamic data of primitive types, -as shown on the example below. -The DynamicData class has a specific :func:`get` and :func:`set` functions for each primitive -type of the list. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_PRIMITIVES - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_string: - -String and WString ------------------- - -Strings are pretty similar to primitive types, the main difference being -that they need to set the size of the ``buffer`` that they can manage. -By default this size is set to 255 characters. - -DynamicTypeBuilderFactory exposes the functions :func:`create_string_type` and :func:`create_wstring_type` -to allow users create the DynamicTypes avoiding the DynamicTypeBuilder step. -The DynamicTypeBuilder can still be used to create String type dynamic data, -as shown on the example below. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_STRINGS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_alias: - -Alias ------ - -Alias types provide an alternative name to an already existing type. -Once the DynamicData is created, users can access its information as if -they were working with the base type. - -DynamicTypeBuilderFactory exposes the function :func:`create_alias_type` to allow users -create the Alias types avoiding the DynamicTypeBuilder step. -The DynamicTypeBuilder can still be used to create Alias, -as shown on the example below. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_ALIAS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_enumeration: - -Enumeration ------------ - -An enumeration contains a set of supported values and a selected value among those supported. -The supported values must be configured using the DynamicTypeBuilder, using the :func:`add_member` function -for each supported value. -The input to this function is the index and the name of the value we want to add. - -The DynamicData class has functions :func:`get_enum_value` and :func:`set_enum_value` to work -with value index or value name name strings. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_ENUMERATIONS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_bitmask: - -Bitmask -------- - -Bitmasks are similar to `enumeration` types, but their members work as bit flags that can be individually turned on and -off. Bit operations can be applied when testing or setting a bitmask value. -DynamicData has the special functions :func:`get_bitmask_value` and :func:`set_bitmask_value` which allow to retrieve or -modify the full value instead of accessing each bit. - -Bitmasks can be bound to any number of bits up to 64. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_BITMASKS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_structure: - -Structure ---------- - -Structures are the common complex types, they allow to add any kind of members inside them. -They do not have any value, they are only used to contain other types. - -To manage the types inside the structure, users can call the :func:`get` and :func:`set` functions -according to the kind of the type inside the structure using their ``ids``. -If the structure contains a complex value, it should be used with ``loan_value`` to -access to it and ``return_loaned_value`` to release that pointer. -DynamicData manages the counter of loaned values and users can not loan a value that -has been loaned previously without calling ``return_loaned_value`` before. - -The ``ids`` must be consecutive starting by zero, and the DynamicType will change that -Id if it doesn't match with the next value. -If two members have the same Id, after adding the second one, the previous -will change its Id to the next value. -To get the Id of a member by name, DynamicData exposes the function :func:`get_member_id_by_name`. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_STRUCTS - :end-before: //!-- - :dedent: 8 - -Structures allow inheritance, exactly with the same OOP meaning. To inherit from another structure, we must create the -structure calling the :func:`create_child_struct_builder` of the factory. This function is shared with bitsets and will -deduce our type depending on the parent's type. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_STRUCTS-INHERIT - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_bitset: - -Bitset ------- - -Bitset types are similar to `structure` types, but their members are merely `bitfields`, which are stored optimally. -In the static version of bitsets, each bit uses just one bit in memory (with platform limitations) without alignment -considerations. A bitfield can be anonymous (cannot be addressed) to skip unused bits within a bitset. - -Each bitfield in a bitset can be modified through their minimal needed primitive representation. - -+--------------------------+--------------------------+ -| Number of bits | Primitive | -+--------------------------+--------------------------+ -| ``1`` | ``BOOLEAN`` | -+--------------------------+--------------------------+ -| ``2-8`` | ``UINT8`` | -+--------------------------+--------------------------+ -| ``9-16`` | ``UINT16`` | -+--------------------------+--------------------------+ -| ``17-32`` | ``UINT32`` | -+--------------------------+--------------------------+ -| ``33-64`` | ``UINT64`` | -+--------------------------+--------------------------+ - -Each bitfield (or member) works like its primitive type with the only difference that the internal storage only -modifies the involved bits instead of the full primitive value. - -Bit_bound and position of the bitfield can be set using annotations (useful when converting between static and dynamic -bitsets). - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_BITSETS - :end-before: //!-- - :dedent: 8 - -Bitsets allows inheritance, exactly with the same OOP meaning. To inherit from another bitset, we must create the -bitset calling the ``create_child_struct_builder`` of the factory. This function is shared with structures and will -deduce our type depending on the parent's type. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_BITSETS-INHERIT - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_union: - -Union ------ - -Unions are a special kind of structures where only one of the members is active -at the same time. -To control these members, users must set the ``discriminator`` type that is going to be used -to select the current member calling the ``create_union_builder`` function. -The ``discriminator`` itself is a DynamicType of any primitive type, string type or union type. - -Every member that is going to be added needs at least one ``union_case_index`` to set -how it is going to be selected and, optionally, if it is the default value of the union. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_UNIONS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_sequence: - -Sequence --------- - -A complex type that manages its members as a list of items allowing users to -insert, remove or access to a member of the list. To create this type users -need to specify the type that it is going to store and optionally the size -limit of the list. - -To ease the memory management of this type, DynamicData has these functions: - - - :func:`insert_sequence_data`: Creates a new element at the end of the list and returns - the ``id`` of the new element. - - :func:`remove_sequence_data`: Removes the element of the given index and refreshes the ``ids`` - to keep the consistency of the list. - - :func:`clear_data`: Removes all the elements of the list. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_SEQUENCES - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_array: - -Array ------ - -Arrays are pretty similar to sequences with two main differences: -they can have multiple dimensions and they do not need their elements -to be stored consecutively. - -An array needs to know the number of dimensions it is managing. -For that, users must provide a vector with as many elements as dimensions in the array. -Each element in the vector represents the size of the given dimension. -If the value of an element is set to zero, the default value applies (``100``). - -Id values on the :func:`set` and :func:`get` functions of DynamicData correspond to the array index. -To ease the management of array elements, every :func:`set` function in DynamicData class creates -the item if the given index is empty. - -To ease the memory management of this type, DynamicData has these functions: - - * :func:`insert_array_data`: Creates a new element at the end of the array and returns - the ``id`` of the new element. - * :func:`remove_array_data`: Clears the element of the given index. - * :func:`clear_data`: Removes all the elements of the array. - * :func:`get_array_index`: Returns the position id giving a vector of indexes on every dimension - that the arrays support, which is useful in multidimensional arrays. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_ARRAYS - :end-before: //!-- - :dedent: 8 - -.. _dynamictypes_supportedtypes_map: - -Map ---- - -Maps contain a list of 'key-value' pair types, allowing users to insert, remove or -modify the element types of the map. -The main difference with sequences is that the map works with pairs of elements and -creates copies of the key element to block the access to these elements. - -To create a map, users must set the types of the key and the value elements, and, -optionally, the size limit of the map. - -To ease the memory management of this type, `DynamicData` has these functions: - - * :func:`insert_map_data`: Inserts a new key value pair and returns the ids of the newly - created key and value elements. - * :func:`remove_map_data`: Uses the given id to find the key element and removes the key - and the value elements from the map. - * :func:`clear_data`: Removes all the elements from the map. - -.. literalinclude:: /../code/CodeTester.cpp - :language: c++ - :start-after: //DYNAMIC_TYPES_CREATE_MAPS - :end-before: //!-- - :dedent: 8 - diff --git a/docs/fastdds/dynamic_types/xml_profiles.rst b/docs/fastdds/dynamic_types/xml_profiles.rst deleted file mode 100644 index 90b53e8dd..000000000 --- a/docs/fastdds/dynamic_types/xml_profiles.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. include:: ../../03-exports/aliases-api.include -.. include:: ../../03-exports/aliases.include - -.. _dynamictypes_xmlprofiles: - - -XML profiles ------------- - -:ref:`XMLDynamicTypes` allows *eProsima Fast DDS* to create DynamicTypes directly defining them through XML. -This allows any application to change |TopicDataTypes| without the need to change its source code. - -Please, refer to :ref:`XMLDynamicTypes` for further information about how to use this feature. - - - - diff --git a/docs/fastdds/xml_configuration/dynamic_types.rst b/docs/fastdds/xml_configuration/dynamic_types.rst index 2732f0752..7f926e9fd 100644 --- a/docs/fastdds/xml_configuration/dynamic_types.rst +++ b/docs/fastdds/xml_configuration/dynamic_types.rst @@ -61,6 +61,8 @@ Member types are defined as any type that can belong to a `Struct`_ or a `Union` `Typedef`_. These can be defined by the ```` XML tag. +.. _xmldynamictypes_primivites: + Primitive types *************** @@ -90,10 +92,25 @@ Please, refer to :ref:`dynamictypes_supportedtypes_primitive` for more informati All of them are defined as follows: -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-GENERIC<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_PRIMITIVES<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_PRIMITIVES + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Primitives `. + +.. _xmldynamictypes_strings: Bounded strings *************** @@ -102,10 +119,25 @@ Bounded strings are defined as any other ``string`` or ``wstring`` but adding th maximum length available for that specific string. Please, refer to :ref:`dynamictypes_supportedtypes_string` for more information on string type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-BOUNDEDSTRINGS<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_STRINGS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_STRINGS + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Strings `. + +.. _xmldynamictypes_sequence: Sequences ********* @@ -115,10 +147,25 @@ The sequence type is implemented by setting three attributes: ``name``, ``type`` The type of its content should be defined by the ``type`` attribute. Please, refer to :ref:`dynamictypes_supportedtypes_sequence` section for more information on sequence type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-SEQUENCES<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_SEQUENCES<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_SEQUENCES + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Sequences `. + +.. _xmldynamictypes_array: Arrays ****** @@ -127,10 +174,25 @@ Arrays are defined in the same way as any other member type but they add the att The format of the ``arrayDimensions`` attribute value is the size of each dimension separated by commas. Please, refer to :ref:`dynamictypes_supportedtypes_array` explanation for more information on array type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-ARRAYS<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_ARRAYS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_ARRAYS + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Arrays `. + +.. _xmldynamictypes_map: Maps **** @@ -139,10 +201,25 @@ Maps are similar to sequences, but they need to define two content types. The ``key_type`` defines the type of the map key, while the ``type`` defines the map value type. See section :ref:`dynamictypes_supportedtypes_map` for more information on map type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-MAPS<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_MAPS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_MAPS + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Maps `. + +.. _xmldynamictypes_complextypes: Complex types """"""""""""" @@ -153,13 +230,45 @@ The ``type`` in this case is ``nonBasic`` (not a `Primitive types`_) and the nam given in the ``nonBasicTypeName`` attribute. Please, refer to :ref:`dynamictypes_complextypes` section for more information on complex types. -The following example shows a new structure with the ``primitive_types_example`` struct defined in `Primitive types`_ -example. +The following example shows structure having another structure as a member. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-COMPLEX<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_COMPLEX_STRUCTS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_COMPLEX_STRUCTS + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Nested Types `. + +This example shows union having another union as a member. + +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_COMPLEX_UNIONS<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_COMPLEX_UNIONS + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Nested Types `. Complex types attributes ************************ @@ -190,6 +299,8 @@ these attributes are then defined in the following table. * - ``mapMaxLength`` - Maximum length of a `Maps`_. +.. _xmldynamictypes_typedef: + Typedef """"""" @@ -200,10 +311,25 @@ Maps, arrays and sequences can be elements within another container using ```` element corresponds to :ref:`dynamictypes_supportedtypes_alias` in :ref:`dynamictypes_supportedtypes` section. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-TYPEDEF<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_TYPEDEF<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_TYPEDEF + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Alias `. + +.. _xmldynamictypes_enums: Enumerations """""""""""" @@ -212,10 +338,25 @@ The ```` type is defined by its attribute ``name`` and a set of ```` is defined by two attributes: a mandatory ``name`` and an optional unsigned integer ``value``. Please, refer to :ref:`dynamictypes_supportedtypes_enumeration` for more information on the ```` type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-DYN-ENUM<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_ENUM<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_ENUM + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Enumerations `. + +.. _xmldynamictypes_struct: Struct """""" @@ -223,20 +364,50 @@ Struct The ```` element is defined by its ``name`` attribute and its ```` child elements. Please, refer to :ref:`dynamictypes_supportedtypes_structure` for more information on the ```` type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-STRUCT<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_STRUCT<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_STRUCT + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Structures `. + +.. _xmldynamictypes_struct_inheritance: Structs can inherit from another struct. This is implemented by defining the value of the ``baseType`` attribute, on the child ```` element to be the value of the ``name`` attribute of the parent ```` element. This is exemplified by the code snippet below. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-STRUCT-INHERIT<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_STRUCT_INHERITANCE<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_STRUCT_INHERITANCE + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Structures Inheritance `. + +.. _xmldynamictypes_union: Union """"" @@ -248,10 +419,25 @@ Each ```` element has one or more ```` elements, which ```` type, and a unique ```` element. Please, refer to :ref:`dynamictypes_supportedtypes_union` for more information on the ```` type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-UNION<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_UNION<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_UNION + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Unions `. + +.. _xmldynamictypes_bitset: Bitset """""" @@ -264,17 +450,50 @@ A ```` without ``name`` attribute is an inaccessible set of bits. Its management ``type`` can ease the ```` modification and access. Please, refer to :ref:`dynamictypes_supportedtypes_bitset` for more information about the ```` type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-BITSET<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_BITSET<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_BITSET + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Bitset `. + +.. _xmldynamictypes_bitset_inheritance: + +Moreover, bitsets can inherit from another bitsets. +This is implemented by defining the value of the ``baseType`` attribute, on the child ```` element to be the +value of the ``name`` attribute of the parent ```` element. +This is exemplified by the code snippet below. -Moreover, bitsets can inherit from another bitsets: +.. tabs:: -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-BITSET-INHERIT<--> - :end-before: <--> + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_BITSET_INHERITANCE<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_BITSET_INHERITANCE + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Bitset Inheritance `. + +.. _xmldynamictypes_bitmask: Bitmask """"""" @@ -287,10 +506,23 @@ The ```` element must define the ``name`` attribute and it might defi the ``positition`` attribute. Please, refer to :ref:`dynamictypes_supportedtypes_bitmask` for more information on the ```` type. -.. literalinclude:: /../code/XMLTester.xml - :language: xml - :start-after: XML-BITMASK<--> - :end-before: <--> +.. tabs:: + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: XML_BITMASK<--> + :end-before: <--> + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //!--CPP_BITMASK + :end-before: //!-- + +For a full example of how to define this type, please refer to :ref:`Bitmasks `. .. _Usage: @@ -298,11 +530,10 @@ Loading dynamic types in a *Fast DDS* application ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In the *Fast DDS* application that will make use of the *XML Types*, the XML files that -define the types must be loaded before trying to instantiate |DynamicPubSubType| objects of these types. +define the types must be loaded before trying to instantiate |DynamicPubSubType-api| objects of these types. .. literalinclude:: /../code/DDSCodeTester.cpp :language: c++ :start-after: //XML-USAGE :end-before: //!-- :dedent: 8 - diff --git a/docs/fastddsgen/dataTypes/dataTypes.rst b/docs/fastddsgen/dataTypes/dataTypes.rst index 9e458ff67..d3d7ff810 100644 --- a/docs/fastddsgen/dataTypes/dataTypes.rst +++ b/docs/fastddsgen/dataTypes/dataTypes.rst @@ -484,7 +484,7 @@ Additionally, the following standard annotations are builtin (recognized and pas +-------------------------+--------------------------------------------------------------------------------------------+ | @position | Setting a position to an element or group of elements. Used by bitmasks_. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @value | Allow setting a constant value to any element.Used by enumeration's members. | +| @value | [Unimplemented] Allow setting a constant value to a element.Used by enumeration's members. | +-------------------------+--------------------------------------------------------------------------------------------+ | @key | Alias for eProsima's @Key annotation. Indicate that a data member is part of the key |br| | | | (please refer to :ref:`dds_layer_topic_instances` for more information). | @@ -494,7 +494,7 @@ Additionally, the following standard annotations are builtin (recognized and pas +-------------------------+--------------------------------------------------------------------------------------------+ | @default_literal | Allow selecting one member as the default within a collection. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @default | Allow specifying the default value of the annotated element. | +| @default | [Unimplemented] Allow specifying the default value of the annotated element. | +-------------------------+--------------------------------------------------------------------------------------------+ | @range | [Unimplemented] Allow specifying a range of allowed values for the annotated element. | +-------------------------+--------------------------------------------------------------------------------------------+ @@ -502,7 +502,7 @@ Additionally, the following standard annotations are builtin (recognized and pas +-------------------------+--------------------------------------------------------------------------------------------+ | @max | [Unimplemented] Allow specifying a maximum value for the annotated element. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @unit | [Unimplemented] Allow specifying a unit of measurement for the annotated element. | +| @unit | Allow specifying a unit of measurement for the annotated element. | +-------------------------+--------------------------------------------------------------------------------------------+ | @bit_bound | Allow setting a size to a bitmasks_. | +-------------------------+--------------------------------------------------------------------------------------------+ @@ -511,15 +511,15 @@ Additionally, the following standard annotations are builtin (recognized and pas | @nested | Allow indicating that the objects from the type under annotation will |br| | | | always be nested within another one. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @verbatim | [Unimplemented] Allow injecting some user-provided information into what the compiler |br| | +| @verbatim | Allow injecting some user-provided information into what the compiler |br| | | | will generate. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @service | [Unimplemented] Allow indicating that an interface is to be treated as a service. | +| @service | Allow indicating that an interface is to be treated as a service. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @oneway | [Unimplemented] Allow indicating that an operation is one way only, meaning that |br| | +| @oneway | Allow indicating that an operation is one way only, meaning that |br| | | | related information flow will go from client to server but not back. | +-------------------------+--------------------------------------------------------------------------------------------+ -| @ami | [Unimplemented] Allow indicating that an interface or an operation is to be made |br| | +| @ami | Allow indicating that an interface or an operation is to be made |br| | | | callable asynchronously. | +-------------------------+--------------------------------------------------------------------------------------------+ | @non_serialized | The annotated member will be omitted from serialization. | diff --git a/docs/notes/previous_versions/v2.4.2.rst b/docs/notes/previous_versions/v2.4.2.rst index 3d152dbd3..2a6ca73a8 100644 --- a/docs/notes/previous_versions/v2.4.2.rst +++ b/docs/notes/previous_versions/v2.4.2.rst @@ -6,7 +6,7 @@ This release includes the following **improvements**: 1. Enable memory protection on :ref:`DataSharing ` readers 2. Add const overload of ``DataReader::guid()`` 3. Set recommended statistics :ref:`DataReaderQos ` to ``PREALLOCATED_WITH_REALLOC`` -4. Allow fully qualified name on :ref:`MemberDescriptor ` +4. Allow fully qualified name on MemberDescriptor This release includes the following bugfixes: