TypeDescriptor.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_TYPE_DESCRIPTOR_H
  15. #define TYPES_TYPE_DESCRIPTOR_H
  16. #include <fastrtps/types/TypesBase.h>
  17. #include <fastrtps/types/DynamicTypePtr.h>
  18. class MemberDescriptor;
  19. class DynamicType;
  20. namespace eprosima {
  21. namespace fastrtps {
  22. namespace types {
  23. class TypeDescriptor
  24. {
  25. protected:
  26. TypeKind kind_; // Type Kind.
  27. std::string name_; // Type Name.
  28. DynamicType_ptr base_type_; // SuperType of an structure or base type of an alias type.
  29. DynamicType_ptr discriminator_type_; // Discrimination type for a union.
  30. std::vector<uint32_t> bound_; // Length for strings, arrays, sequences, maps and bitmasks.
  31. DynamicType_ptr element_type_; // Value Type for arrays, sequences, maps, bitmasks.
  32. DynamicType_ptr key_element_type_; // Key Type for maps.
  33. std::vector<AnnotationDescriptor*> annotation_; // Annotations to apply
  34. void clean();
  35. bool is_type_name_consistent(const std::string& sName) const;
  36. friend class DynamicTypeBuilderFactory;
  37. friend class TypeObjectFactory;
  38. friend class DynamicType;
  39. friend class MemberDescriptor;
  40. friend class DynamicDataHelper;
  41. public:
  42. TypeDescriptor();
  43. TypeDescriptor(const TypeDescriptor* other);
  44. TypeDescriptor(
  45. const std::string& name,
  46. TypeKind kind);
  47. ~TypeDescriptor();
  48. ReturnCode_t copy_from(const TypeDescriptor* descriptor);
  49. bool equals(const TypeDescriptor* descriptor) const;
  50. bool is_consistent() const;
  51. DynamicType_ptr get_base_type() const;
  52. uint32_t get_bounds(uint32_t index = 0) const;
  53. uint32_t get_bounds_size() const;
  54. DynamicType_ptr get_discriminator_type() const;
  55. DynamicType_ptr get_element_type() const;
  56. DynamicType_ptr get_key_element_type() const;
  57. TypeKind get_kind() const;
  58. std::string get_name() const;
  59. uint32_t get_total_bounds() const;
  60. void set_kind(TypeKind kind);
  61. void set_name(std::string name);
  62. ReturnCode_t apply_annotation(AnnotationDescriptor& descriptor);
  63. ReturnCode_t apply_annotation(
  64. const std::string& annotation_name,
  65. const std::string& key,
  66. const std::string& value);
  67. AnnotationDescriptor* get_annotation(const std::string& name) const;
  68. // Annotations application
  69. bool annotation_is_extensibility() const;
  70. bool annotation_is_mutable() const;
  71. bool annotation_is_final() const;
  72. bool annotation_is_appendable() const;
  73. bool annotation_is_nested() const;
  74. bool annotation_is_bit_bound() const;
  75. bool annotation_is_key() const;
  76. bool annotation_is_non_serialized() const;
  77. // Annotation getters
  78. std::string annotation_get_extensibility() const;
  79. bool annotation_get_nested() const;
  80. uint16_t annotation_get_bit_bound() const;
  81. bool annotation_get_key() const;
  82. // Annotation setters
  83. void annotation_set_extensibility(const std::string& extensibility);
  84. void annotation_set_mutable();
  85. void annotation_set_final();
  86. void annotation_set_appendable();
  87. void annotation_set_nested(bool nested);
  88. void annotation_set_bit_bound(uint16_t bit_bound);
  89. void annotation_set_key(bool key);
  90. void annotation_set_non_serialized(bool non_serialized);
  91. };
  92. } // namespace types
  93. } // namespace fastrtps
  94. } // namespace eprosima
  95. #endif // TYPES_TYPE_DESCRIPTOR_H