DynamicType.h 4.6 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_H
  15. #define TYPES_DYNAMIC_TYPE_H
  16. #include <fastrtps/types/TypesBase.h>
  17. #include <fastrtps/types/DynamicTypePtr.h>
  18. namespace eprosima {
  19. namespace fastdds {
  20. namespace dds {
  21. class DomainParticipantImpl;
  22. } // namespace dds
  23. } // namespace fastdds
  24. namespace fastrtps {
  25. namespace types {
  26. class AnnotationDescriptor;
  27. class TypeDescriptor;
  28. class DynamicTypeMember;
  29. class DynamicTypeBuilder;
  30. class DynamicType
  31. {
  32. protected:
  33. friend class DynamicTypeBuilder;
  34. friend class DynamicTypeBuilderFactory;
  35. friend class MemberDescriptor;
  36. friend class TypeDescriptor;
  37. friend class DynamicData;
  38. friend class DynamicDataFactory;
  39. friend class AnnotationDescriptor;
  40. friend class TypeObjectFactory;
  41. friend class DynamicTypeMember;
  42. friend class DynamicDataHelper;
  43. friend class fastdds::dds::DomainParticipantImpl;
  44. DynamicType();
  45. DynamicType(const TypeDescriptor* descriptor);
  46. DynamicType(const DynamicTypeBuilder* other);
  47. virtual ~DynamicType();
  48. virtual void clear();
  49. ReturnCode_t copy_from_builder(const DynamicTypeBuilder* other);
  50. // Checks if there is a member with the given name.
  51. bool exists_member_by_name(const std::string& name) const;
  52. // This method is used by Dynamic Data to override the name of the types based on ALIAS.
  53. void set_name(const std::string& name);
  54. ReturnCode_t apply_annotation(AnnotationDescriptor& descriptor);
  55. ReturnCode_t apply_annotation(
  56. const std::string& annotation_name,
  57. const std::string& key,
  58. const std::string& value);
  59. ReturnCode_t apply_annotation_to_member(
  60. MemberId id,
  61. AnnotationDescriptor& descriptor);
  62. ReturnCode_t apply_annotation_to_member(
  63. MemberId id,
  64. const std::string& annotation_name,
  65. const std::string& key,
  66. const std::string& value);
  67. ReturnCode_t get_annotation(
  68. AnnotationDescriptor& descriptor,
  69. uint32_t idx);
  70. uint32_t get_annotation_count();
  71. DynamicType_ptr get_base_type() const;
  72. DynamicType_ptr get_discriminator_type() const;
  73. DynamicType_ptr get_element_type() const;
  74. DynamicType_ptr get_key_element_type() const;
  75. ReturnCode_t get_member(
  76. DynamicTypeMember& member,
  77. MemberId id);
  78. ReturnCode_t get_member_by_name(
  79. DynamicTypeMember& member,
  80. const std::string& name);
  81. TypeDescriptor* descriptor_;
  82. std::map<MemberId, DynamicTypeMember*> member_by_id_; // Aggregated members
  83. std::map<std::string, DynamicTypeMember*> member_by_name_; // Uses the pointers from "member_by_id_".
  84. std::string name_;
  85. TypeKind kind_;
  86. bool is_key_defined_;
  87. public:
  88. RTPS_DllAPI bool equals(const DynamicType* other) const;
  89. RTPS_DllAPI ReturnCode_t get_all_members(std::map<MemberId, DynamicTypeMember*>& members);
  90. RTPS_DllAPI ReturnCode_t get_all_members_by_name(std::map<std::string, DynamicTypeMember*>& members);
  91. RTPS_DllAPI uint32_t get_bounds(uint32_t index = 0) const;
  92. RTPS_DllAPI uint32_t get_bounds_size() const;
  93. RTPS_DllAPI ReturnCode_t get_descriptor(TypeDescriptor* descriptor) const;
  94. RTPS_DllAPI const TypeDescriptor* get_descriptor() const;
  95. RTPS_DllAPI TypeDescriptor* get_descriptor();
  96. RTPS_DllAPI bool key_annotation() const;
  97. RTPS_DllAPI inline TypeKind get_kind() const
  98. {
  99. return kind_;
  100. }
  101. RTPS_DllAPI std::string get_name() const;
  102. RTPS_DllAPI MemberId get_members_count() const;
  103. RTPS_DllAPI uint32_t get_total_bounds() const;
  104. RTPS_DllAPI const TypeDescriptor* get_type_descriptor() const
  105. {
  106. return descriptor_;
  107. }
  108. RTPS_DllAPI bool has_children() const;
  109. RTPS_DllAPI bool is_consistent() const;
  110. RTPS_DllAPI bool is_complex_kind() const;
  111. RTPS_DllAPI bool is_discriminator_type() const;
  112. RTPS_DllAPI size_t get_size() const;
  113. };
  114. } // namespace types
  115. } // namespace fastrtps
  116. } // namespace eprosima
  117. #endif // TYPES_DYNAMIC_TYPE_H