DynamicTypeBuilder.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_DYNAMIC_TYPE_BUILDER_H
  15. #define TYPES_DYNAMIC_TYPE_BUILDER_H
  16. #include <fastrtps/types/TypesBase.h>
  17. #include <fastrtps/types/DynamicTypePtr.h>
  18. namespace eprosima {
  19. namespace fastrtps {
  20. namespace types {
  21. class AnnotationDescriptor;
  22. class TypeDescriptor;
  23. class MemberDescriptor;
  24. class DynamicType;
  25. class DynamicTypeMember;
  26. class DynamicTypeBuilder
  27. {
  28. protected:
  29. DynamicTypeBuilder();
  30. DynamicTypeBuilder(const DynamicTypeBuilder* builder);
  31. DynamicTypeBuilder(const TypeDescriptor* descriptor);
  32. virtual ~DynamicTypeBuilder();
  33. friend class DynamicType;
  34. friend class DynamicTypeBuilderFactory;
  35. TypeDescriptor* descriptor_;
  36. std::map<MemberId, DynamicTypeMember*> member_by_id_; // Aggregated members
  37. std::map<std::string, DynamicTypeMember*> member_by_name_; // Uses the pointers from "member_by_id_".
  38. std::string name_;
  39. TypeKind kind_;
  40. MemberId current_member_id_;
  41. uint32_t max_index_;
  42. ReturnCode_t _apply_annotation_to_member(
  43. MemberId id,
  44. AnnotationDescriptor& descriptor);
  45. ReturnCode_t _apply_annotation_to_member(
  46. MemberId id,
  47. const std::string& annotation_name,
  48. const std::string& key,
  49. const std::string& value);
  50. bool check_union_configuration(const MemberDescriptor* descriptor);
  51. // Checks if there is a member with the given name.
  52. bool exists_member_by_name(const std::string& name) const;
  53. void refresh_member_ids();
  54. void clear();
  55. ReturnCode_t copy_from_builder(const DynamicTypeBuilder* other);
  56. public:
  57. RTPS_DllAPI ReturnCode_t add_empty_member(
  58. uint32_t index,
  59. const std::string& name);
  60. RTPS_DllAPI ReturnCode_t add_member(const MemberDescriptor* descriptor);
  61. RTPS_DllAPI ReturnCode_t add_member(
  62. MemberId id,
  63. const std::string& name,
  64. DynamicTypeBuilder* type_ = nullptr);
  65. RTPS_DllAPI ReturnCode_t add_member(
  66. MemberId id,
  67. const std::string& name,
  68. DynamicTypeBuilder* type_,
  69. const std::string& defaultValue);
  70. RTPS_DllAPI ReturnCode_t add_member(
  71. MemberId id,
  72. const std::string& name,
  73. DynamicTypeBuilder* type_,
  74. const std::string& defaultValue,
  75. const std::vector<uint64_t>& unionLabels,
  76. bool isDefaultLabel);
  77. RTPS_DllAPI ReturnCode_t add_member(
  78. MemberId id,
  79. const std::string& name,
  80. DynamicType_ptr type_ = DynamicType_ptr(nullptr));
  81. RTPS_DllAPI ReturnCode_t add_member(
  82. MemberId id,
  83. const std::string& name,
  84. DynamicType_ptr type_,
  85. const std::string& defaultValue);
  86. RTPS_DllAPI ReturnCode_t add_member(
  87. MemberId id,
  88. const std::string& name,
  89. DynamicType_ptr type_,
  90. const std::string& defaultValue,
  91. const std::vector<uint64_t>& unionLabels,
  92. bool isDefaultLabel);
  93. RTPS_DllAPI ReturnCode_t apply_annotation(AnnotationDescriptor& descriptor);
  94. RTPS_DllAPI ReturnCode_t apply_annotation(
  95. const std::string& annotation_name,
  96. const std::string& key,
  97. const std::string& value);
  98. RTPS_DllAPI ReturnCode_t apply_annotation_to_member(
  99. MemberId id,
  100. AnnotationDescriptor& descriptor);
  101. RTPS_DllAPI ReturnCode_t apply_annotation_to_member(
  102. MemberId id,
  103. const std::string& annotation_name,
  104. const std::string& key,
  105. const std::string& value);
  106. RTPS_DllAPI DynamicType_ptr build();
  107. RTPS_DllAPI ReturnCode_t copy_from(const DynamicTypeBuilder* other);
  108. ReturnCode_t get_all_members(std::map<MemberId, DynamicTypeMember*>& members);
  109. RTPS_DllAPI inline TypeKind get_kind() const
  110. {
  111. return kind_;
  112. }
  113. RTPS_DllAPI std::string get_name() const;
  114. RTPS_DllAPI MemberId get_member_id_by_name(const std::string& name) const;
  115. const TypeDescriptor* get_type_descriptor() const
  116. {
  117. return descriptor_;
  118. }
  119. bool is_consistent() const;
  120. bool is_discriminator_type() const;
  121. RTPS_DllAPI ReturnCode_t set_name(const std::string& name);
  122. };
  123. } // namespace types
  124. } // namespace fastrtps
  125. } // namespace eprosima
  126. #endif // TYPES_DYNAMIC_TYPE_BUILDER_H