From b9348aa603d38d0cfd8d638db089a5681e4e7beb Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 2 Nov 2018 11:22:52 -0700 Subject: [PATCH 1/2] rename dynamic array to sequence --- .../TypeSupport_impl.hpp | 106 +++++++++--------- .../rmw_fastrtps_dynamic_cpp/macros.hpp | 10 +- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp index 632b946d2..c06a61eee 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp @@ -36,37 +36,37 @@ namespace rmw_fastrtps_dynamic_cpp { template -struct GenericCArray; +struct GenericCSequence; // multiple definitions of ambiguous primitive types -SPECIALIZE_GENERIC_C_ARRAY(bool, bool) -SPECIALIZE_GENERIC_C_ARRAY(byte, uint8_t) -SPECIALIZE_GENERIC_C_ARRAY(char, char) -SPECIALIZE_GENERIC_C_ARRAY(float32, float) -SPECIALIZE_GENERIC_C_ARRAY(float64, double) -SPECIALIZE_GENERIC_C_ARRAY(int8, int8_t) -SPECIALIZE_GENERIC_C_ARRAY(int16, int16_t) -SPECIALIZE_GENERIC_C_ARRAY(uint16, uint16_t) -SPECIALIZE_GENERIC_C_ARRAY(int32, int32_t) -SPECIALIZE_GENERIC_C_ARRAY(uint32, uint32_t) -SPECIALIZE_GENERIC_C_ARRAY(int64, int64_t) -SPECIALIZE_GENERIC_C_ARRAY(uint64, uint64_t) - -typedef struct rosidl_generator_c__void__Array +SPECIALIZE_GENERIC_C_SEQUENCE(bool, bool) +SPECIALIZE_GENERIC_C_SEQUENCE(byte, uint8_t) +SPECIALIZE_GENERIC_C_SEQUENCE(char, char) +SPECIALIZE_GENERIC_C_SEQUENCE(float32, float) +SPECIALIZE_GENERIC_C_SEQUENCE(float64, double) +SPECIALIZE_GENERIC_C_SEQUENCE(int8, int8_t) +SPECIALIZE_GENERIC_C_SEQUENCE(int16, int16_t) +SPECIALIZE_GENERIC_C_SEQUENCE(uint16, uint16_t) +SPECIALIZE_GENERIC_C_SEQUENCE(int32, int32_t) +SPECIALIZE_GENERIC_C_SEQUENCE(uint32, uint32_t) +SPECIALIZE_GENERIC_C_SEQUENCE(int64, int64_t) +SPECIALIZE_GENERIC_C_SEQUENCE(uint64, uint64_t) + +typedef struct rosidl_generator_c__void__Sequence { void * data; /// The number of valid items in data size_t size; /// The number of allocated items in data size_t capacity; -} rosidl_generator_c__void__Array; +} rosidl_generator_c__void__Sequence; inline bool -rosidl_generator_c__void__Array__init( - rosidl_generator_c__void__Array * array, size_t size, size_t member_size) +rosidl_generator_c__void__Sequence__init( + rosidl_generator_c__void__Sequence * sequence, size_t size, size_t member_size) { - if (!array) { + if (!sequence) { return false; } void * data = nullptr; @@ -76,31 +76,31 @@ rosidl_generator_c__void__Array__init( return false; } } - array->data = data; - array->size = size; - array->capacity = size; + sequence->data = data; + sequence->size = size; + sequence->capacity = size; return true; } inline void -rosidl_generator_c__void__Array__fini(rosidl_generator_c__void__Array * array) +rosidl_generator_c__void__Sequence__fini(rosidl_generator_c__void__Sequence * sequence) { - if (!array) { + if (!sequence) { return; } - if (array->data) { + if (sequence->data) { // ensure that data and capacity values are consistent - assert(array->capacity > 0); - // finalize all array elements - free(array->data); - array->data = nullptr; - array->size = 0; - array->capacity = 0; + assert(sequence->capacity > 0); + // finalize all sequence elements + free(sequence->data); + sequence->data = nullptr; + sequence->size = 0; + sequence->capacity = 0; } else { // ensure that data, size, and capacity values are consistent - assert(0 == array->size); - assert(0 == array->capacity); + assert(0 == sequence->size); + assert(0 == sequence->capacity); } } @@ -224,7 +224,7 @@ void serialize_field( } else if (member->array_size_ && !member->is_upper_bound_) { ser.serializeArray(static_cast(field), member->array_size_); } else { - auto & data = *reinterpret_cast::type *>(field); + auto & data = *reinterpret_cast::type *>(field); ser.serializeSequence(reinterpret_cast(data.data), data.size); } } @@ -257,11 +257,11 @@ void serialize_field( ser.serialize(tmpstring); } } else { - auto & string_array_field = *reinterpret_cast(field); + auto & string_sequence_field = *reinterpret_cast(field); std::vector cpp_string_vector; - for (size_t i = 0; i < string_array_field.size; ++i) { + for (size_t i = 0; i < string_sequence_field.size; ++i) { cpp_string_vector.push_back( - CStringHelper::convert_to_std_string(string_array_field.data[i])); + CStringHelper::convert_to_std_string(string_sequence_field.data[i])); } ser << cpp_string_vector; } @@ -293,12 +293,12 @@ size_t get_array_size_and_assign_field( void * & subros_message, size_t, size_t) { - auto tmparray = static_cast(field); - if (member->is_upper_bound_ && tmparray->size > member->array_size_) { + auto tmpsequence = static_cast(field); + if (member->is_upper_bound_ && tmpsequence->size > member->array_size_) { throw std::runtime_error("vector overcomes the maximum length"); } - subros_message = reinterpret_cast(tmparray->data); - return tmparray->size; + subros_message = reinterpret_cast(tmpsequence->data); + return tmpsequence->size; } template @@ -474,7 +474,7 @@ size_t next_field_align( current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - auto & data = *reinterpret_cast::type *>(field); + auto & data = *reinterpret_cast::type *>(field); current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, item_size); current_alignment += item_size * data.size; } @@ -503,10 +503,10 @@ size_t next_field_align( } else { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - auto & string_array_field = *reinterpret_cast(field); - for (size_t i = 0; i < string_array_field.size; ++i) { + auto & string_sequence_field = *reinterpret_cast(field); + for (size_t i = 0; i < string_sequence_field.size; ++i) { current_alignment = CStringHelper::next_field_align( - &(string_array_field.data[i]), current_alignment); + &(string_sequence_field.data[i]), current_alignment); } } } @@ -662,10 +662,10 @@ void deserialize_field( } else if (member->array_size_ && !member->is_upper_bound_) { deser.deserializeArray(static_cast(field), member->array_size_); } else { - auto & data = *reinterpret_cast::type *>(field); + auto & data = *reinterpret_cast::type *>(field); int32_t dsize = 0; deser >> dsize; - GenericCArray::init(&data, dsize); + GenericCSequence::init(&data, dsize); deser.deserializeArray(reinterpret_cast(data.data), dsize); } } @@ -697,13 +697,13 @@ inline void deserialize_field( std::vector cpp_string_vector; deser >> cpp_string_vector; - auto & string_array_field = *reinterpret_cast(field); - if (!rosidl_generator_c__String__Array__init(&string_array_field, cpp_string_vector.size())) { + auto & string_sequence_field = *reinterpret_cast(field); + if (!rosidl_generator_c__String__Sequence__init(&string_sequence_field, cpp_string_vector.size())) { throw std::runtime_error("unable to initialize rosidl_generator_c__String array"); } for (size_t i = 0; i < cpp_string_vector.size(); ++i) { - if (!rosidl_generator_c__String__assign(&string_array_field.data[i], + if (!rosidl_generator_c__String__assign(&string_sequence_field.data[i], cpp_string_vector[i].c_str())) { throw std::runtime_error("unable to assign rosidl_generator_c__String"); @@ -749,9 +749,9 @@ inline size_t get_submessage_array_deserialize( // Deserialize length uint32_t vsize = 0; deser >> vsize; - auto tmparray = static_cast(field); - rosidl_generator_c__void__Array__init(tmparray, vsize, sub_members_size); - subros_message = reinterpret_cast(tmparray->data); + auto tmpsequence = static_cast(field); + rosidl_generator_c__void__Sequence__init(tmpsequence, vsize, sub_members_size); + subros_message = reinterpret_cast(tmpsequence->data); return vsize; } diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp index 1334aa47c..2fbe1918a 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/macros.hpp @@ -18,18 +18,18 @@ #include #include -#define SPECIALIZE_GENERIC_C_ARRAY(C_NAME, C_TYPE) \ +#define SPECIALIZE_GENERIC_C_SEQUENCE(C_NAME, C_TYPE) \ template<> \ - struct GenericCArray \ + struct GenericCSequence \ { \ - using type = rosidl_generator_c__ ## C_NAME ## __Array; \ + using type = rosidl_generator_c__ ## C_NAME ## __Sequence; \ \ static void fini(type * array) { \ - rosidl_generator_c__ ## C_NAME ## __Array__fini(array); \ + rosidl_generator_c__ ## C_NAME ## __Sequence__fini(array); \ } \ \ static bool init(type * array, size_t size) { \ - return rosidl_generator_c__ ## C_NAME ## __Array__init(array, size); \ + return rosidl_generator_c__ ## C_NAME ## __Sequence__init(array, size); \ } \ }; From 07bbfc5f9ae66637511684748908ec0d11d7c331 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 2 Nov 2018 11:53:34 -0700 Subject: [PATCH 2/2] rename files --- .../include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp index c06a61eee..04419c218 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp @@ -30,7 +30,7 @@ #include "rosidl_typesupport_introspection_c/message_introspection.h" #include "rosidl_typesupport_introspection_c/service_introspection.h" -#include "rosidl_generator_c/primitives_array_functions.h" +#include "rosidl_generator_c/primitives_sequence_functions.h" namespace rmw_fastrtps_dynamic_cpp {