Skip to content

Commit efd82d0

Browse files
authored
Enumerations are traslated to C++ signed integer enumeration (#821)
Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
1 parent fd95234 commit efd82d0

3 files changed

Lines changed: 46 additions & 39 deletions

File tree

code/DDSCodeTester.cpp

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,22 +1049,22 @@ class RemoteDiscoveryDomainParticipantListener : public DomainParticipantListene
10491049
// Get remote type information
10501050
xtypes::TypeObject remote_type_object;
10511051
if (RETCODE_OK != DomainParticipantFactory::get_instance()->type_object_registry().get_type_object(
1052-
info.info.type_information().type_information.complete().typeid_with_size().type_id(),
1053-
remote_type_object))
1052+
info.info.type_information().type_information.complete().typeid_with_size().type_id(),
1053+
remote_type_object))
10541054
{
10551055
// Error
10561056
return;
10571057
}
10581058
// Register remotely discovered type
10591059
DynamicType::_ref_type remote_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object(
1060-
remote_type_object)->build();
1060+
remote_type_object)->build();
10611061
TypeSupport dyn_type_support(new DynamicPubSubType(remote_type));
10621062
dyn_type_support.register_type(participant);
10631063

10641064
// Create a Topic with the remotely discovered type.
10651065
Topic* topic =
10661066
participant->create_topic(info.info.topicName().to_string(), dyn_type_support.get_type_name(),
1067-
TOPIC_QOS_DEFAULT);
1067+
TOPIC_QOS_DEFAULT);
10681068
if (nullptr == topic)
10691069
{
10701070
// Error
@@ -1097,22 +1097,22 @@ class RemoteDiscoveryDomainParticipantListener : public DomainParticipantListene
10971097
// Get remote type information
10981098
xtypes::TypeObject remote_type_object;
10991099
if (RETCODE_OK != DomainParticipantFactory::get_instance()->type_object_registry().get_type_object(
1100-
info.info.type_information().type_information.complete().typeid_with_size().type_id(),
1101-
remote_type_object))
1100+
info.info.type_information().type_information.complete().typeid_with_size().type_id(),
1101+
remote_type_object))
11021102
{
11031103
// Error
11041104
return;
11051105
}
11061106
// Register remotely discovered type
11071107
DynamicType::_ref_type remote_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object(
1108-
remote_type_object)->build();
1108+
remote_type_object)->build();
11091109
TypeSupport dyn_type_support(new DynamicPubSubType(remote_type));
11101110
dyn_type_support.register_type(participant);
11111111

11121112
// Create a Topic with the remotely discovered type.
11131113
Topic* topic =
11141114
participant->create_topic(info.info.topicName().to_string(), dyn_type_support.get_type_name(),
1115-
TOPIC_QOS_DEFAULT);
1115+
TOPIC_QOS_DEFAULT);
11161116
if (nullptr == topic)
11171117
{
11181118
// Error
@@ -1135,6 +1135,7 @@ class RemoteDiscoveryDomainParticipantListener : public DomainParticipantListene
11351135
return;
11361136
}
11371137
}
1138+
11381139
};
11391140
//!--
11401141

@@ -4326,12 +4327,15 @@ void dds_qos_examples()
43264327
// This example only applies to DomainParticipant entities
43274328
DomainParticipantQos participant_qos;
43284329
// Set the maximum size of participant resource limits collection to 3 and it allocation configuration to fixed size
4329-
participant_qos.allocation().participants = eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(
4330+
participant_qos.allocation().participants =
4331+
eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(
43304332
3u);
43314333
// Set the maximum size of reader's resource limits collection to 2 and its allocation configuration to fixed size
4332-
participant_qos.allocation().readers = eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(2u);
4334+
participant_qos.allocation().readers =
4335+
eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(2u);
43334336
// Set the maximum size of writer's resource limits collection to 1 and its allocation configuration to fixed size
4334-
participant_qos.allocation().writers = eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(1u);
4337+
participant_qos.allocation().writers =
4338+
eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(1u);
43354339
// Set the maximum size of the partition data to 256
43364340
participant_qos.allocation().data_limits.max_partitions = 256u;
43374341
// Set the maximum size of the user data to 256
@@ -4513,7 +4517,8 @@ void dds_qos_examples()
45134517
// Set use_builtin_transports to false
45144518
participant_qos.transport().use_builtin_transports = false;
45154519
// [OPTIONAL] Set ThreadSettings for the builtin transports reception threads
4516-
participant_qos.transport().builtin_transports_reception_threads_ = eprosima::fastdds::rtps::ThreadSettings{2, 2, 2, 2};
4520+
participant_qos.transport().builtin_transports_reception_threads_ =
4521+
eprosima::fastdds::rtps::ThreadSettings{2, 2, 2, 2};
45174522
// Set max_msg_size_no_frag to a value > 65500 KB
45184523
participant_qos.transport().max_msg_size_no_frag = 70000;
45194524
// Configure netmask filter
@@ -4542,7 +4547,8 @@ void dds_qos_examples()
45424547
meta_external_locator.kind = LOCATOR_KIND_UDPv4;
45434548
meta_external_locator.port = 34567;
45444549
meta_external_locator.mask(24);
4545-
participant_qos.wire_protocol().builtin.metatraffic_external_unicast_locators[1][0].push_back(meta_external_locator);
4550+
participant_qos.wire_protocol().builtin.metatraffic_external_unicast_locators[1][0].push_back(
4551+
meta_external_locator);
45464552
// Add locator to default unicast locator list
45474553
eprosima::fastdds::rtps::Locator_t unicast_locator;
45484554
eprosima::fastdds::rtps::IPLocator::setIPv4(unicast_locator, 192, 168, 1, 41);
@@ -4879,7 +4885,7 @@ void dynamictypes_examples()
48794885
type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8));
48804886
type_descriptor->bound().push_back(static_cast<uint32_t>(LENGTH_UNLIMITED));
48814887
member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build());
4882-
*/
4888+
*/
48834889

48844890
struct_builder->add_member(member_descriptor);
48854891
member_descriptor->name("my_wstring");
@@ -4892,7 +4898,7 @@ void dynamictypes_examples()
48924898
type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16));
48934899
type_descriptor->bound().push_back(static_cast<uint32_t>(LENGTH_UNLIMITED));
48944900
member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build());
4895-
*/
4901+
*/
48964902

48974903
struct_builder->add_member(member_descriptor);
48984904
member_descriptor->name("my_bounded_string");
@@ -4905,7 +4911,7 @@ void dynamictypes_examples()
49054911
type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8));
49064912
type_descriptor->bound().push_back(41925);
49074913
member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build());
4908-
*/
4914+
*/
49094915

49104916
struct_builder->add_member(member_descriptor);
49114917
member_descriptor->name("my_bounded_wstring");
@@ -4918,7 +4924,7 @@ void dynamictypes_examples()
49184924
type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16));
49194925
type_descriptor->bound().push_back(20925);
49204926
member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build());
4921-
*/
4927+
*/
49224928

49234929
struct_builder->add_member(member_descriptor);
49244930

@@ -4936,7 +4942,7 @@ void dynamictypes_examples()
49364942
}
49374943
{
49384944
//!--CPP_ENUM
4939-
enum MyEnum : uint32_t
4945+
enum MyEnum : int32_t
49404946
{
49414947
A,
49424948
B,
@@ -4957,15 +4963,15 @@ void dynamictypes_examples()
49574963
create_type(enum_type_descriptor)};
49584964
// Add enum literals to the enum type
49594965
MemberDescriptor::_ref_type enum_member_descriptor {traits<MemberDescriptor>::make_shared()};
4960-
enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32));
4966+
enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32));
49614967
enum_member_descriptor->name("A");
49624968
enum_builder->add_member(enum_member_descriptor);
49634969
enum_member_descriptor = traits<MemberDescriptor>::make_shared();
4964-
enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32));
4970+
enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32));
49654971
enum_member_descriptor->name("B");
49664972
enum_builder->add_member(enum_member_descriptor);
49674973
enum_member_descriptor = traits<MemberDescriptor>::make_shared();
4968-
enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32));
4974+
enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32));
49694975
enum_member_descriptor->name("C");
49704976
enum_builder->add_member(enum_member_descriptor);
49714977
// Build the enum type
@@ -4986,7 +4992,7 @@ void dynamictypes_examples()
49864992

49874993
/* Alternative
49884994
uint32_t in_value {2}; // Selecting MyEnum::C
4989-
*/
4995+
*/
49904996

49914997
uint32_t out_value {0};
49924998
data->set_uint32_value(data->get_member_id_by_name("my_enum"), in_value);
@@ -5014,7 +5020,7 @@ void dynamictypes_examples()
50145020
bitmask_type_descriptor->bound().push_back(8);
50155021
DynamicTypeBuilder::_ref_type bitmask_builder {DynamicTypeBuilderFactory::get_instance()->create_type(
50165022
bitmask_type_descriptor)};
5017-
*/
5023+
*/
50185024

50195025
// Add bitfield members to the bitmask type
50205026
MemberDescriptor::_ref_type bitfield_member_descriptor {traits<MemberDescriptor>::make_shared()};
@@ -5097,7 +5103,8 @@ void dynamictypes_examples()
50975103
alias_bounded_string_type_descriptor->base_type(DynamicTypeBuilderFactory::get_instance()->
50985104
create_string_type(100)->build());
50995105
DynamicTypeBuilder::_ref_type alias_bounded_string_builder {DynamicTypeBuilderFactory::get_instance()->
5100-
create_type(alias_bounded_string_type_descriptor)};
5106+
create_type(
5107+
alias_bounded_string_type_descriptor)};
51015108
// Build the alias type for the bounded string
51025109
DynamicType::_ref_type alias_bounded_string_type = alias_bounded_string_builder->build();
51035110

@@ -5107,7 +5114,7 @@ void dynamictypes_examples()
51075114
recursive_alias_type_descriptor->name("MyRecursiveAlias");
51085115
recursive_alias_type_descriptor->base_type(aliasenum_type);
51095116
DynamicTypeBuilder::_ref_type recursive_alias_builder {DynamicTypeBuilderFactory::get_instance()->
5110-
create_type(recursive_alias_type_descriptor)};
5117+
create_type(recursive_alias_type_descriptor)};
51115118
// Build the recursive alias type
51125119
DynamicType::_ref_type recursive_alias_type = recursive_alias_builder->build();
51135120

@@ -5164,7 +5171,7 @@ void dynamictypes_examples()
51645171
type_descriptor->bound().push_back(static_cast<uint32_t>(LENGTH_UNLIMITED));
51655172
sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(
51665173
type_descriptor)->build());
5167-
*/
5174+
*/
51685175

51695176
// Add the sequence member to the struct
51705177
struct_builder->add_member(sequence_member_descriptor);
@@ -5181,7 +5188,7 @@ void dynamictypes_examples()
51815188
type_descriptor->bound().push_back(5);
51825189
sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(
51835190
type_descriptor)->build());
5184-
*/
5191+
*/
51855192

51865193
// Add the sequence member to the struct
51875194
struct_builder->add_member(sequence_member_descriptor);
@@ -5233,7 +5240,7 @@ void dynamictypes_examples()
52335240
type_descriptor->bound().push_back(4);
52345241
array_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(
52355242
type_descriptor)->build());
5236-
*/
5243+
*/
52375244

52385245
// Add the array member to the struct
52395246
struct_builder->add_member(array_member_descriptor);
@@ -5278,9 +5285,9 @@ void dynamictypes_examples()
52785285
MemberDescriptor::_ref_type map_member_descriptor {traits<MemberDescriptor>::make_shared()};
52795286
map_member_descriptor->name("string_long_array_unbounded_map");
52805287
map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_map_type(
5281-
DynamicTypeBuilderFactory::get_instance()->create_string_type(static_cast<uint32_t>(
5282-
LENGTH_UNLIMITED))->build(), alias_bounded_string_type, static_cast<uint32_t>(
5283-
LENGTH_UNLIMITED))->build());
5288+
DynamicTypeBuilderFactory::get_instance()->create_string_type(static_cast<uint32_t>(
5289+
LENGTH_UNLIMITED))->build(), alias_bounded_string_type, static_cast<uint32_t>(
5290+
LENGTH_UNLIMITED))->build());
52845291

52855292
/* Alternative
52865293
type_descriptor = traits<TypeDescriptor>::make_shared();
@@ -5291,7 +5298,7 @@ void dynamictypes_examples()
52915298
type_descriptor->bound().push_back(static_cast<uint32_t>(LENGTH_UNLIMITED));
52925299
map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(
52935300
type_descriptor)->build());
5294-
*/
5301+
*/
52955302

52965303
// Add the map member to the struct
52975304
struct_builder->add_member(map_member_descriptor);
@@ -5310,7 +5317,7 @@ void dynamictypes_examples()
53105317
type_descriptor->bound().push_back(2);
53115318
map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(
53125319
type_descriptor)->build());
5313-
*/
5320+
*/
53145321

53155322
struct_builder->add_member(map_member_descriptor);
53165323
// Build the struct type
@@ -5373,7 +5380,7 @@ void dynamictypes_examples()
53735380
complexstruct_type_descriptor->name("ComplexStruct");
53745381
complexstruct_type_descriptor->base_type(parentstruct_type);
53755382
DynamicTypeBuilder::_ref_type complexstruct_builder {DynamicTypeBuilderFactory::get_instance()->
5376-
create_type(complexstruct_type_descriptor)};
5383+
create_type(complexstruct_type_descriptor)};
53775384
// Add members to the complex struct type
53785385
MemberDescriptor::_ref_type complexstruct_member {traits<MemberDescriptor>::make_shared()};
53795386
complexstruct_member->name("complex_member");
@@ -5550,7 +5557,7 @@ void dynamictypes_examples()
55505557
MemberDescriptor::_ref_type member_descriptor {traits<MemberDescriptor>::make_shared()};
55515558
member_descriptor->name("string_var");
55525559
member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_string_type(static_cast<uint32_t>(
5553-
LENGTH_UNLIMITED))->build());
5560+
LENGTH_UNLIMITED))->build());
55545561
type_builder->add_member(member_descriptor);
55555562

55565563
// Create the annotation type
@@ -5671,7 +5678,7 @@ void xml_profiles_examples()
56715678
DynamicType::_ref_type my_struct_type;
56725679
if (RETCODE_OK !=
56735680
DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name(
5674-
"MyStruct", my_struct_type))
5681+
"MyStruct", my_struct_type))
56755682
{
56765683
// Error
56775684
return;

code/FastDDSGenCodeTester.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class ChildBitset : public ParentBitset
159159
//!
160160

161161
// ENUMERATION_DATA_TYPE
162-
enum Enumeration : uint32_t
162+
enum Enumeration : int32_t
163163
{
164164
RED,
165165
GREEN,

docs/fastdds/xtypes/language_binding.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ The behavior is the same as setting the :code:`@value` :ref:`builtin annotation<
302302

303303
Currently, Fast DDS-Gen does not support :code:`@value` builtin annotation.
304304

305-
As the enumeration type is basically a primitive type which might take only some specific values defined with the
305+
As the enumeration type is basically a signed integer type which might take only some specific values defined with the
306306
enumeration literals, the corresponding DynamicData getters and setters are the ones corresponding to the underlying
307-
primitive type (and any other method promotable to that specific primitive type).
307+
signed integer type (and any other method promotable to that specific primitive type).
308308

309309
.. tabs::
310310

0 commit comments

Comments
 (0)