DynamicTypeBuilderFactory.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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_FACTORY_H
  15. #define TYPES_DYNAMIC_TYPE_BUILDER_FACTORY_H
  16. #include <fastrtps/types/TypesBase.h>
  17. #include <fastrtps/types/AnnotationParameterValue.h>
  18. #include <fastrtps/types/DynamicTypePtr.h>
  19. #include <mutex>
  20. //#define DISABLE_DYNAMIC_MEMORY_CHECK
  21. namespace eprosima {
  22. namespace fastrtps {
  23. namespace types {
  24. class AnnotationDescriptor;
  25. class DynamicTypeBuilder;
  26. class TypeDescriptor;
  27. class TypeIdentifier;
  28. class MemberDescriptor;
  29. class TypeObject;
  30. class DynamicType;
  31. class DynamicType_ptr;
  32. class AnnotationParameterValue;
  33. class DynamicTypeBuilderFactory
  34. {
  35. protected:
  36. DynamicTypeBuilderFactory();
  37. inline void add_builder_to_list(DynamicTypeBuilder* pBuilder);
  38. DynamicType_ptr build_type(DynamicType_ptr other);
  39. void build_alias_type_code(
  40. const TypeDescriptor* descriptor,
  41. TypeObject& object,
  42. bool complete = true) const;
  43. void build_string8_type_code(
  44. const TypeDescriptor* descriptor) const;
  45. void build_string16_type_code(
  46. const TypeDescriptor* descriptor) const;
  47. void build_sequence_type_code(
  48. const TypeDescriptor* descriptor,
  49. TypeObject& object,
  50. bool complete = true) const;
  51. void build_array_type_code(
  52. const TypeDescriptor* descriptor,
  53. TypeObject& object,
  54. bool complete = true) const;
  55. void build_map_type_code(
  56. const TypeDescriptor* descriptor,
  57. TypeObject& object,
  58. bool complete = true) const;
  59. void build_enum_type_code(
  60. const TypeDescriptor* descriptor,
  61. TypeObject& object,
  62. const std::vector<const MemberDescriptor*> members,
  63. bool complete = true) const;
  64. void build_struct_type_code(
  65. const TypeDescriptor* descriptor,
  66. TypeObject& object,
  67. const std::vector<const MemberDescriptor*> members,
  68. bool complete = true) const;
  69. void build_union_type_code(
  70. const TypeDescriptor* descriptor,
  71. TypeObject& object,
  72. const std::vector<const MemberDescriptor*> members,
  73. bool complete = true) const;
  74. void build_bitset_type_code(
  75. const TypeDescriptor* descriptor,
  76. TypeObject& object,
  77. const std::vector<const MemberDescriptor*> members,
  78. bool complete = true) const;
  79. void build_bitmask_type_code(
  80. const TypeDescriptor* descriptor,
  81. TypeObject& object,
  82. const std::vector<const MemberDescriptor*> members,
  83. bool complete = true) const;
  84. void build_annotation_type_code(
  85. const TypeDescriptor* descriptor,
  86. TypeObject& object,
  87. const std::vector<const MemberDescriptor*> members,
  88. bool complete = true) const;
  89. void set_annotation_default_value(
  90. AnnotationParameterValue& apv,
  91. const MemberDescriptor* member) const;
  92. void apply_type_annotations(
  93. AppliedAnnotationSeq& annotations,
  94. const TypeDescriptor* descriptor) const;
  95. #ifndef DISABLE_DYNAMIC_MEMORY_CHECK
  96. std::vector<DynamicTypeBuilder*> builders_list_;
  97. mutable std::recursive_mutex mutex_;
  98. #endif
  99. public:
  100. RTPS_DllAPI static DynamicTypeBuilderFactory* get_instance();
  101. RTPS_DllAPI static ReturnCode_t delete_instance();
  102. ~DynamicTypeBuilderFactory();
  103. RTPS_DllAPI DynamicType_ptr get_primitive_type(TypeKind kind);
  104. RTPS_DllAPI ReturnCode_t delete_builder(DynamicTypeBuilder* builder);
  105. RTPS_DllAPI ReturnCode_t delete_type(DynamicType* type);
  106. RTPS_DllAPI DynamicTypeBuilder* create_custom_builder(
  107. const TypeDescriptor* descriptor,
  108. const std::string& name = "");
  109. RTPS_DllAPI DynamicTypeBuilder* create_builder_copy(const DynamicTypeBuilder* type);
  110. RTPS_DllAPI DynamicTypeBuilder* create_int32_builder();
  111. RTPS_DllAPI DynamicTypeBuilder* create_uint32_builder();
  112. RTPS_DllAPI DynamicTypeBuilder* create_int16_builder();
  113. RTPS_DllAPI DynamicTypeBuilder* create_uint16_builder();
  114. RTPS_DllAPI DynamicTypeBuilder* create_int64_builder();
  115. RTPS_DllAPI DynamicTypeBuilder* create_uint64_builder();
  116. RTPS_DllAPI DynamicTypeBuilder* create_float32_builder();
  117. RTPS_DllAPI DynamicTypeBuilder* create_float64_builder();
  118. RTPS_DllAPI DynamicTypeBuilder* create_float128_builder();
  119. RTPS_DllAPI DynamicTypeBuilder* create_char8_builder();
  120. RTPS_DllAPI DynamicTypeBuilder* create_char16_builder();
  121. RTPS_DllAPI DynamicTypeBuilder* create_bool_builder();
  122. RTPS_DllAPI DynamicTypeBuilder* create_byte_builder();
  123. RTPS_DllAPI DynamicTypeBuilder* create_string_builder(uint32_t bound = MAX_STRING_LENGTH);
  124. RTPS_DllAPI DynamicTypeBuilder* create_wstring_builder(uint32_t bound = MAX_STRING_LENGTH);
  125. RTPS_DllAPI DynamicTypeBuilder* create_sequence_builder(
  126. const DynamicTypeBuilder* element_type,
  127. uint32_t bound = MAX_ELEMENTS_COUNT);
  128. RTPS_DllAPI DynamicTypeBuilder* create_sequence_builder(
  129. const DynamicType_ptr type,
  130. uint32_t bound = MAX_ELEMENTS_COUNT);
  131. RTPS_DllAPI DynamicTypeBuilder* create_array_builder(
  132. const DynamicTypeBuilder* element_type,
  133. const std::vector<uint32_t>& bounds);
  134. RTPS_DllAPI DynamicTypeBuilder* create_array_builder(
  135. const DynamicType_ptr type,
  136. const std::vector<uint32_t>& bounds);
  137. RTPS_DllAPI DynamicTypeBuilder* create_map_builder(
  138. DynamicTypeBuilder* key_element_type,
  139. DynamicTypeBuilder* element_type,
  140. uint32_t bound = MAX_ELEMENTS_COUNT);
  141. RTPS_DllAPI DynamicTypeBuilder* create_map_builder(
  142. DynamicType_ptr key_type,
  143. DynamicType_ptr value_type,
  144. uint32_t bound = MAX_ELEMENTS_COUNT);
  145. RTPS_DllAPI DynamicTypeBuilder* create_bitmask_builder(uint32_t bound);
  146. RTPS_DllAPI DynamicTypeBuilder* create_bitset_builder();
  147. RTPS_DllAPI DynamicTypeBuilder* create_alias_builder(
  148. DynamicTypeBuilder* base_type,
  149. const std::string& sName);
  150. RTPS_DllAPI DynamicTypeBuilder* create_alias_builder(
  151. DynamicType_ptr base_type,
  152. const std::string& sName);
  153. RTPS_DllAPI DynamicTypeBuilder* create_enum_builder();
  154. RTPS_DllAPI DynamicTypeBuilder* create_struct_builder();
  155. RTPS_DllAPI DynamicTypeBuilder* create_child_struct_builder(DynamicTypeBuilder* parent_type);
  156. RTPS_DllAPI DynamicTypeBuilder* create_union_builder(DynamicTypeBuilder* discriminator_type);
  157. RTPS_DllAPI DynamicTypeBuilder* create_union_builder(DynamicType_ptr discriminator_type);
  158. RTPS_DllAPI DynamicType_ptr create_annotation_primitive(const std::string& name);
  159. RTPS_DllAPI DynamicType_ptr create_type(
  160. const TypeDescriptor* descriptor,
  161. const std::string& name = "");
  162. RTPS_DllAPI DynamicType_ptr create_type(const DynamicTypeBuilder* other);
  163. RTPS_DllAPI DynamicType_ptr create_alias_type(
  164. DynamicTypeBuilder* base_type,
  165. const std::string& sName);
  166. RTPS_DllAPI DynamicType_ptr create_alias_type(
  167. DynamicType_ptr base_type,
  168. const std::string& sName);
  169. RTPS_DllAPI DynamicType_ptr create_int32_type();
  170. RTPS_DllAPI DynamicType_ptr create_uint32_type();
  171. RTPS_DllAPI DynamicType_ptr create_int16_type();
  172. RTPS_DllAPI DynamicType_ptr create_uint16_type();
  173. RTPS_DllAPI DynamicType_ptr create_int64_type();
  174. RTPS_DllAPI DynamicType_ptr create_uint64_type();
  175. RTPS_DllAPI DynamicType_ptr create_float32_type();
  176. RTPS_DllAPI DynamicType_ptr create_float64_type();
  177. RTPS_DllAPI DynamicType_ptr create_float128_type();
  178. RTPS_DllAPI DynamicType_ptr create_char8_type();
  179. RTPS_DllAPI DynamicType_ptr create_char16_type();
  180. RTPS_DllAPI DynamicType_ptr create_bool_type();
  181. RTPS_DllAPI DynamicType_ptr create_byte_type();
  182. RTPS_DllAPI DynamicType_ptr create_string_type(uint32_t bound = MAX_STRING_LENGTH);
  183. RTPS_DllAPI DynamicType_ptr create_wstring_type(uint32_t bound = MAX_STRING_LENGTH);
  184. RTPS_DllAPI DynamicType_ptr create_bitset_type(uint32_t bound);
  185. RTPS_DllAPI void build_type_identifier(
  186. const DynamicType_ptr type,
  187. TypeIdentifier& identifier,
  188. bool complete = true) const;
  189. RTPS_DllAPI void build_type_identifier(
  190. const TypeDescriptor* descriptor,
  191. TypeIdentifier& identifier,
  192. bool complete = true) const;
  193. RTPS_DllAPI void build_type_object(
  194. const DynamicType_ptr type,
  195. TypeObject& object,
  196. bool complete = true,
  197. bool force = false) const;
  198. RTPS_DllAPI void build_type_object(
  199. const TypeDescriptor* descriptor,
  200. TypeObject& object,
  201. const std::vector<const MemberDescriptor*>* members = nullptr,
  202. bool complete = true,
  203. bool force = false) const;
  204. RTPS_DllAPI bool is_empty() const;
  205. };
  206. } // namespace types
  207. } // namespace fastrtps
  208. } // namespace eprosima
  209. #endif // TYPES_DYNAMIC_TYPE_BUILDER_FACTORY_H