Coverage Report

Created: 2026-10-19 14:15

src/zserio/TypeInfo.h
Line
Count
Source
1
#ifndef ZSERIO_TYPE_INFO_INC_H
2
#define ZSERIO_TYPE_INFO_INC_H
3
4
#include <algorithm>
5
#include <memory>
6
#include <string>
7
8
#include "zserio/AnyHolder.h"
9
#include "zserio/BitBuffer.h"
10
#include "zserio/CppRuntimeException.h"
11
#include "zserio/ITypeInfo.h"
12
#include "zserio/Types.h"
13
14
namespace zserio
15
{
16
17
/**
18
 * Type information abstract base class.
19
 *
20
 * This base class implements fully the methods getSchemaName(), getSchemaName() and getCppType(). All other
21
 * interface methods just throw an exception.
22
 */
23
template <typename ALLOC>
24
class TypeInfoBase : public IBasicTypeInfo<ALLOC>
25
{
26
public:
27
    /**
28
     * Constructor.
29
     *
30
     * \param schemaName The schema name to be stored in type information.
31
     * \param schemaType The schema type to be stored in type information.
32
     * \param cppType The C++ type to be stored in type information.
33
     */
34
    TypeInfoBase(StringView schemaName, SchemaType schemaType, CppType cppType);
35
36
    /**
37
     * Copying and moving is disallowed!
38
     * \{
39
     */
40
    TypeInfoBase(const TypeInfoBase&) = delete;
41
    TypeInfoBase& operator=(const TypeInfoBase&) = delete;
42
43
    TypeInfoBase(const TypeInfoBase&&) = delete;
44
    TypeInfoBase& operator=(const TypeInfoBase&&) = delete;
45
    /**
46
     * \}
47
     */
48
49
315
    ~TypeInfoBase() override = 0;
50
51
    StringView getSchemaName() const override;
52
    SchemaType getSchemaType() const override;
53
    CppType getCppType() const override;
54
    uint8_t getBitSize() const override;
55
56
    Span<const BasicFieldInfo<ALLOC>> getFields() const override;
57
    Span<const BasicParameterInfo<ALLOC>> getParameters() const override;
58
    Span<const BasicFunctionInfo<ALLOC>> getFunctions() const override;
59
60
    StringView getSelector() const override;
61
    Span<const BasicCaseInfo<ALLOC>> getCases() const override;
62
63
    const IBasicTypeInfo<ALLOC>& getUnderlyingType() const override;
64
    Span<const StringView> getUnderlyingTypeArguments() const override;
65
    Span<const ItemInfo> getEnumItems() const override;
66
    Span<const ItemInfo> getBitmaskValues() const override;
67
68
    Span<const BasicColumnInfo<ALLOC>> getColumns() const override;
69
    StringView getSqlConstraint() const override;
70
    StringView getVirtualTableUsing() const override;
71
    bool isWithoutRowId() const override;
72
73
    Span<const BasicTableInfo<ALLOC>> getTables() const override;
74
75
    StringView getTemplateName() const override;
76
    Span<const BasicTemplateArgumentInfo<ALLOC>> getTemplateArguments() const override;
77
78
    Span<const BasicMessageInfo<ALLOC>> getMessages() const override;
79
    Span<const BasicMethodInfo<ALLOC>> getMethods() const override;
80
81
    IBasicReflectablePtr<ALLOC> createInstance(const ALLOC& allocator) const override;
82
    IBasicReflectablePtr<ALLOC> createInstance() const override;
83
84
private:
85
    StringView m_schemaName;
86
    SchemaType m_schemaType;
87
    CppType m_cppType;
88
};
89
90
/**
91
 * Type information abstract base class for builtin types.
92
 */
93
template <typename ALLOC = std::allocator<uint8_t>>
94
class BuiltinTypeInfo : public TypeInfoBase<ALLOC>
95
{
96
protected:
97
    /**
98
     * Constructor.
99
     *
100
     * \param schemaName The schema name to be stored in type information.
101
     * \param schemaType The schema type to be stored in type information.
102
     * \param cppType The C++ type to be stored in type information.
103
     */
104
    BuiltinTypeInfo(StringView schemaName, SchemaType schemaType, CppType cppType);
105
106
public:
107
    /**
108
     * Gets the type information of bool schema type.
109
     *
110
     * \return Reference to the type information of bool schema type.
111
     */
112
    static const IBasicTypeInfo<ALLOC>& getBool();
113
114
    /**
115
     * Gets the type information of int8 schema type.
116
     *
117
     * \return Reference to the type information of int8 schema type.
118
     */
119
    static const IBasicTypeInfo<ALLOC>& getInt8();
120
121
    /**
122
     * Gets the type information of int16 schema type.
123
     *
124
     * \return Reference to the type information of int16 schema type.
125
     */
126
    static const IBasicTypeInfo<ALLOC>& getInt16();
127
128
    /**
129
     * Gets the type information of int32 schema type.
130
     *
131
     * \return Reference to the type information of int32 schema type.
132
     */
133
    static const IBasicTypeInfo<ALLOC>& getInt32();
134
135
    /**
136
     * Gets the type information of int64 schema type.
137
     *
138
     * \return Reference to the type information of int64 schema type.
139
     */
140
    static const IBasicTypeInfo<ALLOC>& getInt64();
141
142
    /**
143
     * Gets the type information of uint8 schema type.
144
     *
145
     * \return Reference to the type information of uint8 schema type.
146
     */
147
    static const IBasicTypeInfo<ALLOC>& getUInt8();
148
149
    /**
150
     * Gets the type information of uint16 schema type.
151
     *
152
     * \return Reference to the type information of uint16 schema type.
153
     */
154
    static const IBasicTypeInfo<ALLOC>& getUInt16();
155
156
    /**
157
     * Gets the type information of uint32 schema type.
158
     *
159
     * \return Reference to the type information of uint32 schema type.
160
     */
161
    static const IBasicTypeInfo<ALLOC>& getUInt32();
162
163
    /**
164
     * Gets the type information of uint64 schema type.
165
     *
166
     * \return Reference to the type information of uint64 schema type.
167
     */
168
    static const IBasicTypeInfo<ALLOC>& getUInt64();
169
170
    /**
171
     * Gets the type information of varint16 schema type.
172
     *
173
     * \return Reference to the type information of varint16 schema type.
174
     */
175
    static const IBasicTypeInfo<ALLOC>& getVarInt16();
176
177
    /**
178
     * Gets the type information of varint32 schema type.
179
     *
180
     * \return Reference to the type information of varint32 schema type.
181
     */
182
    static const IBasicTypeInfo<ALLOC>& getVarInt32();
183
184
    /**
185
     * Gets the type information of varint64 schema type.
186
     *
187
     * \return Reference to the type information of varint64 schema type.
188
     */
189
    static const IBasicTypeInfo<ALLOC>& getVarInt64();
190
191
    /**
192
     * Gets the type information of varint schema type.
193
     *
194
     * \return Reference to the type information of varint schema type.
195
     */
196
    static const IBasicTypeInfo<ALLOC>& getVarInt();
197
198
    /**
199
     * Gets the type information of varuint16 schema type.
200
     *
201
     * \return Reference to the type information of varuint16 schema type.
202
     */
203
    static const IBasicTypeInfo<ALLOC>& getVarUInt16();
204
205
    /**
206
     * Gets the type information of varuint32 schema type.
207
     *
208
     * \return Reference to the type information of varuint32 schema type.
209
     */
210
    static const IBasicTypeInfo<ALLOC>& getVarUInt32();
211
212
    /**
213
     * Gets the type information of varuint64 schema type.
214
     *
215
     * \return Reference to the type information of varuint64 schema type.
216
     */
217
    static const IBasicTypeInfo<ALLOC>& getVarUInt64();
218
219
    /**
220
     * Gets the type information of varuint schema type.
221
     *
222
     * \return Reference to the type information of varuint schema type.
223
     */
224
    static const IBasicTypeInfo<ALLOC>& getVarUInt();
225
226
    /**
227
     * Gets the type information of varsize schema type.
228
     *
229
     * \return Reference to the type information of varsize schema type.
230
     */
231
    static const IBasicTypeInfo<ALLOC>& getVarSize();
232
233
    /**
234
     * Gets the type information of float16 schema type.
235
     *
236
     * \return Reference to the type information of float16 schema type.
237
     */
238
    static const IBasicTypeInfo<ALLOC>& getFloat16();
239
240
    /**
241
     * Gets the type information of float32 schema type.
242
     *
243
     * \return Reference to the type information of float32 schema type.
244
     */
245
    static const IBasicTypeInfo<ALLOC>& getFloat32();
246
247
    /**
248
     * Gets the type information of float64 schema type.
249
     *
250
     * \return Reference to the type information of float64 schema type.
251
     */
252
    static const IBasicTypeInfo<ALLOC>& getFloat64();
253
254
    /**
255
     * Gets the type information of bytes schema type.
256
     *
257
     * \return Reference to the type information of bytes schema type.
258
     */
259
    static const IBasicTypeInfo<ALLOC>& getBytes();
260
261
    /**
262
     * Gets the type information of string schema type.
263
     *
264
     * \return Reference to the type information of string schema type.
265
     */
266
    static const IBasicTypeInfo<ALLOC>& getString();
267
268
    /**
269
     * Gets the type information of extern schema type.
270
     *
271
     * \return Reference to the type information of extern schema type.
272
     */
273
    static const IBasicTypeInfo<ALLOC>& getBitBuffer();
274
275
    /**
276
     * Gets the type information of fixed signed bit field schema type.
277
     *
278
     * \param bitSize The bit size of the bit field.
279
     *
280
     * \return Reference to the type information of fixed signed bit field schema type.
281
     */
282
    static const IBasicTypeInfo<ALLOC>& getFixedSignedBitField(uint8_t bitSize);
283
284
    /**
285
     * Gets the type information of fixed unsigned bit field schema type.
286
     *
287
     * \param bitSize The bit size of the bit field.
288
     *
289
     * \return Reference to the type information of fixed unsigned bit field schema type.
290
     */
291
    static const IBasicTypeInfo<ALLOC>& getFixedUnsignedBitField(uint8_t bitSize);
292
293
    /**
294
     * Gets the type information of dynamic signed bit field schema type.
295
     *
296
     * \param maxBitSize The maximum bit size of the dynamic bit field.
297
     *
298
     * \return Reference to the type information of dynamic signed bit field schema type.
299
     */
300
    static const IBasicTypeInfo<ALLOC>& getDynamicSignedBitField(uint8_t maxBitSize);
301
302
    /**
303
     * Gets the type information of dynamic unsigned bit field schema type.
304
     *
305
     * \param maxBitSize The maximum bit size of the dynamic bit field.
306
     *
307
     * \return Reference to the type information of dynamic unsigned bit field schema type.
308
     */
309
    static const IBasicTypeInfo<ALLOC>& getDynamicUnsignedBitField(uint8_t maxBitSize);
310
};
311
312
/**
313
 * Type information abstract base class for fixed size builtin types.
314
 */
315
template <typename ALLOC>
316
class FixedSizeBuiltinTypeInfo : public BuiltinTypeInfo<ALLOC>
317
{
318
protected:
319
    /**
320
     * Constructor.
321
     *
322
     * \param schemaName The schema name to be stored in type information.
323
     * \param schemaType The schema type to be stored in type information.
324
     * \param cppType The C++ type to be stored in type information.
325
     * \param bitSize The bit size of the fixed size integral schema type.
326
     */
327
    FixedSizeBuiltinTypeInfo(StringView schemaName, SchemaType schemaType, CppType cppType, uint8_t bitSize);
328
329
public:
330
    uint8_t getBitSize() const override;
331
332
    /**
333
     * Gets the type information of bool schema type.
334
     *
335
     * \return Reference to the type information of bool schema type.
336
     */
337
    static const IBasicTypeInfo<ALLOC>& getBool();
338
339
    /**
340
     * Gets the type information of int8 schema type.
341
     *
342
     * \return Reference to the type information of int8 schema type.
343
     */
344
    static const IBasicTypeInfo<ALLOC>& getInt8();
345
346
    /**
347
     * Gets the type information of int16 schema type.
348
     *
349
     * \return Reference to the type information of int16 schema type.
350
     */
351
    static const IBasicTypeInfo<ALLOC>& getInt16();
352
353
    /**
354
     * Gets the type information of int32 schema type.
355
     *
356
     * \return Reference to the type information of int32 schema type.
357
     */
358
    static const IBasicTypeInfo<ALLOC>& getInt32();
359
360
    /**
361
     * Gets the type information of int64 schema type.
362
     *
363
     * \return Reference to the type information of int64 schema type.
364
     */
365
    static const IBasicTypeInfo<ALLOC>& getInt64();
366
367
    /**
368
     * Gets the type information of uint8 schema type.
369
     *
370
     * \return Reference to the type information of uint8 schema type.
371
     */
372
    static const IBasicTypeInfo<ALLOC>& getUInt8();
373
374
    /**
375
     * Gets the type information of uint16 schema type.
376
     *
377
     * \return Reference to the type information of uint16 schema type.
378
     */
379
    static const IBasicTypeInfo<ALLOC>& getUInt16();
380
381
    /**
382
     * Gets the type information of uint32 schema type.
383
     *
384
     * \return Reference to the type information of uint32 schema type.
385
     */
386
    static const IBasicTypeInfo<ALLOC>& getUInt32();
387
388
    /**
389
     * Gets the type information of uint64 schema type.
390
     *
391
     * \return Reference to the type information of uint64 schema type.
392
     */
393
    static const IBasicTypeInfo<ALLOC>& getUInt64();
394
395
    /**
396
     * Gets the type information of float16 schema type.
397
     *
398
     * \return Reference to the type information of float16 schema type.
399
     */
400
    static const IBasicTypeInfo<ALLOC>& getFloat16();
401
402
    /**
403
     * Gets the type information of float32 schema type.
404
     *
405
     * \return Reference to the type information of float32 schema type.
406
     */
407
    static const IBasicTypeInfo<ALLOC>& getFloat32();
408
409
    /**
410
     * Gets the type information of float64 schema type.
411
     *
412
     * \return Reference to the type information of float64 schema type.
413
     */
414
    static const IBasicTypeInfo<ALLOC>& getFloat64();
415
416
    /**
417
     * Gets the type information of fixed signed bit field schema type.
418
     *
419
     * \param bitSize The bit size of the bit field.
420
     *
421
     * \return Reference to the type information of fixed signed bit field schema type.
422
     */
423
    static const IBasicTypeInfo<ALLOC>& getFixedSignedBitField(uint8_t bitSize);
424
425
    /**
426
     * Gets the type information of fixed unsigned bit field schema type.
427
     *
428
     * \param bitSize The bit size of the bit field.
429
     *
430
     * \return Reference to the type information of fixed unsigned bit field schema type.
431
     */
432
    static const IBasicTypeInfo<ALLOC>& getFixedUnsignedBitField(uint8_t bitSize);
433
434
private:
435
    uint8_t m_bitSize;
436
};
437
438
/**
439
 * Type information abstract base class for templatable types.
440
 */
441
template <typename ALLOC>
442
class TemplatableTypeInfoBase : public TypeInfoBase<ALLOC>
443
{
444
public:
445
    /**
446
     * Constructor.
447
     *
448
     * \param schemaName The schema name to be stored in type information.
449
     * \param schemaType The schema type to be stored in type information.
450
     * \param cppType The C++ type to be stored in type information.
451
     * \param templateName The full schema template name.
452
     * \param templateArguments The sequence of type information for template arguments.
453
     */
454
    TemplatableTypeInfoBase(StringView schemaName, SchemaType schemaType, CppType cppType,
455
            StringView templateName, Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments);
456
457
50
    ~TemplatableTypeInfoBase() override = 0;
458
459
    TemplatableTypeInfoBase(const TemplatableTypeInfoBase&) = default;
460
    TemplatableTypeInfoBase& operator=(const TemplatableTypeInfoBase&) = default;
461
462
    TemplatableTypeInfoBase(TemplatableTypeInfoBase&&) = default;
463
    TemplatableTypeInfoBase& operator=(TemplatableTypeInfoBase&&) = default;
464
465
    StringView getTemplateName() const override;
466
    Span<const BasicTemplateArgumentInfo<ALLOC>> getTemplateArguments() const override;
467
468
private:
469
    StringView m_templateName;
470
    Span<const BasicTemplateArgumentInfo<ALLOC>> m_templateArguments;
471
};
472
473
/**
474
 * Type information abstract base class for compound types.
475
 */
476
template <typename ALLOC>
477
class CompoundTypeInfoBase : public TemplatableTypeInfoBase<ALLOC>
478
{
479
public:
480
    using TypeInfoBase<ALLOC>::getSchemaName;
481
    using CreateInstanceFunc = IBasicReflectablePtr<ALLOC> (*)(const ALLOC&);
482
483
    /**
484
     * Constructor.
485
     *
486
     * \param schemaName The schema name to be stored in type information.
487
     * \param schemaType The schema type to be stored in type information.
488
     * \param cppType The C++ type to be stored in type information.
489
     * \param templateName The full schema template name.
490
     * \param templateArguments The sequence of type information for template arguments.
491
     * \param fields The sequence of type information for fields.
492
     * \param parameters The sequence of type information for parameters.
493
     * \param functions The sequence of type information for functions.
494
     */
495
    CompoundTypeInfoBase(StringView schemaName, CreateInstanceFunc createInstanceFunc, SchemaType schemaType,
496
            CppType cppType, StringView templateName,
497
            Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
498
            Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
499
            Span<const BasicFunctionInfo<ALLOC>> functions);
500
501
49
    ~CompoundTypeInfoBase() override = 0;
502
503
    CompoundTypeInfoBase(const CompoundTypeInfoBase&) = default;
504
    CompoundTypeInfoBase& operator=(const CompoundTypeInfoBase&) = default;
505
506
    CompoundTypeInfoBase(CompoundTypeInfoBase&&) = default;
507
    CompoundTypeInfoBase& operator=(CompoundTypeInfoBase&&) = default;
508
509
    Span<const BasicFieldInfo<ALLOC>> getFields() const override;
510
    Span<const BasicParameterInfo<ALLOC>> getParameters() const override;
511
    Span<const BasicFunctionInfo<ALLOC>> getFunctions() const override;
512
513
    IBasicReflectablePtr<ALLOC> createInstance(const ALLOC& allocator) const override;
514
515
private:
516
    CreateInstanceFunc m_createInstanceFunc;
517
    Span<const BasicFieldInfo<ALLOC>> m_fields;
518
    Span<const BasicParameterInfo<ALLOC>> m_parameters;
519
    Span<const BasicFunctionInfo<ALLOC>> m_functions;
520
};
521
522
/**
523
 * Type information class for structure types.
524
 */
525
template <typename ALLOC>
526
class StructTypeInfo : public CompoundTypeInfoBase<ALLOC>
527
{
528
public:
529
    using CreateInstanceFunc = typename CompoundTypeInfoBase<ALLOC>::CreateInstanceFunc;
530
531
    /**
532
     * Constructor.
533
     *
534
     * \param schemaName The schema name to be stored in type information.
535
     * \param templateName The full schema template name.
536
     * \param templateArguments The sequence of type information for template arguments.
537
     * \param fields The sequence of type information for fields.
538
     * \param parameters The sequence of type information for parameters.
539
     * \param functions The sequence of type information for functions.
540
     */
541
    StructTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc, StringView templateName,
542
            Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
543
            Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
544
            Span<const BasicFunctionInfo<ALLOC>> functions);
545
};
546
547
/**
548
 * Type information class for union types.
549
 */
550
template <typename ALLOC>
551
class UnionTypeInfo : public CompoundTypeInfoBase<ALLOC>
552
{
553
public:
554
    using CreateInstanceFunc = typename CompoundTypeInfoBase<ALLOC>::CreateInstanceFunc;
555
556
    /**
557
     * Constructor.
558
     *
559
     * \param schemaName The schema name to be stored in type information.
560
     * \param templateName The full schema template name.
561
     * \param templateArguments The sequence of type information for template arguments.
562
     * \param fields The sequence of type information for fields.
563
     * \param parameters The sequence of type information for parameters.
564
     * \param functions The sequence of type information for functions.
565
     */
566
    UnionTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc, StringView templateName,
567
            Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
568
            Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
569
            Span<const BasicFunctionInfo<ALLOC>> functions);
570
};
571
572
/**
573
 * Type information class for choice types.
574
 */
575
template <typename ALLOC>
576
class ChoiceTypeInfo : public CompoundTypeInfoBase<ALLOC>
577
{
578
public:
579
    using CreateInstanceFunc = typename CompoundTypeInfoBase<ALLOC>::CreateInstanceFunc;
580
581
    /**
582
     * Constructor.
583
     *
584
     * \param schemaName The schema name to be stored in type information.
585
     * \param templateName The full schema template name.
586
     * \param templateArguments The sequence of type information for template arguments.
587
     * \param fields The sequence of type information for fields.
588
     * \param parameters The sequence of type information for parameters.
589
     * \param functions The sequence of type information for functions.
590
     * \param selector The selector expression.
591
     * \param cases The sequence of type information for cases.
592
     */
593
    ChoiceTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc, StringView templateName,
594
            Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
595
            Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
596
            Span<const BasicFunctionInfo<ALLOC>> functions, StringView selector,
597
            Span<const BasicCaseInfo<ALLOC>> cases);
598
599
    StringView getSelector() const override;
600
    Span<const BasicCaseInfo<ALLOC>> getCases() const override;
601
602
private:
603
    StringView m_selector;
604
    Span<const BasicCaseInfo<ALLOC>> m_cases;
605
};
606
607
/**
608
 * Type information abstract base class for enumeration and bitmask types.
609
 */
610
template <typename ALLOC>
611
class TypeInfoWithUnderlyingTypeBase : public TypeInfoBase<ALLOC>
612
{
613
public:
614
    /**
615
     * Constructor.
616
     *
617
     * \param schemaName The schema name to be stored in type information.
618
     * \param schemaType The schema type to be stored in type information.
619
     * \param cppType The C++ type to be stored in type information.
620
     * \param underlyingType The reference to type information of underlying zserio type.
621
     * \param underlyingTypeArguments The underlying zserio type arguments.
622
     */
623
    TypeInfoWithUnderlyingTypeBase(StringView schemaName, SchemaType schemaType, CppType cppType,
624
            const IBasicTypeInfo<ALLOC>& underlyingType, Span<const StringView> underlyingTypeArguments);
625
626
    const IBasicTypeInfo<ALLOC>& getUnderlyingType() const override;
627
    Span<const StringView> getUnderlyingTypeArguments() const override;
628
629
private:
630
    const IBasicTypeInfo<ALLOC>& m_underlyingType;
631
    Span<const StringView> m_underlyingTypeArguments;
632
};
633
634
/**
635
 * Type information class for enumeration types.
636
 */
637
template <typename ALLOC>
638
class EnumTypeInfo : public TypeInfoWithUnderlyingTypeBase<ALLOC>
639
{
640
public:
641
    /**
642
     * Constructor.
643
     *
644
     * \param schemaName The schema name to be stored in type information.
645
     * \param underlyingType The reference to type information of underlying zserio type.
646
     * \param underlyingTypeArguments The underlying zserio type arguments.
647
     * \param enumItems The sequence of type information for enumeration items.
648
     */
649
    EnumTypeInfo(StringView schemaName, const IBasicTypeInfo<ALLOC>& underlyingType,
650
            Span<const StringView> underlyingTypeArguments, Span<const ItemInfo> enumItems);
651
652
    Span<const ItemInfo> getEnumItems() const override;
653
654
private:
655
    Span<const ItemInfo> m_enumItems;
656
};
657
658
/**
659
 * Type information class for bitmask types.
660
 */
661
template <typename ALLOC>
662
class BitmaskTypeInfo : public TypeInfoWithUnderlyingTypeBase<ALLOC>
663
{
664
public:
665
    /**
666
     * Constructor.
667
     *
668
     * \param schemaName The schema name to be stored in type information.
669
     * \param underlyingType The reference to type information of underlying zserio type.
670
     * \param underlyingTypeArguments The underlying zserio type arguments.
671
     * \param bitmaskValues The sequence of type information for bitmask values.
672
     */
673
    BitmaskTypeInfo(StringView schemaName, const IBasicTypeInfo<ALLOC>& underlyingType,
674
            Span<const StringView> underlyingTypeArguments, Span<const ItemInfo> bitmaskValues);
675
676
    Span<const ItemInfo> getBitmaskValues() const override;
677
678
private:
679
    Span<const ItemInfo> m_bitmaskValues;
680
};
681
682
/**
683
 * Type information class for SQL table types.
684
 */
685
template <typename ALLOC>
686
class SqlTableTypeInfo : public TemplatableTypeInfoBase<ALLOC>
687
{
688
public:
689
    /**
690
     * Constructor.
691
     *
692
     * \param schemaName The schema name to be stored in type information.
693
     * \param templateName The full schema template name.
694
     * \param templateArguments The sequence of type information for template arguments.
695
     * \param columns The sequence of type information for columns.
696
     * \param sqlConstraint The SQL table constraint.
697
     * \param virtualTableUsing The SQL virtual table using specification.
698
     * \param isWithoutRowId true if SQL table is without row id table, otherwise false.
699
     */
700
    SqlTableTypeInfo(StringView schemaName, StringView templateName,
701
            Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
702
            Span<const BasicColumnInfo<ALLOC>> columns, StringView sqlConstraint, StringView virtualTableUsing,
703
            bool isWithoutRowId);
704
705
    Span<const BasicColumnInfo<ALLOC>> getColumns() const override;
706
    StringView getSqlConstraint() const override;
707
    StringView getVirtualTableUsing() const override;
708
    bool isWithoutRowId() const override;
709
710
private:
711
    Span<const BasicColumnInfo<ALLOC>> m_columns;
712
    StringView m_sqlConstraint;
713
    StringView m_virtualTableUsing;
714
    bool m_isWithoutRowId;
715
};
716
717
/**
718
 * Type information class for SQL database types.
719
 */
720
template <typename ALLOC>
721
class SqlDatabaseTypeInfo : public TypeInfoBase<ALLOC>
722
{
723
public:
724
    /**
725
     * Constructor.
726
     *
727
     * \param schemaName The schema name to be stored in type information.
728
     * \param tables The sequence of type information for tables.
729
     */
730
    SqlDatabaseTypeInfo(StringView schemaName, Span<const BasicTableInfo<ALLOC>> tables);
731
732
    Span<const BasicTableInfo<ALLOC>> getTables() const override;
733
734
private:
735
    Span<const BasicTableInfo<ALLOC>> m_tables;
736
};
737
738
/**
739
 * Type information class for pubsub types.
740
 */
741
template <typename ALLOC>
742
class PubsubTypeInfo : public TypeInfoBase<ALLOC>
743
{
744
public:
745
    /**
746
     * Constructor.
747
     *
748
     * \param schemaName The schema name to be stored in type information.
749
     * \param messages The sequence of type information for pubsub messages.
750
     */
751
    PubsubTypeInfo(StringView schemaName, Span<const BasicMessageInfo<ALLOC>> messages);
752
753
    Span<const BasicMessageInfo<ALLOC>> getMessages() const override;
754
755
private:
756
    Span<const BasicMessageInfo<ALLOC>> m_messages;
757
};
758
759
/**
760
 * Type information class for service types.
761
 */
762
template <typename ALLOC>
763
class ServiceTypeInfo : public TypeInfoBase<ALLOC>
764
{
765
public:
766
    /**
767
     * Constructor.
768
     *
769
     * \param schemaName The schema name to be stored in type information.
770
     * \param methods The sequence of type information for service methods.
771
     */
772
    ServiceTypeInfo(StringView schemaName, Span<const BasicMethodInfo<ALLOC>> methods);
773
774
    Span<const BasicMethodInfo<ALLOC>> getMethods() const override;
775
776
private:
777
    Span<const BasicMethodInfo<ALLOC>> m_methods;
778
};
779
780
/**
781
 * Type info for recursive types used as a wrapper around generated static typeInfo method to prevent
782
 * infinite recursion in type info definition.
783
 */
784
template <typename ALLOC>
785
class RecursiveTypeInfo : public IBasicTypeInfo<ALLOC>
786
{
787
public:
788
    /** Typedef to pointer to static typeInfo method on generated objects. */
789
    using TypeInfoFunc = const IBasicTypeInfo<ALLOC>& (*)();
790
791
    /**
792
     * Constructor.
793
     *
794
     * \param typeInfoFunc Pointer to static typeInfo method.
795
     */
796
    explicit RecursiveTypeInfo(TypeInfoFunc typeInfoFunc) :
797
            m_typeInfoFunc(typeInfoFunc)
798
1
    {}
799
800
1
    ~RecursiveTypeInfo() override = default;
801
802
    /**
803
     * Copying and moving is disallowed!
804
     * \{
805
     */
806
    RecursiveTypeInfo(const RecursiveTypeInfo&) = delete;
807
    RecursiveTypeInfo& operator=(const RecursiveTypeInfo&) = delete;
808
809
    RecursiveTypeInfo(const RecursiveTypeInfo&&) = delete;
810
    RecursiveTypeInfo& operator=(const RecursiveTypeInfo&&) = delete;
811
    /**
812
     * \}
813
     */
814
815
    StringView getSchemaName() const override;
816
    SchemaType getSchemaType() const override;
817
    CppType getCppType() const override;
818
    uint8_t getBitSize() const override;
819
820
    Span<const BasicFieldInfo<ALLOC>> getFields() const override;
821
    Span<const BasicParameterInfo<ALLOC>> getParameters() const override;
822
    Span<const BasicFunctionInfo<ALLOC>> getFunctions() const override;
823
824
    StringView getSelector() const override;
825
    Span<const BasicCaseInfo<ALLOC>> getCases() const override;
826
827
    const IBasicTypeInfo<ALLOC>& getUnderlyingType() const override;
828
    Span<const StringView> getUnderlyingTypeArguments() const override;
829
    Span<const ItemInfo> getEnumItems() const override;
830
    Span<const ItemInfo> getBitmaskValues() const override;
831
832
    Span<const BasicColumnInfo<ALLOC>> getColumns() const override;
833
    StringView getSqlConstraint() const override;
834
    StringView getVirtualTableUsing() const override;
835
    bool isWithoutRowId() const override;
836
837
    Span<const BasicTableInfo<ALLOC>> getTables() const override;
838
839
    StringView getTemplateName() const override;
840
    Span<const BasicTemplateArgumentInfo<ALLOC>> getTemplateArguments() const override;
841
842
    Span<const BasicMessageInfo<ALLOC>> getMessages() const override;
843
    Span<const BasicMethodInfo<ALLOC>> getMethods() const override;
844
845
    IBasicReflectablePtr<ALLOC> createInstance(const ALLOC& allocator) const override;
846
    IBasicReflectablePtr<ALLOC> createInstance() const override;
847
848
private:
849
    TypeInfoFunc m_typeInfoFunc;
850
};
851
852
template <typename ALLOC>
853
TypeInfoBase<ALLOC>::TypeInfoBase(StringView schemaName, SchemaType schemaType, CppType cppType) :
854
        m_schemaName(schemaName),
855
        m_schemaType(schemaType),
856
        m_cppType(cppType)
857
315
{}
858
859
template <typename ALLOC>
860
TypeInfoBase<ALLOC>::~TypeInfoBase() = default;
861
862
template <typename ALLOC>
863
StringView TypeInfoBase<ALLOC>::getSchemaName() const
864
16.0k
{
865
16.0k
    return m_schemaName;
866
16.0k
}
867
868
template <typename ALLOC>
869
SchemaType TypeInfoBase<ALLOC>::getSchemaType() const
870
3.76k
{
871
3.76k
    return m_schemaType;
872
3.76k
}
873
874
template <typename ALLOC>
875
CppType TypeInfoBase<ALLOC>::getCppType() const
876
970
{
877
970
    return m_cppType;
878
970
}
879
880
template <typename ALLOC>
881
uint8_t TypeInfoBase<ALLOC>::getBitSize() const
882
150
{
883
150
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a fixed size type!";
884
150
}
885
886
template <typename ALLOC>
887
Span<const BasicFieldInfo<ALLOC>> TypeInfoBase<ALLOC>::getFields() const
888
286
{
889
286
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a compound type!";
890
286
}
891
892
template <typename ALLOC>
893
Span<const BasicParameterInfo<ALLOC>> TypeInfoBase<ALLOC>::getParameters() const
894
286
{
895
286
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a compound type!";
896
286
}
897
898
template <typename ALLOC>
899
Span<const BasicFunctionInfo<ALLOC>> TypeInfoBase<ALLOC>::getFunctions() const
900
286
{
901
286
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a compound type!";
902
286
}
903
904
template <typename ALLOC>
905
StringView TypeInfoBase<ALLOC>::getSelector() const
906
289
{
907
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a choice type!";
908
289
}
909
910
template <typename ALLOC>
911
Span<const BasicCaseInfo<ALLOC>> TypeInfoBase<ALLOC>::getCases() const
912
289
{
913
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a choice type!";
914
289
}
915
916
template <typename ALLOC>
917
const IBasicTypeInfo<ALLOC>& TypeInfoBase<ALLOC>::getUnderlyingType() const
918
288
{
919
288
    throw CppRuntimeException("Type '") << getSchemaName() << "' does not have underlying type!";
920
288
}
921
922
template <typename ALLOC>
923
Span<const StringView> TypeInfoBase<ALLOC>::getUnderlyingTypeArguments() const
924
288
{
925
288
    throw CppRuntimeException("Type '") << getSchemaName() << "' does not have underlying type!";
926
288
}
927
928
template <typename ALLOC>
929
Span<const ItemInfo> TypeInfoBase<ALLOC>::getEnumItems() const
930
289
{
931
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not an enum type!";
932
289
}
933
934
template <typename ALLOC>
935
Span<const ItemInfo> TypeInfoBase<ALLOC>::getBitmaskValues() const
936
289
{
937
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a bitmask type!";
938
289
}
939
940
template <typename ALLOC>
941
Span<const BasicColumnInfo<ALLOC>> TypeInfoBase<ALLOC>::getColumns() const
942
289
{
943
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a SQL table type!";
944
289
}
945
946
template <typename ALLOC>
947
StringView TypeInfoBase<ALLOC>::getSqlConstraint() const
948
289
{
949
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a SQL table type!";
950
289
}
951
952
template <typename ALLOC>
953
StringView TypeInfoBase<ALLOC>::getVirtualTableUsing() const
954
289
{
955
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a SQL table type!";
956
289
}
957
958
template <typename ALLOC>
959
bool TypeInfoBase<ALLOC>::isWithoutRowId() const
960
289
{
961
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a SQL table type!";
962
289
}
963
964
template <typename ALLOC>
965
Span<const BasicTableInfo<ALLOC>> TypeInfoBase<ALLOC>::getTables() const
966
289
{
967
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a SQL database type!";
968
289
}
969
970
template <typename ALLOC>
971
StringView TypeInfoBase<ALLOC>::getTemplateName() const
972
285
{
973
285
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a templatable type!";
974
285
}
975
976
template <typename ALLOC>
977
Span<const BasicTemplateArgumentInfo<ALLOC>> TypeInfoBase<ALLOC>::getTemplateArguments() const
978
285
{
979
285
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a templatable type!";
980
285
}
981
982
template <typename ALLOC>
983
Span<const BasicMessageInfo<ALLOC>> TypeInfoBase<ALLOC>::getMessages() const
984
289
{
985
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a pubsub type!";
986
289
}
987
988
template <typename ALLOC>
989
Span<const BasicMethodInfo<ALLOC>> TypeInfoBase<ALLOC>::getMethods() const
990
289
{
991
289
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a service type!";
992
289
}
993
994
template <typename ALLOC>
995
IBasicReflectablePtr<ALLOC> TypeInfoBase<ALLOC>::createInstance(const ALLOC&) const
996
286
{
997
286
    throw CppRuntimeException("Type '") << getSchemaName() << "' is not a compound type!";
998
286
}
999
1000
template <typename ALLOC>
1001
IBasicReflectablePtr<ALLOC> TypeInfoBase<ALLOC>::createInstance() const
1002
281
{
1003
281
    return createInstance(ALLOC());
1004
281
}
1005
1006
template <typename ALLOC>
1007
BuiltinTypeInfo<ALLOC>::BuiltinTypeInfo(StringView schemaName, SchemaType schemaType, CppType cppType) :
1008
        TypeInfoBase<ALLOC>(schemaName, schemaType, cppType)
1009
162
{}
1010
1011
template <typename ALLOC>
1012
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getBool()
1013
59
{
1014
59
    return FixedSizeBuiltinTypeInfo<ALLOC>::getBool();
1015
59
}
1016
1017
template <typename ALLOC>
1018
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getInt8()
1019
103
{
1020
103
    return FixedSizeBuiltinTypeInfo<ALLOC>::getInt8();
1021
103
}
1022
1023
template <typename ALLOC>
1024
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getInt16()
1025
59
{
1026
59
    return FixedSizeBuiltinTypeInfo<ALLOC>::getInt16();
1027
59
}
1028
1029
template <typename ALLOC>
1030
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getInt32()
1031
64
{
1032
64
    return FixedSizeBuiltinTypeInfo<ALLOC>::getInt32();
1033
64
}
1034
1035
template <typename ALLOC>
1036
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getInt64()
1037
57
{
1038
57
    return FixedSizeBuiltinTypeInfo<ALLOC>::getInt64();
1039
57
}
1040
1041
template <typename ALLOC>
1042
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getUInt8()
1043
124
{
1044
124
    return FixedSizeBuiltinTypeInfo<ALLOC>::getUInt8();
1045
124
}
1046
1047
template <typename ALLOC>
1048
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getUInt16()
1049
59
{
1050
59
    return FixedSizeBuiltinTypeInfo<ALLOC>::getUInt16();
1051
59
}
1052
1053
template <typename ALLOC>
1054
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getUInt32()
1055
239
{
1056
239
    return FixedSizeBuiltinTypeInfo<ALLOC>::getUInt32();
1057
239
}
1058
1059
template <typename ALLOC>
1060
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getUInt64()
1061
59
{
1062
59
    return FixedSizeBuiltinTypeInfo<ALLOC>::getUInt64();
1063
59
}
1064
1065
template <typename ALLOC>
1066
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarInt16()
1067
13
{
1068
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1069
13
            makeStringView("varint16"), SchemaType::VARINT16, CppType::INT16};
1070
13
    return typeInfo;
1071
13
}
1072
1073
template <typename ALLOC>
1074
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarInt32()
1075
13
{
1076
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1077
13
            makeStringView("varint32"), SchemaType::VARINT32, CppType::INT32};
1078
13
    return typeInfo;
1079
13
}
1080
1081
template <typename ALLOC>
1082
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarInt64()
1083
13
{
1084
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1085
13
            makeStringView("varint64"), SchemaType::VARINT64, CppType::INT64};
1086
13
    return typeInfo;
1087
13
}
1088
1089
template <typename ALLOC>
1090
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarInt()
1091
14
{
1092
14
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1093
14
            makeStringView("varint"), SchemaType::VARINT, CppType::INT64};
1094
14
    return typeInfo;
1095
14
}
1096
1097
template <typename ALLOC>
1098
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarUInt16()
1099
13
{
1100
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1101
13
            makeStringView("varuint16"), SchemaType::VARUINT16, CppType::UINT16};
1102
13
    return typeInfo;
1103
13
}
1104
1105
template <typename ALLOC>
1106
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarUInt32()
1107
13
{
1108
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1109
13
            makeStringView("varuint32"), SchemaType::VARUINT32, CppType::UINT32};
1110
13
    return typeInfo;
1111
13
}
1112
1113
template <typename ALLOC>
1114
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarUInt64()
1115
13
{
1116
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1117
13
            makeStringView("varuint64"), SchemaType::VARUINT64, CppType::UINT64};
1118
13
    return typeInfo;
1119
13
}
1120
1121
template <typename ALLOC>
1122
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarUInt()
1123
13
{
1124
13
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1125
13
            makeStringView("varuint"), SchemaType::VARUINT, CppType::UINT64};
1126
13
    return typeInfo;
1127
13
}
1128
1129
template <typename ALLOC>
1130
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getVarSize()
1131
14
{
1132
14
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1133
14
            makeStringView("varsize"), SchemaType::VARSIZE, CppType::UINT32};
1134
14
    return typeInfo;
1135
14
}
1136
1137
template <typename ALLOC>
1138
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getFloat16()
1139
14
{
1140
14
    return FixedSizeBuiltinTypeInfo<ALLOC>::getFloat16();
1141
14
}
1142
1143
template <typename ALLOC>
1144
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getFloat32()
1145
53
{
1146
53
    return FixedSizeBuiltinTypeInfo<ALLOC>::getFloat32();
1147
53
}
1148
1149
template <typename ALLOC>
1150
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getFloat64()
1151
81
{
1152
81
    return FixedSizeBuiltinTypeInfo<ALLOC>::getFloat64();
1153
81
}
1154
1155
template <typename ALLOC>
1156
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getBytes()
1157
78
{
1158
78
    static const BuiltinTypeInfo<ALLOC> typeInfo = {makeStringView("bytes"), SchemaType::BYTES, CppType::BYTES};
1159
78
    return typeInfo;
1160
78
}
1161
1162
template <typename ALLOC>
1163
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getString()
1164
228
{
1165
228
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1166
228
            makeStringView("string"), SchemaType::STRING, CppType::STRING};
1167
228
    return typeInfo;
1168
228
}
1169
1170
template <typename ALLOC>
1171
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getBitBuffer()
1172
76
{
1173
76
    static const BuiltinTypeInfo<ALLOC> typeInfo = {
1174
76
            makeStringView("extern"), SchemaType::EXTERN, CppType::BIT_BUFFER};
1175
76
    return typeInfo;
1176
76
}
1177
1178
template <typename ALLOC>
1179
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getFixedSignedBitField(uint8_t bitSize)
1180
321
{
1181
321
    return FixedSizeBuiltinTypeInfo<ALLOC>::getFixedSignedBitField(bitSize);
1182
321
}
1183
1184
template <typename ALLOC>
1185
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(uint8_t bitSize)
1186
352
{
1187
352
    return FixedSizeBuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(bitSize);
1188
352
}
1189
1190
template <typename ALLOC>
1191
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getDynamicSignedBitField(uint8_t maxBitSize)
1192
291
{
1193
291
    if (maxBitSize == 0 || 
maxBitSize > 64290
)
1194
193
    {
1195
193
        throw CppRuntimeException("BuiltinTypeInfo::getDynamicSignedBitField: Invalid max bit size '")
1196
193
                << maxBitSize << "'!";
1197
193
    }
1198
1199
98
    if (maxBitSize <= 8)
1200
30
    {
1201
30
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1202
30
                "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT8};
1203
30
        return typeInfo;
1204
30
    }
1205
68
    else if (maxBitSize <= 16)
1206
12
    {
1207
12
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1208
12
                "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT16};
1209
12
        return typeInfo;
1210
12
    }
1211
56
    else if (maxBitSize <= 32)
1212
20
    {
1213
20
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1214
20
                "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT32};
1215
20
        return typeInfo;
1216
20
    }
1217
36
    else
1218
36
    {
1219
36
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1220
36
                "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT64};
1221
36
        return typeInfo;
1222
36
    }
1223
98
}
1224
1225
template <typename ALLOC>
1226
const IBasicTypeInfo<ALLOC>& BuiltinTypeInfo<ALLOC>::getDynamicUnsignedBitField(uint8_t maxBitSize)
1227
284
{
1228
284
    if (maxBitSize == 0 || 
maxBitSize > 64283
)
1229
193
    {
1230
193
        throw CppRuntimeException("BuiltinTypeInfo::getDynamicUnsignedBitField: Invalid max bit size '")
1231
193
                << maxBitSize << "'!";
1232
193
    }
1233
1234
91
    if (maxBitSize <= 8)
1235
23
    {
1236
23
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1237
23
                "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT8};
1238
23
        return typeInfo;
1239
23
    }
1240
68
    else if (maxBitSize <= 16)
1241
12
    {
1242
12
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1243
12
                "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT16};
1244
12
        return typeInfo;
1245
12
    }
1246
56
    else if (maxBitSize <= 32)
1247
20
    {
1248
20
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1249
20
                "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT32};
1250
20
        return typeInfo;
1251
20
    }
1252
36
    else
1253
36
    {
1254
36
        static const BuiltinTypeInfo<ALLOC> typeInfo = {
1255
36
                "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT64};
1256
36
        return typeInfo;
1257
36
    }
1258
91
}
1259
1260
template <typename ALLOC>
1261
FixedSizeBuiltinTypeInfo<ALLOC>::FixedSizeBuiltinTypeInfo(
1262
        StringView schemaName, SchemaType schemaType, CppType cppType, uint8_t bitSize) :
1263
        BuiltinTypeInfo<ALLOC>(schemaName, schemaType, cppType),
1264
        m_bitSize(bitSize)
1265
141
{}
1266
1267
template <typename ALLOC>
1268
uint8_t FixedSizeBuiltinTypeInfo<ALLOC>::getBitSize() const
1269
233
{
1270
233
    return m_bitSize;
1271
233
}
1272
1273
template <typename ALLOC>
1274
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getBool()
1275
59
{
1276
59
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1277
59
            makeStringView("bool"), SchemaType::BOOL, CppType::BOOL, 1};
1278
59
    return typeInfo;
1279
59
}
1280
1281
template <typename ALLOC>
1282
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getInt8()
1283
103
{
1284
103
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1285
103
            makeStringView("int8"), SchemaType::INT8, CppType::INT8, 8};
1286
103
    return typeInfo;
1287
103
}
1288
1289
template <typename ALLOC>
1290
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getInt16()
1291
59
{
1292
59
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1293
59
            makeStringView("int16"), SchemaType::INT16, CppType::INT16, 16};
1294
59
    return typeInfo;
1295
59
}
1296
1297
template <typename ALLOC>
1298
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getInt32()
1299
64
{
1300
64
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1301
64
            makeStringView("int32"), SchemaType::INT32, CppType::INT32, 32};
1302
64
    return typeInfo;
1303
64
}
1304
1305
template <typename ALLOC>
1306
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getInt64()
1307
57
{
1308
57
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1309
57
            makeStringView("int64"), SchemaType::INT64, CppType::INT64, 64};
1310
57
    return typeInfo;
1311
57
}
1312
1313
template <typename ALLOC>
1314
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getUInt8()
1315
124
{
1316
124
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1317
124
            makeStringView("uint8"), SchemaType::UINT8, CppType::UINT8, 8};
1318
124
    return typeInfo;
1319
124
}
1320
1321
template <typename ALLOC>
1322
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getUInt16()
1323
59
{
1324
59
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1325
59
            makeStringView("uint16"), SchemaType::UINT16, CppType::UINT16, 16};
1326
59
    return typeInfo;
1327
59
}
1328
1329
template <typename ALLOC>
1330
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getUInt32()
1331
239
{
1332
239
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1333
239
            makeStringView("uint32"), SchemaType::UINT32, CppType::UINT32, 32};
1334
239
    return typeInfo;
1335
239
}
1336
1337
template <typename ALLOC>
1338
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getUInt64()
1339
59
{
1340
59
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1341
59
            makeStringView("uint64"), SchemaType::UINT64, CppType::UINT64, 64};
1342
59
    return typeInfo;
1343
59
}
1344
1345
template <typename ALLOC>
1346
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getFloat16()
1347
14
{
1348
14
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1349
14
            makeStringView("float16"), SchemaType::FLOAT16, CppType::FLOAT, 16};
1350
14
    return typeInfo;
1351
14
}
1352
1353
template <typename ALLOC>
1354
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getFloat32()
1355
53
{
1356
53
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1357
53
            makeStringView("float32"), SchemaType::FLOAT32, CppType::FLOAT, 32};
1358
53
    return typeInfo;
1359
53
}
1360
1361
template <typename ALLOC>
1362
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getFloat64()
1363
81
{
1364
81
    static const FixedSizeBuiltinTypeInfo<ALLOC> typeInfo = {
1365
81
            makeStringView("float64"), SchemaType::FLOAT64, CppType::DOUBLE, 64};
1366
81
    return typeInfo;
1367
81
}
1368
1369
template <typename ALLOC>
1370
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getFixedSignedBitField(uint8_t bitSize)
1371
321
{
1372
321
    if (bitSize == 0 || 
bitSize > 64320
)
1373
193
    {
1374
193
        throw CppRuntimeException("FixedSizeBuiltinTypeInfo::getFixedSignedBitField: Invalid bit size '")
1375
193
                << bitSize << "'!";
1376
193
    }
1377
1378
128
    static const std::array<FixedSizeBuiltinTypeInfo<ALLOC>, 64> bitFieldTypeInfoArray = {
1379
128
            {{"int:1"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 1},
1380
128
                    {"int:2"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 2},
1381
128
                    {"int:3"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 3},
1382
128
                    {"int:4"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 4},
1383
128
                    {"int:5"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 5},
1384
128
                    {"int:6"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 6},
1385
128
                    {"int:7"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 7},
1386
128
                    {"int:8"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT8, 8},
1387
128
                    {"int:9"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 9},
1388
128
                    {"int:10"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 10},
1389
128
                    {"int:11"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 11},
1390
128
                    {"int:12"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 12},
1391
128
                    {"int:13"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 13},
1392
128
                    {"int:14"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 14},
1393
128
                    {"int:15"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 15},
1394
128
                    {"int:16"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT16, 16},
1395
128
                    {"int:17"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 17},
1396
128
                    {"int:18"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 18},
1397
128
                    {"int:19"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 19},
1398
128
                    {"int:20"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 20},
1399
128
                    {"int:21"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 21},
1400
128
                    {"int:22"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 22},
1401
128
                    {"int:23"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 23},
1402
128
                    {"int:24"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 24},
1403
128
                    {"int:25"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 25},
1404
128
                    {"int:26"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 26},
1405
128
                    {"int:27"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 27},
1406
128
                    {"int:28"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 28},
1407
128
                    {"int:29"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 29},
1408
128
                    {"int:30"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 30},
1409
128
                    {"int:31"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 31},
1410
128
                    {"int:32"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT32, 32},
1411
128
                    {"int:33"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 33},
1412
128
                    {"int:34"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 34},
1413
128
                    {"int:35"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 35},
1414
128
                    {"int:36"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 36},
1415
128
                    {"int:37"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 37},
1416
128
                    {"int:38"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 38},
1417
128
                    {"int:39"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 39},
1418
128
                    {"int:40"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 40},
1419
128
                    {"int:41"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 41},
1420
128
                    {"int:42"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 42},
1421
128
                    {"int:43"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 43},
1422
128
                    {"int:44"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 44},
1423
128
                    {"int:45"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 45},
1424
128
                    {"int:46"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 46},
1425
128
                    {"int:47"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 47},
1426
128
                    {"int:48"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 48},
1427
128
                    {"int:49"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 49},
1428
128
                    {"int:50"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 50},
1429
128
                    {"int:51"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 51},
1430
128
                    {"int:52"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 52},
1431
128
                    {"int:53"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 53},
1432
128
                    {"int:54"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 54},
1433
128
                    {"int:55"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 55},
1434
128
                    {"int:56"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 56},
1435
128
                    {"int:57"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 57},
1436
128
                    {"int:58"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 58},
1437
128
                    {"int:59"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 59},
1438
128
                    {"int:60"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 60},
1439
128
                    {"int:61"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 61},
1440
128
                    {"int:62"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 62},
1441
128
                    {"int:63"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 63},
1442
128
                    {"int:64"_sv, SchemaType::FIXED_SIGNED_BITFIELD, CppType::INT64, 64}}};
1443
1444
128
    return bitFieldTypeInfoArray[bitSize - 1U];
1445
321
}
1446
1447
template <typename ALLOC>
1448
const IBasicTypeInfo<ALLOC>& FixedSizeBuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(uint8_t bitSize)
1449
352
{
1450
352
    if (bitSize == 0 || 
bitSize > 64351
)
1451
193
    {
1452
193
        throw CppRuntimeException("FixedSizeBuiltinTypeInfo::getFixedUnsignedBitField: Invalid bit size '")
1453
193
                << bitSize << "'!";
1454
193
    }
1455
1456
159
    static const std::array<FixedSizeBuiltinTypeInfo<ALLOC>, 64> bitFieldTypeInfoArray = {
1457
159
            {{"bit:1"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 1},
1458
159
                    {"bit:2"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 2},
1459
159
                    {"bit:3"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 3},
1460
159
                    {"bit:4"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 4},
1461
159
                    {"bit:5"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 5},
1462
159
                    {"bit:6"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 6},
1463
159
                    {"bit:7"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 7},
1464
159
                    {"bit:8"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT8, 8},
1465
159
                    {"bit:9"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 9},
1466
159
                    {"bit:10"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 10},
1467
159
                    {"bit:11"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 11},
1468
159
                    {"bit:12"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 12},
1469
159
                    {"bit:13"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 13},
1470
159
                    {"bit:14"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 14},
1471
159
                    {"bit:15"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 15},
1472
159
                    {"bit:16"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT16, 16},
1473
159
                    {"bit:17"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 17},
1474
159
                    {"bit:18"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 18},
1475
159
                    {"bit:19"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 19},
1476
159
                    {"bit:20"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 20},
1477
159
                    {"bit:21"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 21},
1478
159
                    {"bit:22"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 22},
1479
159
                    {"bit:23"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 23},
1480
159
                    {"bit:24"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 24},
1481
159
                    {"bit:25"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 25},
1482
159
                    {"bit:26"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 26},
1483
159
                    {"bit:27"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 27},
1484
159
                    {"bit:28"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 28},
1485
159
                    {"bit:29"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 29},
1486
159
                    {"bit:30"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 30},
1487
159
                    {"bit:31"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 31},
1488
159
                    {"bit:32"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT32, 32},
1489
159
                    {"bit:33"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 33},
1490
159
                    {"bit:34"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 34},
1491
159
                    {"bit:35"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 35},
1492
159
                    {"bit:36"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 36},
1493
159
                    {"bit:37"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 37},
1494
159
                    {"bit:38"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 38},
1495
159
                    {"bit:39"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 39},
1496
159
                    {"bit:40"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 40},
1497
159
                    {"bit:41"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 41},
1498
159
                    {"bit:42"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 42},
1499
159
                    {"bit:43"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 43},
1500
159
                    {"bit:44"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 44},
1501
159
                    {"bit:45"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 45},
1502
159
                    {"bit:46"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 46},
1503
159
                    {"bit:47"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 47},
1504
159
                    {"bit:48"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 48},
1505
159
                    {"bit:49"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 49},
1506
159
                    {"bit:50"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 50},
1507
159
                    {"bit:51"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 51},
1508
159
                    {"bit:52"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 52},
1509
159
                    {"bit:53"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 53},
1510
159
                    {"bit:54"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 54},
1511
159
                    {"bit:55"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 55},
1512
159
                    {"bit:56"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 56},
1513
159
                    {"bit:57"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 57},
1514
159
                    {"bit:58"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 58},
1515
159
                    {"bit:59"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 59},
1516
159
                    {"bit:60"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 60},
1517
159
                    {"bit:61"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 61},
1518
159
                    {"bit:62"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 62},
1519
159
                    {"bit:63"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 63},
1520
159
                    {"bit:64"_sv, SchemaType::FIXED_UNSIGNED_BITFIELD, CppType::UINT64, 64}}};
1521
1522
159
    return bitFieldTypeInfoArray[static_cast<size_t>(bitSize - 1)];
1523
352
}
1524
1525
template <typename ALLOC>
1526
TemplatableTypeInfoBase<ALLOC>::TemplatableTypeInfoBase(StringView schemaName, SchemaType schemaType,
1527
        CppType cppType, StringView templateName,
1528
        Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments) :
1529
        TypeInfoBase<ALLOC>(schemaName, schemaType, cppType),
1530
        m_templateName(templateName),
1531
        m_templateArguments(templateArguments)
1532
50
{}
1533
1534
template <typename ALLOC>
1535
TemplatableTypeInfoBase<ALLOC>::~TemplatableTypeInfoBase() = default;
1536
1537
template <typename ALLOC>
1538
StringView TemplatableTypeInfoBase<ALLOC>::getTemplateName() const
1539
6
{
1540
6
    return m_templateName;
1541
6
}
1542
1543
template <typename ALLOC>
1544
Span<const BasicTemplateArgumentInfo<ALLOC>> TemplatableTypeInfoBase<ALLOC>::getTemplateArguments() const
1545
5
{
1546
5
    return m_templateArguments;
1547
5
}
1548
1549
template <typename ALLOC>
1550
CompoundTypeInfoBase<ALLOC>::CompoundTypeInfoBase(StringView schemaName, CreateInstanceFunc createInstanceFunc,
1551
        SchemaType schemaType, CppType cppType, StringView templateName,
1552
        Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
1553
        Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
1554
        Span<const BasicFunctionInfo<ALLOC>> functions) :
1555
        TemplatableTypeInfoBase<ALLOC>(schemaName, schemaType, cppType, templateName, templateArguments),
1556
        m_createInstanceFunc(createInstanceFunc),
1557
        m_fields(fields),
1558
        m_parameters(parameters),
1559
        m_functions(functions)
1560
49
{}
1561
1562
template <typename ALLOC>
1563
CompoundTypeInfoBase<ALLOC>::~CompoundTypeInfoBase() = default;
1564
1565
template <typename ALLOC>
1566
Span<const BasicFieldInfo<ALLOC>> CompoundTypeInfoBase<ALLOC>::getFields() const
1567
731
{
1568
731
    return m_fields;
1569
731
}
1570
1571
template <typename ALLOC>
1572
Span<const BasicParameterInfo<ALLOC>> CompoundTypeInfoBase<ALLOC>::getParameters() const
1573
127
{
1574
127
    return m_parameters;
1575
127
}
1576
1577
template <typename ALLOC>
1578
Span<const BasicFunctionInfo<ALLOC>> CompoundTypeInfoBase<ALLOC>::getFunctions() const
1579
69
{
1580
69
    return m_functions;
1581
69
}
1582
1583
template <typename ALLOC>
1584
IBasicReflectablePtr<ALLOC> CompoundTypeInfoBase<ALLOC>::createInstance(const ALLOC& allocator) const
1585
90
{
1586
90
    if (!m_createInstanceFunc)
1587
5
    {
1588
5
        throw CppRuntimeException("Reflectable '")
1589
5
                << getSchemaName() << "': Cannot create instance, "
1590
5
                << "either '-withoutWriterCode' or '-withoutReflectionCode' zserio option is used!";
1591
5
    }
1592
85
    return m_createInstanceFunc(allocator);
1593
90
}
1594
1595
template <typename ALLOC>
1596
StructTypeInfo<ALLOC>::StructTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc,
1597
        StringView templateName, Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
1598
        Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
1599
        Span<const BasicFunctionInfo<ALLOC>> functions) :
1600
        CompoundTypeInfoBase<ALLOC>(schemaName, createInstanceFunc, SchemaType::STRUCT, CppType::STRUCT,
1601
                templateName, templateArguments, fields, parameters, functions)
1602
43
{}
1603
1604
template <typename ALLOC>
1605
UnionTypeInfo<ALLOC>::UnionTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc,
1606
        StringView templateName, Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
1607
        Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
1608
        Span<const BasicFunctionInfo<ALLOC>> functions) :
1609
        CompoundTypeInfoBase<ALLOC>(schemaName, createInstanceFunc, SchemaType::UNION, CppType::UNION,
1610
                templateName, templateArguments, fields, parameters, functions)
1611
3
{}
1612
1613
template <typename ALLOC>
1614
ChoiceTypeInfo<ALLOC>::ChoiceTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc,
1615
        StringView templateName, Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
1616
        Span<const BasicFieldInfo<ALLOC>> fields, Span<const BasicParameterInfo<ALLOC>> parameters,
1617
        Span<const BasicFunctionInfo<ALLOC>> functions, StringView selector,
1618
        Span<const BasicCaseInfo<ALLOC>> cases) :
1619
        CompoundTypeInfoBase<ALLOC>(schemaName, createInstanceFunc, SchemaType::CHOICE, CppType::CHOICE,
1620
                templateName, templateArguments, fields, parameters, functions),
1621
        m_selector(selector),
1622
        m_cases(cases)
1623
3
{}
1624
1625
template <typename ALLOC>
1626
StringView ChoiceTypeInfo<ALLOC>::getSelector() const
1627
1
{
1628
1
    return m_selector;
1629
1
}
1630
1631
template <typename ALLOC>
1632
Span<const BasicCaseInfo<ALLOC>> ChoiceTypeInfo<ALLOC>::getCases() const
1633
1
{
1634
1
    return m_cases;
1635
1
}
1636
1637
template <typename ALLOC>
1638
SqlTableTypeInfo<ALLOC>::SqlTableTypeInfo(StringView schemaName, StringView templateName,
1639
        Span<const BasicTemplateArgumentInfo<ALLOC>> templateArguments,
1640
        Span<const BasicColumnInfo<ALLOC>> columns, StringView sqlConstraint, StringView virtualTableUsing,
1641
        bool isWithoutRowId) :
1642
        TemplatableTypeInfoBase<ALLOC>(
1643
                schemaName, SchemaType::SQL_TABLE, CppType::SQL_TABLE, templateName, templateArguments),
1644
        m_columns(columns),
1645
        m_sqlConstraint(sqlConstraint),
1646
        m_virtualTableUsing(virtualTableUsing),
1647
        m_isWithoutRowId(isWithoutRowId)
1648
1
{}
1649
1650
template <typename ALLOC>
1651
Span<const BasicColumnInfo<ALLOC>> SqlTableTypeInfo<ALLOC>::getColumns() const
1652
1
{
1653
1
    return m_columns;
1654
1
}
1655
1656
template <typename ALLOC>
1657
StringView SqlTableTypeInfo<ALLOC>::getSqlConstraint() const
1658
1
{
1659
1
    return m_sqlConstraint;
1660
1
}
1661
1662
template <typename ALLOC>
1663
StringView SqlTableTypeInfo<ALLOC>::getVirtualTableUsing() const
1664
1
{
1665
1
    return m_virtualTableUsing;
1666
1
}
1667
1668
template <typename ALLOC>
1669
bool SqlTableTypeInfo<ALLOC>::isWithoutRowId() const
1670
1
{
1671
1
    return m_isWithoutRowId;
1672
1
}
1673
1674
template <typename ALLOC>
1675
SqlDatabaseTypeInfo<ALLOC>::SqlDatabaseTypeInfo(
1676
        StringView schemaName, Span<const BasicTableInfo<ALLOC>> tables) :
1677
        TypeInfoBase<ALLOC>(schemaName, SchemaType::SQL_DATABASE, CppType::SQL_DATABASE),
1678
        m_tables(tables)
1679
1
{}
1680
1681
template <typename ALLOC>
1682
Span<const BasicTableInfo<ALLOC>> SqlDatabaseTypeInfo<ALLOC>::getTables() const
1683
1
{
1684
1
    return m_tables;
1685
1
}
1686
1687
template <typename ALLOC>
1688
TypeInfoWithUnderlyingTypeBase<ALLOC>::TypeInfoWithUnderlyingTypeBase(StringView schemaName,
1689
        SchemaType schemaType, CppType cppType, const IBasicTypeInfo<ALLOC>& underlyingType,
1690
        Span<const StringView> underlyingTypeArguments) :
1691
        TypeInfoBase<ALLOC>(schemaName, schemaType, cppType),
1692
        m_underlyingType(underlyingType),
1693
        m_underlyingTypeArguments(underlyingTypeArguments)
1694
98
{}
1695
1696
template <typename ALLOC>
1697
const IBasicTypeInfo<ALLOC>& TypeInfoWithUnderlyingTypeBase<ALLOC>::getUnderlyingType() const
1698
79
{
1699
79
    return m_underlyingType;
1700
79
}
1701
1702
template <typename ALLOC>
1703
Span<const StringView> TypeInfoWithUnderlyingTypeBase<ALLOC>::getUnderlyingTypeArguments() const
1704
2
{
1705
2
    return m_underlyingTypeArguments;
1706
2
}
1707
1708
template <typename ALLOC>
1709
EnumTypeInfo<ALLOC>::EnumTypeInfo(StringView schemaName, const IBasicTypeInfo<ALLOC>& underlyingType,
1710
        Span<const StringView> underlyingTypeArguments, Span<const ItemInfo> enumItems) :
1711
        TypeInfoWithUnderlyingTypeBase<ALLOC>(
1712
                schemaName, SchemaType::ENUM, CppType::ENUM, underlyingType, underlyingTypeArguments),
1713
        m_enumItems(enumItems)
1714
63
{}
1715
1716
template <typename ALLOC>
1717
Span<const ItemInfo> EnumTypeInfo<ALLOC>::getEnumItems() const
1718
23
{
1719
23
    return m_enumItems;
1720
23
}
1721
1722
template <typename ALLOC>
1723
BitmaskTypeInfo<ALLOC>::BitmaskTypeInfo(StringView schemaName, const IBasicTypeInfo<ALLOC>& underlyingType,
1724
        Span<const StringView> underlyingTypeArguments, Span<const ItemInfo> bitmaskValues) :
1725
        TypeInfoWithUnderlyingTypeBase<ALLOC>(
1726
                schemaName, SchemaType::BITMASK, CppType::BITMASK, underlyingType, underlyingTypeArguments),
1727
        m_bitmaskValues(bitmaskValues)
1728
35
{}
1729
1730
template <typename ALLOC>
1731
Span<const ItemInfo> BitmaskTypeInfo<ALLOC>::getBitmaskValues() const
1732
48
{
1733
48
    return m_bitmaskValues;
1734
48
}
1735
1736
template <typename ALLOC>
1737
PubsubTypeInfo<ALLOC>::PubsubTypeInfo(StringView schemaName, Span<const BasicMessageInfo<ALLOC>> messages) :
1738
        TypeInfoBase<ALLOC>(schemaName, SchemaType::PUBSUB, CppType::PUBSUB),
1739
        m_messages(messages)
1740
1
{}
1741
1742
template <typename ALLOC>
1743
Span<const BasicMessageInfo<ALLOC>> PubsubTypeInfo<ALLOC>::getMessages() const
1744
1
{
1745
1
    return m_messages;
1746
1
}
1747
1748
template <typename ALLOC>
1749
ServiceTypeInfo<ALLOC>::ServiceTypeInfo(StringView schemaName, Span<const BasicMethodInfo<ALLOC>> methods) :
1750
        TypeInfoBase<ALLOC>(schemaName, SchemaType::SERVICE, CppType::SERVICE),
1751
        m_methods(methods)
1752
1
{}
1753
1754
template <typename ALLOC>
1755
Span<const BasicMethodInfo<ALLOC>> ServiceTypeInfo<ALLOC>::getMethods() const
1756
1
{
1757
1
    return m_methods;
1758
1
}
1759
1760
template <typename ALLOC>
1761
StringView RecursiveTypeInfo<ALLOC>::getSchemaName() const
1762
1
{
1763
1
    return m_typeInfoFunc().getSchemaName();
1764
1
}
1765
1766
template <typename ALLOC>
1767
SchemaType RecursiveTypeInfo<ALLOC>::getSchemaType() const
1768
1
{
1769
1
    return m_typeInfoFunc().getSchemaType();
1770
1
}
1771
1772
template <typename ALLOC>
1773
CppType RecursiveTypeInfo<ALLOC>::getCppType() const
1774
1
{
1775
1
    return m_typeInfoFunc().getCppType();
1776
1
}
1777
1778
template <typename ALLOC>
1779
uint8_t RecursiveTypeInfo<ALLOC>::getBitSize() const
1780
1
{
1781
1
    return m_typeInfoFunc().getBitSize();
1782
1
}
1783
1784
template <typename ALLOC>
1785
Span<const BasicFieldInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getFields() const
1786
1
{
1787
1
    return m_typeInfoFunc().getFields();
1788
1
}
1789
1790
template <typename ALLOC>
1791
Span<const BasicParameterInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getParameters() const
1792
1
{
1793
1
    return m_typeInfoFunc().getParameters();
1794
1
}
1795
1796
template <typename ALLOC>
1797
Span<const BasicFunctionInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getFunctions() const
1798
1
{
1799
1
    return m_typeInfoFunc().getFunctions();
1800
1
}
1801
1802
template <typename ALLOC>
1803
StringView RecursiveTypeInfo<ALLOC>::getSelector() const
1804
1
{
1805
1
    return m_typeInfoFunc().getSelector();
1806
1
}
1807
1808
template <typename ALLOC>
1809
Span<const BasicCaseInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getCases() const
1810
1
{
1811
1
    return m_typeInfoFunc().getCases();
1812
1
}
1813
1814
template <typename ALLOC>
1815
const IBasicTypeInfo<ALLOC>& RecursiveTypeInfo<ALLOC>::getUnderlyingType() const
1816
1
{
1817
1
    return m_typeInfoFunc().getUnderlyingType();
1818
1
}
1819
1820
template <typename ALLOC>
1821
Span<const StringView> RecursiveTypeInfo<ALLOC>::getUnderlyingTypeArguments() const
1822
1
{
1823
1
    return m_typeInfoFunc().getUnderlyingTypeArguments();
1824
1
}
1825
1826
template <typename ALLOC>
1827
Span<const ItemInfo> RecursiveTypeInfo<ALLOC>::getEnumItems() const
1828
1
{
1829
1
    return m_typeInfoFunc().getEnumItems();
1830
1
}
1831
1832
template <typename ALLOC>
1833
Span<const ItemInfo> RecursiveTypeInfo<ALLOC>::getBitmaskValues() const
1834
1
{
1835
1
    return m_typeInfoFunc().getBitmaskValues();
1836
1
}
1837
1838
template <typename ALLOC>
1839
Span<const BasicColumnInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getColumns() const
1840
1
{
1841
1
    return m_typeInfoFunc().getColumns();
1842
1
}
1843
1844
template <typename ALLOC>
1845
StringView RecursiveTypeInfo<ALLOC>::getSqlConstraint() const
1846
1
{
1847
1
    return m_typeInfoFunc().getSqlConstraint();
1848
1
}
1849
1850
template <typename ALLOC>
1851
StringView RecursiveTypeInfo<ALLOC>::getVirtualTableUsing() const
1852
1
{
1853
1
    return m_typeInfoFunc().getVirtualTableUsing();
1854
1
}
1855
1856
template <typename ALLOC>
1857
bool RecursiveTypeInfo<ALLOC>::isWithoutRowId() const
1858
1
{
1859
1
    return m_typeInfoFunc().isWithoutRowId();
1860
1
}
1861
1862
template <typename ALLOC>
1863
Span<const BasicTableInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getTables() const
1864
1
{
1865
1
    return m_typeInfoFunc().getTables();
1866
1
}
1867
1868
template <typename ALLOC>
1869
StringView RecursiveTypeInfo<ALLOC>::getTemplateName() const
1870
1
{
1871
1
    return m_typeInfoFunc().getTemplateName();
1872
1
}
1873
1874
template <typename ALLOC>
1875
Span<const BasicTemplateArgumentInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getTemplateArguments() const
1876
1
{
1877
1
    return m_typeInfoFunc().getTemplateArguments();
1878
1
}
1879
1880
template <typename ALLOC>
1881
Span<const BasicMessageInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getMessages() const
1882
1
{
1883
1
    return m_typeInfoFunc().getMessages();
1884
1
}
1885
1886
template <typename ALLOC>
1887
Span<const BasicMethodInfo<ALLOC>> RecursiveTypeInfo<ALLOC>::getMethods() const
1888
1
{
1889
1
    return m_typeInfoFunc().getMethods();
1890
1
}
1891
1892
template <typename ALLOC>
1893
IBasicReflectablePtr<ALLOC> RecursiveTypeInfo<ALLOC>::createInstance(const ALLOC& allocator) const
1894
2
{
1895
2
    return m_typeInfoFunc().createInstance(allocator);
1896
2
}
1897
1898
template <typename ALLOC>
1899
IBasicReflectablePtr<ALLOC> RecursiveTypeInfo<ALLOC>::createInstance() const
1900
1
{
1901
1
    return createInstance(ALLOC());
1902
1
}
1903
1904
} // namespace zserio
1905
1906
#endif // ZSERIO_TYPE_INFO_INC_H