OpenDDS  Snapshot(2023/04/28-20:55)
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(DDS::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 
156  DDS::UInt64& value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind);
158  DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::TypeKind kind, DDS::UInt64 value);
160  DDS::Int64& value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind);
162  DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::TypeKind kind, DDS::Int64 value);
163 
164 OpenDDS_Dcps_Export DDS::UInt32 bound_total(DDS::TypeDescriptor_var descriptor);
165 
167  DDS::DynamicType_ptr type, DDS::TypeKind& bound_kind);
169  DDS::UInt64& value, DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id);
170 
171 OpenDDS_Dcps_Export DDS::ReturnCode_t enum_bound(DDS::DynamicType_ptr enum_type, DDS::TypeKind& bound_kind);
172 
174  DDS::Int32& value, DDS::DynamicType_ptr enum_type, DDS::DynamicData_ptr src, DDS::MemberId id);
176  DDS::Int32& value, DDS::DynamicData_ptr src, DDS::MemberId id)
177 {
178  DDS::DynamicType_var enum_type;
179  const DDS::ReturnCode_t rc = get_member_type(enum_type, src, id);
180  if (rc != DDS::RETCODE_OK) {
181  return rc;
182  }
183  return get_enum_value(value, enum_type, src, id);
184 }
185 
187  DDS::DynamicType_ptr enum_type, DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::Int32 value);
189  DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::Int32 value)
190 {
191  DDS::DynamicType_var enum_type;
192  const DDS::ReturnCode_t rc = get_member_type(enum_type, dest, id);
193  if (rc != DDS::RETCODE_OK) {
194  return rc;
195  }
196  return set_enum_value(enum_type, dest, id, value);
197 }
198 
200  DDS::DynamicType_ptr enum_type, DDS::DynamicData_ptr dest, DDS::MemberId id,
201  const char* enumeral_name);
203  DDS::DynamicData_ptr dest, DDS::MemberId id, const char* enumeral_name)
204 {
205  DDS::DynamicType_var enum_type;
206  const DDS::ReturnCode_t rc = get_member_type(enum_type, dest, id);
207  if (rc != DDS::RETCODE_OK) {
208  return rc;
209  }
210  return set_enum_value(enum_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 
219  DDS::DynamicData_ptr dest, DDS::MemberId dest_id,
220  DDS::DynamicData_ptr src, DDS::MemberId src_id);
221 OpenDDS_Dcps_Export DDS::ReturnCode_t copy(DDS::DynamicData_ptr dest, DDS::DynamicData_ptr src);
222 
223 } // namespace XTypes
224 } // namespace OpenDDS
226 
227 #endif // OPENDDS_SAFETY_PROFILE
228 #endif
DCPS::Extensibility dds_to_opendds_ext(DDS::ExtensibilityKind ext)
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)
ACE_CDR::ULong MemberId
Definition: TypeObject.h:910
const LogLevel::Value value
Definition: debug.cpp:61
DDS::ReturnCode_t get_enumerator_value(DDS::Int32 &value, const char *name, DDS::DynamicType_ptr type)
std::string String
DDS::ReturnCode_t get_member_type(DDS::DynamicType_var &member_type, DDS::DynamicType_ptr container_type, DDS::MemberId id)
DDS::ReturnCode_t set_int_value(DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::TypeKind kind, DDS::Int64 value)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
bool dynamic_type_is_valid(DDS::DynamicType_ptr type)
Definition: XTypes/Utils.h:20
MemberPathParser(const char *path)
Definition: XTypes/Utils.h:52
DDS::ReturnCode_t get_keys(DDS::DynamicType_ptr type, MemberPathVec &paths)
DDS::ReturnCode_t copy_member(DDS::DynamicData_ptr dest, DDS::MemberId dest_id, DDS::DynamicData_ptr src, DDS::MemberId src_id)
size_t strlen(const char *s)
ACE_CDR::Octet TypeKind
Definition: TypeObject.h:210
DDS::ReturnCode_t compare_members(int &result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b, DDS::MemberId id)
typedef OPENDDS_VECTOR(MemberPair) MatchedSet
DDS::ReturnCode_t get_enum_value(DDS::Int32 &value, DDS::DynamicType_ptr enum_type, DDS::DynamicData_ptr src, DDS::MemberId id)
STL namespace.
MemberPath & id(DDS::MemberId id)
Definition: XTypes/Utils.h:101
DDS::ReturnCode_t get_bitmask_value(DDS::UInt64 &value, DDS::DynamicType_ptr type, DDS::DynamicData_ptr src, DDS::MemberId id)
DDS::UInt32 bound_total(DDS::TypeDescriptor_var descriptor)
DDS::ReturnCode_t get_values(DDS::DynamicType_ptr type, MemberPathVec &paths, Filter filter)
const char *const name
Definition: debug.cpp:60
DDS::ReturnCode_t less_than(bool &result, DDS::DynamicData_ptr a, DDS::DynamicData_ptr b, Filter filter)
ExtensibilityKind
MemberPathParser(const DCPS::String &path)
Definition: XTypes/Utils.h:61
DDS::ReturnCode_t enum_bound(DDS::DynamicType_ptr enum_type, DDS::TypeKind &bound_kind)
DDS::ReturnCode_t copy(DDS::DynamicData_ptr dest, DDS::DynamicData_ptr src)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
DDS::ReturnCode_t get_enumerator_name(DDS::String8_var &name, DDS::Int32 value, DDS::DynamicType_ptr type)
MemberPath(const MemberPath &other, DDS::MemberId id)
Definition: XTypes/Utils.h:95
const ReturnCode_t RETCODE_OK
DDS::ReturnCode_t get_int_value(DDS::Int64 &value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind)
DDS::ReturnCode_t set_enum_value(DDS::DynamicType_ptr enum_type, DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::Int32 value)
DDS::ReturnCode_t get_uint_value(DDS::UInt64 &value, DDS::DynamicData_ptr src, DDS::MemberId id, DDS::TypeKind kind)
DDS::ReturnCode_t max_extensibility(DDS::DynamicType_ptr type, DCPS::Extensibility &ext)
DDS::ReturnCode_t set_uint_value(DDS::DynamicData_ptr dest, DDS::MemberId id, DDS::TypeKind kind, DDS::UInt64 value)
DDS::ReturnCode_t bitmask_bound(DDS::DynamicType_ptr type, DDS::TypeKind &bound_kind)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
DDS::ReturnCode_t key_count(DDS::DynamicType_ptr type, size_t &count)
extensibility(MUTABLE) struct TypeLookup_getTypes_In
Definition: TypeLookup.idl:29