Fast RTPS  Version 2.1.0
Fast RTPS
MemberDescriptor.h
1 // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef TYPES_MEMBER_DESCRIPTOR_H
16 #define TYPES_MEMBER_DESCRIPTOR_H
17 
18 #include <fastrtps/types/TypesBase.h>
19 #include <fastrtps/types/DynamicTypePtr.h>
20 
21 namespace eprosima{
22 namespace fastrtps{
23 namespace types{
24 
25 class DynamicType;
26 class AnnotationDescriptor;
27 
29 {
30 protected:
31  std::string name_; // Name of the member
32  MemberId id_; // MemberId, it should be filled automatically when the member is added.
33  DynamicType_ptr type_; // Member's Type.
34  std::string default_value_; // Default value of the member in string.
35  uint32_t index_; // Definition order of the member inside it's parent.
36  std::vector<uint64_t> labels_; // Case Labels for unions.
37  bool default_label_; // TRUE if it's the default option of a union.
38 
39  std::vector<AnnotationDescriptor*> annotation_; // Annotations to apply
40 
42  friend class DynamicData;
43  friend class DynamicTypeMember;
44  friend class TypeObjectFactory;
45 
46  bool is_default_value_consistent(const std::string& sDefaultValue) const;
47 
48  bool is_type_name_consistent(const std::string& sName) const;
49 
50 public:
51  RTPS_DllAPI MemberDescriptor();
52 
53  RTPS_DllAPI MemberDescriptor(
54  uint32_t index,
55  const std::string& name);
56 
57  RTPS_DllAPI MemberDescriptor(
58  MemberId id,
59  const std::string& name,
61 
62  RTPS_DllAPI MemberDescriptor(
63  MemberId id,
64  const std::string& name,
66  const std::string& defaultValue);
67 
68  RTPS_DllAPI MemberDescriptor(
69  MemberId id,
70  const std::string& name,
72  const std::string& defaultValue,
73  const std::vector<uint64_t>& unionLabels,
74  bool isDefaultLabel);
75 
76  RTPS_DllAPI MemberDescriptor(const MemberDescriptor* descriptor);
77 
78  RTPS_DllAPI ~MemberDescriptor();
79 
80  bool check_union_labels(const std::vector<uint64_t>& labels) const;
81 
82  RTPS_DllAPI ReturnCode_t copy_from(const MemberDescriptor* other);
83 
84  RTPS_DllAPI bool equals(const MemberDescriptor* other) const;
85 
86  RTPS_DllAPI TypeKind get_kind() const;
87 
88  RTPS_DllAPI MemberId get_id() const;
89 
90  RTPS_DllAPI uint32_t get_index() const;
91 
92  RTPS_DllAPI std::string get_name() const;
93 
94  RTPS_DllAPI std::vector<uint64_t> get_union_labels() const;
95 
96  RTPS_DllAPI std::string get_default_value() const
97  {
98  if (!default_value_.empty())
99  {
100  return default_value_;
101  }
102  // Try annotation
103  return annotation_get_default();
104  }
105 
106  RTPS_DllAPI bool is_default_union_value() const;
107 
108  RTPS_DllAPI bool is_consistent(TypeKind parentKind) const;
109 
110  RTPS_DllAPI void add_union_case_index(uint64_t value);
111 
112  RTPS_DllAPI void set_id(MemberId id);
113 
114  RTPS_DllAPI void set_index(uint32_t index);
115 
116  RTPS_DllAPI void set_name(const std::string& name);
117 
118  RTPS_DllAPI void set_type(DynamicType_ptr type);
119 
120  RTPS_DllAPI DynamicType_ptr get_type() const
121  {
122  return type_;
123  }
124 
125  RTPS_DllAPI void set_default_union_value(bool bDefault);
126 
127  RTPS_DllAPI void set_default_value(const std::string& value)
128  {
129  default_value_ = value;
130  }
131 
132  // Annotations
134 
136  const std::string& annotation_name,
137  const std::string& key,
138  const std::string& value);
139 
140  AnnotationDescriptor* get_annotation(const std::string& name) const;
141 
142  // Annotations application
143  RTPS_DllAPI bool annotation_is_optional() const;
144 
145  RTPS_DllAPI bool annotation_is_key() const;
146 
147  RTPS_DllAPI bool annotation_is_must_understand() const;
148 
149  RTPS_DllAPI bool annotation_is_non_serialized() const;
150 
151  RTPS_DllAPI bool annotation_is_value() const;
152 
153  RTPS_DllAPI bool annotation_is_default_literal() const;
154 
155  RTPS_DllAPI bool annotation_is_position() const;
156 
157  RTPS_DllAPI bool annotation_is_bit_bound() const;
158 
159  // Annotations getters
160  RTPS_DllAPI bool annotation_get_key() const;
161 
162  RTPS_DllAPI std::string annotation_get_value() const;
163 
164  RTPS_DllAPI std::string annotation_get_default() const;
165 
166  RTPS_DllAPI uint16_t annotation_get_position() const;
167 
168  RTPS_DllAPI uint16_t annotation_get_bit_bound() const;
169 
170  // Annotations setters
171  RTPS_DllAPI void annotation_set_optional(bool optional);
172 
173  RTPS_DllAPI void annotation_set_key(bool key);
174 
175  RTPS_DllAPI void annotation_set_must_understand(bool must_understand);
176 
177  RTPS_DllAPI void annotation_set_non_serialized(bool non_serialized);
178 
179  RTPS_DllAPI void annotation_set_value(const std::string& value);
180 
181  RTPS_DllAPI void annotation_set_default(const std::string& default_value);
182 
183  RTPS_DllAPI void annotation_set_default_literal();
184 
185  RTPS_DllAPI void annotation_set_position(uint16_t position);
186 
187  RTPS_DllAPI void annotation_set_bit_bound(uint16_t bit_bound);
188 };
189 
190 } // namespace types
191 } // namespace fastrtps
192 } // namespace eprosima
193 
194 #endif // TYPES_MEMBER_DESCRIPTOR_H
Definition: AnnotationDescriptor.h:29
Definition: DynamicData.h:32
Definition: DynamicTypePtr.h:27
Definition: DynamicTypeBuilderFactory.h:40
Definition: DynamicTypeMember.h:29
Definition: MemberDescriptor.h:29
RTPS_DllAPI bool annotation_is_key() const
RTPS_DllAPI bool annotation_is_default_literal() const
RTPS_DllAPI std::string annotation_get_default() const
bool default_label_
Definition: MemberDescriptor.h:37
RTPS_DllAPI uint16_t annotation_get_position() const
RTPS_DllAPI void add_union_case_index(uint64_t value)
RTPS_DllAPI bool annotation_is_position() const
RTPS_DllAPI void annotation_set_default(const std::string &default_value)
RTPS_DllAPI bool annotation_is_bit_bound() const
bool is_default_value_consistent(const std::string &sDefaultValue) const
DynamicType_ptr type_
Definition: MemberDescriptor.h:33
uint32_t index_
Definition: MemberDescriptor.h:35
RTPS_DllAPI bool is_consistent(TypeKind parentKind) const
RTPS_DllAPI void annotation_set_position(uint16_t position)
ReturnCode_t apply_annotation(AnnotationDescriptor &descriptor)
RTPS_DllAPI TypeKind get_kind() const
std::string name_
Definition: MemberDescriptor.h:31
RTPS_DllAPI void annotation_set_value(const std::string &value)
bool check_union_labels(const std::vector< uint64_t > &labels) const
RTPS_DllAPI ReturnCode_t copy_from(const MemberDescriptor *other)
RTPS_DllAPI std::string get_name() const
RTPS_DllAPI void annotation_set_bit_bound(uint16_t bit_bound)
RTPS_DllAPI void annotation_set_optional(bool optional)
std::string default_value_
Definition: MemberDescriptor.h:34
RTPS_DllAPI void annotation_set_must_understand(bool must_understand)
RTPS_DllAPI MemberDescriptor(uint32_t index, const std::string &name)
RTPS_DllAPI void set_default_union_value(bool bDefault)
RTPS_DllAPI void set_type(DynamicType_ptr type)
RTPS_DllAPI MemberDescriptor(MemberId id, const std::string &name, DynamicType_ptr type_, const std::string &defaultValue, const std::vector< uint64_t > &unionLabels, bool isDefaultLabel)
RTPS_DllAPI DynamicType_ptr get_type() const
Definition: MemberDescriptor.h:120
RTPS_DllAPI void annotation_set_non_serialized(bool non_serialized)
RTPS_DllAPI uint32_t get_index() const
RTPS_DllAPI bool annotation_is_non_serialized() const
RTPS_DllAPI void set_default_value(const std::string &value)
Definition: MemberDescriptor.h:127
RTPS_DllAPI bool equals(const MemberDescriptor *other) const
RTPS_DllAPI MemberDescriptor(MemberId id, const std::string &name, DynamicType_ptr type_)
RTPS_DllAPI void annotation_set_key(bool key)
MemberId id_
Definition: MemberDescriptor.h:32
bool is_type_name_consistent(const std::string &sName) const
RTPS_DllAPI bool is_default_union_value() const
std::vector< uint64_t > labels_
Definition: MemberDescriptor.h:36
RTPS_DllAPI void set_index(uint32_t index)
ReturnCode_t apply_annotation(const std::string &annotation_name, const std::string &key, const std::string &value)
RTPS_DllAPI MemberId get_id() const
RTPS_DllAPI std::string get_default_value() const
Definition: MemberDescriptor.h:96
RTPS_DllAPI bool annotation_get_key() const
RTPS_DllAPI bool annotation_is_value() const
RTPS_DllAPI MemberDescriptor(MemberId id, const std::string &name, DynamicType_ptr type_, const std::string &defaultValue)
RTPS_DllAPI MemberDescriptor(const MemberDescriptor *descriptor)
RTPS_DllAPI bool annotation_is_optional() const
RTPS_DllAPI void set_id(MemberId id)
RTPS_DllAPI uint16_t annotation_get_bit_bound() const
std::vector< AnnotationDescriptor * > annotation_
Definition: MemberDescriptor.h:39
RTPS_DllAPI std::vector< uint64_t > get_union_labels() const
RTPS_DllAPI bool annotation_is_must_understand() const
AnnotationDescriptor * get_annotation(const std::string &name) const
RTPS_DllAPI void set_name(const std::string &name)
RTPS_DllAPI std::string annotation_get_value() const
Definition: TypesBase.h:204
Definition: TypeObjectFactory.h:29
uint32_t MemberId
Definition: TypesBase.h:272
octet TypeKind
Definition: TypesBase.h:115
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23