123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #ifndef TYPES_DYNAMIC_DATA_H
- #define TYPES_DYNAMIC_DATA_H
- #include <fastrtps/types/TypesBase.h>
- #include <fastrtps/types/DynamicDataPtr.h>
- #include <fastrtps/types/DynamicTypePtr.h>
- //#define DYNAMIC_TYPES_CHECKING
- namespace eprosima {
- namespace fastrtps {
- namespace types {
- class DynamicType;
- class MemberDescriptor;
- class DynamicData
- {
- protected:
- DynamicData();
- DynamicData(const DynamicData* pData);
- DynamicData(DynamicType_ptr pType);
- ~DynamicData();
- void add_value(
- TypeKind kind,
- MemberId id);
- void create_members(DynamicType_ptr pType);
- void create_members(const DynamicData* pData);
- void clean();
- void clean_members();
- void* clone_value(
- MemberId id,
- TypeKind kind) const;
- bool compare_values(
- TypeKind kind,
- void* left,
- void* right) const;
- ReturnCode_t insert_array_data(MemberId indexId);
- void serialize_empty_data(
- const DynamicType_ptr pType,
- eprosima::fastcdr::Cdr& cdr) const;
- void set_default_value(MemberId id);
- void get_value(
- std::string& sOutValue,
- MemberId id = MEMBER_ID_INVALID) const;
- void set_value(
- const std::string& sValue,
- MemberId id = MEMBER_ID_INVALID);
- void set_type_name(const std::string& name);
- ReturnCode_t set_union_id(MemberId id);
- void update_union_discriminator();
- void sort_member_ids(MemberId startId);
- void set_union_discriminator(DynamicData* pData);
- // Serializes and deserializes the Dynamic Data.
- bool deserialize(eprosima::fastcdr::Cdr& cdr);
- bool deserialize_discriminator(eprosima::fastcdr::Cdr& cdr);
- static size_t getCdrSerializedSize(
- const DynamicData* data,
- size_t current_alignment = 0);
- static size_t getEmptyCdrSerializedSize(
- const DynamicType* type,
- size_t current_alignment = 0);
- static size_t getKeyMaxCdrSerializedSize(
- const DynamicType_ptr type,
- size_t current_alignment = 0);
- static size_t getMaxCdrSerializedSize(
- const DynamicType_ptr type,
- size_t current_alignment = 0);
- void serialize(eprosima::fastcdr::Cdr& cdr) const;
- void serialize_discriminator(eprosima::fastcdr::Cdr& cdr) const;
- void serializeKey(eprosima::fastcdr::Cdr& cdr) const;
- DynamicType_ptr type_;
- std::map<MemberId, MemberDescriptor*> descriptors_;
- #ifdef DYNAMIC_TYPES_CHECKING
- int32_t int32_value_;
- uint32_t uint32_value_;
- int16_t int16_value_;
- uint16_t uint16_value_;
- int64_t int64_value_;
- uint64_t uint64_value_;
- float float32_value_;
- double float64_value_;
- long double float128_value_;
- char char8_value_;
- wchar_t char16_value_;
- octet byte_value_;
- bool bool_value_;
- std::string string_value_;
- std::wstring wstring_value_;
- std::map<MemberId, DynamicData*> complex_values_;
- #else
- std::map<MemberId, void*> values_;
- #endif
- std::vector<MemberId> loaned_values_;
- bool key_element_;
- DynamicData* default_array_value_;
- uint64_t union_label_;
- MemberId union_id_;
- DynamicData* union_discriminator_;
- uint64_t discriminator_value_;
- friend class DynamicDataFactory;
- friend class DynamicPubSubType;
- friend class DynamicDataHelper;
- public:
- RTPS_DllAPI ReturnCode_t get_descriptor(
- MemberDescriptor& value,
- MemberId id);
- RTPS_DllAPI ReturnCode_t set_descriptor(
- MemberId id,
- const MemberDescriptor* value);
- RTPS_DllAPI ReturnCode_t clear_all_values();
- RTPS_DllAPI ReturnCode_t clear_nonkey_values();
- RTPS_DllAPI ReturnCode_t clear_value(MemberId id);
- RTPS_DllAPI bool equals(const DynamicData* other) const;
- RTPS_DllAPI TypeKind get_kind() const;
- RTPS_DllAPI uint32_t get_item_count() const;
- RTPS_DllAPI std::string get_name();
- RTPS_DllAPI MemberId get_member_id_by_name(const std::string& name) const;
- RTPS_DllAPI MemberId get_member_id_at_index(uint32_t index) const;
- RTPS_DllAPI DynamicData* loan_value(MemberId id);
- RTPS_DllAPI ReturnCode_t return_loaned_value(const DynamicData* value);
- RTPS_DllAPI MemberId get_array_index(const std::vector<uint32_t>& position);
- RTPS_DllAPI ReturnCode_t insert_sequence_data(MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_int32_value(
- int32_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_uint32_value(
- uint32_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_int16_value(
- int16_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_uint16_value(
- uint16_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_int64_value(
- int64_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_uint64_value(
- uint64_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_float32_value(
- float value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_float64_value(
- double value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_float128_value(
- long double value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_char8_value(
- char value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_char16_value(
- wchar_t value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_byte_value(
- octet value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_bool_value(
- bool value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_string_value(
- const std::string& value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_wstring_value(
- const std::wstring& value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_enum_value(
- const std::string& value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_complex_value(
- const DynamicData* value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_complex_value(
- DynamicData* value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t insert_complex_value(
- DynamicData_ptr value,
- MemberId& outId);
- RTPS_DllAPI ReturnCode_t remove_sequence_data(MemberId id);
- RTPS_DllAPI ReturnCode_t clear_data();
- RTPS_DllAPI ReturnCode_t clear_array_data(MemberId indexId);
- RTPS_DllAPI ReturnCode_t insert_map_data(
- const DynamicData* key,
- MemberId& outKeyId,
- MemberId& outValueId);
- RTPS_DllAPI ReturnCode_t insert_map_data(
- const DynamicData* key,
- DynamicData* value,
- MemberId& outKey,
- MemberId& outValue);
- RTPS_DllAPI ReturnCode_t insert_map_data(
- const DynamicData* key,
- const DynamicData* value,
- MemberId& outKey,
- MemberId& outValue);
- RTPS_DllAPI ReturnCode_t insert_map_data(
- const DynamicData* key,
- DynamicData_ptr value,
- MemberId& outKey,
- MemberId& outValue);
- RTPS_DllAPI ReturnCode_t remove_map_data(MemberId keyId);
- RTPS_DllAPI ReturnCode_t get_int32_value(
- int32_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_int32_value(
- int32_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_uint32_value(
- uint32_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_uint32_value(
- uint32_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_int16_value(
- int16_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_int16_value(
- int16_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_uint16_value(
- uint16_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_uint16_value(
- uint16_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_int64_value(
- int64_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_int64_value(
- int64_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_uint64_value(
- uint64_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_uint64_value(
- uint64_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_float32_value(
- float& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_float32_value(
- float value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_float64_value(
- double& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_float64_value(
- double value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_float128_value(
- long double& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_float128_value(
- long double value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_char8_value(
- char& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_char8_value(
- char value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_char16_value(
- wchar_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_char16_value(
- wchar_t value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_byte_value(
- octet& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_byte_value(
- octet value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_int8_value(
- int8_t& value,
- MemberId id) const
- {
- octet aux;
- ReturnCode_t result = get_byte_value(aux, id);
- value = static_cast<int8_t>(aux);
- return result;
- }
- RTPS_DllAPI ReturnCode_t set_int8_value(
- int8_t value,
- MemberId id = MEMBER_ID_INVALID)
- {
- return set_byte_value(static_cast<octet>(value), id);
- }
- RTPS_DllAPI ReturnCode_t get_uint8_value(
- uint8_t& value,
- MemberId id) const
- {
- octet aux;
- ReturnCode_t result = get_byte_value(aux, id);
- value = static_cast<uint8_t>(aux);
- return result;
- }
- RTPS_DllAPI ReturnCode_t set_uint8_value(
- uint8_t value,
- MemberId id = MEMBER_ID_INVALID)
- {
- return set_byte_value(static_cast<octet>(value), id);
- }
- RTPS_DllAPI ReturnCode_t get_bool_value(
- bool& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_bool_value(
- bool value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t set_bool_value(
- bool value,
- const std::string& name)
- {
- MemberId id = get_member_id_by_name(name);
- if (id != MEMBER_ID_INVALID)
- {
- return set_bool_value(value, id);
- }
- return ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- RTPS_DllAPI ReturnCode_t get_string_value(
- std::string& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_string_value(
- const std::string& value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_wstring_value(
- std::wstring& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_wstring_value(
- const std::wstring& value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_enum_value(
- std::string& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_enum_value(
- const std::string& value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_enum_value(
- uint32_t& value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_enum_value(
- const uint32_t& value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_bitmask_value(uint64_t& value) const;
- RTPS_DllAPI uint64_t get_bitmask_value() const
- {
- uint64_t value;
- if (get_bitmask_value(value) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI ReturnCode_t set_bitmask_value(uint64_t value);
- RTPS_DllAPI ReturnCode_t get_complex_value(
- DynamicData** value,
- MemberId id) const;
- RTPS_DllAPI ReturnCode_t set_complex_value(
- DynamicData* value,
- MemberId id = MEMBER_ID_INVALID);
- RTPS_DllAPI ReturnCode_t get_union_label(uint64_t& value) const;
- // Basic types returns (copy)
- RTPS_DllAPI int32_t get_int32_value(MemberId id) const
- {
- int32_t value;
- if (get_int32_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI uint32_t get_uint32_value(MemberId id) const
- {
- uint32_t value;
- if (get_uint32_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI int16_t get_int16_value(MemberId id) const
- {
- int16_t value;
- if (get_int16_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI uint16_t get_uint16_value(MemberId id) const
- {
- uint16_t value;
- if (get_uint16_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI int64_t get_int64_value(MemberId id) const
- {
- int64_t value;
- if (get_int64_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI uint64_t get_uint64_value(MemberId id) const
- {
- uint64_t value;
- if (get_uint64_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI float get_float32_value(MemberId id) const
- {
- float value;
- if (get_float32_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI double get_float64_value(MemberId id) const
- {
- double value;
- if (get_float64_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI long double get_float128_value(MemberId id) const
- {
- long double value;
- if (get_float128_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI char get_char8_value(MemberId id) const
- {
- char value;
- if (get_char8_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI wchar_t get_char16_value(MemberId id) const
- {
- wchar_t value;
- if (get_char16_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI octet get_byte_value(MemberId id) const
- {
- octet value;
- if (get_byte_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI int8_t get_int8_value(MemberId id) const
- {
- int8_t value;
- if (get_int8_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI uint8_t get_uint8_value(MemberId id) const
- {
- uint8_t value;
- if (get_uint8_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI bool get_bool_value(MemberId id) const
- {
- bool value;
- if (get_bool_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI bool get_bool_value(const std::string& name) const
- {
- MemberId id = get_member_id_by_name(name);
- bool value;
- if (get_bool_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI std::string get_string_value(MemberId id) const
- {
- std::string value;
- if (get_string_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI std::wstring get_wstring_value(MemberId id) const
- {
- std::wstring value;
- if (get_wstring_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI std::string get_enum_value(MemberId id) const
- {
- std::string value;
- if (get_enum_value(value, id) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI uint64_t get_union_label() const
- {
- uint64_t value;
- if (get_union_label(value) != ReturnCode_t::RETCODE_OK)
- {
- throw ReturnCode_t::RETCODE_BAD_PARAMETER;
- }
- return value;
- }
- RTPS_DllAPI uint64_t get_discriminator_value() const
- {
- return discriminator_value_;
- }
- RTPS_DllAPI void get_discriminator_value(uint64_t& outValue) const
- {
- outValue = discriminator_value_;
- }
- RTPS_DllAPI void set_discriminator_value(uint64_t value)
- {
- discriminator_value_ = value;
- }
- };
- } // namespace types
- } // namespace fastrtps
- } // namespace eprosima
- #endif // TYPES_DYNAMIC_DATA_H
|