Fast DDS  Version 3.6.1.0
Fast DDS
TypeSupport.hpp
1 // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
19 #ifndef FASTDDS_DDS_TOPIC__TYPESUPPORT_HPP
20 #define FASTDDS_DDS_TOPIC__TYPESUPPORT_HPP
21 
22 #include <string>
23 #include <functional>
24 #include <memory>
25 
26 #include <fastdds/dds/common/InstanceHandle.hpp>
27 #include <fastdds/dds/core/ReturnCode.hpp>
28 #include <fastdds/dds/topic/TopicDataType.hpp>
29 #include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
30 #include <fastdds/fastdds_dll.hpp>
31 
32 namespace eprosima {
33 namespace fastdds {
34 namespace dds {
35 
36 class DomainParticipant;
37 
46 class TypeSupport : public std::shared_ptr<TopicDataType>
47 {
48 public:
49 
50  using Base = std::shared_ptr<TopicDataType>;
51 
55  FASTDDS_EXPORTED_API TypeSupport() noexcept = default;
56 
62  FASTDDS_EXPORTED_API TypeSupport(
63  const TypeSupport& type) noexcept = default;
64 
70  FASTDDS_EXPORTED_API TypeSupport(
71  TypeSupport&& type) noexcept = default;
72 
78  FASTDDS_EXPORTED_API TypeSupport& operator = (
79  const TypeSupport& type) noexcept = default;
80 
86  FASTDDS_EXPORTED_API TypeSupport& operator = (
87  TypeSupport&& type) noexcept = default;
88 
96  FASTDDS_EXPORTED_API explicit TypeSupport(
97  TopicDataType* ptr)
98  : std::shared_ptr<TopicDataType>(ptr)
99  {
100  }
101 
109  FASTDDS_EXPORTED_API virtual ReturnCode_t register_type(
110  DomainParticipant* participant) const;
111 
120  FASTDDS_EXPORTED_API virtual ReturnCode_t register_type(
121  DomainParticipant* participant,
122  std::string type_name) const;
123 
129  FASTDDS_EXPORTED_API virtual const std::string& get_type_name() const
130  {
131  return get()->get_name();
132  }
133 
142  FASTDDS_EXPORTED_API virtual bool serialize(
143  const void* const data,
145  DataRepresentationId_t data_representation);
146 
154  FASTDDS_EXPORTED_API virtual bool deserialize(
156  void* data);
157 
165  FASTDDS_EXPORTED_API virtual uint32_t calculate_serialized_size(
166  const void* const data,
167  DataRepresentationId_t data_representation)
168  {
169  return get()->calculate_serialized_size(data, data_representation);
170  }
171 
177  FASTDDS_EXPORTED_API virtual void* create_data()
178  {
179  return get()->create_data();
180  }
181 
187  FASTDDS_EXPORTED_API virtual void delete_data(
188  void* data)
189  {
190  return get()->delete_data(data);
191  }
192 
201  FASTDDS_EXPORTED_API virtual bool compute_key(
202  const void* const data,
203  InstanceHandle_t& i_handle,
204  bool force_md5 = false)
205  {
206  return get()->compute_key(data, i_handle, force_md5);
207  }
208 
217  FASTDDS_EXPORTED_API virtual bool compute_key(
219  InstanceHandle_t& i_handle,
220  bool force_md5 = false)
221  {
222  return get()->compute_key(payload, i_handle, force_md5);
223  }
224 
225  FASTDDS_EXPORTED_API virtual bool operator ==(
226  const TypeSupport& type_support)
227  {
228  return get()->max_serialized_type_size == type_support->max_serialized_type_size
229  && get()->is_compute_key_provided == type_support->is_compute_key_provided
230  && get()->get_name() == type_support->get_name()
231  && get()->type_identifiers() == type_support->type_identifiers();
232  }
233 
239  FASTDDS_EXPORTED_API bool empty() const
240  {
241  return get() == nullptr;
242  }
243 
247  FASTDDS_EXPORTED_API virtual inline bool is_bounded() const
248  {
249  return get()->is_bounded();
250  }
251 
255  FASTDDS_EXPORTED_API virtual inline bool is_plain(
256  DataRepresentationId_t data_representation) const
257  {
258  return get()->is_plain(data_representation);
259  }
260 
261  FASTDDS_EXPORTED_API bool operator !=(
262  std::nullptr_t) const
263  {
264  return bool(*this);
265  }
266 
267  FASTDDS_EXPORTED_API bool operator ==(
268  std::nullptr_t) const
269  {
270  return !*this;
271  }
272 
273 };
274 
275 } // namespace dds
276 } // namespace fastdds
277 } // namespace eprosima
278 
279 #endif // FASTDDS_DDS_TOPIC__TYPESUPPORT_HPP
Class DomainParticipant used to group Publishers and Subscribers into a single working unit.
Definition: DomainParticipant.hpp:86
Class TopicDataType used to provide the DomainRTPSParticipant with the methods to serialize,...
Definition: TopicDataType.hpp:61
Class TypeSupport used to provide the DomainRTPSParticipant with the methods to serialize,...
Definition: TypeSupport.hpp:47
FASTDDS_EXPORTED_API TypeSupport() noexcept=default
Constructor.
FASTDDS_EXPORTED_API bool operator!=(std::nullptr_t) const
Definition: TypeSupport.hpp:261
virtual FASTDDS_EXPORTED_API bool serialize(const void *const data, fastdds::rtps::SerializedPayload_t &payload, DataRepresentationId_t data_representation)
Serializes the data.
virtual FASTDDS_EXPORTED_API bool is_plain(DataRepresentationId_t data_representation) const
Checks if the type is plain when using a specific encoding.
Definition: TypeSupport.hpp:255
virtual FASTDDS_EXPORTED_API bool compute_key(const void *const data, InstanceHandle_t &i_handle, bool force_md5=false)
Getter for the data key.
Definition: TypeSupport.hpp:201
virtual FASTDDS_EXPORTED_API uint32_t calculate_serialized_size(const void *const data, DataRepresentationId_t data_representation)
Returns a function which can be used to calculate the serialized size of the provided data.
Definition: TypeSupport.hpp:165
FASTDDS_EXPORTED_API bool empty() const
Check if the TypeSupport is empty.
Definition: TypeSupport.hpp:239
std::shared_ptr< TopicDataType > Base
Definition: TypeSupport.hpp:50
virtual FASTDDS_EXPORTED_API const std::string & get_type_name() const
Getter for the type name.
Definition: TypeSupport.hpp:129
virtual FASTDDS_EXPORTED_API bool is_bounded() const
Checks if the type is bounded.
Definition: TypeSupport.hpp:247
virtual FASTDDS_EXPORTED_API ReturnCode_t register_type(DomainParticipant *participant) const
Registers the type on a participant.
virtual FASTDDS_EXPORTED_API bool compute_key(fastdds::rtps::SerializedPayload_t &payload, InstanceHandle_t &i_handle, bool force_md5=false)
Getter for the data key.
Definition: TypeSupport.hpp:217
virtual FASTDDS_EXPORTED_API bool deserialize(fastdds::rtps::SerializedPayload_t &payload, void *data)
Deserializes the data.
virtual FASTDDS_EXPORTED_API bool operator==(const TypeSupport &type_support)
Definition: TypeSupport.hpp:225
virtual FASTDDS_EXPORTED_API void * create_data()
Creates new data.
Definition: TypeSupport.hpp:177
virtual FASTDDS_EXPORTED_API void delete_data(void *data)
Deletes data.
Definition: TypeSupport.hpp:187
virtual FASTDDS_EXPORTED_API ReturnCode_t register_type(DomainParticipant *participant, std::string type_name) const
Registers the type on a participant.
Definition: DomainParticipant.hpp:46
enum eprosima::fastdds::dds::DataRepresentationId DataRepresentationId_t
Enum DataRepresentationId, different kinds of topic data representation.
int32_t ReturnCode_t
Definition: DDSReturnCode.hpp:59
Definition: EntityId_t.hpp:388
Struct InstanceHandle_t, used to contain the key for WITH_KEY topics.
Definition: InstanceHandle.hpp:154
Structure SerializedPayload_t.
Definition: SerializedPayload.hpp:59