RTI Routing Service Version 7.7.0
TypeInfo.hpp
1/*
2 * (c) Copyright, Real-Time Innovations, 2017.
3 * All rights reserved.
4 *
5 * No duplications, whole or partial, manual or electronic, may be made
6 * without express written permission. Any such copies, or
7 * revisions thereof, must display this notice unaltered.
8 * This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10
11#ifndef RTI_ROUTING_ADAPTER_TYPE_INFOHPP_
12#define RTI_ROUTING_ADAPTER_TYPE_INFOHPP_
13
14// IMPORTANT: macros.hpp must be the first RTI header included in every header
15// file so that symbols are exported correctly on Windows
16#include <dds/core/macros.hpp>
17
18#include <routingservice/routingservice_infrastructure.h>
19#include <dds/core/Value.hpp>
20#include <dds/core/SafeEnumeration.hpp>
21#include <dds/core/xtypes/DynamicType.hpp>
22#include <rti/core/NativeValueType.hpp>
23
24namespace rti { namespace routing {
25
45 enum type {
54 DYNAMIC_TYPE = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_DYNAMIC_TYPE,
64 XML = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_XML,
70 JAVA_OBJECT = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_JAVA_OBJECT,
77 CUSTOM = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_FIRST_CUSTOM_REPRESENTATION
78 };
79};
80
89typedef dds::core::safe_enum<TypeRepresentationKind_def> TypeRepresentationKind;
90
91
92class TypeInfoAdapter {
93public:
94 typedef RTI_RoutingServiceTypeInfo native_type;
95
96 static void initialize(native_type& native_value)
97 {
98 static const native_type default_value = {
99 NULL,
100 DDS_BOOLEAN_TRUE,
101 RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_DYNAMIC_TYPE,
102 NULL};
103 native_value = default_value;
104 }
105
106 static void finalize(native_type& native_value)
107 {
108 if (native_value.type_name != NULL) {
109 RTIOsapiHeap_freeString(native_value.type_name);
110 native_value.type_name = NULL;
111 }
112 }
113
114 static void copy(native_type& destination, const native_type& source)
115 {
116 char *result = DDS_String_replace(
117 &destination.type_name,
118 source.type_name);
119 if (source.type_name != NULL && result == NULL) {
120 throw std::bad_alloc();
121 }
122 destination.can_be_optimized = source.can_be_optimized;
123 destination.type_representation_kind =
124 source.type_representation_kind;
125 destination.type_representation =
126 source.type_representation;
127 }
128
129 static bool equals(const native_type& first, const native_type& second)
130 {
131 if (strcmp(first.type_name, second.type_name) != 0) {
132 return false;
133 }
134 if (first.type_representation_kind
135 != second.type_representation_kind) {
136 return false;
137 }
138
139 return first.type_representation == second.type_representation;
140 }
141
142};
143
144class TypeInfo;
145
146}
147
148// native_type_traits needs to be defined in rti::core
149namespace core {
150
151template <>
152struct native_type_traits<rti::routing::TypeInfo> {
153 typedef rti::routing::TypeInfoAdapter adapter_type;
154 typedef RTI_RoutingServiceTypeInfo native_type;
155};
156
157}
158
159namespace routing {
160
171class TypeInfo : public rti::core::NativeValueType<TypeInfo> {
172public:
173 RTI_NATIVE_VALUE_TYPE_DEFINE_DEFAULT_MOVE_OPERATIONS(TypeInfo)
174
175 typedef rti::core::NativeValueType<TypeInfo> Base;
176
182 typedef RTI_RoutingServiceTypeRepresentation TypeRepresentationType;
183public:
184
195 const std::string& the_type_name,
196 TypeRepresentationKind the_type_representation_kind =
197 TypeRepresentationKind::DYNAMIC_TYPE)
198 {
199 type_name(the_type_name);
200 type_representation_kind(the_type_representation_kind);
201 native().can_be_optimized = DDS_BOOLEAN_TRUE;
202 }
203
204 TypeInfo(const struct RTI_RoutingServiceTypeInfo &native_stream_info)
205 : Base(native_stream_info)
206 {
207 }
208
212 std::string type_name() const
213 {
214 return native().type_name;
215 }
216
226 TypeInfo& type_name(const std::string& the_type_name)
227 {
228
229 if (DDS_String_replace(
230 &native().type_name,
231 the_type_name.c_str()) == NULL) {
232 throw std::bad_alloc();
233 }
234
235 return *this;
236 }
237
242 {
243 return static_cast<TypeRepresentationKind::type>(
244 native().type_representation_kind);
245 }
246
255 TypeRepresentationKind the_type_representation_kind)
256 {
257 native().type_representation_kind = static_cast<int>(
258 the_type_representation_kind.underlying());
259 return *this;
260 }
261
266 {
267 return native().type_representation;
268 }
269
279 {
280 native().type_representation = the_type_representation;
281 return *this;
282 }
283
290 const dds::core::xtypes::DynamicType& dynamic_type() const
291 {
292 if (type_representation_kind() != TypeRepresentationKind::DYNAMIC_TYPE) {
293 throw dds::core::IllegalOperationError(
294 "type representation is not dynamic type");
295 }
296
297 const DDS_TypeCode *native_typecode = reinterpret_cast<DDS_TypeCode*>(
299 return rti::core::native_conversions::cast_from_native<
300 dds::core::xtypes::DynamicType>(*native_typecode);
301 }
302
311 void dynamic_type(const dds::core::xtypes::DynamicType *dynamic_type)
312 {
313 DDS_TypeCode *native_typecode = const_cast<DDS_TypeCode*>(
314 reinterpret_cast<const DDS_TypeCode *>(dynamic_type));
315 type_representation(static_cast<TypeRepresentationType>(native_typecode));
316 type_representation_kind(TypeRepresentationKind::DYNAMIC_TYPE);
317 }
318};
319
320}}
321
322#endif // RTI_ROUTING_ADAPTER_TYPE_INFOHPP_
valid type representations that RTI Routing Service accepts.
Definition of the type information associated with a RTI Routing Service stream.
Definition: TypeInfo.hpp:171
const dds::core::xtypes::DynamicType & dynamic_type() const
Returns the type_representation as DynamicType object.
Definition: TypeInfo.hpp:290
TypeInfo & type_name(const std::string &the_type_name)
Sets the registered name of the type associated with the data.
Definition: TypeInfo.hpp:226
void dynamic_type(const dds::core::xtypes::DynamicType *dynamic_type)
Sets the type representation value as DynamicType object.
Definition: TypeInfo.hpp:311
TypeRepresentationKind type_representation_kind() const
Getter (see setter with the same name)
Definition: TypeInfo.hpp:241
std::string type_name() const
Getter (see setter with the same name)
Definition: TypeInfo.hpp:212
TypeInfo & type_representation(TypeRepresentationType the_type_representation)
Sets the type representation value.
Definition: TypeInfo.hpp:278
TypeInfo & type_representation_kind(TypeRepresentationKind the_type_representation_kind)
Sets the type representation kind.
Definition: TypeInfo.hpp:254
RTI_RoutingServiceTypeRepresentation TypeRepresentationType
Type representation defined as an opaque pointer.
Definition: TypeInfo.hpp:182
TypeInfo(const std::string &the_type_name, TypeRepresentationKind the_type_representation_kind=TypeRepresentationKind::DYNAMIC_TYPE)
Constructs a TypeInfo with the minimum required information.
Definition: TypeInfo.hpp:194
TypeRepresentationType type_representation() const
Getter (see setter with the same name)
Definition: TypeInfo.hpp:265
The definition of the rti::routing::TypeRepresentationKind.
Definition: TypeInfo.hpp:41
type
Definition of all the possible type representation kinds.
Definition: TypeInfo.hpp:45
@ XML
[Not supported] XML type representation.
Definition: TypeInfo.hpp:64
@ CUSTOM
[Not supported] Custom type representation.
Definition: TypeInfo.hpp:77
@ DYNAMIC_TYPE
Dynamic type representation.
Definition: TypeInfo.hpp:54
@ JAVA_OBJECT
[Not supported] Java object type representation.
Definition: TypeInfo.hpp:70