MemberDescriptor.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #ifndef TYPES_MEMBER_DESCRIPTOR_H
  15. #define TYPES_MEMBER_DESCRIPTOR_H
  16. #include <fastrtps/types/TypesBase.h>
  17. #include <fastrtps/types/DynamicTypePtr.h>
  18. namespace eprosima{
  19. namespace fastrtps{
  20. namespace types{
  21. class DynamicType;
  22. class AnnotationDescriptor;
  23. class MemberDescriptor
  24. {
  25. protected:
  26. std::string name_; // Name of the member
  27. MemberId id_; // MemberId, it should be filled automatically when the member is added.
  28. DynamicType_ptr type_; // Member's Type.
  29. std::string default_value_; // Default value of the member in string.
  30. uint32_t index_; // Definition order of the member inside it's parent.
  31. std::vector<uint64_t> labels_; // Case Labels for unions.
  32. bool default_label_; // TRUE if it's the default option of a union.
  33. std::vector<AnnotationDescriptor*> annotation_; // Annotations to apply
  34. friend class DynamicTypeBuilderFactory;
  35. friend class DynamicData;
  36. friend class DynamicTypeMember;
  37. friend class TypeObjectFactory;
  38. bool is_default_value_consistent(const std::string& sDefaultValue) const;
  39. bool is_type_name_consistent(const std::string& sName) const;
  40. public:
  41. RTPS_DllAPI MemberDescriptor();
  42. RTPS_DllAPI MemberDescriptor(
  43. uint32_t index,
  44. const std::string& name);
  45. RTPS_DllAPI MemberDescriptor(
  46. MemberId id,
  47. const std::string& name,
  48. DynamicType_ptr type_);
  49. RTPS_DllAPI MemberDescriptor(
  50. MemberId id,
  51. const std::string& name,
  52. DynamicType_ptr type_,
  53. const std::string& defaultValue);
  54. RTPS_DllAPI MemberDescriptor(
  55. MemberId id,
  56. const std::string& name,
  57. DynamicType_ptr type_,
  58. const std::string& defaultValue,
  59. const std::vector<uint64_t>& unionLabels,
  60. bool isDefaultLabel);
  61. RTPS_DllAPI MemberDescriptor(const MemberDescriptor* descriptor);
  62. RTPS_DllAPI ~MemberDescriptor();
  63. bool check_union_labels(const std::vector<uint64_t>& labels) const;
  64. RTPS_DllAPI ReturnCode_t copy_from(const MemberDescriptor* other);
  65. RTPS_DllAPI bool equals(const MemberDescriptor* other) const;
  66. RTPS_DllAPI TypeKind get_kind() const;
  67. RTPS_DllAPI MemberId get_id() const;
  68. RTPS_DllAPI uint32_t get_index() const;
  69. RTPS_DllAPI std::string get_name() const;
  70. RTPS_DllAPI std::vector<uint64_t> get_union_labels() const;
  71. RTPS_DllAPI std::string get_default_value() const
  72. {
  73. if (!default_value_.empty())
  74. {
  75. return default_value_;
  76. }
  77. // Try annotation
  78. return annotation_get_default();
  79. }
  80. RTPS_DllAPI bool is_default_union_value() const;
  81. RTPS_DllAPI bool is_consistent(TypeKind parentKind) const;
  82. RTPS_DllAPI void add_union_case_index(uint64_t value);
  83. RTPS_DllAPI void set_id(MemberId id);
  84. RTPS_DllAPI void set_index(uint32_t index);
  85. RTPS_DllAPI void set_name(const std::string& name);
  86. RTPS_DllAPI void set_type(DynamicType_ptr type);
  87. RTPS_DllAPI DynamicType_ptr get_type() const
  88. {
  89. return type_;
  90. }
  91. RTPS_DllAPI void set_default_union_value(bool bDefault);
  92. RTPS_DllAPI void set_default_value(const std::string& value)
  93. {
  94. default_value_ = value;
  95. }
  96. // Annotations
  97. ReturnCode_t apply_annotation(AnnotationDescriptor& descriptor);
  98. ReturnCode_t apply_annotation(
  99. const std::string& annotation_name,
  100. const std::string& key,
  101. const std::string& value);
  102. AnnotationDescriptor* get_annotation(const std::string& name) const;
  103. // Annotations application
  104. RTPS_DllAPI bool annotation_is_optional() const;
  105. RTPS_DllAPI bool annotation_is_key() const;
  106. RTPS_DllAPI bool annotation_is_must_understand() const;
  107. RTPS_DllAPI bool annotation_is_non_serialized() const;
  108. RTPS_DllAPI bool annotation_is_value() const;
  109. RTPS_DllAPI bool annotation_is_default_literal() const;
  110. RTPS_DllAPI bool annotation_is_position() const;
  111. RTPS_DllAPI bool annotation_is_bit_bound() const;
  112. // Annotations getters
  113. RTPS_DllAPI bool annotation_get_key() const;
  114. RTPS_DllAPI std::string annotation_get_value() const;
  115. RTPS_DllAPI std::string annotation_get_default() const;
  116. RTPS_DllAPI uint16_t annotation_get_position() const;
  117. RTPS_DllAPI uint16_t annotation_get_bit_bound() const;
  118. // Annotations setters
  119. RTPS_DllAPI void annotation_set_optional(bool optional);
  120. RTPS_DllAPI void annotation_set_key(bool key);
  121. RTPS_DllAPI void annotation_set_must_understand(bool must_understand);
  122. RTPS_DllAPI void annotation_set_non_serialized(bool non_serialized);
  123. RTPS_DllAPI void annotation_set_value(const std::string& value);
  124. RTPS_DllAPI void annotation_set_default(const std::string& default_value);
  125. RTPS_DllAPI void annotation_set_default_literal();
  126. RTPS_DllAPI void annotation_set_position(uint16_t position);
  127. RTPS_DllAPI void annotation_set_bit_bound(uint16_t bit_bound);
  128. };
  129. } // namespace types
  130. } // namespace fastrtps
  131. } // namespace eprosima
  132. #endif // TYPES_MEMBER_DESCRIPTOR_H