OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Public Attributes | List of all members
OpenDDS::XTypes::MemberPath Class Reference

#include <Utils.h>

Public Member Functions

typedef OPENDDS_VECTOR (DDS::MemberId) MemberIdVec
 
 MemberPath ()
 
 MemberPath (const MemberPath &other, DDS::MemberId id)
 
MemberPathid (DDS::MemberId id)
 
size_t level () const
 
DDS::ReturnCode_t resolve_string_path (DDS::DynamicType_ptr type, const DCPS::String &path)
 
DDS::ReturnCode_t get_member_from_type (DDS::DynamicType_ptr type, DDS::DynamicTypeMember_var &member)
 
DDS::ReturnCode_t get_member_from_data (DDS::DynamicData_ptr data, DDS::DynamicData_var &container, DDS::MemberId &member_id)
 

Public Attributes

MemberIdVec ids
 

Detailed Description

Provides access to a specific member using MemberIds that may be nested inside a DynamicType or DynamicData.

Definition at line 86 of file XTypes/Utils.h.

Constructor & Destructor Documentation

◆ MemberPath() [1/2]

OpenDDS::XTypes::MemberPath::MemberPath ( )
inline

Definition at line 91 of file XTypes/Utils.h.

92  {
93  }

◆ MemberPath() [2/2]

OpenDDS::XTypes::MemberPath::MemberPath ( const MemberPath other,
DDS::MemberId  id 
)
inline

Definition at line 95 of file XTypes/Utils.h.

96  : ids(other.ids)
97  {
98  ids.push_back(id);
99  }

Member Function Documentation

◆ get_member_from_data()

DDS::ReturnCode_t OpenDDS::XTypes::MemberPath::get_member_from_data ( DDS::DynamicData_ptr  data,
DDS::DynamicData_var &  container,
DDS::MemberId member_id 
)

DynamicData itself holds the access methods to its members, so in order to access them, we have to give both the containing Dynamic Data and the member ID.

Definition at line 314 of file XTypes/Utils.cpp.

References ACE_ERROR, OpenDDS::XTypes::DynamicTypeMembersByIdImpl::begin(), OpenDDS::XTypes::DISCRIMINATOR_ID, OpenDDS::XTypes::DynamicTypeMembersByIdImpl::end(), OpenDDS::XTypes::Filter_All, OpenDDS::XTypes::Filter_Keys, OpenDDS::XTypes::Filter_NestedKeys, OpenDDS::XTypes::Filter_NonKeys, OpenDDS::XTypes::get_base_type(), id(), level(), LM_NOTICE, OpenDDS::DCPS::log_level, OpenDDS::DCPS::LogLevel::Notice, OpenDDS::XTypes::MemberPathParser::path, DDS::RETCODE_BAD_PARAMETER, DDS::RETCODE_ILLEGAL_OPERATION, DDS::RETCODE_OK, OpenDDS::XTypes::TK_STRUCTURE, OpenDDS::XTypes::TK_UNION, and OpenDDS::XTypes::typekind_to_string().

316 {
317  container = 0;
318  if (ids.empty()) {
320  }
321 
322  MemberIdVec::iterator it = ids.begin();
323  DDS::DynamicData_var current_container = DDS::DynamicData::_duplicate(data);
324  while (true) {
325  const DDS::MemberId current_id = *it;
326  if (++it == ids.end()) {
327  member_id = current_id;
328  break;
329  }
330 
331  DDS::DynamicData_var next;
332  DDS::ReturnCode_t rc = current_container->get_complex_value(next, current_id);
333  if (rc != DDS::RETCODE_OK) {
334  return rc;
335  }
336  current_container = next;
337  }
338  container = current_container;
339 
340  return DDS::RETCODE_OK;
341 }
ACE_CDR::ULong MemberId
Definition: TypeObject.h:910
const ReturnCode_t RETCODE_ILLEGAL_OPERATION
const ReturnCode_t RETCODE_OK

◆ get_member_from_type()

DDS::ReturnCode_t OpenDDS::XTypes::MemberPath::get_member_from_type ( DDS::DynamicType_ptr  type,
DDS::DynamicTypeMember_var &  member 
)

Definition at line 272 of file XTypes/Utils.cpp.

References OpenDDS::XTypes::get_base_type(), DDS::RETCODE_BAD_PARAMETER, DDS::RETCODE_ILLEGAL_OPERATION, and DDS::RETCODE_OK.

274 {
275  member = 0;
276  if (ids.empty()) {
278  }
279 
280  DDS::DynamicType_var base_type = get_base_type(type);
281  if (!base_type) {
283  }
284 
285  MemberIdVec::iterator it = ids.begin();
286  DDS::DynamicType_var current_type = DDS::DynamicType::_duplicate(type);
287  DDS::DynamicTypeMember_var current_member;
288  while (true) {
289  DDS::ReturnCode_t rc = current_type->get_member(current_member, *it);
290  if (rc != DDS::RETCODE_OK) {
291  return rc;
292  }
293 
294  if (++it == ids.end()) {
295  break;
296  }
297 
298  DDS::MemberDescriptor_var md;
299  rc = current_member->get_descriptor(md);
300  if (rc != DDS::RETCODE_OK) {
301  return rc;
302  }
303  DDS::DynamicType_var next = get_base_type(md->type());
304  if (!next) {
306  }
307  current_type = next;
308  }
309  member = current_member;
310 
311  return DDS::RETCODE_OK;
312 }
const ReturnCode_t RETCODE_ILLEGAL_OPERATION
const ReturnCode_t RETCODE_OK
DDS::DynamicType_var get_base_type(DDS::DynamicType_ptr type)
const ReturnCode_t RETCODE_BAD_PARAMETER

◆ id()

MemberPath& OpenDDS::XTypes::MemberPath::id ( DDS::MemberId  id)
inline

Definition at line 101 of file XTypes/Utils.h.

Referenced by get_member_from_data().

102  {
103  ids.push_back(id);
104  return *this;
105  }

◆ level()

size_t OpenDDS::XTypes::MemberPath::level ( ) const
inline

Definition at line 107 of file XTypes/Utils.h.

References OpenDDS::XTypes::OPENDDS_VECTOR().

Referenced by get_member_from_data().

107 { return ids.size(); }

◆ OPENDDS_VECTOR()

typedef OpenDDS::XTypes::MemberPath::OPENDDS_VECTOR ( DDS::MemberId  )

◆ resolve_string_path()

DDS::ReturnCode_t OpenDDS::XTypes::MemberPath::resolve_string_path ( DDS::DynamicType_ptr  type,
const DCPS::String path 
)

Definition at line 227 of file XTypes/Utils.cpp.

References ACE_ERROR, OpenDDS::XTypes::get_base_type(), OpenDDS::XTypes::MemberPathParser::get_next_subpath(), OpenDDS::XTypes::MemberPathParser::in_subscript, LM_NOTICE, OpenDDS::DCPS::log_level, OpenDDS::DCPS::LogLevel::Notice, DDS::RETCODE_BAD_PARAMETER, DDS::RETCODE_OK, DDS::RETCODE_UNSUPPORTED, and OpenDDS::XTypes::MemberPathParser::subpath.

228 {
229  DDS::DynamicType_var current_type = get_base_type(type);
230  if (!current_type) {
232  }
233 
234  MemberPathParser parser(path);
235  while (parser.get_next_subpath()) {
236  if (parser.in_subscript) {
237  if (log_level >= LogLevel::Notice) {
238  ACE_ERROR((LM_NOTICE, "(%P|%t) NOTICE: MemberPath::resolve_string_path: "
239  "given \"%C\", which contains subscripts and these are currently not supported\n",
240  path.c_str()));
241  }
243  }
244  DDS::DynamicTypeMember_var dtm;
245  DDS::ReturnCode_t rc = current_type->get_member_by_name(dtm, parser.subpath.c_str());
246  if (rc != DDS::RETCODE_OK) {
247  return rc;
248  }
249  id(dtm->get_id());
250 
251  DDS::MemberDescriptor_var md;
252  rc = dtm->get_descriptor(md);
253  if (rc != DDS::RETCODE_OK) {
254  return rc;
255  }
256  DDS::DynamicType_var next = get_base_type(md->type());
257  if (!next) {
259  }
260  current_type = next;
261  }
262 
263  if (log_level >= LogLevel::Notice) {
264  ACE_ERROR((LM_NOTICE, "(%P|%t) NOTICE: MemberPath::resolve_string_path: "
265  "parser failed to parse \"%C\"\n", path.c_str()));
266  return DDS::RETCODE_OK;
267  }
268 
270 }
OpenDDS_Dcps_Export LogLevel log_level
#define ACE_ERROR(X)
const ReturnCode_t RETCODE_OK
DDS::DynamicType_var get_base_type(DDS::DynamicType_ptr type)
const ReturnCode_t RETCODE_BAD_PARAMETER
MemberPath & id(DDS::MemberId id)
Definition: XTypes/Utils.h:101
const ReturnCode_t RETCODE_UNSUPPORTED

Member Data Documentation

◆ ids

MemberIdVec OpenDDS::XTypes::MemberPath::ids

Definition at line 89 of file XTypes/Utils.h.


The documentation for this class was generated from the following files: