RTI Routing Service  Version 6.0.1
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
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 <rti/core/NativeValueType.hpp>
22 
23 namespace rti { namespace routing {
24 
44  enum type {
53  DYNAMIC_TYPE = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_DYNAMIC_TYPE,
63  XML = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_XML,
69  JAVA_OBJECT = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_JAVA_OBJECT,
76  CUSTOM = RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_FIRST_CUSTOM_REPRESENTATION
77  };
78 };
79 
88 typedef dds::core::safe_enum<TypeRepresentationKind_def> TypeRepresentationKind;
89 
90 
91 class TypeInfoAdapter {
92 public:
93  typedef RTI_RoutingServiceTypeInfo native_type;
94 
95  static void initialize(native_type& native_value)
96  {
97  static const native_type default_value = {
98  NULL,
99  RTI_ROUTING_SERVICE_TYPE_REPRESENTATION_DYNAMIC_TYPE,
100  NULL};
101  native_value = default_value;
102  }
103 
104  static void finalize(native_type& native_value)
105  {
106  if (native_value.type_name != NULL) {
107  RTIOsapiHeap_freeString(native_value.type_name);
108  native_value.type_name = NULL;
109  }
110  }
111 
112  static void copy(native_type& destination, const native_type& source)
113  {
114  char *result = DDS_String_replace(
115  &destination.type_name,
116  source.type_name);
117  if (source.type_name != NULL && result == NULL) {
118  throw std::bad_alloc();
119  }
120  destination.type_representation_kind =
121  source.type_representation_kind;
122  destination.type_representation =
123  source.type_representation;
124  }
125 
126  static bool equals(const native_type& first, const native_type& second)
127  {
128  if (strcmp(first.type_name, second.type_name) != 0) {
129  return false;
130  }
131  if (first.type_representation_kind
132  != second.type_representation_kind) {
133  return false;
134  }
135 
136  return first.type_representation == second.type_representation;
137  }
138 
139 };
140 
141 class TypeInfo;
142 
143 }
144 
145 // native_type_traits needs to be defined in rti::core
146 namespace core {
147 
148 template <>
149 struct native_type_traits<rti::routing::TypeInfo> {
150  typedef rti::routing::TypeInfoAdapter adapter_type;
151  typedef RTI_RoutingServiceTypeInfo native_type;
152 };
153 
154 }
155 
156 namespace routing {
157 
168 class TypeInfo : public rti::core::NativeValueType<TypeInfo> {
169 public:
170  RTI_NATIVE_VALUE_TYPE_DEFINE_DEFAULT_MOVE_OPERATIONS(TypeInfo)
171 
172  typedef rti::core::NativeValueType<TypeInfo> Base;
173 
179  typedef RTI_RoutingServiceTypeRepresentation TypeRepresentationType;
180 public:
181 
192  std::string& the_type_name,
193  TypeRepresentationKind the_type_representation_kind =
194  TypeRepresentationKind::DYNAMIC_TYPE)
195  {
196  type_name(the_type_name);
197  type_representation_kind(the_type_representation_kind);
198  }
199 
200  TypeInfo(const struct RTI_RoutingServiceTypeInfo &native_stream_info)
201  : Base(native_stream_info)
202  {
203  }
204 
208  std::string type_name() const
209  {
210  return native().type_name;
211  }
212 
222  TypeInfo& type_name(const std::string& the_type_name)
223  {
224 
225  if (DDS_String_replace(
226  &native().type_name,
227  the_type_name.c_str()) == NULL) {
228  throw std::bad_alloc();
229  }
230 
231  return *this;
232  }
233 
237  TypeRepresentationKind type_representation_kind() const
238  {
239  return static_cast<TypeRepresentationKind::type>(
240  native().type_representation_kind);
241  }
242 
251  TypeRepresentationKind the_type_representation_kind)
252  {
253  native().type_representation_kind = static_cast<int>(
254  the_type_representation_kind.underlying());
255  return *this;
256  }
257 
262  {
263  return native().type_representation;
264  }
265 
275  {
276  native().type_representation = the_type_representation;
277  return *this;
278  }
279 };
280 
281 }}
282 
283 #endif // RTI_ROUTING_ADAPTER_TYPE_INFOHPP_

RTI Routing Service Version 6.0.1 Copyright © Sun Nov 17 2019 Real-Time Innovations, Inc