OpenDDS  Snapshot(2023/04/28-20:55)
TypeAssignability.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_TYPE_ASSIGNABILITY_H
7 #define OPENDDS_DCPS_XTYPES_TYPE_ASSIGNABILITY_H
8 
9 #include "TypeObject.h"
10 #include "TypeLookupService.h"
11 
12 #include <utility>
13 #include <map>
14 #include <cmath>
15 
17 
18 namespace OpenDDS {
19 namespace XTypes {
20 
21 // Set of pairs of members with each pair contains members from
22 // two structure types that have the same member ID and name
23 // (or have the same member ID if ignore_member_names is true)
24 typedef std::pair<const MinimalStructMember*, const MinimalStructMember*> MemberPair;
25 typedef OPENDDS_VECTOR(MemberPair) MatchedSet;
26 
27 // From the reader's TypeConsistencyEnforcementQosPolicy
32  bool ignore_member_names; // Only this affects assignability currently
33 };
34 
36 public:
38  : tl_service_(tls)
39  {
40  // Use default type consistency values
41  type_consistency_.prevent_type_widening = false;
42  type_consistency_.ignore_sequence_bounds = true;
43  type_consistency_.ignore_string_bounds = true;
44  type_consistency_.ignore_member_names = false;
45  }
46 
48  TypeConsistencyAttributes type_consistency)
49  : tl_service_(tls)
50  , type_consistency_(type_consistency) {}
51 
52  // Check whether ta is-assignable-from tb
53  bool assignable(const TypeObject& ta, const TypeObject& tb) const;
54  bool assignable(const TypeObject& ta, const TypeIdentifier& tb) const;
55  bool assignable(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
56  bool assignable(const TypeIdentifier& ta, const TypeObject& tb) const;
57 
58  // The following set_* functions, if called prior to the assignable
59  // functions, can change the behavior of type assignability
60 
61  // No affect on assignability currently
63  {
64  type_consistency_.prevent_type_widening = value;
65  }
66 
67  // No affect on assignability currently
69  {
70  type_consistency_.ignore_sequence_bounds = value;
71  }
72 
73  // No affect on assignability currently
75  {
76  type_consistency_.ignore_string_bounds = value;
77  }
78 
79  // Currently, only this affects assignability's behavior
81  {
82  type_consistency_.ignore_member_names = value;
83  }
84 
85  void insert_entry(const TypeIdentifier& ti, const TypeObject& tobj)
86  {
87  tl_service_->add(ti, tobj);
88  }
89 
90 private:
91  bool assignable_alias(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
92  bool assignable_annotation(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
93  bool assignable_annotation(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
94  bool assignable_struct(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
95  bool assignable_struct(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
96  bool assignable_union(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
97  bool assignable_union(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
98  bool assignable_bitset(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
99  bool assignable_bitset(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
100  bool assignable_sequence(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
101  bool assignable_sequence(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
102  bool assignable_array(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
103  bool assignable_array(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
104  bool assignable_map(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
105  bool assignable_map(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
106  bool assignable_enum(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
107  bool assignable_enum(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
108  bool assignable_bitmask(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
109  bool assignable_bitmask(const MinimalTypeObject& ta, const TypeIdentifier& tb) const;
110  bool assignable_extended(const MinimalTypeObject& ta, const MinimalTypeObject& tb) const;
111 
112  bool assignable_primitive(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
113  bool assignable_primitive(const TypeIdentifier& ta, const MinimalTypeObject& tb) const;
114  bool assignable_string(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
115  bool assignable_string(const TypeIdentifier& ta, const MinimalTypeObject& tb) const;
116  bool assignable_plain_sequence(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
117  bool assignable_plain_sequence(const TypeIdentifier& ta, const MinimalTypeObject& tb) const;
118  bool assignable_plain_array(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
119  bool assignable_plain_array(const TypeIdentifier& ta, const MinimalTypeObject& tb) const;
120  bool assignable_plain_map(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
121  bool assignable_plain_map(const TypeIdentifier& ta, const MinimalTypeObject& tb) const;
122 
123  // General helpers
124  bool strongly_assignable(const TypeIdentifier& ta, const TypeIdentifier& tb) const;
125  bool is_delimited(const TypeIdentifier& ti) const;
126  bool is_delimited(const MinimalTypeObject& tobj) const;
127  bool is_delimited_with_flags(TypeFlag flags) const;
128  bool equal_type_id(const TypeIdentifier& tia, const TypeIdentifier& tib) const;
129  const TypeIdentifier& get_base_type(const MinimalTypeObject& type) const;
130 
131  // Helpers for assignability of struct
132  void erase_key(MinimalTypeObject& type) const;
133  void hold_key(MinimalTypeObject& type) const;
134  bool hold_key(const TypeIdentifier& ti, MinimalTypeObject& to) const;
135  bool struct_rule_enum_key(const MinimalTypeObject& tb, const CommonStructMember& ma) const;
136  bool get_sequence_bound(LBound& b, const CommonStructMember& m) const;
137  bool get_map_bound(LBound& b, const CommonStructMember& m) const;
138  bool get_string_bound(LBound& b, const CommonStructMember& m) const;
139  bool get_struct_member(const MinimalTypeObject*& ret, const CommonStructMember& m) const;
140  bool get_union_member(const MinimalTypeObject*& ret, const CommonStructMember& m) const;
141 
143  {
144  return tl_service_->get_type_object(ti).minimal;
145  }
146 
148 
149  // For now, type assignability applies only ignore_member_names.
150  // In the future, it needs to consider other attibutes as well:
151  // prevent_type_widening, ignore_sequence_bounds, ignore_string_bounds.
153 };
154 
155 } // namepace XTypes
156 } // namespace OpenDDS
157 
159 
160 #endif /* OPENDDS_DCPS_XTYPES_TYPE_ASSIGNABILITY_H */
XTypes::TypeLookupService_rch tl_service_
const LogLevel::Value value
Definition: debug.cpp:61
std::pair< const MinimalStructMember *, const MinimalStructMember * > MemberPair
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
TypeConsistencyAttributes type_consistency_
const MinimalTypeObject & lookup_minimal(const TypeIdentifier &ti) const
DDS::DynamicType_var get_base_type(DDS::DynamicType_ptr type)
typedef OPENDDS_VECTOR(MemberPair) MatchedSet
TypeAssignability(TypeLookupService_rch tls, TypeConsistencyAttributes type_consistency)
TypeAssignability(TypeLookupService_rch tls)
ACE_CDR::UShort TypeFlag
Definition: TypeObject.h:399
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
ACE_CDR::ULong LBound
Definition: TypeObject.h:312
void insert_entry(const TypeIdentifier &ti, const TypeObject &tobj)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28