From 37b1d7f87a94426e4078ecdb6811f7cbc0f916a1 Mon Sep 17 00:00:00 2001 From: Miguel Barro Date: Wed, 12 Apr 2023 13:38:11 +0200 Subject: [PATCH] Refs 17138. Introducing namespaces Signed-off-by: Miguel Barro --- code/CodeTester.cpp | 510 ++++++++++-------- code/DDSCodeTester.cpp | 32 +- .../api_reference/spelling_wordlist.txt | 1 + .../api_reference/xtypes/DynamicData.rst | 2 +- .../api_reference/xtypes/DynamicType.rst | 2 +- .../xtypes/DynamicTypeBuilder.rst | 2 +- .../xtypes/DynamicTypeBuilderFactory.rst | 2 +- 7 files changed, 321 insertions(+), 230 deletions(-) diff --git a/code/CodeTester.cpp b/code/CodeTester.cpp index 3b681c3fb..aeea551b4 100644 --- a/code/CodeTester.cpp +++ b/code/CodeTester.cpp @@ -1,25 +1,26 @@ +#include #include -#include -#include -#include +#include +#include +#include #include +#include #include -#include -#include +#include +#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include +#include +#include #include #include -#include -#include -#include -#include +#include #include @@ -1172,9 +1173,11 @@ void pubsub_api_example_participant_configuration() { DynamicPubSubType* input_type = nullptr; //PUBSUB_API_CONF_PUBSUB_DYNAMIC_SAMPLEINFO + namespace xtypes = eprosima::fastrtps::types::v1_3; + // input_type is an instance of DynamicPubSubType of out current dynamic type DynamicPubSubType* pst = dynamic_cast(input_type); - DynamicData* sample = DynamicDataFactory::get_instance()->create_data(pst->GetDynamicType()); + xtypes::DynamicData* sample = xtypes::DynamicDataFactory::get_instance()->create_data(pst->GetDynamicType()); subscriber->takeNextData(sample, &sample_info); //!-- } @@ -1212,139 +1215,170 @@ void xml_load_and_apply_profiles_check() void xml_dyn_examples_check() { - //XML-DYN-ENUM - DynamicTypeBuilder_ptr enum_builder = DynamicTypeBuilderFactory::get_instance().create_enum_builder(); - enum_builder->set_name("MyEnum"); - enum_builder->add_member(0_id, "A"); - enum_builder->add_member(1_id, "B"); - enum_builder->add_member(2_id, "C"); - DynamicType_ptr enum_type = enum_builder->build(); - //!-- - //XML-TYPEDEF - DynamicTypeBuilder_ptr alias1_builder = DynamicTypeBuilderFactory::get_instance().create_alias_builder( - *enum_type, "MyAlias1"); - DynamicType_ptr alias1_type = alias1_builder->build(); - - std::vector sequence_lengths = { 2, 2 }; - DynamicTypeBuilder_cptr int_builder = DynamicTypeBuilderFactory::get_instance().create_int32_builder(); - DynamicTypeBuilder_ptr array_builder = DynamicTypeBuilderFactory::get_instance().create_array_builder( - *int_builder->build(), sequence_lengths); - DynamicTypeBuilder_ptr alias2_builder = DynamicTypeBuilderFactory::get_instance().create_alias_builder( - *array_builder->build(), "MyAlias2"); - DynamicType_ptr alias2_type = alias2_builder->build(); - //!-- + eprosima::fastrtps::types::v1_3::DynamicType_ptr x_enum_type; + + { + //XML-DYN-ENUM + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilder_ptr enum_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_enum_builder(); + enum_builder->set_name("MyEnum"); + enum_builder->add_member(0_id, "A"); + enum_builder->add_member(1_id, "B"); + enum_builder->add_member(2_id, "C"); + xtypes::DynamicType_ptr enum_type = enum_builder->build(); + //!-- + x_enum_type = enum_type; + } + { + auto enum_type = x_enum_type; + + //XML-TYPEDEF + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilder_ptr alias1_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_builder( + *enum_type, "MyAlias1"); + xtypes::DynamicType_ptr alias1_type = alias1_builder->build(); + + std::vector sequence_lengths = { 2, 2 }; + xtypes::DynamicTypeBuilder_cptr int_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_builder(); + xtypes::DynamicTypeBuilder_ptr array_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_array_builder( + *int_builder->build(), sequence_lengths); + xtypes::DynamicTypeBuilder_ptr alias2_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_builder( + *array_builder->build(), "MyAlias2"); + xtypes::DynamicType_ptr alias2_type = alias2_builder->build(); + //!-- + } { //XML-STRUCT - DynamicType_ptr long_type = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicType_ptr long_long_type = DynamicTypeBuilderFactory::get_instance().create_int64_type(); - DynamicTypeBuilder_ptr struct_builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicType_ptr long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicType_ptr long_long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int64_type(); + xtypes::DynamicTypeBuilder_ptr struct_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); struct_builder->set_name("MyStruct"); struct_builder->add_member(0_id, "first", long_type); struct_builder->add_member(1_id, "second", long_long_type); - DynamicType_ptr struct_type = struct_builder->build(); + xtypes::DynamicType_ptr struct_type = struct_builder->build(); //!-- } { //XML-STRUCT-INHERIT - DynamicType_ptr long_type = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicType_ptr long_long_type = DynamicTypeBuilderFactory::get_instance().create_int64_type(); - DynamicTypeBuilder_ptr struct_builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicType_ptr long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicType_ptr long_long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int64_type(); + xtypes::DynamicTypeBuilder_ptr struct_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); struct_builder->set_name("ParentStruct"); struct_builder->add_member(0_id, "first", long_type); struct_builder->add_member(1_id, "second", long_long_type); - DynamicType_ptr struct_type = struct_builder->build(); + xtypes::DynamicType_ptr struct_type = struct_builder->build(); - DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*struct_type); + xtypes::DynamicTypeBuilder_ptr child_builder = + xtypes::DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*struct_type); child_builder->set_name("ChildStruct"); child_builder->add_member(0_id, "third", long_type); child_builder->add_member(1_id, "fourth", long_long_type); - DynamicType_ptr child_struct_type = child_builder->build(); + xtypes::DynamicType_ptr child_struct_type = child_builder->build(); //!-- } { //XML-UNION - DynamicType_ptr long_type = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicType_ptr long_long_type = DynamicTypeBuilderFactory::get_instance().create_int64_type(); - DynamicType_ptr octet_type = DynamicTypeBuilderFactory::get_instance().create_byte_type(); - DynamicTypeBuilder_ptr struct_builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); - DynamicTypeBuilder_ptr union_builder = DynamicTypeBuilderFactory::get_instance().create_union_builder( + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicType_ptr long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicType_ptr long_long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int64_type(); + xtypes::DynamicType_ptr octet_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_byte_type(); + xtypes::DynamicTypeBuilder_ptr struct_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + xtypes::DynamicTypeBuilder_ptr union_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_union_builder( *octet_type); union_builder->set_name("MyUnion"); union_builder->add_member(0_id, "first", long_type, "", std::vector{ 0, 1 }, false); union_builder->add_member(1_id, "second", struct_builder->build(), "", std::vector{ 2 }, false); union_builder->add_member(2_id, "third", long_long_type, "", std::vector{ }, true); - DynamicType_ptr union_type = union_builder->build(); + xtypes::DynamicType_ptr union_type = union_builder->build(); //!-- } { //XML-GENERIC - DynamicTypeBuilder_cptr long_long_builder = DynamicTypeBuilderFactory::get_instance().create_int64_builder(); - DynamicTypeBuilder_ptr my_builder = DynamicTypeBuilderFactory::get_instance().create_builder_copy(*long_long_builder); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilder_cptr long_long_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_int64_builder(); + xtypes::DynamicTypeBuilder_ptr my_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_builder_copy(*long_long_builder); my_builder->set_name("my_long"); - DynamicType_ptr long_long_type = my_builder->build(); + xtypes::DynamicType_ptr long_long_type = my_builder->build(); //!-- } { //XML-BOUNDEDSTRINGS - DynamicTypeBuilder_cptr string_builder = DynamicTypeBuilderFactory::get_instance().create_string_builder(41925); - DynamicTypeBuilder_ptr my_builder = DynamicTypeBuilderFactory::get_instance().create_builder_copy(*string_builder); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilder_cptr string_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_builder(41925); + xtypes::DynamicTypeBuilder_ptr my_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_builder_copy(*string_builder); my_builder->set_name("my_large_string"); - DynamicType_ptr string_type = my_builder->build(); + xtypes::DynamicType_ptr string_type = my_builder->build(); - DynamicTypeBuilder_cptr wstring_builder = DynamicTypeBuilderFactory::get_instance().create_wstring_builder(20925); - DynamicTypeBuilder_ptr my_wbuilder = DynamicTypeBuilderFactory::get_instance().create_builder_copy(*wstring_builder); + xtypes::DynamicTypeBuilder_cptr wstring_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_wstring_builder(20925); + xtypes::DynamicTypeBuilder_ptr my_wbuilder = xtypes::DynamicTypeBuilderFactory::get_instance().create_builder_copy(*wstring_builder); my_wbuilder->set_name("my_large_wstring"); - DynamicType_ptr wstring_type = my_wbuilder->build(); + xtypes::DynamicType_ptr wstring_type = my_wbuilder->build(); //!-- } { //XML-ARRAYS + namespace xtypes = eprosima::fastrtps::types::v1_3; + std::vector lengths = { 2, 3, 4 }; - DynamicType_ptr long_type = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicTypeBuilder_ptr array_builder = DynamicTypeBuilderFactory::get_instance().create_array_builder( + xtypes::DynamicType_ptr long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr array_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_array_builder( *long_type, lengths); array_builder->set_name("long_array"); - DynamicType_ptr array_type = array_builder->build(); + xtypes::DynamicType_ptr array_type = array_builder->build(); //!-- } { //XML-SEQUENCES + namespace xtypes = eprosima::fastrtps::types::v1_3; + uint32_t child_len = 2; - DynamicType_ptr long_type = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicTypeBuilder_cptr seq_builder = DynamicTypeBuilderFactory::get_instance().create_sequence_builder( + xtypes::DynamicType_ptr long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_cptr seq_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_sequence_builder( *long_type, child_len); uint32_t length = 3; - DynamicTypeBuilder_ptr seq_seq_builder = DynamicTypeBuilderFactory::get_instance().create_sequence_builder( + xtypes::DynamicTypeBuilder_ptr seq_seq_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_sequence_builder( *seq_builder->build(), length); seq_seq_builder->set_name("my_sequence_sequence"); - DynamicType_ptr seq_type = seq_seq_builder->build(); + xtypes::DynamicType_ptr seq_type = seq_seq_builder->build(); //!-- } { //XML-MAPS + namespace xtypes = eprosima::fastrtps::types::v1_3; + uint32_t length = 2; - DynamicType_ptr long_type = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicTypeBuilder_ptr map_builder = DynamicTypeBuilderFactory::get_instance().create_map_builder( + xtypes::DynamicType_ptr long_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr map_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_map_builder( *long_type, *long_type, length); - DynamicTypeBuilder_ptr map_map_builder = DynamicTypeBuilderFactory::get_instance().create_map_builder( + xtypes::DynamicTypeBuilder_ptr map_map_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_map_builder( *long_type, *map_builder->build(), length); map_map_builder->set_name("my_map_map"); - DynamicType_ptr map_type = map_map_builder->build(); + xtypes::DynamicType_ptr map_type = map_map_builder->build(); //!-- } { //XML-BITSET - DynamicTypeBuilderFactory& factory = DynamicTypeBuilderFactory::get_instance(); - DynamicTypeBuilder_ptr builder_ptr = factory.create_bitset_builder(); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilderFactory& factory = xtypes::DynamicTypeBuilderFactory::get_instance(); + xtypes::DynamicTypeBuilder_ptr builder_ptr = factory.create_bitset_builder(); builder_ptr->add_member(0_id, "a", factory.create_byte_type()); builder_ptr->add_member(1_id, "b", factory.create_bool_type()); builder_ptr->add_member(3_id, "c", factory.create_uint16_type()); @@ -1362,8 +1396,10 @@ void xml_dyn_examples_check() } { //XML-BITMASK - DynamicTypeBuilderFactory& factory = DynamicTypeBuilderFactory::get_instance(); - DynamicTypeBuilder_ptr builder_ptr = factory.create_bitmask_builder(8); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilderFactory& factory = xtypes::DynamicTypeBuilderFactory::get_instance(); + xtypes::DynamicTypeBuilder_ptr builder_ptr = factory.create_bitmask_builder(8); builder_ptr->add_member(0_id, "flag0"); builder_ptr->add_member(1_id, "flag1"); builder_ptr->add_member(2_id, "flag2"); @@ -1373,8 +1409,10 @@ void xml_dyn_examples_check() } { //XML-BITSET-INHERIT - DynamicTypeBuilderFactory& factory = DynamicTypeBuilderFactory::get_instance(); - DynamicTypeBuilder_ptr builder_ptr = factory.create_bitset_builder(); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilderFactory& factory = xtypes::DynamicTypeBuilderFactory::get_instance(); + xtypes::DynamicTypeBuilder_ptr builder_ptr = factory.create_bitset_builder(); builder_ptr->add_member(0_id, "a", factory.create_byte_type()); builder_ptr->add_member(1_id, "b", factory.create_bool_type()); builder_ptr->apply_annotation_to_member(0_id, ANNOTATION_BIT_BOUND_ID, "value", "3"); @@ -1383,7 +1421,7 @@ void xml_dyn_examples_check() builder_ptr->apply_annotation_to_member(1_id, ANNOTATION_POSITION_ID, "value", "3"); builder_ptr->set_name("ParentBitSet"); - DynamicTypeBuilder_ptr child_ptr = factory.create_child_struct_builder(*builder_ptr->build()); + xtypes::DynamicTypeBuilder_ptr child_ptr = factory.create_child_struct_builder(*builder_ptr->build()); child_ptr->add_member(3_id, "c", factory.create_uint16_type()); child_ptr->add_member(4_id, "d", factory.create_int16_type()); child_ptr->apply_annotation_to_member(3_id, ANNOTATION_BIT_BOUND_ID, "value", "10"); @@ -1395,6 +1433,8 @@ void xml_dyn_examples_check() } { //XML-USAGE + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Load the XML File if (eprosima::fastrtps::xmlparser::XMLP_ret::XML_OK != eprosima::fastrtps::xmlparser::XMLProfileManager::loadXMLFile("types.xml")) @@ -1407,8 +1447,8 @@ void xml_dyn_examples_check() eprosima::fastrtps::types::DynamicPubSubType* pbType = eprosima::fastrtps::xmlparser::XMLProfileManager::CreateDynamicPubSubType("MyStruct"); // Create a "MyStruct" instance - eprosima::fastrtps::types::DynamicData* data = - eprosima::fastrtps::types::DynamicDataFactory::get_instance()->create_data( + xtypes::DynamicData* data = + xtypes::DynamicDataFactory::get_instance()->create_data( pbType->GetDynamicType()); //!-- } @@ -1525,8 +1565,10 @@ void dynamictypes_configuration() { { //DYNAMIC_TYPES_QUICK_EXAMPLE + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create a builder for a specific type - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_enum_builder(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_enum_builder(); // Use the builder to configure the type builder->add_member(0_id, "DEFAULT"); @@ -1534,11 +1576,11 @@ void dynamictypes_configuration() builder->add_member(2_id, "SECOND"); // Create the data type using the builder - // The builder will internally use the DynamicTypeBuilderFactory to create the type - DynamicType_ptr type = builder->build(); + // The builder will internally use the xtypes::DynamicTypeBuilderFactory to create the type + xtypes::DynamicType_ptr type = builder->build(); // Create a new data instance of the create data type - DynamicData_ptr data (DynamicDataFactory::get_instance()->create_data(type)); + xtypes::DynamicData_ptr data (xtypes::DynamicDataFactory::get_instance()->create_data(type)); // Now we can set or read data values data->set_int32_value(1); @@ -1550,63 +1592,71 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_PRIMITIVES + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Using Builders - DynamicTypeBuilder_cptr created_builder = DynamicTypeBuilderFactory::get_instance().create_int32_builder(); - DynamicType_ptr created_type = created_builder->build(); - DynamicData* data = DynamicDataFactory::get_instance()->create_data(created_type); + xtypes::DynamicTypeBuilder_cptr created_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_builder(); + xtypes::DynamicType_ptr created_type = created_builder->build(); + xtypes::DynamicData* data = xtypes::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); + xtypes::DynamicType_ptr pType = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicData* data2 = xtypes::DynamicDataFactory::get_instance()->create_data(pType); data2->set_int32_value(1); //!-- } { //DYNAMIC_TYPES_CREATE_STRINGS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Using Builders - DynamicTypeBuilder_cptr created_builder = DynamicTypeBuilderFactory::get_instance().create_string_builder(100); - DynamicType_ptr created_type = created_builder->build(); - DynamicData* data = DynamicDataFactory::get_instance()->create_data(created_type); + xtypes::DynamicTypeBuilder_cptr created_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_builder(100); + xtypes::DynamicType_ptr created_type = created_builder->build(); + xtypes::DynamicData* data = xtypes::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); + xtypes::DynamicType_ptr pType = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_type(100); + xtypes::DynamicData* data2 = xtypes::DynamicDataFactory::get_instance()->create_data(pType); data2->set_string_value("Dynamic String"); //!-- } { //DYNAMIC_TYPES_CREATE_ALIAS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create the base type - DynamicTypeBuilder_cptr base_builder = DynamicTypeBuilderFactory::get_instance().create_string_builder(100); - DynamicType_ptr base_type = base_builder->build(); + xtypes::DynamicTypeBuilder_cptr base_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_builder(100); + xtypes::DynamicType_ptr base_type = base_builder->build(); // Create alias using Builders - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_alias_builder(*base_type, + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_builder(*base_type, "alias"); - DynamicData* data = DynamicDataFactory::get_instance()->create_data(builder->build()); + xtypes::DynamicData* data = xtypes::DynamicDataFactory::get_instance()->create_data(builder->build()); 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); + xtypes::DynamicType_ptr pAliasType = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_type(*base_type, "alias"); + xtypes::DynamicData* data2 = xtypes::DynamicDataFactory::get_instance()->create_data(pAliasType); data2->set_string_value("Dynamic Alias String"); //!-- } { //DYNAMIC_TYPES_CREATE_ENUMERATIONS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Add enumeration values using the DynamicTypeBuilder - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_enum_builder(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_enum_builder(); builder->add_member(0_id, "DEFAULT"); builder->add_member(1_id, "FIRST"); builder->add_member(2_id, "SECOND"); // Create the data instance - DynamicData* data = DynamicDataFactory::get_instance()->create_data(builder.get()); + xtypes::DynamicData* data = xtypes::DynamicDataFactory::get_instance()->create_data(builder.get()); // Access value using the name std::string sValue = "SECOND"; @@ -1624,12 +1674,14 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_BITSETS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create bitfields with the appropriate type for their size - DynamicType_ptr base_type_byte = DynamicTypeBuilderFactory::get_instance().create_byte_type(); - DynamicType_ptr base_type_uint32 = DynamicTypeBuilderFactory::get_instance().create_uint32_type(); + xtypes::DynamicType_ptr base_type_byte = xtypes::DynamicTypeBuilderFactory::get_instance().create_byte_type(); + xtypes::DynamicType_ptr base_type_uint32 = xtypes::DynamicTypeBuilderFactory::get_instance().create_uint32_type(); // Create the bitset with two bitfields - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_bitset_builder(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_bitset_builder(); builder->add_member(0_id, "byte", base_type_byte); builder->add_member(1_id, "uint32", base_type_uint32); @@ -1638,10 +1690,10 @@ void dynamictypes_configuration() builder->apply_annotation_to_member(0_id, ANNOTATION_BIT_BOUND_ID, "value", "2"); // "byte" is 2 bit length builder->apply_annotation_to_member(1_id, ANNOTATION_POSITION_ID, "value", "10"); // "uint32" starts at position 10 (8 bits empty) builder->apply_annotation_to_member(1_id, ANNOTATION_BIT_BOUND_ID, "value", "20"); // "uint32" is 20 bits length - DynamicType_ptr bitset_type = builder->build(); + xtypes::DynamicType_ptr bitset_type = builder->build(); // Create the data instance - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(bitset_type)); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(bitset_type)); // Access values data->set_byte_value(234, 0_id); @@ -1652,22 +1704,24 @@ void dynamictypes_configuration() data->get_uint32_value(uValue, 1_id); //!-- //DYNAMIC_TYPES_CREATE_BITSETS-INHERIT - DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*bitset_type); + xtypes::DynamicTypeBuilder_ptr child_builder = + xtypes::DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*bitset_type); //!-- } { //DYNAMIC_TYPES_CREATE_BITMASKS + namespace xtypes = eprosima::fastrtps::types::v1_3; + uint32_t limit = 5; // Stores as "octet" // Add bitmask flags using the DynamicTypeBuilder - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_bitmask_builder(limit); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_bitmask_builder(limit); builder->add_member(0_id, "FIRST"); builder->add_member(1_id, "SECOND"); // Create the data instance - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(builder->build())); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(builder->build())); // Access the mask values using the name data->set_bool_value(true, "FIRST"); // Set the "FIRST" bit @@ -1685,42 +1739,46 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_STRUCTS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Build a structure with two fields ("first" as int32, "other" as uint64) using DynamicTypeBuilder - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); - builder->add_member(0_id, "first", DynamicTypeBuilderFactory::get_instance().create_int32_type()); - builder->add_member(1_id, "other", DynamicTypeBuilderFactory::get_instance().create_uint64_type()); - DynamicType_ptr struct_type = builder->build(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + builder->add_member(0_id, "first", xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type()); + builder->add_member(1_id, "other", xtypes::DynamicTypeBuilderFactory::get_instance().create_uint64_type()); + xtypes::DynamicType_ptr struct_type = builder->build(); // Create the data instance - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(struct_type)); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(struct_type)); // Access struct members data->set_int32_value(5, 0_id); data->set_uint64_value(13, 1_id); //!-- //DYNAMIC_TYPES_CREATE_STRUCTS-INHERIT - DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*struct_type); + xtypes::DynamicTypeBuilder_ptr child_builder = + xtypes::DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*struct_type); //!-- } { //DYNAMIC_TYPES_CREATE_UNIONS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create the union DynamicTypeBuilder with an int32 discriminator - DynamicType_ptr discriminator = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_union_builder(*discriminator); + xtypes::DynamicType_ptr discriminator = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_union_builder(*discriminator); // Add the union members. "firts" will be the default value - builder->add_member(0_id, "first", DynamicTypeBuilderFactory::get_instance().create_int32_type(), "", + builder->add_member(0_id, "first", xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(), "", std::vector{ 0 }, true); - builder->add_member(0_id, "second", DynamicTypeBuilderFactory::get_instance().create_int64_type(), "", + builder->add_member(0_id, "second", xtypes::DynamicTypeBuilderFactory::get_instance().create_int64_type(), "", std::vector{ 1 }, false); // Create the data instance - DynamicType_ptr union_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(union_type)); + xtypes::DynamicType_ptr union_type = builder->build(); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(union_type)); // Access the values using the member index data->set_int32_value(9, 0_id); @@ -1733,19 +1791,21 @@ void dynamictypes_configuration() } { + namespace xtypes = eprosima::fastrtps::types::v1_3; + //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(); - DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance().create_sequence_builder(*base_type, length); + xtypes::DynamicType_ptr base_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr builder = + xtypes::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)); + xtypes::DynamicType_ptr sequence_type = builder->build(); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(sequence_type)); // Insert and remove elements - MemberId newId, newId2; + xtypes::MemberId newId, newId2; data->insert_int32_value(10, newId); data->insert_int32_value(12, newId2); data->remove_sequence_data(newId); @@ -1754,18 +1814,20 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_ARRAYS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // 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(); - DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance().create_array_builder(*base_type, lengths); + xtypes::DynamicType_ptr base_type = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr builder = + xtypes::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)); + xtypes::DynamicType_ptr array_type = builder->build(); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(array_type)); // Access elements in the multidimensional array - MemberId pos = data->get_array_index({1, 0}); + xtypes::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); @@ -1774,27 +1836,29 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_MAPS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // 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(); - DynamicTypeBuilder_ptr builder = - DynamicTypeBuilderFactory::get_instance().create_map_builder(*base, *base, length); + xtypes::DynamicType_ptr base = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr builder = + xtypes::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)); + xtypes::DynamicType_ptr map_type = builder->build(); + xtypes::DynamicData_ptr data(xtypes::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; + xtypes::DynamicData_ptr key(xtypes::DynamicDataFactory::get_instance()->create_data(base)); + xtypes::MemberId keyId; + xtypes::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; + xtypes::MemberId keyId2; + xtypes::MemberId valueId2; key->set_int32_value(2); data->insert_map_data(key.get(), keyId2, valueId2); @@ -1809,21 +1873,23 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_NESTED_STRUCTS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create a struct type - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); - builder->add_member(0_id, "first", DynamicTypeBuilderFactory::get_instance().create_int32_type()); - builder->add_member(1_id, "other", DynamicTypeBuilderFactory::get_instance().create_uint64_type()); - DynamicType_ptr struct_type = builder->build(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + builder->add_member(0_id, "first", xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type()); + builder->add_member(1_id, "other", xtypes::DynamicTypeBuilderFactory::get_instance().create_uint64_type()); + xtypes::DynamicType_ptr struct_type = builder->build(); // Create a struct type with the previous struct as member - DynamicTypeBuilder_ptr parent_builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + xtypes::DynamicTypeBuilder_ptr parent_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); parent_builder->add_member(0_id, "child_struct", struct_type); - parent_builder->add_member(1_id, "second", DynamicTypeBuilderFactory::get_instance().create_int32_type()); - DynamicType_ptr parent_type = parent_builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(parent_type)); + parent_builder->add_member(1_id, "second", xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type()); + xtypes::DynamicType_ptr parent_type = parent_builder->build(); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(parent_type)); // Access the child struct with the loan operations - DynamicData* child_data = data->loan_value(0_id); + xtypes::DynamicData* child_data = data->loan_value(0_id); child_data->set_int32_value(5, 0_id); child_data->set_uint64_value(13, 1_id); data->return_loaned_value(child_data); @@ -1832,22 +1898,24 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_INHERITANCE_STRUCTS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create a base struct type - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); - builder->add_member(0_id, "first", DynamicTypeBuilderFactory::get_instance().create_int32_type()); - builder->add_member(1_id, "other", DynamicTypeBuilderFactory::get_instance().create_uint64_type()); - DynamicType_ptr base_type = builder->build(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + builder->add_member(0_id, "first", xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type()); + builder->add_member(1_id, "other", xtypes::DynamicTypeBuilderFactory::get_instance().create_uint64_type()); + xtypes::DynamicType_ptr base_type = builder->build(); // Create a struct type derived from the previous struct - DynamicTypeBuilder_ptr child_builder = - DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*base_type); + xtypes::DynamicTypeBuilder_ptr child_builder = + xtypes::DynamicTypeBuilderFactory::get_instance().create_child_struct_builder(*base_type); // Add new members to the derived type - builder->add_member(2_id, "third", DynamicTypeBuilderFactory::get_instance().create_uint64_type()); + builder->add_member(2_id, "third", xtypes::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)); + xtypes::DynamicType_ptr struct_type = child_builder->build(); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(struct_type)); // The derived type includes the members defined on the base type data->set_int32_value(5, 0_id); @@ -1858,54 +1926,58 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_NESTED_ALIAS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Using Builders - DynamicTypeBuilder_cptr created_builder = DynamicTypeBuilderFactory::get_instance().create_string_builder(100); - DynamicType_ptr created_type = created_builder->build(); - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_alias_builder( + xtypes::DynamicTypeBuilder_cptr created_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_builder(100); + xtypes::DynamicType_ptr created_type = created_builder->build(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_builder( *created_type, "alias"); - DynamicType_ptr alias_type = builder->build(); - DynamicTypeBuilder_ptr builder2 = DynamicTypeBuilderFactory::get_instance().create_alias_builder( + xtypes::DynamicType_ptr alias_type = builder->build(); + xtypes::DynamicTypeBuilder_ptr builder2 = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_builder( *alias_type, "alias2"); - DynamicData* data(DynamicDataFactory::get_instance()->create_data(builder2->build())); + xtypes::DynamicData* data(xtypes::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(pAliasType2)); + xtypes::DynamicType_ptr pType = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_type(100); + xtypes::DynamicType_ptr pAliasType = xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_type(*pType, "alias"); + xtypes::DynamicType_ptr pAliasType2 = + xtypes::DynamicTypeBuilderFactory::get_instance().create_alias_type(*pAliasType, "alias2"); + xtypes::DynamicData* data2(xtypes::DynamicDataFactory::get_instance()->create_data(pAliasType2)); data2->set_string_value("Dynamic Alias 2 String"); //!-- } { //DYNAMIC_TYPES_CREATE_NESTED_UNIONS + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create a union DynamicTypeBuilder - DynamicType_ptr discriminator = DynamicTypeBuilderFactory::get_instance().create_int32_type(); - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_union_builder(*discriminator); + xtypes::DynamicType_ptr discriminator = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_union_builder(*discriminator); // Add a int32 to the union builder->add_member( 0_id, // id "first", // name - DynamicTypeBuilderFactory::get_instance().create_int32_type(), // type + xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(), // type "", // default value std::vector{ 0 }, // labels true); // default value // Create a struct type and add it to the union - DynamicTypeBuilder_ptr struct_builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); - struct_builder->add_member(0_id, "first", DynamicTypeBuilderFactory::get_instance().create_int32_type()); - struct_builder->add_member(1_id, "other", DynamicTypeBuilderFactory::get_instance().create_uint64_type()); + xtypes::DynamicTypeBuilder_ptr struct_builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + struct_builder->add_member(0_id, "first", xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type()); + struct_builder->add_member(1_id, "other", xtypes::DynamicTypeBuilderFactory::get_instance().create_uint64_type()); builder->add_member(1_id, "first", struct_builder->build(), "", std::vector{ 1 }, false); // Create the union data instance - DynamicType_ptr union_type = builder->build(); - DynamicData_ptr data(DynamicDataFactory::get_instance()->create_data(union_type)); + xtypes::DynamicType_ptr union_type = builder->build(); + xtypes::DynamicData_ptr data(xtypes::DynamicDataFactory::get_instance()->create_data(union_type)); // Access the struct member using the loan operations - DynamicData* child_data = data->loan_value(1_id); + xtypes::DynamicData* child_data = data->loan_value(1_id); child_data->set_int32_value(9, 0_id); child_data->set_int64_value(13, 1_id); data->return_loaned_value(child_data); @@ -1914,8 +1986,10 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_CREATE_ANNOTATION + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Apply the annotation - DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance().create_struct_builder(); + xtypes::DynamicTypeBuilder_ptr builder = xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder(); //... builder->apply_annotation("MyAnnotation", "value", "5"); builder->apply_annotation("MyAnnotation", "name", "length"); @@ -1924,60 +1998,68 @@ void dynamictypes_configuration() { //DYNAMIC_TYPES_SERIALIZATION - DynamicType_ptr pType = DynamicTypeBuilderFactory::get_instance().create_int32_type(); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicType_ptr pType = xtypes::DynamicTypeBuilderFactory::get_instance().create_int32_type(); DynamicPubSubType pubsubType(pType); // SERIALIZATION EXAMPLE - DynamicData* pData = DynamicDataFactory::get_instance()->create_data(pType); + xtypes::DynamicData* pData = xtypes::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); + xtypes::DynamicData* data2 = xtypes::DynamicDataFactory::get_instance()->create_data(pType); pubsubType.deserialize(&payload, data2); //!-- } { //DYNAMIC_TYPES_NOTES_1 - DynamicTypeBuilder_ptr pBuilder = DynamicTypeBuilderFactory::get_instance().create_string_builder(16); - DynamicType_ptr pType = pBuilder->build(); - DynamicData* pData = DynamicDataFactory::get_instance()->create_data(pType); + namespace xtypes = eprosima::fastrtps::types::v1_3; - DynamicTypeBuilderFactory::get_instance().delete_builder(*pBuilder); - DynamicTypeBuilderFactory::get_instance().delete_type(*pType); - DynamicDataFactory::get_instance()->delete_data(pData); + xtypes::DynamicTypeBuilder_ptr pBuilder = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_builder(16); + xtypes::DynamicType_ptr pType = pBuilder->build(); + xtypes::DynamicData* pData = xtypes::DynamicDataFactory::get_instance()->create_data(pType); + + xtypes::DynamicTypeBuilderFactory::get_instance().delete_builder(*pBuilder); + xtypes::DynamicTypeBuilderFactory::get_instance().delete_type(*pType); + xtypes::DynamicDataFactory::get_instance()->delete_data(pData); //!-- } { //DYNAMIC_TYPES_NOTES_2 - DynamicTypeBuilder_ptr pBuilder = DynamicTypeBuilderFactory::get_instance().create_string_builder(16); - DynamicType_ptr pType = pBuilder->build(); - DynamicData_ptr pData(DynamicDataFactory::get_instance()->create_data(pType)); + namespace xtypes = eprosima::fastrtps::types::v1_3; + + xtypes::DynamicTypeBuilder_ptr pBuilder = xtypes::DynamicTypeBuilderFactory::get_instance().create_string_builder(16); + xtypes::DynamicType_ptr pType = pBuilder->build(); + xtypes::DynamicData_ptr pData(xtypes::DynamicDataFactory::get_instance()->create_data(pType)); //!-- } { //DYNAMIC_HELLO_WORLD_API + namespace xtypes = eprosima::fastrtps::types::v1_3; + // In HelloWorldPublisher.h // Dynamic Types - eprosima::fastrtps::types::DynamicData* m_DynHello; - eprosima::fastrtps::types::DynamicPubSubType m_DynType; + xtypes::DynamicData* m_DynHello; + DynamicPubSubType m_DynType; // In HelloWorldPublisher.cpp // Create basic builders - DynamicTypeBuilder_ptr struct_type_builder(DynamicTypeBuilderFactory::get_instance().create_struct_builder()); + xtypes::DynamicTypeBuilder_ptr struct_type_builder(xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder()); // Add members to the struct. - struct_type_builder->add_member(0_id, "index", DynamicTypeBuilderFactory::get_instance().create_uint32_type()); - struct_type_builder->add_member(1_id, "message", DynamicTypeBuilderFactory::get_instance().create_string_type()); + struct_type_builder->add_member(0_id, "index", xtypes::DynamicTypeBuilderFactory::get_instance().create_uint32_type()); + struct_type_builder->add_member(1_id, "message", xtypes::DynamicTypeBuilderFactory::get_instance().create_string_type()); struct_type_builder->set_name("HelloWorld"); - DynamicType_ptr dynType = struct_type_builder->build(); + xtypes::DynamicType_ptr dynType = struct_type_builder->build(); m_DynType.SetDynamicType(dynType); - m_DynHello = DynamicDataFactory::get_instance()->create_data(dynType); + m_DynHello = xtypes::DynamicDataFactory::get_instance()->create_data(dynType); m_DynHello->set_uint32_value(0, 0_id); m_DynHello->set_string_value("HelloWorld", 1_id); //!-- @@ -1985,23 +2067,25 @@ void dynamictypes_configuration() { //DYNAMIC_HELLO_WORLD_API + namespace xtypes = eprosima::fastrtps::types::v1_3; + // In HelloWorldPublisher.h // Dynamic Types - eprosima::fastrtps::types::DynamicData* m_DynHello; - eprosima::fastrtps::types::DynamicPubSubType m_DynType; + xtypes::DynamicData* m_DynHello; + DynamicPubSubType m_DynType; // In HelloWorldPublisher.cpp // Create basic builders - DynamicTypeBuilder_ptr struct_type_builder(DynamicTypeBuilderFactory::get_instance().create_struct_builder()); + xtypes::DynamicTypeBuilder_ptr struct_type_builder(xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder()); // Add members to the struct. - struct_type_builder->add_member(0_id, "index", DynamicTypeBuilderFactory::get_instance().create_uint32_type()); - struct_type_builder->add_member(1_id, "message", DynamicTypeBuilderFactory::get_instance().create_string_type()); + struct_type_builder->add_member(0_id, "index", xtypes::DynamicTypeBuilderFactory::get_instance().create_uint32_type()); + struct_type_builder->add_member(1_id, "message", xtypes::DynamicTypeBuilderFactory::get_instance().create_string_type()); struct_type_builder->set_name("HelloWorld"); - DynamicType_ptr dynType = struct_type_builder->build(); + xtypes::DynamicType_ptr dynType = struct_type_builder->build(); m_DynType.SetDynamicType(dynType); - m_DynHello = DynamicDataFactory::get_instance()->create_data(dynType); + m_DynHello = xtypes::DynamicDataFactory::get_instance()->create_data(dynType); m_DynHello->set_uint32_value(0, 0_id); m_DynHello->set_string_value("HelloWorld", 1_id); //!-- diff --git a/code/DDSCodeTester.cpp b/code/DDSCodeTester.cpp index 509df54e5..47e32eeef 100644 --- a/code/DDSCodeTester.cpp +++ b/code/DDSCodeTester.cpp @@ -49,7 +49,6 @@ #include using namespace eprosima::fastdds::dds; -using namespace eprosima::fastrtps::types::literals; class CustomChainingTransportDescriptor : public eprosima::fastdds::rtps::ChainingTransportDescriptor { @@ -206,7 +205,7 @@ class CustomDomainParticipantListener : public DomainParticipantListener const eprosima::fastrtps::string_255& topic, const eprosima::fastrtps::types::TypeIdentifier* identifier, const eprosima::fastrtps::types::TypeObject* object, - eprosima::fastrtps::types::DynamicType_ptr dyn_type) override + eprosima::fastrtps::types::v1_3::DynamicType_ptr dyn_type) override { static_cast(participant); static_cast(request_sample_id); @@ -879,7 +878,7 @@ class DiscoveryDomainParticipantListener : public DomainParticipantListener const eprosima::fastrtps::string_255& topic, const eprosima::fastrtps::types::TypeIdentifier* identifier, const eprosima::fastrtps::types::TypeObject* object, - eprosima::fastrtps::types::DynamicType_ptr dyn_type) override + eprosima::fastrtps::types::v1_3::DynamicType_ptr dyn_type) override { static_cast(participant); static_cast(request_sample_id); @@ -1632,6 +1631,8 @@ void dds_topic_examples() { //DDS_DYNAMIC_TYPES + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create a DomainParticipant in the desired domain DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT); @@ -1645,7 +1646,7 @@ void dds_topic_examples() eprosima::fastrtps::xmlparser::XMLProfileManager::loadXMLFile("example_type.xml"); // Retrieve the an instance of the desired type and register it - eprosima::fastrtps::types::DynamicType_ptr dyn_type = + xtypes::DynamicType_ptr dyn_type = eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName("DynamicType")->build(); TypeSupport dyn_type_support(new eprosima::fastrtps::types::DynamicPubSubType(dyn_type)); dyn_type_support.register_type(participant, nullptr); @@ -4340,6 +4341,8 @@ void xml_profiles_examples() } { //XML-USAGE + namespace xtypes = eprosima::fastrtps::types::v1_3; + // Create a DomainParticipant DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT); @@ -4354,7 +4357,7 @@ void xml_profiles_examples() DomainParticipantFactory::get_instance()->load_XML_profiles_file("my_profiles.xml")) { // Retrieve the an instance of MyStruct type - eprosima::fastrtps::types::DynamicType_ptr my_struct_type = + xtypes::DynamicType_ptr my_struct_type = eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName("MyStruct")->build(); // Register MyStruct type TypeSupport my_struct_type_support(new eprosima::fastrtps::types::DynamicPubSubType(my_struct_type)); @@ -5277,6 +5280,9 @@ void dds_persistence_examples() * }; */ + using namespace eprosima::fastrtps::types; + namespace xtypes = v1_3; + // Configure persistence service plugin for DomainParticipant DomainParticipantQos pqos; pqos.properties().properties().emplace_back("dds.persistence.plugin", "builtin.SQLITE3"); @@ -5292,26 +5298,26 @@ void dds_persistence_examples() ********************************************************************************************************/ // Create a struct builder for a type with name "persistence_topic_type" const std::string topic_type_name = "persistence_topic_type"; - eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_type_builder( - eprosima::fastrtps::types::DynamicTypeBuilderFactory::get_instance().create_struct_builder()); + xtypes::DynamicTypeBuilder_ptr struct_type_builder( + xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder()); struct_type_builder->set_name(topic_type_name); // The type consists of two members, and index and a message. Add members to the struct. struct_type_builder->add_member(0, "index", - eprosima::fastrtps::types::DynamicTypeBuilderFactory::get_instance().create_uint32_type()); + xtypes::DynamicTypeBuilderFactory::get_instance().create_uint32_type()); struct_type_builder->add_member(1, "message", - eprosima::fastrtps::types::DynamicTypeBuilderFactory::get_instance().create_string_type()); + xtypes::DynamicTypeBuilderFactory::get_instance().create_string_type()); // Build the type - eprosima::fastrtps::types::DynamicType_ptr dyn_type_ptr = struct_type_builder->build(); + xtypes::DynamicType_ptr dyn_type_ptr = struct_type_builder->build(); // Create type support and register the type - TypeSupport type_support(new eprosima::fastrtps::types::DynamicPubSubType(dyn_type_ptr)); + TypeSupport type_support(new DynamicPubSubType(dyn_type_ptr)); type_support.register_type(participant); // Create data sample a populate data. This is to be used when calling `writer->write()` - eprosima::fastrtps::types::DynamicData* dyn_helloworld; - dyn_helloworld = eprosima::fastrtps::types::DynamicDataFactory::get_instance()->create_data(dyn_type_ptr); + xtypes::DynamicData* dyn_helloworld; + dyn_helloworld = xtypes::DynamicDataFactory::get_instance()->create_data(dyn_type_ptr); dyn_helloworld->set_uint32_value(0, 0_id); dyn_helloworld->set_string_value("HelloWorld", 1_id); /******************************************************************************************************** diff --git a/docs/fastdds/api_reference/spelling_wordlist.txt b/docs/fastdds/api_reference/spelling_wordlist.txt index 8ee9c87ee..46314a0d6 100644 --- a/docs/fastdds/api_reference/spelling_wordlist.txt +++ b/docs/fastdds/api_reference/spelling_wordlist.txt @@ -170,6 +170,7 @@ typedef TypeIdentifier TypeIdV TypeInformation +TypeKind typelookup TypeLookup TypeLookup diff --git a/docs/fastdds/api_reference/xtypes/DynamicData.rst b/docs/fastdds/api_reference/xtypes/DynamicData.rst index 628e07d67..e54fefa4a 100644 --- a/docs/fastdds/api_reference/xtypes/DynamicData.rst +++ b/docs/fastdds/api_reference/xtypes/DynamicData.rst @@ -5,6 +5,6 @@ DynamicType ----------- -.. doxygenclass:: eprosima::fastrtps::types::DynamicData +.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicData :project: FastDDS :members: diff --git a/docs/fastdds/api_reference/xtypes/DynamicType.rst b/docs/fastdds/api_reference/xtypes/DynamicType.rst index cb49630e8..dc2810382 100644 --- a/docs/fastdds/api_reference/xtypes/DynamicType.rst +++ b/docs/fastdds/api_reference/xtypes/DynamicType.rst @@ -5,6 +5,6 @@ DynamicType ----------- -.. doxygenclass:: eprosima::fastrtps::types::DynamicType +.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicType :project: FastDDS :members: diff --git a/docs/fastdds/api_reference/xtypes/DynamicTypeBuilder.rst b/docs/fastdds/api_reference/xtypes/DynamicTypeBuilder.rst index 32e593b46..300291e67 100644 --- a/docs/fastdds/api_reference/xtypes/DynamicTypeBuilder.rst +++ b/docs/fastdds/api_reference/xtypes/DynamicTypeBuilder.rst @@ -5,6 +5,6 @@ DynamicTypeBuilder ------------------ -.. doxygenclass:: eprosima::fastrtps::types::DynamicTypeBuilder +.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicTypeBuilder :project: FastDDS :members: diff --git a/docs/fastdds/api_reference/xtypes/DynamicTypeBuilderFactory.rst b/docs/fastdds/api_reference/xtypes/DynamicTypeBuilderFactory.rst index 783d36363..4ac57c679 100644 --- a/docs/fastdds/api_reference/xtypes/DynamicTypeBuilderFactory.rst +++ b/docs/fastdds/api_reference/xtypes/DynamicTypeBuilderFactory.rst @@ -5,6 +5,6 @@ DynamicTypeBuilderFactory ------------------------- -.. doxygenclass:: eprosima::fastrtps::types::DynamicTypeBuilderFactory +.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicTypeBuilderFactory :project: FastDDS :members: