Zserio C++17 runtime library  0.5.0
Built for Zserio 2.17.0
ITypeInfo.h
Go to the documentation of this file.
1 #ifndef ZSERIO_I_TYPE_INFO_INC_H
2 #define ZSERIO_I_TYPE_INFO_INC_H
3 
4 #include <string_view>
5 
7 #include "zserio/Span.h"
8 #include "zserio/Traits.h"
9 
10 namespace zserio
11 {
12 
14 enum class CppType
15 {
16  BOOL,
17  INT8,
18  INT16,
19  INT32,
20  INT64,
21  UINT8,
22  UINT16,
23  UINT32,
24  UINT64,
25  FLOAT,
26  DOUBLE,
27  BYTES,
28  STRING,
29  BIT_BUFFER,
30  ENUM,
31  BITMASK,
32  STRUCT,
33  CHOICE,
34  UNION,
35  SQL_TABLE,
36  SQL_DATABASE,
37  SERVICE,
38  PUBSUB
39 };
40 
41 // TODO[Mi-L@]: Do we still need STD integers?
42 // Currently not used since runtime won't recognize bit:16 and uint16.
44 enum class SchemaType
45 {
46  BOOL,
47  INT1,
48  INT2,
49  INT3,
50  INT4,
51  INT5,
52  INT6,
53  INT7,
54  INT8,
55  INT9,
56  INT10,
57  INT11,
58  INT12,
59  INT13,
60  INT14,
61  INT15,
62  INT16,
63  INT17,
64  INT18,
65  INT19,
66  INT20,
67  INT21,
68  INT22,
69  INT23,
70  INT24,
71  INT25,
72  INT26,
73  INT27,
74  INT28,
75  INT29,
76  INT30,
77  INT31,
78  INT32,
79  INT33,
80  INT34,
81  INT35,
82  INT36,
83  INT37,
84  INT38,
85  INT39,
86  INT40,
87  INT41,
88  INT42,
89  INT43,
90  INT44,
91  INT45,
92  INT46,
93  INT47,
94  INT48,
95  INT49,
96  INT50,
97  INT51,
98  INT52,
99  INT53,
100  INT54,
101  INT55,
102  INT56,
103  INT57,
104  INT58,
105  INT59,
106  INT60,
107  INT61,
108  INT62,
109  INT63,
110  INT64,
111  UINT1,
112  UINT2,
113  UINT3,
114  UINT4,
115  UINT5,
116  UINT6,
117  UINT7,
118  UINT8,
119  UINT9,
120  UINT10,
121  UINT11,
122  UINT12,
123  UINT13,
124  UINT14,
125  UINT15,
126  UINT16,
127  UINT17,
128  UINT18,
129  UINT19,
130  UINT20,
131  UINT21,
132  UINT22,
133  UINT23,
134  UINT24,
135  UINT25,
136  UINT26,
137  UINT27,
138  UINT28,
139  UINT29,
140  UINT30,
141  UINT31,
142  UINT32,
143  UINT33,
144  UINT34,
145  UINT35,
146  UINT36,
147  UINT37,
148  UINT38,
149  UINT39,
150  UINT40,
151  UINT41,
152  UINT42,
153  UINT43,
154  UINT44,
155  UINT45,
156  UINT46,
157  UINT47,
158  UINT48,
159  UINT49,
160  UINT50,
161  UINT51,
162  UINT52,
163  UINT53,
164  UINT54,
165  UINT55,
166  UINT56,
167  UINT57,
168  UINT58,
169  UINT59,
170  UINT60,
171  UINT61,
172  UINT62,
173  UINT63,
174  UINT64,
175  VARINT16,
176  VARINT32,
177  VARINT64,
178  VARINT,
179  VARUINT16,
180  VARUINT32,
181  VARUINT64,
182  VARUINT,
183  VARSIZE,
186  FLOAT16,
187  FLOAT32,
188  FLOAT64,
189  BYTES,
190  STRING,
191  EXTERN,
192  ENUM,
193  BITMASK,
194  STRUCT,
195  CHOICE,
196  UNION,
197  SQL_TABLE,
198  SQL_DATABASE,
199  SERVICE,
200  PUBSUB
201 };
202 
203 // forward declarations
204 template <typename ALLOC>
205 struct BasicFieldInfo;
206 template <typename ALLOC>
207 struct BasicParameterInfo;
208 template <typename ALLOC>
209 struct BasicFunctionInfo;
210 template <typename ALLOC>
211 struct BasicCaseInfo;
212 template <typename ALLOC>
213 struct BasicColumnInfo;
214 template <typename ALLOC>
215 struct BasicTableInfo;
216 struct ItemInfo;
217 template <typename ALLOC>
218 struct BasicTemplateArgumentInfo;
219 template <typename ALLOC>
220 struct BasicMessageInfo;
221 template <typename ALLOC>
222 struct BasicMethodInfo;
223 
233 template <typename ALLOC = std::allocator<uint8_t>>
235 {
236 public:
240  virtual ~IBasicTypeInfo() = default;
241 
247  virtual std::string_view getSchemaName() const = 0;
248 
254  virtual SchemaType getSchemaType() const = 0;
255 
261  virtual CppType getCppType() const = 0;
262 
263  // method for fixed size integral types
264 
272  virtual uint8_t getBitSize() const = 0;
273 
274  // methods for compound types
275 
284 
293 
302 
303  // methods for choice type
304 
312  virtual std::string_view getSelector() const = 0;
313 
322 
323  // methods for enumeration and bitmask types
324 
332  virtual const IBasicTypeInfo<ALLOC>& getUnderlyingType() const = 0;
333 
341  virtual Span<const ItemInfo> getEnumItems() const = 0;
342 
351 
352  // methods for SQL table types
353 
362 
370  virtual std::string_view getSqlConstraint() const = 0;
371 
379  virtual std::string_view getVirtualTableUsing() const = 0;
380 
388  virtual bool isWithoutRowId() const = 0;
389 
390  // method for SQL database type
391 
400 
401  // methods for templatable types
402 
410  virtual std::string_view getTemplateName() const = 0;
411 
420 
421  // method for pubsub type
422 
431 
432  // method for service type
433 
442 
452  virtual IBasicReflectableDataPtr<ALLOC> createInstance(const ALLOC& allocator) const = 0;
453 
464 };
465 
469 template <typename ALLOC = std::allocator<uint8_t>>
471 {
472  BasicFieldInfo(std::string_view schemaName_, const IBasicTypeInfo<ALLOC>& typeInfo_,
473  Span<const std::string_view> typeArguments_, bool isExtended_, std::string_view alignment_,
474  std::string_view offset_, std::string_view initializer_, bool isOptional_,
475  std::string_view optionalCondition_, std::string_view constraint_, bool isArray_,
476  std::string_view arrayLength_, bool isPacked_, bool isImplicit_) :
477  schemaName(schemaName_),
478  typeInfo(typeInfo_),
479  typeArguments(typeArguments_),
480  isExtended(isExtended_),
481  alignment(alignment_),
482  offset(offset_),
483  initializer(initializer_),
484  isOptional(isOptional_),
485  optionalCondition(optionalCondition_),
486  constraint(constraint_),
487  isArray(isArray_),
488  arrayLength(arrayLength_),
489  isPacked(isPacked_),
490  isImplicit(isImplicit_)
491  {}
492 
493  std::string_view schemaName;
496  bool isExtended;
497  std::string_view alignment;
498  std::string_view offset;
499  std::string_view initializer;
500  bool isOptional;
501  std::string_view optionalCondition;
502  std::string_view constraint;
503  bool isArray;
504  std::string_view arrayLength;
505  bool isPacked;
506  bool isImplicit;
507 };
508 
512 template <typename ALLOC = std::allocator<uint8_t>>
514 {
515  std::string_view schemaName;
517 };
518 
522 template <typename ALLOC = std::allocator<uint8_t>>
524 {
525  std::string_view schemaName;
527  std::string_view functionResult;
528 };
529 
533 template <typename ALLOC = std::allocator<uint8_t>>
535 {
538 };
539 
543 struct ItemInfo
544 {
545  ItemInfo(std::string_view schemaName_, uint64_t value_, bool isDeprecated_, bool isRemoved_) :
546  schemaName(schemaName_),
547  value(value_),
548  isDeprecated(isDeprecated_),
549  isRemoved(isRemoved_)
550  {}
551 
552  std::string_view schemaName;
553  uint64_t value;
555  bool isRemoved;
556 };
557 
561 template <typename ALLOC = std::allocator<uint8_t>>
563 {
564  BasicColumnInfo(std::string_view schemaName_, const IBasicTypeInfo<ALLOC>& typeInfo_,
565  Span<const std::string_view> typeArguments_, std::string_view sqlTypeName_,
566  std::string_view sqlConstraint_, bool isVirtual_) :
567  schemaName(schemaName_),
568  typeInfo(typeInfo_),
569  typeArguments(typeArguments_),
570  sqlTypeName(sqlTypeName_),
571  sqlConstraint(sqlConstraint_),
572  isVirtual(isVirtual_)
573  {}
574 
575  std::string_view schemaName;
578  std::string_view sqlTypeName;
579  std::string_view sqlConstraint;
580  bool isVirtual;
581 };
582 
586 template <typename ALLOC = std::allocator<uint8_t>>
588 {
589  std::string_view schemaName;
591 };
592 
596 template <typename ALLOC = std::allocator<uint8_t>>
598 {
600 };
601 
605 template <typename ALLOC = std::allocator<uint8_t>>
607 {
608  BasicMessageInfo(std::string_view schemaName_, const IBasicTypeInfo<ALLOC>& typeInfo_, bool isPublished_,
609  bool isSubscribed_, std::string_view topic_) :
610  schemaName(schemaName_),
611  typeInfo(typeInfo_),
612  isPublished(isPublished_),
613  isSubscribed(isSubscribed_),
614  topic(topic_)
615  {}
616 
617  std::string_view schemaName;
619  bool isPublished;
621  std::string_view topic;
622 };
623 
627 template <typename ALLOC = std::allocator<uint8_t>>
629 {
631  std::string_view schemaName;
636 };
637 
638 namespace detail
639 {
640 
642 template <typename T, typename ALLOC>
643 struct TypeInfo;
644 
645 template <typename T, typename V = void>
646 struct type_info_default_alloc
647 {
648  using type = std::allocator<uint8_t>;
649 };
650 
651 template <typename T>
652 struct type_info_default_alloc<T, std::enable_if_t<has_allocator_v<T>>>
653 {
654  using type = RebindAlloc<typename T::allocator_type, uint8_t>;
655 };
656 
657 template <typename T, typename V = void>
658 using type_info_default_alloc_t = typename type_info_default_alloc<T, V>::type;
659 
660 } // namespace detail
661 
667 template <typename T, typename ALLOC = detail::type_info_default_alloc_t<T>>
669 {
671 }
672 
687 } // namespace zserio
688 
689 #endif // ZSERIO_I_TYPE_INFO_INC_H
virtual Span< const BasicMethodInfo< ALLOC > > getMethods() const =0
virtual Span< const BasicTemplateArgumentInfo< ALLOC > > getTemplateArguments() const =0
virtual Span< const BasicCaseInfo< ALLOC > > getCases() const =0
virtual ~IBasicTypeInfo()=default
virtual Span< const BasicFieldInfo< ALLOC > > getFields() const =0
virtual std::string_view getVirtualTableUsing() const =0
virtual uint8_t getBitSize() const =0
virtual bool isWithoutRowId() const =0
virtual Span< const BasicParameterInfo< ALLOC > > getParameters() const =0
virtual IBasicReflectableDataPtr< ALLOC > createInstance(const ALLOC &allocator) const =0
virtual const IBasicTypeInfo< ALLOC > & getUnderlyingType() const =0
virtual std::string_view getSqlConstraint() const =0
virtual Span< const BasicMessageInfo< ALLOC > > getMessages() const =0
virtual Span< const BasicTableInfo< ALLOC > > getTables() const =0
virtual std::string_view getTemplateName() const =0
virtual Span< const BasicFunctionInfo< ALLOC > > getFunctions() const =0
virtual IBasicReflectableDataPtr< ALLOC > createInstance() const =0
virtual Span< const BasicColumnInfo< ALLOC > > getColumns() const =0
virtual CppType getCppType() const =0
virtual Span< const ItemInfo > getEnumItems() const =0
virtual SchemaType getSchemaType() const =0
virtual std::string_view getSelector() const =0
virtual Span< const ItemInfo > getBitmaskValues() const =0
virtual std::string_view getSchemaName() const =0
Definition: BitBuffer.h:602
typename IBasicReflectableData< ALLOC >::Ptr IBasicReflectableDataPtr
decltype(auto) get(BasicVariant< ALLOC, INDEX, T... > &var)
Definition: Variant.h:812
SchemaType
Definition: ITypeInfo.h:45
const IBasicTypeInfo< ALLOC > & typeInfo()
Definition: ITypeInfo.h:668
const BasicFieldInfo< ALLOC > * field
Definition: ITypeInfo.h:537
Span< const std::string_view > caseExpressions
Definition: ITypeInfo.h:536
std::string_view schemaName
Definition: ITypeInfo.h:575
Span< const std::string_view > typeArguments
Definition: ITypeInfo.h:577
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:576
std::string_view sqlConstraint
Definition: ITypeInfo.h:579
BasicColumnInfo(std::string_view schemaName_, const IBasicTypeInfo< ALLOC > &typeInfo_, Span< const std::string_view > typeArguments_, std::string_view sqlTypeName_, std::string_view sqlConstraint_, bool isVirtual_)
Definition: ITypeInfo.h:564
std::string_view sqlTypeName
Definition: ITypeInfo.h:578
std::string_view arrayLength
Definition: ITypeInfo.h:504
std::string_view constraint
Definition: ITypeInfo.h:502
BasicFieldInfo(std::string_view schemaName_, const IBasicTypeInfo< ALLOC > &typeInfo_, Span< const std::string_view > typeArguments_, bool isExtended_, std::string_view alignment_, std::string_view offset_, std::string_view initializer_, bool isOptional_, std::string_view optionalCondition_, std::string_view constraint_, bool isArray_, std::string_view arrayLength_, bool isPacked_, bool isImplicit_)
Definition: ITypeInfo.h:472
std::string_view offset
Definition: ITypeInfo.h:498
std::string_view schemaName
Definition: ITypeInfo.h:493
std::string_view initializer
Definition: ITypeInfo.h:499
Span< const std::string_view > typeArguments
Definition: ITypeInfo.h:495
std::string_view optionalCondition
Definition: ITypeInfo.h:501
std::string_view alignment
Definition: ITypeInfo.h:497
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:494
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:526
std::string_view schemaName
Definition: ITypeInfo.h:525
std::string_view functionResult
Definition: ITypeInfo.h:527
std::string_view schemaName
Definition: ITypeInfo.h:617
BasicMessageInfo(std::string_view schemaName_, const IBasicTypeInfo< ALLOC > &typeInfo_, bool isPublished_, bool isSubscribed_, std::string_view topic_)
Definition: ITypeInfo.h:608
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:618
std::string_view topic
Definition: ITypeInfo.h:621
std::string_view schemaName
Definition: ITypeInfo.h:631
const IBasicTypeInfo< ALLOC > & requestTypeInfo
Definition: ITypeInfo.h:635
const IBasicTypeInfo< ALLOC > & responseTypeInfo
Definition: ITypeInfo.h:633
std::string_view schemaName
Definition: ITypeInfo.h:515
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:516
std::string_view schemaName
Definition: ITypeInfo.h:589
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:590
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:599
uint64_t value
Definition: ITypeInfo.h:553
ItemInfo(std::string_view schemaName_, uint64_t value_, bool isDeprecated_, bool isRemoved_)
Definition: ITypeInfo.h:545
std::string_view schemaName
Definition: ITypeInfo.h:552