OpenDDS  Snapshot(2023/04/28-20:55)
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
RefWrapper Struct Reference

#include <dds_generator.h>

Collaboration diagram for RefWrapper:
Collaboration graph
[legend]

Public Member Functions

 RefWrapper (AST_Type *type, const std::string &type_name, const std::string &to_wrap, bool is_const=true)
 
 RefWrapper (AST_Type *type, const std::string &type_name, const std::string &fieldref, const std::string &local, bool is_const=true)
 
RefWrapperdone (Intro *intro=0)
 
std::string ref () const
 
std::string wrapped_type_name () const
 
bool needs_dda_tag () const
 
void generate_tag () const
 
std::string get_tag_name () const
 
std::string get_var_name (const std::string &var_name) const
 
std::string value_access (const std::string &var_name="") const
 
std::string seq_check_empty () const
 
std::string seq_get_length () const
 
std::string seq_resize (const std::string &new_size) const
 
std::string seq_get_buffer () const
 
std::string flat_collection_access (std::string index) const
 
std::string stream () const
 
std::string classic_array_copy () const
 

Public Attributes

const bool cpp11_
 
AST_Type *const type_
 
const std::string type_name_
 
const std::string to_wrap_
 
const char *const shift_op_
 
const std::string fieldref_
 
const std::string local_
 
bool is_const_
 
bool nested_key_only_
 
bool classic_array_copy_
 
bool dynamic_data_adapter_
 
std::string classic_array_copy_var_
 
AST_Typedef * typedef_node_
 

Private Member Functions

std::string get_tag_name_i () const
 

Private Attributes

bool done_
 
std::string wrapped_type_name_
 
std::string ref_
 
std::string value_access_pre_
 
std::string value_access_post_
 
bool needs_dda_tag_
 

Detailed Description

Handling wrapping and unwrapping references in the wrapper types: NestedKeyOnly, IDL::DistinctType, and *_forany.

Definition at line 1365 of file dds_generator.h.

Constructor & Destructor Documentation

◆ RefWrapper() [1/2]

RefWrapper::RefWrapper ( AST_Type *  type,
const std::string &  type_name,
const std::string &  to_wrap,
bool  is_const = true 
)
inline

Definition at line 1380 of file dds_generator.h.

1382  : cpp11_(be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11)
1383  , type_(type)
1384  , type_name_(type_name)
1385  , to_wrap_(strip_shift_op(to_wrap))
1386  , shift_op_(get_shift_op(to_wrap))
1387  , is_const_(is_const)
1388  , nested_key_only_(false)
1389  , classic_array_copy_(false)
1390  , dynamic_data_adapter_(false)
1391  , typedef_node_(0)
1392  , done_(false)
1393  {
1394  }
AST_Typedef * typedef_node_
const std::string type_name_
bool classic_array_copy_
std::string strip_shift_op(const std::string &s)
AST_Type *const type_
bool nested_key_only_
const char *const shift_op_
const std::string to_wrap_
BE_GlobalData * be_global
Definition: be_global.cpp:44
const char * get_shift_op(const std::string &s)
bool dynamic_data_adapter_
const bool cpp11_

◆ RefWrapper() [2/2]

RefWrapper::RefWrapper ( AST_Type *  type,
const std::string &  type_name,
const std::string &  fieldref,
const std::string &  local,
bool  is_const = true 
)
inline

Definition at line 1396 of file dds_generator.h.

1398  : cpp11_(be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11)
1399  , type_(type)
1400  , type_name_(type_name)
1401  , shift_op_("")
1402  , fieldref_(strip_shift_op(fieldref))
1403  , local_(local)
1404  , is_const_(is_const)
1405  , nested_key_only_(false)
1406  , classic_array_copy_(false)
1407  , dynamic_data_adapter_(false)
1408  , typedef_node_(0)
1409  , done_(false)
1410  {
1411  }
AST_Typedef * typedef_node_
const std::string type_name_
bool classic_array_copy_
std::string strip_shift_op(const std::string &s)
const std::string fieldref_
AST_Type *const type_
bool nested_key_only_
const char *const shift_op_
BE_GlobalData * be_global
Definition: be_global.cpp:44
bool dynamic_data_adapter_
const std::string local_
const bool cpp11_

Member Function Documentation

◆ classic_array_copy()

std::string RefWrapper::classic_array_copy ( ) const
inline

Definition at line 1584 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

1585  {
1586  return type_name_ + "_copy(" + to_wrap_ + ", " + classic_array_copy_var_ + ".in());";
1587  }
const std::string type_name_
std::string classic_array_copy_var_
const std::string to_wrap_

◆ done()

RefWrapper& RefWrapper::done ( Intro intro = 0)
inline

Definition at line 1413 of file dds_generator.h.

References ACE_ASSERT, needs_distinct_type(), needs_forany(), needs_nested_key_only(), shift_in, and dds_generator::valid_var_name().

Referenced by marshal_generator::gen_enum(), and marshal_generator::gen_typedef().

1414  {
1415  ACE_ASSERT(!done_);
1416 
1417  if (is_const_ && !std::strcmp(shift_op_, shift_in)) {
1418  is_const_ = false;
1419  }
1420  const std::string const_str = is_const_ ? "const " : "";
1421  const bool forany = classic_array_copy_ || needs_forany(type_);
1422  const bool distinct_type = needs_distinct_type(type_);
1423  needs_dda_tag_ = dynamic_data_adapter_ && (forany || distinct_type);
1424  nested_key_only_ = nested_key_only_ &&
1427  bool by_ref = true;
1428 
1429  if (to_wrap_.size()) {
1430  ref_ = to_wrap_;
1431  } else {
1432  ref_ = fieldref_;
1433  if (local_.size()) {
1434  ref_ += '.' + local_;
1435  }
1436  }
1437 
1438  if (forany && !dynamic_data_adapter_) {
1439  const std::string forany_type = type_name_ + "_forany";
1440  if (classic_array_copy_) {
1441  const std::string var_name = dds_generator::valid_var_name(ref_) + "_tmp_var";
1442  classic_array_copy_var_ = var_name;
1443  if (intro) {
1444  intro->insert(type_name_ + "_var " + var_name + "= " + type_name_ + "_alloc();");
1445  }
1446  ref_ = var_name;
1447  }
1448  const std::string var_name = dds_generator::valid_var_name(ref_) + "_forany";
1449  wrapped_type_name_ = forany_type;
1450  if (intro) {
1451  std::string line = forany_type + " " + var_name;
1452  if (classic_array_copy_) {
1453  line += " = " + ref_ + ".inout();";
1454  } else {
1455  line += "(const_cast<" + type_name_ + "_slice*>(" + ref_ + "));";
1456  }
1457  intro->insert(line);
1458  }
1459  ref_ = var_name;
1460  }
1461 
1462  if (nested_key_only_) {
1464  std::string("NestedKeyOnly<") + const_str + wrapped_type_name_ + ">";
1466  const std::string nko_arg = "(" + ref_ + ")";
1467  if (is_const_) {
1468  ref_ = wrapped_type_name_ + nko_arg;
1469  } else {
1470  ref_ = dds_generator::valid_var_name(ref_) + "_nested_key_only";
1471  if (intro) {
1472  intro->insert(wrapped_type_name_ + " " + ref_ + nko_arg + ";");
1473  }
1474  }
1475  }
1476 
1477  if (distinct_type && !dynamic_data_adapter_) {
1478  wrapped_type_name_ =
1479  std::string("IDL::DistinctType<") + const_str + wrapped_type_name_ +
1480  ", " + get_tag_name_i() + ">";
1481  value_access_pre_ += "(*";
1483  const std::string idt_arg = "(" + ref_ + ")";
1484  if (is_const_) {
1485  ref_ = wrapped_type_name_ + idt_arg;
1486  } else {
1487  ref_ = dds_generator::valid_var_name(ref_) + "_distinct_type";
1488  if (intro) {
1489  intro->insert(wrapped_type_name_ + " " + ref_ + idt_arg + ";");
1490  }
1491  }
1492  by_ref = false;
1493  }
1494 
1495  wrapped_type_name_ = const_str + wrapped_type_name_ + (by_ref ? "&" : "");
1496  done_ = true;
1497  return *this;
1498  }
bool needs_forany(AST_Type *type)
AST_Typedef * typedef_node_
const std::string type_name_
void insert(const std::string &line)
const char *const shift_in
std::string get_tag_name_i() const
std::string classic_array_copy_var_
std::string value_access_pre_
bool classic_array_copy_
std::string wrapped_type_name_
const std::string fieldref_
static std::string valid_var_name(const std::string &str)
AST_Type *const type_
bool nested_key_only_
const char *const shift_op_
bool needs_dda_tag_
#define ACE_ASSERT(X)
const std::string to_wrap_
std::string ref_
bool dynamic_data_adapter_
const std::string local_
std::string value_access_post_
bool needs_distinct_type(AST_Type *type)
bool needs_nested_key_only(AST_Type *type)

◆ flat_collection_access()

std::string RefWrapper::flat_collection_access ( std::string  index) const
inline

Definition at line 1563 of file dds_generator.h.

References OpenDDS::DCPS::ref().

1564  {
1565  AST_Array* const array_node = dynamic_cast<AST_Array*>(type_);
1566  std::string ref;
1567  if (array_node) {
1568  ref = "(&" + value_access();
1569  for (ACE_CDR::ULong dim = array_node->n_dims(); dim; --dim) {
1570  ref += "[0]";
1571  }
1572  ref += ")";
1573  } else {
1574  ref = value_access();
1575  }
1576  return ref += "[" + index + "]";
1577  }
AST_Type *const type_
ACE_UINT32 ULong
std::string value_access(const std::string &var_name="") const
std::string ref() const

◆ generate_tag()

void RefWrapper::generate_tag ( ) const
inline

Definition at line 1518 of file dds_generator.h.

References be_global, and dds_generator::get_tag_name().

Referenced by marshal_generator::gen_enum().

1519  {
1520  if (cpp11_ || needs_dda_tag_) {
1521  be_global->header_ << "struct " << get_tag_name() << " {};\n\n";
1522  }
1523  }
std::string get_tag_name() const
bool needs_dda_tag_
BE_GlobalData * be_global
Definition: be_global.cpp:44
const bool cpp11_

◆ get_tag_name()

std::string RefWrapper::get_tag_name ( ) const
inline

Definition at line 1525 of file dds_generator.h.

References ACE_ASSERT.

1526  {
1527  ACE_ASSERT(done_);
1528  return get_tag_name_i();
1529  }
std::string get_tag_name_i() const
#define ACE_ASSERT(X)

◆ get_tag_name_i()

std::string RefWrapper::get_tag_name_i ( ) const
inlineprivate

Definition at line 1597 of file dds_generator.h.

References dds_generator::get_tag_name().

1598  {
1599  std::string qualifier;
1600  if (nested_key_only_) {
1601  qualifier = "_nested_key_only";
1602  } else if (needs_dda_tag_) {
1603  qualifier = "_dda";
1604  }
1605  return dds_generator::get_tag_name(type_name_, qualifier);
1606  }
const std::string type_name_
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
bool nested_key_only_
bool needs_dda_tag_

◆ get_var_name()

std::string RefWrapper::get_var_name ( const std::string &  var_name) const
inline

Definition at line 1531 of file dds_generator.h.

1532  {
1533  return var_name.size() ? var_name : to_wrap_;
1534  }
const std::string to_wrap_

◆ needs_dda_tag()

bool RefWrapper::needs_dda_tag ( ) const
inline

Definition at line 1512 of file dds_generator.h.

References ACE_ASSERT.

1513  {
1514  ACE_ASSERT(done_);
1515  return needs_dda_tag_;
1516  }
bool needs_dda_tag_
#define ACE_ASSERT(X)

◆ ref()

std::string RefWrapper::ref ( void  ) const
inline

Definition at line 1500 of file dds_generator.h.

References ACE_ASSERT.

Referenced by marshal_generator::gen_enum(), and marshal_generator::gen_typedef().

1501  {
1502  ACE_ASSERT(done_);
1503  return ref_;
1504  }
#define ACE_ASSERT(X)
std::string ref_

◆ seq_check_empty()

std::string RefWrapper::seq_check_empty ( ) const
inline

Definition at line 1541 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

1542  {
1543  return value_access() + (cpp11_ ? ".empty()" : ".length() == 0");
1544  }
std::string value_access(const std::string &var_name="") const
const bool cpp11_

◆ seq_get_buffer()

std::string RefWrapper::seq_get_buffer ( ) const
inline

Definition at line 1558 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

1559  {
1560  return value_access() + (cpp11_ ? ".data()" : ".get_buffer()");
1561  }
std::string value_access(const std::string &var_name="") const
const bool cpp11_

◆ seq_get_length()

std::string RefWrapper::seq_get_length ( ) const
inline

Definition at line 1546 of file dds_generator.h.

References value.

Referenced by marshal_generator::gen_enum().

1547  {
1548  const std::string value = value_access();
1549  return cpp11_ ? "static_cast<uint32_t>(" + value + ".size())" : value + ".length()";
1550  }
const LogLevel::Value value
Definition: debug.cpp:61
std::string value_access(const std::string &var_name="") const
const bool cpp11_

◆ seq_resize()

std::string RefWrapper::seq_resize ( const std::string &  new_size) const
inline

Definition at line 1552 of file dds_generator.h.

References value.

Referenced by marshal_generator::gen_enum().

1553  {
1554  const std::string value = value_access();
1555  return value + (cpp11_ ? ".resize" : ".length") + "(" + new_size + ");\n";
1556  }
const LogLevel::Value value
Definition: debug.cpp:61
std::string value_access(const std::string &var_name="") const
const bool cpp11_

◆ stream()

std::string RefWrapper::stream ( void  ) const
inline

Definition at line 1579 of file dds_generator.h.

References OpenDDS::DCPS::ref().

Referenced by marshal_generator::gen_typedef().

1580  {
1581  return shift_op_ + ref();
1582  }
const char *const shift_op_
std::string ref() const

◆ value_access()

std::string RefWrapper::value_access ( const std::string &  var_name = "") const
inline

Definition at line 1536 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

1537  {
1538  return value_access_pre_ + get_var_name(var_name) + value_access_post_;
1539  }
std::string value_access_pre_
std::string get_var_name(const std::string &var_name) const
std::string value_access_post_

◆ wrapped_type_name()

std::string RefWrapper::wrapped_type_name ( ) const
inline

Definition at line 1506 of file dds_generator.h.

References ACE_ASSERT.

Referenced by marshal_generator::gen_enum().

1507  {
1508  ACE_ASSERT(done_);
1509  return wrapped_type_name_;
1510  }
std::string wrapped_type_name_
#define ACE_ASSERT(X)

Member Data Documentation

◆ classic_array_copy_

bool RefWrapper::classic_array_copy_

Definition at line 1375 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

◆ classic_array_copy_var_

std::string RefWrapper::classic_array_copy_var_

Definition at line 1377 of file dds_generator.h.

◆ cpp11_

const bool RefWrapper::cpp11_

Definition at line 1366 of file dds_generator.h.

◆ done_

bool RefWrapper::done_
private

Definition at line 1590 of file dds_generator.h.

◆ dynamic_data_adapter_

bool RefWrapper::dynamic_data_adapter_

Definition at line 1376 of file dds_generator.h.

◆ fieldref_

const std::string RefWrapper::fieldref_

Definition at line 1371 of file dds_generator.h.

◆ is_const_

bool RefWrapper::is_const_

Definition at line 1373 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

◆ local_

const std::string RefWrapper::local_

Definition at line 1372 of file dds_generator.h.

◆ needs_dda_tag_

bool RefWrapper::needs_dda_tag_
private

Definition at line 1595 of file dds_generator.h.

◆ nested_key_only_

bool RefWrapper::nested_key_only_

◆ ref_

std::string RefWrapper::ref_
private

Definition at line 1592 of file dds_generator.h.

◆ shift_op_

const char* const RefWrapper::shift_op_

Definition at line 1370 of file dds_generator.h.

◆ to_wrap_

const std::string RefWrapper::to_wrap_

Definition at line 1369 of file dds_generator.h.

◆ type_

AST_Type* const RefWrapper::type_

Definition at line 1367 of file dds_generator.h.

◆ type_name_

const std::string RefWrapper::type_name_

Definition at line 1368 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

◆ typedef_node_

AST_Typedef* RefWrapper::typedef_node_

Definition at line 1378 of file dds_generator.h.

Referenced by marshal_generator::gen_enum().

◆ value_access_post_

std::string RefWrapper::value_access_post_
private

Definition at line 1594 of file dds_generator.h.

◆ value_access_pre_

std::string RefWrapper::value_access_pre_
private

Definition at line 1593 of file dds_generator.h.

◆ wrapped_type_name_

std::string RefWrapper::wrapped_type_name_
private

Definition at line 1591 of file dds_generator.h.


The documentation for this struct was generated from the following file: