OpenDDS  Snapshot(2023/04/07-19:43)
XTypes/Utils.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_XTYPES_UTILS_H
7 #define OPENDDS_DCPS_XTYPES_UTILS_H
8 
9 #ifndef OPENDDS_SAFETY_PROFILE
10 # include <dds/DCPS/Serializer.h>
11 
12 # include <dds/DdsDynamicDataC.h>
13 
14 # include <cstring>
15 
17 namespace OpenDDS {
18 namespace XTypes {
19 
20 inline bool dynamic_type_is_valid(DDS::DynamicType_ptr type)
21 {
22  DDS::TypeDescriptor_var td;
23  return type && type->get_descriptor(td) == DDS::RETCODE_OK && td;
24 }
25 
27  DDS::DynamicType_ptr type, DCPS::Extensibility& ext);
29  DDS::DynamicType_ptr type, DCPS::Extensibility& ext);
31 
32 /**
33  * Iterate over parts of a member name path that can be the name of a
34  * field inside a function or an array element nested multiple levels inside a
35  * type.
36  *
37  * Examples:
38  * "member_a"
39  * "member_b[2]"
40  * "member_b[2].x"
41  * "[2]" (If the DynamicData is indexed or keyed)
42  */
44 public:
45  size_t pos;
46  size_t left;
47  const char* path;
48  bool error;
51 
52  MemberPathParser(const char* path)
53  : pos(0)
54  , left(path ? std::strlen(path) : 0)
55  , path(left > 0 ? path : 0)
56  , error(false)
57  , in_subscript(false)
58  {
59  }
60 
62  : pos(0)
63  , left(path.size())
64  , path(left > 0 ? path.c_str() : 0)
65  , error(false)
66  , in_subscript(false)
67  {
68  }
69 
70  bool consume(size_t by);
71 
72  /**
73  * Put the next member name or subscript value in subpath and which kind in
74  * in_subscript. Returns false when the end of the path is reached or there
75  * was an error in which case error is set to true.
76  */
77  bool get_next_subpath();
78 
79  bool get_index(CORBA::UInt32 &index);
80 };
81 
82 /**
83  * Provides access to a specific member using MemberIds that may be nested
84  * inside a DynamicType or DynamicData.
85  */
87 public:
88  typedef OPENDDS_VECTOR(DDS::MemberId) MemberIdVec;
89  MemberIdVec ids;
90 
92  {
93  }
94 
96  : ids(other.ids)
97  {
98  ids.push_back(id);
99  }
100 
102  {
103  ids.push_back(id);
104  return *this;
105  }
106 
107  size_t level() const { return ids.size(); }
108 
109  DDS::ReturnCode_t resolve_string_path(
110  DDS::DynamicType_ptr type, const DCPS::String &path);
111 
112  DDS::ReturnCode_t get_member_from_type(
113  DDS::DynamicType_ptr type, DDS::DynamicTypeMember_var& member);
114 
115  /**
116  * DynamicData itself holds the access methods to its members, so in order to
117  * access them, we have to give both the containing Dynamic Data and the
118  * member ID.
119  */
120  DDS::ReturnCode_t get_member_from_data(
121  DDS::DynamicData_ptr data, DDS::DynamicData_var& container, DDS::MemberId& member_id);
122 };
123 typedef OPENDDS_VECTOR(MemberPath) MemberPathVec;
124 
125 enum Filter {
130 };
131 
133  DDS::DynamicType_ptr type, MemberPathVec& paths, Filter filter);
134 OpenDDS_Dcps_Export DDS::ReturnCode_t get_keys(DDS::DynamicType_ptr type, MemberPathVec& paths);
135 OpenDDS_Dcps_Export bool is_key(DDS::DynamicType_ptr type, const char* field);
136 OpenDDS_Dcps_Export DDS::ReturnCode_t key_count(DDS::DynamicType_ptr type, size_t& count);
137 
139  bool& result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b, Filter filter);
141  bool& result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b);
143  int& result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b, DDS::MemberId id);
144 
146  DDS::DynamicType_var& member_type, DDS::DynamicType_ptr container_type, DDS::MemberId id);
147 
149  DDS::DynamicType_var& member_type, DDS::DynamicData_ptr container, DDS::MemberId id)
150 {
151  DDS::DynamicType_var container_type = container->type();
152  return get_member_type(member_type, container_type, id);
153 }
154 
157 
159  CORBA::UInt64& value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind);
161  DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::TypeKind kind, CORBA::UInt64 value);
163  CORBA::Int64& value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind);
165  DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::TypeKind kind, CORBA::Int64 value);
166 
168  DDS::DynamicType_ptr type, DDS::TypeKind& bound_kind);
170  CORBA::UInt64& value, DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id);
171 
172 OpenDDS_Dcps_Export DDS::ReturnCode_t enum_bound(DDS::DynamicType_ptr type, DDS::TypeKind& bound_kind);
173 
175  CORBA::Int32& value, DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id);
177  CORBA::Int32& value, DDS::DynamicData_ptr src, DDS::MemberId id)
178 {
179  DDS::DynamicType_var type;
180  const DDS::ReturnCode_t rc = get_member_type(type, src, id);
181  if (rc != DDS::RETCODE_OK) {
182  return rc;
183  }
184  return get_enum_value(value, type, src, id);
185 }
186 
188  DDS::DynamicType_ptr type, DDS::DynamicData_ptr dest, DDS::MemberId id, CORBA::Int32 value);
190  DDS::DynamicData_ptr dest, DDS::MemberId id, CORBA::Int32 value)
191 {
192  DDS::DynamicType_var type;
193  const DDS::ReturnCode_t rc = get_member_type(type, dest, id);
194  if (rc != DDS::RETCODE_OK) {
195  return rc;
196  }
197  return set_enum_value(type, dest, id, value);
198 }
199 
201  DDS::DynamicType_ptr type, DDS::DynamicData_ptr dest, DDS::MemberId id, const char* enumeral_name);
203  DDS::DynamicData_ptr dest, DDS::MemberId id, const char* enumeral_name)
204 {
205  DDS::DynamicType_var type;
206  const DDS::ReturnCode_t rc = get_member_type(type, dest, id);
207  if (rc != DDS::RETCODE_OK) {
208  return rc;
209  }
210  return set_enum_value(type, dest, id, enumeral_name);
211 }
212 
214  DDS::String8_var& name, DDS::Int32 value, DDS::DynamicType_ptr type);
216  DDS::Int32& value, const char* name, DDS::DynamicType_ptr type);
217 
218 } // namespace XTypes
219 } // namespace OpenDDS
221 
222 #endif // OPENDDS_SAFETY_PROFILE
223 #endif
ACE_CDR::ULong MemberId
Definition: TypeObject.h:910
const LogLevel::Value value
Definition: debug.cpp:61
ACE_CDR::Int32 Int32
DDS::ReturnCode_t get_enumerator_value(DDS::Int32 &value, const char *name, DDS::DynamicType_ptr type)
DDS::ReturnCode_t get_member_type(DDS::DynamicType_var &member_type, DDS::DynamicType_ptr container_type, DDS::MemberId id)
const ReturnCode_t RETCODE_OK
DDS::ReturnCode_t get_int_value(CORBA::Int64 &value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind)
DDS::ReturnCode_t max_extensibility(DDS::DynamicType_ptr type, DCPS::Extensibility &ext)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
DDS::ReturnCode_t key_count(DDS::DynamicType_ptr type, size_t &count)
DDS::ReturnCode_t set_enum_value(DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id, CORBA::Int32 value)
bool is_key(DDS::DynamicType_ptr type, const char *field)
DDS::ReturnCode_t key_less_than(bool &result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
MemberPathParser(const DCPS::String &path)
Definition: XTypes/Utils.h:61
size_t strlen(const char *s)
DDS::ReturnCode_t set_int_value(DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind, CORBA::Int64 value)
typedef OPENDDS_VECTOR(MemberPair) MatchedSet
STL namespace.
DDS::ReturnCode_t compare_members(int &result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b, DDS::MemberId id)
DDS::ReturnCode_t bitmask_bound(DDS::DynamicType_ptr type, DDS::TypeKind &bound_kind)
ACE_CDR::UInt64 UInt64
DDS::ReturnCode_t get_keys(DDS::DynamicType_ptr type, MemberPathVec &paths)
DDS::ReturnCode_t set_uint_value(DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind, CORBA::UInt64 value)
DDS::ReturnCode_t enum_bound(DDS::DynamicType_ptr type, DDS::TypeKind &bound_kind)
bool is_int(DDS::TypeKind tk)
DDS::ReturnCode_t get_bitmask_value(CORBA::UInt64 &value, DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id)
const char *const name
Definition: debug.cpp:60
ACE_CDR::Int64 Int64
MemberPathParser(const char *path)
Definition: XTypes/Utils.h:52
MemberPath & id(DDS::MemberId id)
Definition: XTypes/Utils.h:101
bool is_uint(DDS::TypeKind tk)
DDS::ReturnCode_t get_uint_value(CORBA::UInt64 &value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind)
DDS::ReturnCode_t less_than(bool &result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b, Filter filter)
DDS::ReturnCode_t get_enum_value(CORBA::Int32 &value, DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id)
std::string String
DDS::ReturnCode_t get_enumerator_name(DDS::String8_var &name, DDS::Int32 value, DDS::DynamicType_ptr type)
DDS::ReturnCode_t get_values(DDS::DynamicType_ptr type, MemberPathVec &paths, Filter filter)
MemberPath(const MemberPath &other, DDS::MemberId id)
Definition: XTypes/Utils.h:95
ACE_CDR::UInt32 UInt32
ACE_CDR::Octet TypeKind
Definition: TypeObject.h:210
extensibility(MUTABLE) struct TypeLookup_getTypes_In
Definition: TypeLookup.idl:29
ExtensibilityKind
DCPS::Extensibility dds_to_opendds_ext(DDS::ExtensibilityKind ext)
bool dynamic_type_is_valid(DDS::DynamicType_ptr type)
Definition: XTypes/Utils.h:20