Coverage Report

Created: 2024-07-18 11:41

src/zserio/Reflectable.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef ZSERIO_REFLECTABLE_H_INC
2
#define ZSERIO_REFLECTABLE_H_INC
3
4
#include <functional>
5
#include <type_traits>
6
7
#include "zserio/AllocatorHolder.h"
8
#include "zserio/BitSizeOfCalculator.h"
9
#include "zserio/CppRuntimeException.h"
10
#include "zserio/IReflectable.h"
11
#include "zserio/Span.h"
12
#include "zserio/StringConvertUtil.h"
13
#include "zserio/Traits.h"
14
#include "zserio/TypeInfo.h"
15
#include "zserio/TypeInfoUtil.h"
16
17
namespace zserio
18
{
19
20
/**
21
 * Base class for all reflectable implementations.
22
 *
23
 * Implements the find() feature and overrides all generic methods except of write() and bitSizeOf() with
24
 * default throw behavior.
25
 */
26
template <typename ALLOC>
27
class ReflectableBase : public IBasicReflectable<ALLOC>
28
{
29
public:
30
    /**
31
     * Constructor.
32
     *
33
     * \param typeInfo Type info of the reflected object.
34
     */
35
    explicit ReflectableBase(const IBasicTypeInfo<ALLOC>& typeInfo);
36
37
    /** Destructor. */
38
1.68k
    ~ReflectableBase() override = 0;
39
40
    /**
41
     * Copying and moving is disallowed!
42
     * \{
43
     */
44
    ReflectableBase(const ReflectableBase&) = delete;
45
    ReflectableBase& operator=(const ReflectableBase&) = delete;
46
47
    ReflectableBase(const ReflectableBase&&) = delete;
48
    ReflectableBase& operator=(const ReflectableBase&&) = delete;
49
    /**
50
     * \}
51
     */
52
53
    const IBasicTypeInfo<ALLOC>& getTypeInfo() const override;
54
    bool isArray() const override;
55
56
    void initializeChildren() override;
57
    void initialize(const vector<AnyHolder<ALLOC>, ALLOC>& typeArguments) override;
58
    size_t initializeOffsets(size_t bitPosition) override;
59
    size_t initializeOffsets() override;
60
    size_t bitSizeOf(size_t bitPosition) const override;
61
    size_t bitSizeOf() const override;
62
    void write(BitStreamWriter& writer) const override;
63
64
    IBasicReflectableConstPtr<ALLOC> getField(StringView name) const override;
65
    IBasicReflectablePtr<ALLOC> getField(StringView name) override;
66
    IBasicReflectablePtr<ALLOC> createField(StringView name) override;
67
    void setField(StringView name, const AnyHolder<ALLOC>& value) override;
68
    IBasicReflectableConstPtr<ALLOC> getParameter(StringView name) const override;
69
    IBasicReflectablePtr<ALLOC> getParameter(StringView name) override;
70
    IBasicReflectableConstPtr<ALLOC> callFunction(StringView name) const override;
71
    IBasicReflectablePtr<ALLOC> callFunction(StringView name) override;
72
73
    StringView getChoice() const override;
74
75
    IBasicReflectableConstPtr<ALLOC> find(StringView path) const override;
76
    IBasicReflectablePtr<ALLOC> find(StringView path) override;
77
    IBasicReflectableConstPtr<ALLOC> operator[](StringView path) const override;
78
    IBasicReflectablePtr<ALLOC> operator[](StringView path) override;
79
80
    size_t size() const override;
81
    void resize(size_t size) override;
82
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override;
83
    IBasicReflectablePtr<ALLOC> at(size_t index) override;
84
    IBasicReflectableConstPtr<ALLOC> operator[](size_t index) const override;
85
    IBasicReflectablePtr<ALLOC> operator[](size_t index) override;
86
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override;
87
    void append(const AnyHolder<ALLOC>& value) override;
88
89
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override;
90
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override;
91
    AnyHolder<ALLOC> getAnyValue() const override;
92
    AnyHolder<ALLOC> getAnyValue() override;
93
94
    // exact checked getters
95
    bool getBool() const override;
96
    int8_t getInt8() const override;
97
    int16_t getInt16() const override;
98
    int32_t getInt32() const override;
99
    int64_t getInt64() const override;
100
    uint8_t getUInt8() const override;
101
    uint16_t getUInt16() const override;
102
    uint32_t getUInt32() const override;
103
    uint64_t getUInt64() const override;
104
    float getFloat() const override;
105
    double getDouble() const override;
106
    Span<const uint8_t> getBytes() const override;
107
    StringView getStringView() const override;
108
    const BasicBitBuffer<ALLOC>& getBitBuffer() const override;
109
110
    // convenience conversions
111
    int64_t toInt() const override;
112
    uint64_t toUInt() const override;
113
    double toDouble() const override;
114
    string<ALLOC> toString(const ALLOC& allocator) const override;
115
    string<ALLOC> toString() const override;
116
117
private:
118
    const IBasicTypeInfo<ALLOC>& m_typeInfo;
119
};
120
121
/**
122
 * Base class for all builtin reflectables.
123
 */
124
template <typename ALLOC, typename T, typename = void>
125
class BuiltinReflectableBase : public ReflectableBase<ALLOC>
126
{
127
private:
128
    using Base = ReflectableBase<ALLOC>;
129
130
protected:
131
    BuiltinReflectableBase(const IBasicTypeInfo<ALLOC>& typeInfo, const T& value) :
132
            Base(typeInfo),
133
            m_value(value)
134
32
    {}
135
136
    const T& getValue() const
137
52
    {
138
52
        return m_value;
139
52
    }
140
141
public:
142
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
143
4
    {
144
4
        return AnyHolder<ALLOC>(std::cref(getValue()), allocator);
145
4
    }
146
147
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
148
4
    {
149
        // we have only const reference, thus return it
150
4
        return AnyHolder<ALLOC>(std::cref(getValue()), allocator);
151
4
    }
152
153
private:
154
    const T& m_value;
155
};
156
157
/**
158
 * Specialization of the BuiltinReflectableBase base class for numeric (arithmetic) types, string view and span.
159
 *
160
 * Hold the value instead of reference.
161
 */
162
template <typename ALLOC, typename T>
163
class BuiltinReflectableBase<ALLOC, T,
164
        typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, StringView>::value ||
165
                is_span<T>::value>::type> : public ReflectableBase<ALLOC>
166
{
167
private:
168
    using Base = ReflectableBase<ALLOC>;
169
170
protected:
171
    BuiltinReflectableBase(const IBasicTypeInfo<ALLOC>& typeInfo, T value) :
172
            Base(typeInfo),
173
            m_value(value)
174
851
    {}
175
176
    T getValue() const
177
2.06k
    {
178
2.06k
        return m_value;
179
2.06k
    }
180
181
public:
182
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
183
174
    {
184
174
        return AnyHolder<ALLOC>(m_value, allocator);
185
174
    }
186
187
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
188
99
    {
189
99
        return AnyHolder<ALLOC>(m_value, allocator);
190
99
    }
191
192
private:
193
    T m_value;
194
};
195
196
/**
197
 * Base class for integral reflectables.
198
 *
199
 * Implements toString() and toDouble() conversions, implements write() for all integral builtin types.
200
 *
201
 * Hold dynamic bit size even though it has sense only for dynamic bit fields (otherwise it's always set to 0).
202
 * This solution was chosen for simplicity.
203
 */
204
template <typename ALLOC, typename T>
205
class IntegralReflectableBase : public BuiltinReflectableBase<ALLOC, T>
206
{
207
protected:
208
    static_assert(std::is_integral<T>::value, "T must be a signed integral type!");
209
210
    using Base = BuiltinReflectableBase<ALLOC, T>;
211
212
public:
213
    IntegralReflectableBase(const IBasicTypeInfo<ALLOC>& typeInfo, T value) :
214
            Base(typeInfo, value)
215
592
    {}
216
217
    double toDouble() const override
218
243
    {
219
243
        return static_cast<double>(Base::getValue());
220
243
    }
221
222
    string<ALLOC> toString(const ALLOC& allocator) const override
223
232
    {
224
232
        return ::zserio::toString<ALLOC>(Base::getValue(), allocator);
225
232
    }
226
};
227
228
/**
229
 * Base class for signed integral reflectables.
230
 *
231
 * Implements toInt() conversion.
232
 */
233
template <typename ALLOC, typename T>
234
class SignedReflectableBase : public IntegralReflectableBase<ALLOC, T>
235
{
236
protected:
237
    static_assert(std::is_signed<T>::value, "T must be a signed integral type!");
238
239
    using Base = IntegralReflectableBase<ALLOC, T>;
240
241
    using Base::Base;
242
243
public:
244
    int64_t toInt() const override
245
150
    {
246
150
        return Base::getValue();
247
150
    }
248
};
249
250
/**
251
 * Base class for unsigned integral reflectables.
252
 *
253
 * Implements toUInt() conversion.
254
 */
255
template <typename ALLOC, typename T>
256
class UnsignedReflectableBase : public IntegralReflectableBase<ALLOC, T>
257
{
258
protected:
259
    static_assert(std::is_unsigned<T>::value, "T must be an unsigned integral type!");
260
261
    using Base = IntegralReflectableBase<ALLOC, T>;
262
263
    using Base::Base;
264
265
public:
266
    uint64_t toUInt() const override
267
233
    {
268
233
        return Base::getValue();
269
233
    }
270
};
271
272
/**
273
 * Reflectable for values of bool type.
274
 */
275
template <typename ALLOC>
276
class BoolReflectable : public UnsignedReflectableBase<ALLOC, bool>
277
{
278
private:
279
    using Base = UnsignedReflectableBase<ALLOC, bool>;
280
281
public:
282
    static const IBasicTypeInfo<ALLOC>& typeInfo()
283
23
    {
284
23
        return BuiltinTypeInfo<ALLOC>::getBool();
285
23
    }
286
287
    explicit BoolReflectable(bool value) :
288
            Base(typeInfo(), value)
289
21
    {}
290
291
    size_t bitSizeOf(size_t) const override
292
9
    {
293
9
        return 1;
294
9
    }
295
296
    void write(BitStreamWriter& writer) const override
297
9
    {
298
9
        writer.writeBool(Base::getValue());
299
9
    }
300
301
    bool getBool() const override
302
27
    {
303
27
        return Base::getValue();
304
27
    }
305
};
306
307
/**
308
 * Base class for 8-bit signed integral reflectables.
309
 *
310
 * Implements getInt8() conversion.
311
 */
312
template <typename ALLOC>
313
class Int8ReflectableBase : public SignedReflectableBase<ALLOC, int8_t>
314
{
315
protected:
316
    using Base = SignedReflectableBase<ALLOC, int8_t>;
317
318
    using Base::Base;
319
320
public:
321
    int8_t getInt8() const override
322
96
    {
323
96
        return Base::getValue();
324
96
    }
325
};
326
327
/**
328
 * Base class for 16-bit signed integral reflectables.
329
 *
330
 * Implements getInt16() conversion.
331
 */
332
template <typename ALLOC>
333
class Int16ReflectableBase : public SignedReflectableBase<ALLOC, int16_t>
334
{
335
protected:
336
    using Base = SignedReflectableBase<ALLOC, int16_t>;
337
338
    using Base::Base;
339
340
public:
341
    int16_t getInt16() const override
342
40
    {
343
40
        return Base::getValue();
344
40
    }
345
};
346
347
/**
348
 * Base class for 32-bit signed integral reflectables.
349
 *
350
 * Implements getInt32() conversion.
351
 */
352
template <typename ALLOC>
353
class Int32ReflectableBase : public SignedReflectableBase<ALLOC, int32_t>
354
{
355
protected:
356
    using Base = SignedReflectableBase<ALLOC, int32_t>;
357
358
    using Base::Base;
359
360
public:
361
    int32_t getInt32() const override
362
55
    {
363
55
        return Base::getValue();
364
55
    }
365
};
366
367
/**
368
 * Base class for 64-bit signed integral reflectables.
369
 *
370
 * Implements getInt64() conversion.
371
 */
372
template <typename ALLOC>
373
class Int64ReflectableBase : public SignedReflectableBase<ALLOC, int64_t>
374
{
375
protected:
376
    using Base = SignedReflectableBase<ALLOC, int64_t>;
377
378
    using Base::Base;
379
380
public:
381
    int64_t getInt64() const override
382
58
    {
383
58
        return Base::getValue();
384
58
    }
385
};
386
387
/**
388
 * Base class for 8-bit unsigned integral reflectables.
389
 *
390
 * Implements getUInt8() conversion.
391
 */
392
template <typename ALLOC>
393
class UInt8ReflectableBase : public UnsignedReflectableBase<ALLOC, uint8_t>
394
{
395
protected:
396
    using Base = UnsignedReflectableBase<ALLOC, uint8_t>;
397
398
    using Base::Base;
399
400
public:
401
    uint8_t getUInt8() const override
402
62
    {
403
62
        return Base::getValue();
404
62
    }
405
};
406
407
/**
408
 * Base class for 16-bit unsigned integral reflectables.
409
 *
410
 * Implements getUInt16() conversion.
411
 */
412
template <typename ALLOC>
413
class UInt16ReflectableBase : public UnsignedReflectableBase<ALLOC, uint16_t>
414
{
415
protected:
416
    using Base = UnsignedReflectableBase<ALLOC, uint16_t>;
417
418
    using Base::Base;
419
420
public:
421
    uint16_t getUInt16() const override
422
40
    {
423
40
        return Base::getValue();
424
40
    }
425
};
426
427
/**
428
 * Base class for 32-bit unsigned integral reflectables.
429
 *
430
 * Implements getUInt32() conversion.
431
 */
432
template <typename ALLOC>
433
class UInt32ReflectableBase : public UnsignedReflectableBase<ALLOC, uint32_t>
434
{
435
protected:
436
    using Base = UnsignedReflectableBase<ALLOC, uint32_t>;
437
438
    using Base::Base;
439
440
public:
441
    uint32_t getUInt32() const override
442
111
    {
443
111
        return Base::getValue();
444
111
    }
445
};
446
447
/**
448
 * Base class for 64-bit unsigned integral reflectables.
449
 *
450
 * Implements getUInt64() conversion.
451
 */
452
template <typename ALLOC>
453
class UInt64ReflectableBase : public UnsignedReflectableBase<ALLOC, uint64_t>
454
{
455
protected:
456
    using Base = UnsignedReflectableBase<ALLOC, uint64_t>;
457
458
    using Base::Base;
459
460
public:
461
    uint64_t getUInt64() const override
462
58
    {
463
58
        return Base::getValue();
464
58
    }
465
};
466
467
/**
468
 * Reflectable for int8 type.
469
 */
470
template <typename ALLOC>
471
class Int8Reflectable : public Int8ReflectableBase<ALLOC>
472
{
473
private:
474
    using Base = Int8ReflectableBase<ALLOC>;
475
476
public:
477
    static const IBasicTypeInfo<ALLOC>& typeInfo()
478
32
    {
479
32
        return BuiltinTypeInfo<ALLOC>::getInt8();
480
32
    }
481
482
    explicit Int8Reflectable(int8_t value) :
483
            Base(typeInfo(), value)
484
30
    {}
485
486
    size_t bitSizeOf(size_t) const override
487
13
    {
488
13
        return 8;
489
13
    }
490
491
    void write(BitStreamWriter& writer) const override
492
13
    {
493
13
        writer.writeSignedBits(Base::getValue(), 8);
494
13
    }
495
};
496
497
/**
498
 * Reflectable for int16 type.
499
 */
500
template <typename ALLOC>
501
class Int16Reflectable : public Int16ReflectableBase<ALLOC>
502
{
503
private:
504
    using Base = Int16ReflectableBase<ALLOC>;
505
506
public:
507
    static const IBasicTypeInfo<ALLOC>& typeInfo()
508
22
    {
509
22
        return BuiltinTypeInfo<ALLOC>::getInt16();
510
22
    }
511
512
    explicit Int16Reflectable(int16_t value) :
513
            Base(typeInfo(), value)
514
20
    {}
515
516
    size_t bitSizeOf(size_t) const override
517
9
    {
518
9
        return 16;
519
9
    }
520
521
    void write(BitStreamWriter& writer) const override
522
9
    {
523
9
        writer.writeSignedBits(Base::getValue(), 16);
524
9
    }
525
};
526
527
/**
528
 * Reflectable for int32 type.
529
 */
530
template <typename ALLOC>
531
class Int32Reflectable : public Int32ReflectableBase<ALLOC>
532
{
533
private:
534
    using Base = Int32ReflectableBase<ALLOC>;
535
536
public:
537
    static const IBasicTypeInfo<ALLOC>& typeInfo()
538
25
    {
539
25
        return BuiltinTypeInfo<ALLOC>::getInt32();
540
25
    }
541
542
    explicit Int32Reflectable(int32_t value) :
543
            Base(typeInfo(), value)
544
23
    {}
545
546
    size_t bitSizeOf(size_t) const override
547
9
    {
548
9
        return 32;
549
9
    }
550
551
    void write(BitStreamWriter& writer) const override
552
9
    {
553
9
        writer.writeSignedBits(Base::getValue(), 32);
554
9
    }
555
};
556
557
/**
558
 * Reflectable for int64 type.
559
 */
560
template <typename ALLOC>
561
class Int64Reflectable : public Int64ReflectableBase<ALLOC>
562
{
563
private:
564
    using Base = Int64ReflectableBase<ALLOC>;
565
566
public:
567
    static const IBasicTypeInfo<ALLOC>& typeInfo()
568
21
    {
569
21
        return BuiltinTypeInfo<ALLOC>::getInt64();
570
21
    }
571
572
    explicit Int64Reflectable(int64_t value) :
573
            Base(typeInfo(), value)
574
19
    {}
575
576
    size_t bitSizeOf(size_t) const override
577
9
    {
578
9
        return 64;
579
9
    }
580
581
    void write(BitStreamWriter& writer) const override
582
9
    {
583
9
        writer.writeSignedBits64(Base::getValue(), 64);
584
9
    }
585
};
586
587
/**
588
 * Reflectable for uint8 type.
589
 */
590
template <typename ALLOC>
591
class UInt8Reflectable : public UInt8ReflectableBase<ALLOC>
592
{
593
private:
594
    using Base = UInt8ReflectableBase<ALLOC>;
595
596
public:
597
    static const IBasicTypeInfo<ALLOC>& typeInfo()
598
47
    {
599
47
        return BuiltinTypeInfo<ALLOC>::getUInt8();
600
47
    }
601
602
    explicit UInt8Reflectable(uint8_t value) :
603
            Base(typeInfo(), value)
604
43
    {}
605
606
    size_t bitSizeOf(size_t) const override
607
9
    {
608
9
        return 8;
609
9
    }
610
611
    void write(BitStreamWriter& writer) const override
612
9
    {
613
9
        writer.writeBits(Base::getValue(), 8);
614
9
    }
615
};
616
617
/**
618
 * Reflectable for uint16 type.
619
 */
620
template <typename ALLOC>
621
class UInt16Reflectable : public UInt16ReflectableBase<ALLOC>
622
{
623
private:
624
    using Base = UInt16ReflectableBase<ALLOC>;
625
626
public:
627
    static const IBasicTypeInfo<ALLOC>& typeInfo()
628
21
    {
629
21
        return BuiltinTypeInfo<ALLOC>::getUInt16();
630
21
    }
631
632
    explicit UInt16Reflectable(uint16_t value) :
633
            Base(typeInfo(), value)
634
19
    {}
635
636
    size_t bitSizeOf(size_t) const override
637
9
    {
638
9
        return 16;
639
9
    }
640
641
    void write(BitStreamWriter& writer) const override
642
9
    {
643
9
        writer.writeBits(Base::getValue(), 16);
644
9
    }
645
};
646
647
/**
648
 * Reflectable for uint32 type.
649
 */
650
template <typename ALLOC>
651
class UInt32Reflectable : public UInt32ReflectableBase<ALLOC>
652
{
653
private:
654
    using Base = UInt32ReflectableBase<ALLOC>;
655
656
public:
657
    static const IBasicTypeInfo<ALLOC>& typeInfo()
658
107
    {
659
107
        return BuiltinTypeInfo<ALLOC>::getUInt32();
660
107
    }
661
662
    explicit UInt32Reflectable(uint32_t value) :
663
            Base(typeInfo(), value)
664
96
    {}
665
666
    size_t bitSizeOf(size_t) const override
667
9
    {
668
9
        return 32;
669
9
    }
670
671
    void write(BitStreamWriter& writer) const override
672
9
    {
673
9
        writer.writeBits(Base::getValue(), 32);
674
9
    }
675
};
676
677
/**
678
 * Reflectable for uint64 type.
679
 */
680
template <typename ALLOC>
681
class UInt64Reflectable : public UInt64ReflectableBase<ALLOC>
682
{
683
private:
684
    using Base = UInt64ReflectableBase<ALLOC>;
685
686
public:
687
    static const IBasicTypeInfo<ALLOC>& typeInfo()
688
22
    {
689
22
        return BuiltinTypeInfo<ALLOC>::getUInt64();
690
22
    }
691
692
    explicit UInt64Reflectable(uint64_t value) :
693
            Base(typeInfo(), value)
694
20
    {}
695
696
    size_t bitSizeOf(size_t) const override
697
9
    {
698
9
        return 64;
699
9
    }
700
701
    void write(BitStreamWriter& writer) const override
702
9
    {
703
9
        writer.writeBits64(Base::getValue(), 64);
704
9
    }
705
};
706
707
template <typename ALLOC, typename T>
708
class FixedSignedBitFieldReflectable;
709
710
template <typename ALLOC>
711
class FixedSignedBitFieldReflectable<ALLOC, int8_t> : public Int8ReflectableBase<ALLOC>
712
{
713
private:
714
    using Base = Int8ReflectableBase<ALLOC>;
715
716
public:
717
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
718
21
    {
719
21
        return BuiltinTypeInfo<ALLOC>::getFixedSignedBitField(bitSize);
720
21
    }
721
722
    FixedSignedBitFieldReflectable(int8_t value, uint8_t bitSize) :
723
            Base(typeInfo(bitSize), value)
724
19
    {
725
19
        if (bitSize > 8)
726
1
        {
727
1
            throw CppRuntimeException("FixedSignedBitFieldReflectable ")
728
1
                    << " - invalid bit size '" << bitSize << "' for 'int8_t' value!";
729
1
        }
730
19
    }
731
732
    size_t bitSizeOf(size_t) const override
733
16
    {
734
16
        return Base::getTypeInfo().getBitSize();
735
16
    }
736
737
    void write(BitStreamWriter& writer) const override
738
16
    {
739
16
        writer.writeSignedBits(Base::getValue(), Base::getTypeInfo().getBitSize());
740
16
    }
741
};
742
743
template <typename ALLOC>
744
class FixedSignedBitFieldReflectable<ALLOC, int16_t> : public Int16ReflectableBase<ALLOC>
745
{
746
private:
747
    using Base = Int16ReflectableBase<ALLOC>;
748
749
public:
750
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
751
3
    {
752
3
        return BuiltinTypeInfo<ALLOC>::getFixedSignedBitField(bitSize);
753
3
    }
754
755
    FixedSignedBitFieldReflectable(int16_t value, uint8_t bitSize) :
756
            Base(typeInfo(bitSize), value)
757
3
    {
758
3
        if (bitSize <= 8 || 
bitSize > 162
)
759
2
        {
760
2
            throw CppRuntimeException("FixedSignedBitFieldReflectable ")
761
2
                    << " - invalid bit size '" << bitSize << "' for 'int16_t' value!";
762
2
        }
763
3
    }
764
765
    size_t bitSizeOf(size_t) const override
766
1
    {
767
1
        return Base::getTypeInfo().getBitSize();
768
1
    }
769
770
    void write(BitStreamWriter& writer) const override
771
1
    {
772
1
        writer.writeSignedBits(Base::getValue(), Base::getTypeInfo().getBitSize());
773
1
    }
774
};
775
776
template <typename ALLOC>
777
class FixedSignedBitFieldReflectable<ALLOC, int32_t> : public Int32ReflectableBase<ALLOC>
778
{
779
private:
780
    using Base = Int32ReflectableBase<ALLOC>;
781
782
public:
783
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
784
37
    {
785
37
        return BuiltinTypeInfo<ALLOC>::getFixedSignedBitField(bitSize);
786
37
    }
787
788
    FixedSignedBitFieldReflectable(int32_t value, uint8_t bitSize) :
789
            Base(typeInfo(bitSize), value)
790
37
    {
791
37
        if (bitSize <= 16 || 
bitSize > 3236
)
792
2
        {
793
2
            throw CppRuntimeException("FixedSignedBitFieldReflectable ")
794
2
                    << " - invalid bit size '" << bitSize << "' for 'int32_t' value!";
795
2
        }
796
37
    }
797
798
    size_t bitSizeOf(size_t) const override
799
1
    {
800
1
        return Base::getTypeInfo().getBitSize();
801
1
    }
802
803
    void write(BitStreamWriter& writer) const override
804
1
    {
805
1
        writer.writeSignedBits(Base::getValue(), Base::getTypeInfo().getBitSize());
806
1
    }
807
};
808
809
template <typename ALLOC>
810
class FixedSignedBitFieldReflectable<ALLOC, int64_t> : public Int64ReflectableBase<ALLOC>
811
{
812
private:
813
    using Base = Int64ReflectableBase<ALLOC>;
814
815
public:
816
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
817
3
    {
818
3
        return BuiltinTypeInfo<ALLOC>::getFixedSignedBitField(bitSize);
819
3
    }
820
821
    FixedSignedBitFieldReflectable(int64_t value, uint8_t bitSize) :
822
            Base(typeInfo(bitSize), value)
823
3
    {
824
3
        if (bitSize <= 32) // check for maximum bit size (64) is done in type info
825
1
        {
826
1
            throw CppRuntimeException("FixedSignedBitFieldReflectable ")
827
1
                    << " - invalid bit size '" << bitSize << "' for 'int64_t' value!";
828
1
        }
829
3
    }
830
831
    size_t bitSizeOf(size_t) const override
832
1
    {
833
1
        return Base::getTypeInfo().getBitSize();
834
1
    }
835
836
    void write(BitStreamWriter& writer) const override
837
1
    {
838
1
        writer.writeSignedBits64(Base::getValue(), Base::getTypeInfo().getBitSize());
839
1
    }
840
};
841
842
template <typename ALLOC, typename T>
843
class FixedUnsignedBitFieldReflectable;
844
845
template <typename ALLOC>
846
class FixedUnsignedBitFieldReflectable<ALLOC, uint8_t> : public UInt8ReflectableBase<ALLOC>
847
{
848
private:
849
    using Base = UInt8ReflectableBase<ALLOC>;
850
851
public:
852
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
853
14
    {
854
14
        return BuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(bitSize);
855
14
    }
856
857
    FixedUnsignedBitFieldReflectable(uint8_t value, uint8_t bitSize) :
858
            Base(typeInfo(bitSize), value)
859
12
    {
860
12
        if (bitSize > 8)
861
1
        {
862
1
            throw CppRuntimeException("FixedUnsignedBitFieldReflectable")
863
1
                    << " - invalid bit size '" << bitSize << "' for 'uint8_t' value!";
864
1
        }
865
12
    }
866
867
    size_t bitSizeOf(size_t) const override
868
11
    {
869
11
        return Base::getTypeInfo().getBitSize();
870
11
    }
871
872
    void write(BitStreamWriter& writer) const override
873
11
    {
874
11
        writer.writeBits(Base::getValue(), Base::getTypeInfo().getBitSize());
875
11
    }
876
};
877
878
template <typename ALLOC>
879
class FixedUnsignedBitFieldReflectable<ALLOC, uint16_t> : public UInt16ReflectableBase<ALLOC>
880
{
881
private:
882
    using Base = UInt16ReflectableBase<ALLOC>;
883
884
public:
885
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
886
3
    {
887
3
        return BuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(bitSize);
888
3
    }
889
890
    FixedUnsignedBitFieldReflectable(uint16_t value, uint8_t bitSize) :
891
            Base(typeInfo(bitSize), value)
892
3
    {
893
3
        if (bitSize <= 8 || 
bitSize > 162
)
894
2
        {
895
2
            throw CppRuntimeException("FixedUnsignedBitFieldReflectable")
896
2
                    << " - invalid bit size '" << bitSize << "' for 'uint16_t' value!";
897
2
        }
898
3
    }
899
900
    size_t bitSizeOf(size_t) const override
901
1
    {
902
1
        return Base::getTypeInfo().getBitSize();
903
1
    }
904
905
    void write(BitStreamWriter& writer) const override
906
1
    {
907
1
        writer.writeBits(Base::getValue(), Base::getTypeInfo().getBitSize());
908
1
    }
909
};
910
911
template <typename ALLOC>
912
class FixedUnsignedBitFieldReflectable<ALLOC, uint32_t> : public UInt32ReflectableBase<ALLOC>
913
{
914
private:
915
    using Base = UInt32ReflectableBase<ALLOC>;
916
917
public:
918
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
919
74
    {
920
74
        return BuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(bitSize);
921
74
    }
922
923
    FixedUnsignedBitFieldReflectable(uint32_t value, uint8_t bitSize) :
924
            Base(typeInfo(bitSize), value)
925
74
    {
926
74
        if (bitSize <= 16 || 
bitSize > 3273
)
927
2
        {
928
2
            throw CppRuntimeException("FixedUnsignedBitFieldReflectable")
929
2
                    << " - invalid bit size '" << bitSize << "' for 'uint32_t' value!";
930
2
        }
931
74
    }
932
933
    size_t bitSizeOf(size_t) const override
934
1
    {
935
1
        return Base::getTypeInfo().getBitSize();
936
1
    }
937
938
    void write(BitStreamWriter& writer) const override
939
1
    {
940
1
        writer.writeBits(Base::getValue(), Base::getTypeInfo().getBitSize());
941
1
    }
942
};
943
944
template <typename ALLOC>
945
class FixedUnsignedBitFieldReflectable<ALLOC, uint64_t> : public UInt64ReflectableBase<ALLOC>
946
{
947
private:
948
    using Base = UInt64ReflectableBase<ALLOC>;
949
950
public:
951
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t bitSize)
952
3
    {
953
3
        return BuiltinTypeInfo<ALLOC>::getFixedUnsignedBitField(bitSize);
954
3
    }
955
956
    FixedUnsignedBitFieldReflectable(uint64_t value, uint8_t bitSize) :
957
            Base(typeInfo(bitSize), value)
958
3
    {
959
3
        if (bitSize <= 32) // check for maximum bit size (64) is done in type info
960
1
        {
961
1
            throw CppRuntimeException("FixedUnsignedBitFieldReflectable")
962
1
                    << " - invalid bit size '" << bitSize << "' for 'uint64_t' value!";
963
1
        }
964
3
    }
965
966
    size_t bitSizeOf(size_t) const override
967
1
    {
968
1
        return Base::getTypeInfo().getBitSize();
969
1
    }
970
971
    void write(BitStreamWriter& writer) const override
972
1
    {
973
1
        writer.writeBits64(Base::getValue(), Base::getTypeInfo().getBitSize());
974
1
    }
975
};
976
977
template <typename ALLOC, typename T>
978
class DynamicSignedBitFieldReflectable;
979
980
template <typename ALLOC>
981
class DynamicSignedBitFieldReflectable<ALLOC, int8_t> : public Int8ReflectableBase<ALLOC>
982
{
983
private:
984
    using Base = Int8ReflectableBase<ALLOC>;
985
986
public:
987
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
988
22
    {
989
22
        return BuiltinTypeInfo<ALLOC>::getDynamicSignedBitField(maxBitSize);
990
22
    }
991
992
    DynamicSignedBitFieldReflectable(int8_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
993
            Base(typeInfo(maxBitSize), value),
994
            m_dynamicBitSize(dynamicBitSize)
995
20
    {
996
20
        if (maxBitSize > 8)
997
1
        {
998
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable")
999
1
                    << " - invalid max bit size '" << maxBitSize << "' for 'int8_t' value!";
1000
1
        }
1001
1002
19
        if (dynamicBitSize > maxBitSize)
1003
1
        {
1004
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1005
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1006
1
        }
1007
19
    }
1008
1009
    size_t bitSizeOf(size_t) const override
1010
16
    {
1011
16
        return m_dynamicBitSize;
1012
16
    }
1013
1014
    void write(BitStreamWriter& writer) const override
1015
16
    {
1016
16
        writer.writeSignedBits(Base::getValue(), m_dynamicBitSize);
1017
16
    }
1018
1019
private:
1020
    uint8_t m_dynamicBitSize;
1021
};
1022
1023
template <typename ALLOC>
1024
class DynamicSignedBitFieldReflectable<ALLOC, int16_t> : public Int16ReflectableBase<ALLOC>
1025
{
1026
private:
1027
    using Base = Int16ReflectableBase<ALLOC>;
1028
1029
public:
1030
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1031
4
    {
1032
4
        return BuiltinTypeInfo<ALLOC>::getDynamicSignedBitField(maxBitSize);
1033
4
    }
1034
1035
    DynamicSignedBitFieldReflectable(int16_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1036
            Base(typeInfo(maxBitSize), value),
1037
            m_dynamicBitSize(dynamicBitSize)
1038
4
    {
1039
4
        if (maxBitSize <= 8 || 
maxBitSize > 163
)
1040
2
        {
1041
2
            throw CppRuntimeException("DynamicSignedBitFieldReflectable")
1042
2
                    << " - invalid max bit size '" << maxBitSize << "' for 'int16_t' value!";
1043
2
        }
1044
1045
2
        if (dynamicBitSize > maxBitSize)
1046
1
        {
1047
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1048
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1049
1
        }
1050
2
    }
1051
1052
    size_t bitSizeOf(size_t) const override
1053
1
    {
1054
1
        return m_dynamicBitSize;
1055
1
    }
1056
1057
    void write(BitStreamWriter& writer) const override
1058
1
    {
1059
1
        writer.writeSignedBits(Base::getValue(), m_dynamicBitSize);
1060
1
    }
1061
1062
private:
1063
    uint8_t m_dynamicBitSize;
1064
};
1065
1066
template <typename ALLOC>
1067
class DynamicSignedBitFieldReflectable<ALLOC, int32_t> : public Int32ReflectableBase<ALLOC>
1068
{
1069
private:
1070
    using Base = Int32ReflectableBase<ALLOC>;
1071
1072
public:
1073
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1074
4
    {
1075
4
        return BuiltinTypeInfo<ALLOC>::getDynamicSignedBitField(maxBitSize);
1076
4
    }
1077
1078
    DynamicSignedBitFieldReflectable(int32_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1079
            Base(typeInfo(maxBitSize), value),
1080
            m_dynamicBitSize(dynamicBitSize)
1081
4
    {
1082
4
        if (maxBitSize <= 16 || 
maxBitSize > 323
)
1083
2
        {
1084
2
            throw CppRuntimeException("DynamicSignedBitFieldReflectable")
1085
2
                    << " - invalid max bit size '" << maxBitSize << "' for 'int32_t' value!";
1086
2
        }
1087
1088
2
        if (dynamicBitSize > maxBitSize)
1089
1
        {
1090
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1091
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1092
1
        }
1093
2
    }
1094
1095
    size_t bitSizeOf(size_t) const override
1096
1
    {
1097
1
        return m_dynamicBitSize;
1098
1
    }
1099
1100
    void write(BitStreamWriter& writer) const override
1101
1
    {
1102
1
        writer.writeSignedBits(Base::getValue(), m_dynamicBitSize);
1103
1
    }
1104
1105
private:
1106
    uint8_t m_dynamicBitSize;
1107
};
1108
1109
template <typename ALLOC>
1110
class DynamicSignedBitFieldReflectable<ALLOC, int64_t> : public Int64ReflectableBase<ALLOC>
1111
{
1112
private:
1113
    using Base = Int64ReflectableBase<ALLOC>;
1114
1115
public:
1116
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1117
5
    {
1118
5
        return BuiltinTypeInfo<ALLOC>::getDynamicSignedBitField(maxBitSize);
1119
5
    }
1120
1121
    DynamicSignedBitFieldReflectable(int64_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1122
            Base(typeInfo(maxBitSize), value),
1123
            m_dynamicBitSize(dynamicBitSize)
1124
5
    {
1125
5
        if (maxBitSize <= 32) // check for maximum bit size (64) is done in type info
1126
1
        {
1127
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable")
1128
1
                    << " - invalid max bit size '" << maxBitSize << "' for 'int64_t' value!";
1129
1
        }
1130
1131
4
        if (dynamicBitSize > maxBitSize)
1132
1
        {
1133
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1134
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1135
1
        }
1136
4
    }
1137
1138
    size_t bitSizeOf(size_t) const override
1139
1
    {
1140
1
        return m_dynamicBitSize;
1141
1
    }
1142
1143
    void write(BitStreamWriter& writer) const override
1144
1
    {
1145
1
        writer.writeSignedBits64(Base::getValue(), m_dynamicBitSize);
1146
1
    }
1147
1148
private:
1149
    uint8_t m_dynamicBitSize;
1150
};
1151
1152
template <typename ALLOC, typename T>
1153
class DynamicUnsignedBitFieldReflectable;
1154
1155
template <typename ALLOC>
1156
class DynamicUnsignedBitFieldReflectable<ALLOC, uint8_t> : public UInt8ReflectableBase<ALLOC>
1157
{
1158
private:
1159
    using Base = UInt8ReflectableBase<ALLOC>;
1160
1161
public:
1162
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1163
15
    {
1164
15
        return BuiltinTypeInfo<ALLOC>::getDynamicUnsignedBitField(maxBitSize);
1165
15
    }
1166
1167
    DynamicUnsignedBitFieldReflectable(uint8_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1168
            Base(typeInfo(maxBitSize), value),
1169
            m_dynamicBitSize(dynamicBitSize)
1170
13
    {
1171
13
        if (maxBitSize > 8)
1172
1
        {
1173
1
            throw CppRuntimeException("DynamicUnsignedBitFieldReflectable")
1174
1
                    << " - invalid max bit size '" << maxBitSize << "' for 'uint8_t' value!";
1175
1
        }
1176
1177
12
        if (dynamicBitSize > maxBitSize)
1178
1
        {
1179
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1180
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1181
1
        }
1182
12
    }
1183
1184
    size_t bitSizeOf(size_t) const override
1185
11
    {
1186
11
        return m_dynamicBitSize;
1187
11
    }
1188
1189
    void write(BitStreamWriter& writer) const override
1190
11
    {
1191
11
        writer.writeBits(Base::getValue(), m_dynamicBitSize);
1192
11
    }
1193
1194
private:
1195
    uint8_t m_dynamicBitSize;
1196
};
1197
1198
template <typename ALLOC>
1199
class DynamicUnsignedBitFieldReflectable<ALLOC, uint16_t> : public UInt16ReflectableBase<ALLOC>
1200
{
1201
private:
1202
    using Base = UInt16ReflectableBase<ALLOC>;
1203
1204
public:
1205
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1206
4
    {
1207
4
        return BuiltinTypeInfo<ALLOC>::getDynamicUnsignedBitField(maxBitSize);
1208
4
    }
1209
1210
    DynamicUnsignedBitFieldReflectable(uint16_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1211
            Base(typeInfo(maxBitSize), value),
1212
            m_dynamicBitSize(dynamicBitSize)
1213
4
    {
1214
4
        if (maxBitSize <= 8 || 
maxBitSize > 163
)
1215
2
        {
1216
2
            throw CppRuntimeException("DynamicUnsignedBitFieldReflectable")
1217
2
                    << " - invalid max bit size '" << maxBitSize << "' for 'uint16_t' value!";
1218
2
        }
1219
1220
2
        if (dynamicBitSize > maxBitSize)
1221
1
        {
1222
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1223
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1224
1
        }
1225
2
    }
1226
1227
    size_t bitSizeOf(size_t) const override
1228
1
    {
1229
1
        return m_dynamicBitSize;
1230
1
    }
1231
1232
    void write(BitStreamWriter& writer) const override
1233
1
    {
1234
1
        writer.writeBits(Base::getValue(), m_dynamicBitSize);
1235
1
    }
1236
1237
private:
1238
    uint8_t m_dynamicBitSize;
1239
};
1240
1241
template <typename ALLOC>
1242
class DynamicUnsignedBitFieldReflectable<ALLOC, uint32_t> : public UInt32ReflectableBase<ALLOC>
1243
{
1244
private:
1245
    using Base = UInt32ReflectableBase<ALLOC>;
1246
1247
public:
1248
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1249
4
    {
1250
4
        return BuiltinTypeInfo<ALLOC>::getDynamicUnsignedBitField(maxBitSize);
1251
4
    }
1252
1253
    DynamicUnsignedBitFieldReflectable(uint32_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1254
            Base(typeInfo(maxBitSize), value),
1255
            m_dynamicBitSize(dynamicBitSize)
1256
4
    {
1257
4
        if (maxBitSize <= 16 || 
maxBitSize > 323
)
1258
2
        {
1259
2
            throw CppRuntimeException("DynamicUnsignedBitFieldReflectable")
1260
2
                    << " - invalid max bit size '" << maxBitSize << "' for 'uint32_t' value!";
1261
2
        }
1262
1263
2
        if (dynamicBitSize > maxBitSize)
1264
1
        {
1265
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1266
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1267
1
        }
1268
2
    }
1269
1270
    size_t bitSizeOf(size_t) const override
1271
1
    {
1272
1
        return m_dynamicBitSize;
1273
1
    }
1274
1275
    void write(BitStreamWriter& writer) const override
1276
1
    {
1277
1
        writer.writeBits(Base::getValue(), m_dynamicBitSize);
1278
1
    }
1279
1280
private:
1281
    uint8_t m_dynamicBitSize;
1282
};
1283
1284
template <typename ALLOC>
1285
class DynamicUnsignedBitFieldReflectable<ALLOC, uint64_t> : public UInt64ReflectableBase<ALLOC>
1286
{
1287
private:
1288
    using Base = UInt64ReflectableBase<ALLOC>;
1289
1290
public:
1291
    static const IBasicTypeInfo<ALLOC>& typeInfo(uint8_t maxBitSize)
1292
5
    {
1293
5
        return BuiltinTypeInfo<ALLOC>::getDynamicUnsignedBitField(maxBitSize);
1294
5
    }
1295
1296
    DynamicUnsignedBitFieldReflectable(uint64_t value, uint8_t maxBitSize, uint8_t dynamicBitSize) :
1297
            Base(typeInfo(maxBitSize), value),
1298
            m_dynamicBitSize(dynamicBitSize)
1299
5
    {
1300
5
        if (maxBitSize <= 32) // check for maximum bit size (64) is done in type info
1301
1
        {
1302
1
            throw CppRuntimeException("DynamicUnsignedBitFieldReflectable")
1303
1
                    << " - invalid max bit size '" << maxBitSize << "' for 'uint64_t' value!";
1304
1
        }
1305
1306
4
        if (dynamicBitSize > maxBitSize)
1307
1
        {
1308
1
            throw CppRuntimeException("DynamicSignedBitFieldReflectable - dynamic bit size '")
1309
1
                    << dynamicBitSize << "' is greater than max bit size '" << maxBitSize << "'!";
1310
1
        }
1311
4
    }
1312
1313
    size_t bitSizeOf(size_t) const override
1314
1
    {
1315
1
        return m_dynamicBitSize;
1316
1
    }
1317
1318
    void write(BitStreamWriter& writer) const override
1319
1
    {
1320
1
        writer.writeBits64(Base::getValue(), m_dynamicBitSize);
1321
1
    }
1322
1323
private:
1324
    uint8_t m_dynamicBitSize;
1325
};
1326
1327
/**
1328
 * Reflectable for varint16 type.
1329
 */
1330
template <typename ALLOC>
1331
class VarInt16Reflectable : public Int16ReflectableBase<ALLOC>
1332
{
1333
private:
1334
    using Base = Int16ReflectableBase<ALLOC>;
1335
1336
public:
1337
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1338
12
    {
1339
12
        return BuiltinTypeInfo<ALLOC>::getVarInt16();
1340
12
    }
1341
1342
    explicit VarInt16Reflectable(int16_t value) :
1343
            Base(typeInfo(), value)
1344
10
    {}
1345
1346
    size_t bitSizeOf(size_t) const override
1347
9
    {
1348
9
        return zserio::bitSizeOfVarInt16(Base::getValue());
1349
9
    }
1350
1351
    void write(BitStreamWriter& writer) const override
1352
9
    {
1353
9
        writer.writeVarInt16(Base::getValue());
1354
9
    }
1355
};
1356
1357
/**
1358
 * Reflectable for varint32 type.
1359
 */
1360
template <typename ALLOC>
1361
class VarInt32Reflectable : public Int32ReflectableBase<ALLOC>
1362
{
1363
private:
1364
    using Base = Int32ReflectableBase<ALLOC>;
1365
1366
public:
1367
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1368
12
    {
1369
12
        return BuiltinTypeInfo<ALLOC>::getVarInt32();
1370
12
    }
1371
1372
    explicit VarInt32Reflectable(int32_t value) :
1373
            Base(typeInfo(), value)
1374
10
    {}
1375
1376
    size_t bitSizeOf(size_t) const override
1377
9
    {
1378
9
        return zserio::bitSizeOfVarInt32(Base::getValue());
1379
9
    }
1380
1381
    void write(BitStreamWriter& writer) const override
1382
9
    {
1383
9
        writer.writeVarInt32(Base::getValue());
1384
9
    }
1385
};
1386
1387
/**
1388
 * Reflectable for varint64 type.
1389
 */
1390
template <typename ALLOC>
1391
class VarInt64Reflectable : public Int64ReflectableBase<ALLOC>
1392
{
1393
private:
1394
    using Base = Int64ReflectableBase<ALLOC>;
1395
1396
public:
1397
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1398
12
    {
1399
12
        return BuiltinTypeInfo<ALLOC>::getVarInt64();
1400
12
    }
1401
1402
    explicit VarInt64Reflectable(int64_t value) :
1403
            Base(typeInfo(), value)
1404
10
    {}
1405
1406
    size_t bitSizeOf(size_t) const override
1407
9
    {
1408
9
        return zserio::bitSizeOfVarInt64(Base::getValue());
1409
9
    }
1410
1411
    void write(BitStreamWriter& writer) const override
1412
9
    {
1413
9
        writer.writeVarInt64(Base::getValue());
1414
9
    }
1415
};
1416
1417
/**
1418
 * Reflectable for varint type.
1419
 */
1420
template <typename ALLOC>
1421
class VarIntReflectable : public Int64ReflectableBase<ALLOC>
1422
{
1423
private:
1424
    using Base = Int64ReflectableBase<ALLOC>;
1425
1426
public:
1427
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1428
13
    {
1429
13
        return BuiltinTypeInfo<ALLOC>::getVarInt();
1430
13
    }
1431
1432
    explicit VarIntReflectable(int64_t value) :
1433
            Base(typeInfo(), value)
1434
11
    {}
1435
1436
    size_t bitSizeOf(size_t) const override
1437
9
    {
1438
9
        return zserio::bitSizeOfVarInt(Base::getValue());
1439
9
    }
1440
1441
    void write(BitStreamWriter& writer) const override
1442
9
    {
1443
9
        writer.writeVarInt(Base::getValue());
1444
9
    }
1445
};
1446
1447
/**
1448
 * Reflectable for varuint16 type.
1449
 */
1450
template <typename ALLOC>
1451
class VarUInt16Reflectable : public UInt16ReflectableBase<ALLOC>
1452
{
1453
private:
1454
    using Base = UInt16ReflectableBase<ALLOC>;
1455
1456
public:
1457
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1458
12
    {
1459
12
        return BuiltinTypeInfo<ALLOC>::getVarUInt16();
1460
12
    }
1461
1462
    explicit VarUInt16Reflectable(uint16_t value) :
1463
            Base(typeInfo(), value)
1464
10
    {}
1465
1466
    size_t bitSizeOf(size_t) const override
1467
9
    {
1468
9
        return zserio::bitSizeOfVarUInt16(Base::getValue());
1469
9
    }
1470
1471
    void write(BitStreamWriter& writer) const override
1472
9
    {
1473
9
        writer.writeVarUInt16(Base::getValue());
1474
9
    }
1475
};
1476
1477
/**
1478
 * Reflectable for varuint32 type.
1479
 */
1480
template <typename ALLOC>
1481
class VarUInt32Reflectable : public UInt32ReflectableBase<ALLOC>
1482
{
1483
private:
1484
    using Base = UInt32ReflectableBase<ALLOC>;
1485
1486
public:
1487
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1488
12
    {
1489
12
        return BuiltinTypeInfo<ALLOC>::getVarUInt32();
1490
12
    }
1491
1492
    explicit VarUInt32Reflectable(uint32_t value) :
1493
            Base(typeInfo(), value)
1494
10
    {}
1495
1496
    size_t bitSizeOf(size_t) const override
1497
9
    {
1498
9
        return zserio::bitSizeOfVarUInt32(Base::getValue());
1499
9
    }
1500
1501
    void write(BitStreamWriter& writer) const override
1502
9
    {
1503
9
        writer.writeVarUInt32(Base::getValue());
1504
9
    }
1505
};
1506
1507
/**
1508
 * Reflectable for varuint64 type.
1509
 */
1510
template <typename ALLOC>
1511
class VarUInt64Reflectable : public UInt64ReflectableBase<ALLOC>
1512
{
1513
private:
1514
    using Base = UInt64ReflectableBase<ALLOC>;
1515
1516
public:
1517
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1518
12
    {
1519
12
        return BuiltinTypeInfo<ALLOC>::getVarUInt64();
1520
12
    }
1521
1522
    explicit VarUInt64Reflectable(uint64_t value) :
1523
            Base(typeInfo(), value)
1524
10
    {}
1525
1526
    size_t bitSizeOf(size_t) const override
1527
9
    {
1528
9
        return zserio::bitSizeOfVarUInt64(Base::getValue());
1529
9
    }
1530
1531
    void write(BitStreamWriter& writer) const override
1532
9
    {
1533
9
        writer.writeVarUInt64(Base::getValue());
1534
9
    }
1535
};
1536
1537
/**
1538
 * Reflectable for varuint type.
1539
 */
1540
template <typename ALLOC>
1541
class VarUIntReflectable : public UInt64ReflectableBase<ALLOC>
1542
{
1543
private:
1544
    using Base = UInt64ReflectableBase<ALLOC>;
1545
1546
public:
1547
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1548
12
    {
1549
12
        return BuiltinTypeInfo<ALLOC>::getVarUInt();
1550
12
    }
1551
1552
    explicit VarUIntReflectable(uint64_t value) :
1553
            Base(typeInfo(), value)
1554
10
    {}
1555
1556
    size_t bitSizeOf(size_t) const override
1557
9
    {
1558
9
        return zserio::bitSizeOfVarUInt(Base::getValue());
1559
9
    }
1560
1561
    void write(BitStreamWriter& writer) const override
1562
9
    {
1563
9
        writer.writeVarUInt(Base::getValue());
1564
9
    }
1565
};
1566
1567
/**
1568
 * Reflectable for varsize type.
1569
 */
1570
template <typename ALLOC>
1571
class VarSizeReflectable : public UInt32ReflectableBase<ALLOC>
1572
{
1573
private:
1574
    using Base = UInt32ReflectableBase<ALLOC>;
1575
1576
public:
1577
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1578
13
    {
1579
13
        return BuiltinTypeInfo<ALLOC>::getVarSize();
1580
13
    }
1581
1582
    explicit VarSizeReflectable(uint32_t value) :
1583
            Base(typeInfo(), value)
1584
11
    {}
1585
1586
    size_t bitSizeOf(size_t) const override
1587
9
    {
1588
9
        return zserio::bitSizeOfVarUInt(Base::getValue());
1589
9
    }
1590
1591
    void write(BitStreamWriter& writer) const override
1592
9
    {
1593
9
        writer.writeVarSize(Base::getValue());
1594
9
    }
1595
};
1596
1597
/**
1598
 * Base class for floating point reflectables.
1599
 */
1600
template <typename ALLOC, typename T>
1601
class FloatingPointReflectableBase : public BuiltinReflectableBase<ALLOC, T>
1602
{
1603
protected:
1604
    static_assert(std::is_floating_point<T>::value, "T must be a floating point type!");
1605
1606
    using BuiltinReflectableBase<ALLOC, T>::getValue;
1607
    using BuiltinReflectableBase<ALLOC, T>::BuiltinReflectableBase;
1608
1609
public:
1610
    double toDouble() const override
1611
61
    {
1612
61
        return static_cast<double>(getValue());
1613
61
    }
1614
};
1615
1616
/**
1617
 * Reflectable for values of 16-bit float type.
1618
 */
1619
template <typename ALLOC>
1620
class Float16Reflectable : public FloatingPointReflectableBase<ALLOC, float>
1621
{
1622
private:
1623
    using Base = FloatingPointReflectableBase<ALLOC, float>;
1624
1625
public:
1626
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1627
13
    {
1628
13
        return BuiltinTypeInfo<ALLOC>::getFloat16();
1629
13
    }
1630
1631
    explicit Float16Reflectable(float value) :
1632
            Base(typeInfo(), value)
1633
11
    {}
1634
1635
    size_t bitSizeOf(size_t) const override
1636
5
    {
1637
5
        return 16;
1638
5
    }
1639
1640
    void write(BitStreamWriter& writer) const override
1641
5
    {
1642
5
        writer.writeFloat16(Base::getValue());
1643
5
    }
1644
1645
    float getFloat() const override
1646
10
    {
1647
10
        return Base::getValue();
1648
10
    }
1649
};
1650
1651
/**
1652
 * Reflectable for values of 32-bit float type.
1653
 */
1654
template <typename ALLOC>
1655
class Float32Reflectable : public FloatingPointReflectableBase<ALLOC, float>
1656
{
1657
private:
1658
    using Base = FloatingPointReflectableBase<ALLOC, float>;
1659
1660
public:
1661
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1662
17
    {
1663
17
        return BuiltinTypeInfo<ALLOC>::getFloat32();
1664
17
    }
1665
1666
    explicit Float32Reflectable(float value) :
1667
            Base(typeInfo(), value)
1668
15
    {}
1669
1670
    size_t bitSizeOf(size_t) const override
1671
7
    {
1672
7
        return 32;
1673
7
    }
1674
1675
    void write(BitStreamWriter& writer) const override
1676
7
    {
1677
7
        writer.writeFloat32(Base::getValue());
1678
7
    }
1679
1680
    float getFloat() const override
1681
15
    {
1682
15
        return Base::getValue();
1683
15
    }
1684
};
1685
1686
/**
1687
 * Reflectable for values of double type.
1688
 */
1689
template <typename ALLOC>
1690
class Float64Reflectable : public FloatingPointReflectableBase<ALLOC, double>
1691
{
1692
private:
1693
    using Base = FloatingPointReflectableBase<ALLOC, double>;
1694
1695
public:
1696
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1697
45
    {
1698
45
        return BuiltinTypeInfo<ALLOC>::getFloat64();
1699
45
    }
1700
1701
    explicit Float64Reflectable(double value) :
1702
            Base(typeInfo(), value)
1703
43
    {}
1704
1705
    size_t bitSizeOf(size_t) const override
1706
7
    {
1707
7
        return 64;
1708
7
    }
1709
1710
    void write(BitStreamWriter& writer) const override
1711
7
    {
1712
7
        writer.writeFloat64(Base::getValue());
1713
7
    }
1714
1715
    double getDouble() const override
1716
15
    {
1717
15
        return Base::getValue();
1718
15
    }
1719
};
1720
1721
/**
1722
 * Reflectable for values of bytes type.
1723
 */
1724
template <typename ALLOC>
1725
class BytesReflectable : public BuiltinReflectableBase<ALLOC, Span<const uint8_t>>
1726
{
1727
private:
1728
    using Base = BuiltinReflectableBase<ALLOC, Span<const uint8_t>>;
1729
1730
public:
1731
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1732
46
    {
1733
46
        return BuiltinTypeInfo<ALLOC>::getBytes();
1734
46
    }
1735
1736
    explicit BytesReflectable(Span<const uint8_t> value) :
1737
            Base(typeInfo(), value)
1738
33
    {}
1739
1740
    size_t bitSizeOf(size_t) const override
1741
7
    {
1742
7
        return zserio::bitSizeOfBytes(Base::getValue());
1743
7
    }
1744
1745
    void write(BitStreamWriter& writer) const override
1746
7
    {
1747
7
        writer.writeBytes(Base::getValue());
1748
7
    }
1749
1750
    Span<const uint8_t> getBytes() const override
1751
54
    {
1752
54
        return Base::getValue();
1753
54
    }
1754
};
1755
1756
/**
1757
 * Reflectable for values of string type.
1758
 */
1759
template <typename ALLOC>
1760
class StringReflectable : public BuiltinReflectableBase<ALLOC, StringView>
1761
{
1762
private:
1763
    using Base = BuiltinReflectableBase<ALLOC, StringView>;
1764
1765
public:
1766
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1767
178
    {
1768
178
        return BuiltinTypeInfo<ALLOC>::getString();
1769
178
    }
1770
1771
    explicit StringReflectable(StringView value) :
1772
            Base(typeInfo(), value)
1773
157
    {}
1774
1775
    size_t bitSizeOf(size_t) const override
1776
11
    {
1777
11
        return zserio::bitSizeOfString(Base::getValue());
1778
11
    }
1779
1780
    void write(BitStreamWriter& writer) const override
1781
11
    {
1782
11
        writer.writeString(Base::getValue());
1783
11
    }
1784
1785
    StringView getStringView() const override
1786
107
    {
1787
107
        return Base::getValue();
1788
107
    }
1789
1790
    string<ALLOC> toString(const ALLOC& allocator) const override
1791
34
    {
1792
34
        return zserio::toString(Base::getValue(), allocator);
1793
34
    }
1794
};
1795
1796
/**
1797
 * Reflectable for values of bit buffer type.
1798
 */
1799
template <typename ALLOC>
1800
class BitBufferReflectable : public BuiltinReflectableBase<ALLOC, BasicBitBuffer<ALLOC>>
1801
{
1802
private:
1803
    using Base = BuiltinReflectableBase<ALLOC, BasicBitBuffer<ALLOC>>;
1804
1805
public:
1806
    static const IBasicTypeInfo<ALLOC>& typeInfo()
1807
44
    {
1808
44
        return BuiltinTypeInfo<ALLOC>::getBitBuffer();
1809
44
    }
1810
1811
    explicit BitBufferReflectable(const BasicBitBuffer<ALLOC>& value) :
1812
            Base(typeInfo(), value)
1813
32
    {}
1814
1815
    size_t bitSizeOf(size_t) const override
1816
7
    {
1817
7
        return zserio::bitSizeOfBitBuffer(Base::getValue());
1818
7
    }
1819
1820
    void write(BitStreamWriter& writer) const override
1821
7
    {
1822
7
        writer.writeBitBuffer(Base::getValue());
1823
7
    }
1824
1825
    const BasicBitBuffer<ALLOC>& getBitBuffer() const override
1826
30
    {
1827
30
        return Base::getValue();
1828
30
    }
1829
};
1830
1831
namespace detail
1832
{
1833
1834
template <typename ALLOC>
1835
IBasicReflectableConstPtr<ALLOC> getFieldFromObject(const IBasicReflectable<ALLOC>& object, StringView name)
1836
626
{
1837
626
    const auto& typeInfo = object.getTypeInfo();
1838
626
    if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1839
176
    {
1840
176
        const auto& fields = typeInfo.getFields();
1841
176
        auto fieldsIt = std::find_if(fields.begin(), fields.end(),
1842
270
                [name](const BasicFieldInfo<ALLOC>& fieldInfo) { return fieldInfo.schemaName == name; });
1843
176
        if (fieldsIt != fields.end())
1844
106
        {
1845
106
            return object.getField(name);
1846
106
        }
1847
176
    }
1848
1849
520
    return nullptr;
1850
626
}
1851
1852
template <typename ALLOC>
1853
IBasicReflectablePtr<ALLOC> getFieldFromObject(IBasicReflectable<ALLOC>& object, StringView name)
1854
488
{
1855
488
    const auto& typeInfo = object.getTypeInfo();
1856
488
    if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1857
175
    {
1858
175
        const auto& fields = typeInfo.getFields();
1859
175
        auto fieldsIt = std::find_if(fields.begin(), fields.end(),
1860
411
                [name](const BasicFieldInfo<ALLOC>& fieldInfo) { return fieldInfo.schemaName == name; });
1861
175
        if (fieldsIt != fields.end())
1862
143
        {
1863
143
            return object.getField(name);
1864
143
        }
1865
175
    }
1866
1867
345
    return nullptr;
1868
488
}
1869
1870
template <typename ALLOC>
1871
IBasicReflectableConstPtr<ALLOC> getParameterFromObject(const IBasicReflectable<ALLOC>& object, StringView name)
1872
520
{
1873
520
    const auto& typeInfo = object.getTypeInfo();
1874
520
    if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1875
70
    {
1876
70
        const auto& parameters = typeInfo.getParameters();
1877
70
        auto parametersIt = std::find_if(
1878
100
                parameters.begin(), parameters.end(), [name](const BasicParameterInfo<ALLOC>& parameterInfo) {
1879
100
                    return parameterInfo.schemaName == name;
1880
100
                });
1881
70
        if (parametersIt != parameters.end())
1882
26
        {
1883
26
            return object.getParameter(name);
1884
26
        }
1885
70
    }
1886
1887
494
    return nullptr;
1888
520
}
1889
1890
template <typename ALLOC>
1891
IBasicReflectablePtr<ALLOC> getParameterFromObject(IBasicReflectable<ALLOC>& object, StringView name)
1892
345
{
1893
345
    const auto& typeInfo = object.getTypeInfo();
1894
345
    if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1895
32
    {
1896
32
        const auto& parameters = typeInfo.getParameters();
1897
32
        auto parametersIt = std::find_if(
1898
39
                parameters.begin(), parameters.end(), [name](const BasicParameterInfo<ALLOC>& parameterInfo) {
1899
39
                    return parameterInfo.schemaName == name;
1900
39
                });
1901
32
        if (parametersIt != parameters.end())
1902
11
        {
1903
11
            return object.getParameter(name);
1904
11
        }
1905
32
    }
1906
1907
334
    return nullptr;
1908
345
}
1909
1910
template <typename ALLOC>
1911
IBasicReflectableConstPtr<ALLOC> callFunctionInObject(const IBasicReflectable<ALLOC>& object, StringView name)
1912
494
{
1913
494
    const auto& typeInfo = object.getTypeInfo();
1914
494
    if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1915
44
    {
1916
44
        const auto& functions = typeInfo.getFunctions();
1917
44
        auto functionsIt = std::find_if(
1918
44
                functions.begin(), functions.end(), [name](const BasicFunctionInfo<ALLOC>& functionInfo) {
1919
32
                    return functionInfo.schemaName == name;
1920
32
                });
1921
44
        if (functionsIt != functions.end())
1922
16
        {
1923
16
            return object.callFunction(name);
1924
16
        }
1925
44
    }
1926
1927
478
    return nullptr;
1928
494
}
1929
1930
template <typename ALLOC>
1931
IBasicReflectablePtr<ALLOC> callFunctionInObject(IBasicReflectable<ALLOC>& object, StringView name)
1932
334
{
1933
334
    const auto& typeInfo = object.getTypeInfo();
1934
334
    if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1935
21
    {
1936
21
        const auto& functions = typeInfo.getFunctions();
1937
21
        auto functionsIt = std::find_if(
1938
21
                functions.begin(), functions.end(), [name](const BasicFunctionInfo<ALLOC>& functionInfo) {
1939
12
                    return functionInfo.schemaName == name;
1940
12
                });
1941
21
        if (functionsIt != functions.end())
1942
6
        {
1943
6
            return object.callFunction(name);
1944
6
        }
1945
21
    }
1946
1947
328
    return nullptr;
1948
334
}
1949
1950
template <typename ALLOC>
1951
IBasicReflectableConstPtr<ALLOC> getFromObject(
1952
        const IBasicReflectable<ALLOC>& object, StringView path, size_t pos)
1953
626
{
1954
626
    try
1955
626
    {
1956
626
        const size_t dotPos = path.find('.', pos);
1957
626
        const bool isLast = dotPos == StringView::npos;
1958
626
        const StringView name = path.substr(pos, dotPos == StringView::npos ? 
StringView::npos82
:
dotPos - pos544
);
1959
1960
626
        auto field = getFieldFromObject(object, name);
1961
626
        if (field)
1962
106
        {
1963
106
            return isLast ? 
std::move(field)16
:
getFromObject(*field, path, dotPos + 1)90
;
1964
106
        }
1965
1966
520
        auto parameter = getParameterFromObject(object, name);
1967
520
        if (parameter)
1968
24
        {
1969
24
            return isLast ? 
std::move(parameter)16
:
getFromObject(*parameter, path, dotPos + 1)8
;
1970
24
        }
1971
1972
496
        auto functionResult = callFunctionInObject(object, name);
1973
496
        if (functionResult)
1974
16
        {
1975
16
            return isLast ? 
std::move(functionResult)8
:
getFromObject(*functionResult, path, dotPos + 1)8
;
1976
16
        }
1977
496
    }
1978
626
    catch (const CppRuntimeException&)
1979
626
    
{}2
1980
1981
480
    return nullptr;
1982
626
}
1983
1984
template <typename ALLOC>
1985
IBasicReflectablePtr<ALLOC> getFromObject(IBasicReflectable<ALLOC>& object, StringView path, size_t pos)
1986
488
{
1987
488
    try
1988
488
    {
1989
488
        const size_t dotPos = path.find('.', pos);
1990
488
        const bool isLast = dotPos == StringView::npos;
1991
488
        const StringView name = path.substr(pos, dotPos == StringView::npos ? 
StringView::npos90
:
dotPos - pos398
);
1992
1993
488
        auto field = getFieldFromObject(object, name);
1994
488
        if (field)
1995
143
        {
1996
143
            return isLast ? 
std::move(field)60
:
getFromObject(*field, path, dotPos + 1)83
;
1997
143
        }
1998
1999
345
        auto parameter = getParameterFromObject(object, name);
2000
345
        if (parameter)
2001
10
        {
2002
10
            return isLast ? 
std::move(parameter)7
:
getFromObject(*parameter, path, dotPos + 1)3
;
2003
10
        }
2004
2005
335
        auto functionResult = callFunctionInObject(object, name);
2006
335
        if (functionResult)
2007
6
        {
2008
6
            return isLast ? 
std::move(functionResult)3
:
getFromObject(*functionResult, path, dotPos + 1)3
;
2009
6
        }
2010
335
    }
2011
488
    catch (const CppRuntimeException&)
2012
488
    
{}1
2013
2014
329
    return nullptr;
2015
488
}
2016
2017
} // namespace detail
2018
2019
/**
2020
 * Base class for reflectable which needs to hold an allocator.
2021
 */
2022
template <typename ALLOC>
2023
class ReflectableAllocatorHolderBase : public ReflectableBase<ALLOC>, public AllocatorHolder<ALLOC>
2024
{
2025
public:
2026
    ReflectableAllocatorHolderBase(const IBasicTypeInfo<ALLOC>& typeInfo, const ALLOC& allocator) :
2027
            ReflectableBase<ALLOC>(typeInfo),
2028
            AllocatorHolder<ALLOC>(allocator)
2029
707
    {}
2030
};
2031
2032
/**
2033
 * Base class for constant reflectable which needs to hold an allocator.
2034
 *
2035
 * Overrides non constant methods and throws exception with info about constness.
2036
 */
2037
template <typename ALLOC>
2038
class ReflectableConstAllocatorHolderBase : public ReflectableAllocatorHolderBase<ALLOC>
2039
{
2040
private:
2041
    using Base = ReflectableAllocatorHolderBase<ALLOC>;
2042
2043
public:
2044
    using Base::Base;
2045
    using Base::getTypeInfo;
2046
2047
    void initializeChildren() override;
2048
    void initialize(const vector<AnyHolder<ALLOC>, ALLOC>& typeArguments) override;
2049
    size_t initializeOffsets(size_t bitPosition) override;
2050
2051
    IBasicReflectablePtr<ALLOC> getField(StringView name) override;
2052
    void setField(StringView name, const AnyHolder<ALLOC>& value) override;
2053
    IBasicReflectablePtr<ALLOC> getParameter(StringView name) override;
2054
    IBasicReflectablePtr<ALLOC> callFunction(StringView name) override;
2055
2056
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override;
2057
};
2058
2059
/**
2060
 * Base class for reflectable arrays.
2061
 *
2062
 * Overrides all generic methods with default throw behaviour.
2063
 */
2064
template <typename ALLOC>
2065
class ReflectableArrayBase : public ReflectableAllocatorHolderBase<ALLOC>
2066
{
2067
private:
2068
    using Base = ReflectableAllocatorHolderBase<ALLOC>;
2069
2070
public:
2071
    using Base::Base;
2072
    using Base::getTypeInfo;
2073
2074
    bool isArray() const override
2075
98
    {
2076
98
        return true;
2077
98
    }
2078
2079
    void initializeChildren() override;
2080
    void initialize(const vector<AnyHolder<ALLOC>, ALLOC>& typeArguments) override;
2081
    size_t initializeOffsets(size_t bitPosition) override;
2082
    size_t bitSizeOf(size_t bitPosition) const override;
2083
    void write(BitStreamWriter& writer) const override;
2084
2085
    IBasicReflectableConstPtr<ALLOC> getField(StringView name) const override;
2086
    IBasicReflectablePtr<ALLOC> getField(StringView name) override;
2087
    IBasicReflectablePtr<ALLOC> createField(StringView name) override;
2088
    void setField(StringView name, const AnyHolder<ALLOC>& value) override;
2089
    IBasicReflectableConstPtr<ALLOC> getParameter(StringView name) const override;
2090
    IBasicReflectablePtr<ALLOC> getParameter(StringView name) override;
2091
    IBasicReflectableConstPtr<ALLOC> callFunction(StringView name) const override;
2092
    IBasicReflectablePtr<ALLOC> callFunction(StringView name) override;
2093
2094
    StringView getChoice() const override;
2095
2096
    IBasicReflectableConstPtr<ALLOC> operator[](size_t index) const override;
2097
    IBasicReflectablePtr<ALLOC> operator[](size_t index) override;
2098
2099
    bool getBool() const override;
2100
    int8_t getInt8() const override;
2101
    int16_t getInt16() const override;
2102
    int32_t getInt32() const override;
2103
    int64_t getInt64() const override;
2104
    uint8_t getUInt8() const override;
2105
    uint16_t getUInt16() const override;
2106
    uint32_t getUInt32() const override;
2107
    uint64_t getUInt64() const override;
2108
    float getFloat() const override;
2109
    double getDouble() const override;
2110
    Span<const uint8_t> getBytes() const override;
2111
    StringView getStringView() const override;
2112
    const BasicBitBuffer<ALLOC>& getBitBuffer() const override;
2113
2114
    int64_t toInt() const override;
2115
    uint64_t toUInt() const override;
2116
    double toDouble() const override;
2117
    string<ALLOC> toString(const ALLOC& allocator) const override;
2118
};
2119
2120
/**
2121
 * Base class for constant reflectable arrays.
2122
 *
2123
 * Overrides non constant methods and throws exception with info about constness.
2124
 */
2125
template <typename ALLOC>
2126
class ReflectableConstArrayBase : public ReflectableArrayBase<ALLOC>
2127
{
2128
private:
2129
    using Base = ReflectableArrayBase<ALLOC>;
2130
2131
public:
2132
    using Base::Base;
2133
    using Base::getTypeInfo;
2134
2135
    void resize(size_t index) override;
2136
    IBasicReflectablePtr<ALLOC> at(size_t index) override;
2137
    IBasicReflectablePtr<ALLOC> operator[](size_t index) override;
2138
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override;
2139
    void append(const AnyHolder<ALLOC>& value) override;
2140
2141
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override;
2142
};
2143
2144
/**
2145
 * Reflectable for arrays of builtin types (except bit field arrays).
2146
 */
2147
/** \{ */
2148
template <typename ALLOC, typename RAW_ARRAY, typename ELEMENT_REFLECTABLE>
2149
class BuiltinReflectableConstArray : public ReflectableConstArrayBase<ALLOC>
2150
{
2151
private:
2152
    using Base = ReflectableConstArrayBase<ALLOC>;
2153
2154
    using ElementReflectable = ELEMENT_REFLECTABLE;
2155
2156
public:
2157
    using Base::at;
2158
    using Base::getTypeInfo;
2159
    using Base::operator[];
2160
    using Base::getAnyValue;
2161
2162
    BuiltinReflectableConstArray(const ALLOC& allocator, const RAW_ARRAY& rawArray) :
2163
            Base(ElementReflectable::typeInfo(), allocator),
2164
            m_rawArray(rawArray)
2165
25
    {}
2166
2167
    size_t size() const override
2168
207
    {
2169
207
        return m_rawArray.size();
2170
207
    }
2171
2172
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2173
135
    {
2174
135
        if (index >= size())
2175
48
        {
2176
48
            throw CppRuntimeException("Index ")
2177
48
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2178
48
                    << "' of size " << size() << "!";
2179
48
        }
2180
2181
87
        return std::allocate_shared<ElementReflectable>(Base::get_allocator(), m_rawArray[index]);
2182
135
    }
2183
2184
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2185
25
    {
2186
25
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2187
25
    }
2188
2189
private:
2190
    const RAW_ARRAY& m_rawArray;
2191
};
2192
2193
template <typename ALLOC, typename RAW_ARRAY, typename ELEMENT_REFLECTABLE>
2194
class BuiltinReflectableArray : public ReflectableArrayBase<ALLOC>
2195
{
2196
private:
2197
    using Base = ReflectableArrayBase<ALLOC>;
2198
2199
    using ElementReflectable = ELEMENT_REFLECTABLE;
2200
2201
public:
2202
    using Base::getTypeInfo;
2203
2204
    BuiltinReflectableArray(const ALLOC& allocator, RAW_ARRAY& rawArray) :
2205
            Base(ElementReflectable::typeInfo(), allocator),
2206
            m_rawArray(rawArray)
2207
74
    {}
2208
2209
    size_t size() const override
2210
367
    {
2211
367
        return m_rawArray.size();
2212
367
    }
2213
2214
    void resize(size_t size) override
2215
8
    {
2216
8
        m_rawArray.resize(size);
2217
8
    }
2218
2219
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2220
47
    {
2221
47
        if (index >= size())
2222
8
        {
2223
8
            throw CppRuntimeException("Index ")
2224
8
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2225
8
                    << "' of size " << size() << "!";
2226
8
        }
2227
2228
39
        return std::allocate_shared<ElementReflectable>(Base::get_allocator(), m_rawArray[index]);
2229
47
    }
2230
2231
    IBasicReflectablePtr<ALLOC> at(size_t index) override
2232
164
    {
2233
164
        if (index >= size())
2234
48
        {
2235
48
            throw CppRuntimeException("Index ")
2236
48
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2237
48
                    << "' of size " << size() << "!";
2238
48
        }
2239
2240
116
        return std::allocate_shared<ElementReflectable>(Base::get_allocator(), m_rawArray[index]);
2241
164
    }
2242
2243
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
2244
8
    {
2245
8
        if (index >= size())
2246
4
        {
2247
4
            throw CppRuntimeException("Index ")
2248
4
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2249
4
                    << "' of size " << size() << "!";
2250
4
        }
2251
2252
4
        m_rawArray[index] = value.template get<typename RAW_ARRAY::value_type>();
2253
4
    }
2254
2255
    void append(const AnyHolder<ALLOC>& value) override
2256
22
    {
2257
22
        m_rawArray.push_back(value.template get<typename RAW_ARRAY::value_type>());
2258
22
    }
2259
2260
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2261
4
    {
2262
4
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2263
4
    }
2264
2265
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
2266
25
    {
2267
25
        return AnyHolder<ALLOC>(std::ref(m_rawArray), allocator);
2268
25
    }
2269
2270
private:
2271
    RAW_ARRAY& m_rawArray;
2272
};
2273
/** \} */
2274
2275
/**
2276
 * Reflectable for arrays of fixed bit fields.
2277
 */
2278
/** \{ */
2279
template <typename ALLOC, typename RAW_ARRAY, typename ELEMENT_REFLECTABLE>
2280
class FixedBitFieldReflectableConstArray : public ReflectableConstArrayBase<ALLOC>
2281
{
2282
private:
2283
    using Base = ReflectableConstArrayBase<ALLOC>;
2284
2285
    using ElementReflectable = ELEMENT_REFLECTABLE;
2286
2287
public:
2288
    using Base::at;
2289
    using Base::getTypeInfo;
2290
    using Base::operator[];
2291
    using Base::getAnyValue;
2292
2293
    FixedBitFieldReflectableConstArray(const ALLOC& allocator, const RAW_ARRAY& rawArray, uint8_t bitSize) :
2294
            Base(ElementReflectable::typeInfo(bitSize), allocator),
2295
            m_rawArray(rawArray)
2296
2
    {}
2297
2298
    size_t size() const override
2299
20
    {
2300
20
        return m_rawArray.size();
2301
20
    }
2302
2303
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2304
14
    {
2305
14
        if (index >= size())
2306
4
        {
2307
4
            throw CppRuntimeException("Index ")
2308
4
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2309
4
                    << "' of size " << size() << "!";
2310
4
        }
2311
2312
10
        return std::allocate_shared<ElementReflectable>(
2313
10
                Base::get_allocator(), m_rawArray[index], getTypeInfo().getBitSize());
2314
14
    }
2315
2316
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2317
2
    {
2318
2
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2319
2
    }
2320
2321
private:
2322
    const RAW_ARRAY& m_rawArray;
2323
};
2324
2325
template <typename ALLOC, typename RAW_ARRAY, typename ELEMENT_REFLECTABLE>
2326
class FixedBitFieldReflectableArray : public ReflectableArrayBase<ALLOC>
2327
{
2328
private:
2329
    using Base = ReflectableArrayBase<ALLOC>;
2330
2331
    using ElementReflectable = ELEMENT_REFLECTABLE;
2332
2333
public:
2334
    using Base::getTypeInfo;
2335
2336
    FixedBitFieldReflectableArray(const ALLOC& allocator, RAW_ARRAY& rawArray, uint8_t bitSize) :
2337
            Base(ElementReflectable::typeInfo(bitSize), allocator),
2338
            m_rawArray(rawArray)
2339
2
    {}
2340
2341
    size_t size() const override
2342
39
    {
2343
39
        return m_rawArray.size();
2344
39
    }
2345
2346
    void resize(size_t size) override
2347
2
    {
2348
2
        m_rawArray.resize(size);
2349
2
    }
2350
2351
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2352
7
    {
2353
7
        if (index >= size())
2354
2
        {
2355
2
            throw CppRuntimeException("Index ")
2356
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2357
2
                    << "' of size " << size() << "!";
2358
2
        }
2359
2360
5
        return std::allocate_shared<ElementReflectable>(
2361
5
                Base::get_allocator(), m_rawArray[index], getTypeInfo().getBitSize());
2362
7
    }
2363
2364
    IBasicReflectablePtr<ALLOC> at(size_t index) override
2365
16
    {
2366
16
        if (index >= size())
2367
4
        {
2368
4
            throw CppRuntimeException("Index ")
2369
4
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2370
4
                    << "' of size " << size() << "!";
2371
4
        }
2372
2373
12
        return std::allocate_shared<ElementReflectable>(
2374
12
                Base::get_allocator(), m_rawArray[index], getTypeInfo().getBitSize());
2375
16
    }
2376
2377
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
2378
2
    {
2379
2
        if (index >= size())
2380
1
        {
2381
1
            throw CppRuntimeException("Index ")
2382
1
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2383
1
                    << "' of size " << size() << "!";
2384
1
        }
2385
2386
1
        m_rawArray[index] = value.template get<typename RAW_ARRAY::value_type>();
2387
1
    }
2388
2389
    void append(const AnyHolder<ALLOC>& value) override
2390
1
    {
2391
1
        m_rawArray.push_back(value.template get<typename RAW_ARRAY::value_type>());
2392
1
    }
2393
2394
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2395
1
    {
2396
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2397
1
    }
2398
2399
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
2400
2
    {
2401
2
        return AnyHolder<ALLOC>(std::ref(m_rawArray), allocator);
2402
2
    }
2403
2404
private:
2405
    RAW_ARRAY& m_rawArray;
2406
};
2407
/** \} */
2408
2409
/**
2410
 * Reflectable for arrays of dynamic bit fields.
2411
 */
2412
/** \{ */
2413
template <typename ALLOC, typename RAW_ARRAY, typename ELEMENT_REFLECTABLE>
2414
class DynamicBitFieldReflectableConstArray : public ReflectableConstArrayBase<ALLOC>
2415
{
2416
private:
2417
    using Base = ReflectableConstArrayBase<ALLOC>;
2418
2419
    using ElementReflectable = ELEMENT_REFLECTABLE;
2420
2421
public:
2422
    using Base::at;
2423
    using Base::getTypeInfo;
2424
    using Base::operator[];
2425
    using Base::getAnyValue;
2426
2427
    DynamicBitFieldReflectableConstArray(
2428
            const ALLOC& allocator, const RAW_ARRAY& rawArray, uint8_t maxBitSize, uint8_t dynamicBitSize) :
2429
            Base(ElementReflectable::typeInfo(maxBitSize), allocator),
2430
            m_rawArray(rawArray),
2431
            m_maxBitSize(maxBitSize),
2432
            m_dynamicBitSize(dynamicBitSize)
2433
2
    {}
2434
2435
    size_t size() const override
2436
20
    {
2437
20
        return m_rawArray.size();
2438
20
    }
2439
2440
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2441
14
    {
2442
14
        if (index >= size())
2443
4
        {
2444
4
            throw CppRuntimeException("Index ")
2445
4
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2446
4
                    << "' of size " << size() << "!";
2447
4
        }
2448
2449
10
        return std::allocate_shared<ElementReflectable>(
2450
10
                Base::get_allocator(), m_rawArray[index], m_maxBitSize, m_dynamicBitSize);
2451
14
    }
2452
2453
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2454
2
    {
2455
2
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2456
2
    }
2457
2458
private:
2459
    const RAW_ARRAY& m_rawArray;
2460
    const uint8_t m_maxBitSize;
2461
    const uint8_t m_dynamicBitSize;
2462
};
2463
2464
template <typename ALLOC, typename RAW_ARRAY, typename ELEMENT_REFLECTABLE>
2465
class DynamicBitFieldReflectableArray : public ReflectableArrayBase<ALLOC>
2466
{
2467
private:
2468
    using Base = ReflectableArrayBase<ALLOC>;
2469
2470
    using ElementReflectable = ELEMENT_REFLECTABLE;
2471
2472
public:
2473
    using Base::getTypeInfo;
2474
2475
    DynamicBitFieldReflectableArray(
2476
            const ALLOC& allocator, RAW_ARRAY& rawArray, uint8_t maxBitSize, uint8_t dynamicBitSize) :
2477
            Base(ElementReflectable::typeInfo(maxBitSize), allocator),
2478
            m_rawArray(rawArray),
2479
            m_maxBitSize(maxBitSize),
2480
            m_dynamicBitSize(dynamicBitSize)
2481
2
    {}
2482
2483
    size_t size() const override
2484
39
    {
2485
39
        return m_rawArray.size();
2486
39
    }
2487
2488
    void resize(size_t size) override
2489
2
    {
2490
2
        m_rawArray.resize(size);
2491
2
    }
2492
2493
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2494
7
    {
2495
7
        if (index >= size())
2496
2
        {
2497
2
            throw CppRuntimeException("Index ")
2498
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2499
2
                    << "' of size " << size() << "!";
2500
2
        }
2501
2502
5
        return std::allocate_shared<ElementReflectable>(
2503
5
                Base::get_allocator(), m_rawArray[index], m_maxBitSize, m_dynamicBitSize);
2504
7
    }
2505
2506
    IBasicReflectablePtr<ALLOC> at(size_t index) override
2507
16
    {
2508
16
        if (index >= size())
2509
4
        {
2510
4
            throw CppRuntimeException("Index ")
2511
4
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2512
4
                    << "' of size " << size() << "!";
2513
4
        }
2514
2515
12
        return std::allocate_shared<ElementReflectable>(
2516
12
                Base::get_allocator(), m_rawArray[index], m_maxBitSize, m_dynamicBitSize);
2517
16
    }
2518
2519
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
2520
2
    {
2521
2
        if (index >= size())
2522
1
        {
2523
1
            throw CppRuntimeException("Index ")
2524
1
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2525
1
                    << "' of size " << size() << "!";
2526
1
        }
2527
2528
1
        m_rawArray[index] = value.template get<typename RAW_ARRAY::value_type>();
2529
1
    }
2530
2531
    void append(const AnyHolder<ALLOC>& value) override
2532
1
    {
2533
1
        m_rawArray.push_back(value.template get<typename RAW_ARRAY::value_type>());
2534
1
    }
2535
2536
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2537
1
    {
2538
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2539
1
    }
2540
2541
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
2542
2
    {
2543
2
        return AnyHolder<ALLOC>(std::ref(m_rawArray), allocator);
2544
2
    }
2545
2546
private:
2547
    RAW_ARRAY& m_rawArray;
2548
    const uint8_t m_maxBitSize;
2549
    const uint8_t m_dynamicBitSize;
2550
};
2551
/** \} */
2552
2553
/**
2554
 * Typedef to a builtin array.
2555
 */
2556
/** \{ */
2557
template <typename ALLOC, typename RAW_ARRAY>
2558
using BoolReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, BoolReflectable<ALLOC>>;
2559
template <typename ALLOC, typename RAW_ARRAY>
2560
using BoolReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, BoolReflectable<ALLOC>>;
2561
2562
template <typename ALLOC, typename RAW_ARRAY>
2563
using Int8ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Int8Reflectable<ALLOC>>;
2564
template <typename ALLOC, typename RAW_ARRAY>
2565
using Int8ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Int8Reflectable<ALLOC>>;
2566
2567
template <typename ALLOC, typename RAW_ARRAY>
2568
using Int16ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Int16Reflectable<ALLOC>>;
2569
template <typename ALLOC, typename RAW_ARRAY>
2570
using Int16ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Int16Reflectable<ALLOC>>;
2571
2572
template <typename ALLOC, typename RAW_ARRAY>
2573
using Int32ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Int32Reflectable<ALLOC>>;
2574
template <typename ALLOC, typename RAW_ARRAY>
2575
using Int32ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Int32Reflectable<ALLOC>>;
2576
2577
template <typename ALLOC, typename RAW_ARRAY>
2578
using Int64ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Int64Reflectable<ALLOC>>;
2579
template <typename ALLOC, typename RAW_ARRAY>
2580
using Int64ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Int64Reflectable<ALLOC>>;
2581
2582
template <typename ALLOC, typename RAW_ARRAY>
2583
using UInt8ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, UInt8Reflectable<ALLOC>>;
2584
template <typename ALLOC, typename RAW_ARRAY>
2585
using UInt8ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, UInt8Reflectable<ALLOC>>;
2586
2587
template <typename ALLOC, typename RAW_ARRAY>
2588
using UInt16ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, UInt16Reflectable<ALLOC>>;
2589
template <typename ALLOC, typename RAW_ARRAY>
2590
using UInt16ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, UInt16Reflectable<ALLOC>>;
2591
2592
template <typename ALLOC, typename RAW_ARRAY>
2593
using UInt32ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, UInt32Reflectable<ALLOC>>;
2594
template <typename ALLOC, typename RAW_ARRAY>
2595
using UInt32ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, UInt32Reflectable<ALLOC>>;
2596
2597
template <typename ALLOC, typename RAW_ARRAY>
2598
using UInt64ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, UInt64Reflectable<ALLOC>>;
2599
template <typename ALLOC, typename RAW_ARRAY>
2600
using UInt64ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, UInt64Reflectable<ALLOC>>;
2601
2602
template <typename ALLOC, typename RAW_ARRAY>
2603
using FixedSignedBitFieldReflectableConstArray = FixedBitFieldReflectableConstArray<ALLOC, RAW_ARRAY,
2604
        FixedSignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2605
template <typename ALLOC, typename RAW_ARRAY>
2606
using FixedSignedBitFieldReflectableArray = FixedBitFieldReflectableArray<ALLOC, RAW_ARRAY,
2607
        FixedSignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2608
2609
template <typename ALLOC, typename RAW_ARRAY>
2610
using FixedUnsignedBitFieldReflectableConstArray = FixedBitFieldReflectableConstArray<ALLOC, RAW_ARRAY,
2611
        FixedUnsignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2612
template <typename ALLOC, typename RAW_ARRAY>
2613
using FixedUnsignedBitFieldReflectableArray = FixedBitFieldReflectableArray<ALLOC, RAW_ARRAY,
2614
        FixedUnsignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2615
2616
template <typename ALLOC, typename RAW_ARRAY>
2617
using DynamicSignedBitFieldReflectableConstArray = DynamicBitFieldReflectableConstArray<ALLOC, RAW_ARRAY,
2618
        DynamicSignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2619
template <typename ALLOC, typename RAW_ARRAY>
2620
using DynamicSignedBitFieldReflectableArray = DynamicBitFieldReflectableArray<ALLOC, RAW_ARRAY,
2621
        DynamicSignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2622
2623
template <typename ALLOC, typename RAW_ARRAY>
2624
using DynamicUnsignedBitFieldReflectableConstArray = DynamicBitFieldReflectableConstArray<ALLOC, RAW_ARRAY,
2625
        DynamicUnsignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2626
template <typename ALLOC, typename RAW_ARRAY>
2627
using DynamicUnsignedBitFieldReflectableArray = DynamicBitFieldReflectableArray<ALLOC, RAW_ARRAY,
2628
        DynamicUnsignedBitFieldReflectable<ALLOC, typename RAW_ARRAY::value_type>>;
2629
2630
template <typename ALLOC, typename RAW_ARRAY>
2631
using VarInt16ReflectableConstArray =
2632
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarInt16Reflectable<ALLOC>>;
2633
template <typename ALLOC, typename RAW_ARRAY>
2634
using VarInt16ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarInt16Reflectable<ALLOC>>;
2635
2636
template <typename ALLOC, typename RAW_ARRAY>
2637
using VarInt32ReflectableConstArray =
2638
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarInt32Reflectable<ALLOC>>;
2639
template <typename ALLOC, typename RAW_ARRAY>
2640
using VarInt32ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarInt32Reflectable<ALLOC>>;
2641
2642
template <typename ALLOC, typename RAW_ARRAY>
2643
using VarInt64ReflectableConstArray =
2644
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarInt64Reflectable<ALLOC>>;
2645
template <typename ALLOC, typename RAW_ARRAY>
2646
using VarInt64ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarInt64Reflectable<ALLOC>>;
2647
2648
template <typename ALLOC, typename RAW_ARRAY>
2649
using VarIntReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarIntReflectable<ALLOC>>;
2650
template <typename ALLOC, typename RAW_ARRAY>
2651
using VarIntReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarIntReflectable<ALLOC>>;
2652
2653
template <typename ALLOC, typename RAW_ARRAY>
2654
using VarUInt16ReflectableConstArray =
2655
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarUInt16Reflectable<ALLOC>>;
2656
template <typename ALLOC, typename RAW_ARRAY>
2657
using VarUInt16ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarUInt16Reflectable<ALLOC>>;
2658
2659
template <typename ALLOC, typename RAW_ARRAY>
2660
using VarUInt32ReflectableConstArray =
2661
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarUInt32Reflectable<ALLOC>>;
2662
template <typename ALLOC, typename RAW_ARRAY>
2663
using VarUInt32ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarUInt32Reflectable<ALLOC>>;
2664
2665
template <typename ALLOC, typename RAW_ARRAY>
2666
using VarUInt64ReflectableConstArray =
2667
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarUInt64Reflectable<ALLOC>>;
2668
template <typename ALLOC, typename RAW_ARRAY>
2669
using VarUInt64ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarUInt64Reflectable<ALLOC>>;
2670
2671
template <typename ALLOC, typename RAW_ARRAY>
2672
using VarUIntReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarUIntReflectable<ALLOC>>;
2673
template <typename ALLOC, typename RAW_ARRAY>
2674
using VarUIntReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarUIntReflectable<ALLOC>>;
2675
2676
template <typename ALLOC, typename RAW_ARRAY>
2677
using VarSizeReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, VarSizeReflectable<ALLOC>>;
2678
template <typename ALLOC, typename RAW_ARRAY>
2679
using VarSizeReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, VarSizeReflectable<ALLOC>>;
2680
2681
template <typename ALLOC, typename RAW_ARRAY>
2682
using Float16ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Float16Reflectable<ALLOC>>;
2683
template <typename ALLOC, typename RAW_ARRAY>
2684
using Float16ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Float16Reflectable<ALLOC>>;
2685
2686
template <typename ALLOC, typename RAW_ARRAY>
2687
using Float32ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Float32Reflectable<ALLOC>>;
2688
template <typename ALLOC, typename RAW_ARRAY>
2689
using Float32ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Float32Reflectable<ALLOC>>;
2690
2691
template <typename ALLOC, typename RAW_ARRAY>
2692
using Float64ReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, Float64Reflectable<ALLOC>>;
2693
template <typename ALLOC, typename RAW_ARRAY>
2694
using Float64ReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, Float64Reflectable<ALLOC>>;
2695
2696
template <typename ALLOC, typename RAW_ARRAY>
2697
using BytesReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, BytesReflectable<ALLOC>>;
2698
template <typename ALLOC, typename RAW_ARRAY>
2699
using BytesReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, BytesReflectable<ALLOC>>;
2700
2701
template <typename ALLOC, typename RAW_ARRAY>
2702
using StringReflectableConstArray = BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, StringReflectable<ALLOC>>;
2703
template <typename ALLOC, typename RAW_ARRAY>
2704
using StringReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, StringReflectable<ALLOC>>;
2705
2706
template <typename ALLOC, typename RAW_ARRAY>
2707
using BitBufferReflectableConstArray =
2708
        BuiltinReflectableConstArray<ALLOC, RAW_ARRAY, BitBufferReflectable<ALLOC>>;
2709
template <typename ALLOC, typename RAW_ARRAY>
2710
using BitBufferReflectableArray = BuiltinReflectableArray<ALLOC, RAW_ARRAY, BitBufferReflectable<ALLOC>>;
2711
/** \} */
2712
2713
/**
2714
 * Reflectable for arrays of compound types.
2715
 */
2716
/** \{ */
2717
template <typename ALLOC, typename RAW_ARRAY>
2718
class CompoundReflectableConstArray : public ReflectableConstArrayBase<ALLOC>
2719
{
2720
private:
2721
    using Base = ReflectableConstArrayBase<ALLOC>;
2722
2723
    using ElementType = typename RAW_ARRAY::value_type;
2724
2725
public:
2726
    using Base::at;
2727
    using Base::getTypeInfo;
2728
    using Base::operator[];
2729
    using Base::getAnyValue;
2730
2731
    CompoundReflectableConstArray(const ALLOC& allocator, const RAW_ARRAY& rawArray) :
2732
            Base(ElementType::typeInfo(), allocator),
2733
            m_rawArray(rawArray)
2734
1
    {}
2735
2736
    size_t size() const override
2737
8
    {
2738
8
        return m_rawArray.size();
2739
8
    }
2740
2741
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2742
4
    {
2743
4
        if (index >= size())
2744
2
        {
2745
2
            throw CppRuntimeException("Index ")
2746
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2747
2
                    << "' of size " << size() << "!";
2748
2
        }
2749
2750
2
        return m_rawArray[index].reflectable(Base::get_allocator());
2751
4
    }
2752
2753
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2754
1
    {
2755
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2756
1
    }
2757
2758
private:
2759
    const RAW_ARRAY& m_rawArray;
2760
};
2761
2762
template <typename ALLOC, typename RAW_ARRAY>
2763
class CompoundReflectableArray : public ReflectableArrayBase<ALLOC>
2764
{
2765
private:
2766
    using Base = ReflectableArrayBase<ALLOC>;
2767
2768
    using ElementType = typename RAW_ARRAY::value_type;
2769
2770
public:
2771
    using Base::getTypeInfo;
2772
2773
    CompoundReflectableArray(const ALLOC& allocator, RAW_ARRAY& rawArray) :
2774
            Base(ElementType::typeInfo(), allocator),
2775
            m_rawArray(rawArray)
2776
41
    {}
2777
2778
    size_t size() const override
2779
112
    {
2780
112
        return m_rawArray.size();
2781
112
    }
2782
2783
    void resize(size_t size) override
2784
5
    {
2785
5
        m_rawArray.resize(size);
2786
5
    }
2787
2788
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2789
31
    {
2790
31
        if (index >= size())
2791
2
        {
2792
2
            throw CppRuntimeException("Index ")
2793
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2794
2
                    << "' of size " << size() << "!";
2795
2
        }
2796
2797
29
        return m_rawArray[index].reflectable(Base::get_allocator());
2798
31
    }
2799
2800
    IBasicReflectablePtr<ALLOC> at(size_t index) override
2801
27
    {
2802
27
        if (index >= size())
2803
2
        {
2804
2
            throw CppRuntimeException("Index ")
2805
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2806
2
                    << "' of size " << size() << "!";
2807
2
        }
2808
2809
25
        return m_rawArray[index].reflectable(Base::get_allocator());
2810
27
    }
2811
2812
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
2813
2
    {
2814
2
        if (index >= size())
2815
1
        {
2816
1
            throw CppRuntimeException("Index ")
2817
1
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2818
1
                    << "' of size " << size() << "!";
2819
1
        }
2820
2821
1
        m_rawArray[index] = value.template get<typename RAW_ARRAY::value_type>();
2822
1
    }
2823
2824
    void append(const AnyHolder<ALLOC>& value) override
2825
2
    {
2826
2
        m_rawArray.push_back(value.template get<typename RAW_ARRAY::value_type>());
2827
2
    }
2828
2829
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2830
1
    {
2831
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2832
1
    }
2833
2834
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
2835
2
    {
2836
2
        return AnyHolder<ALLOC>(std::ref(m_rawArray), allocator);
2837
2
    }
2838
2839
private:
2840
    RAW_ARRAY& m_rawArray;
2841
};
2842
/** \} */
2843
2844
/** Reflectable for arrays of bitmask types. */
2845
/** \{ */
2846
template <typename ALLOC, typename RAW_ARRAY>
2847
class BitmaskReflectableConstArray : public ReflectableConstArrayBase<ALLOC>
2848
{
2849
private:
2850
    using Base = ReflectableConstArrayBase<ALLOC>;
2851
2852
    using ElementType = typename RAW_ARRAY::value_type;
2853
2854
public:
2855
    using Base::at;
2856
    using Base::getTypeInfo;
2857
    using Base::operator[];
2858
    using Base::getAnyValue;
2859
2860
    BitmaskReflectableConstArray(const ALLOC& allocator, const RAW_ARRAY& rawArray) :
2861
            Base(ElementType::typeInfo(), allocator),
2862
            m_rawArray(rawArray)
2863
1
    {}
2864
2865
    size_t size() const override
2866
8
    {
2867
8
        return m_rawArray.size();
2868
8
    }
2869
2870
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2871
5
    {
2872
5
        if (index >= size())
2873
2
        {
2874
2
            throw CppRuntimeException("Index ")
2875
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2876
2
                    << "' of size " << size() << "!";
2877
2
        }
2878
2879
3
        return m_rawArray[index].reflectable(Base::get_allocator());
2880
5
    }
2881
2882
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2883
1
    {
2884
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2885
1
    }
2886
2887
private:
2888
    const RAW_ARRAY& m_rawArray;
2889
};
2890
2891
template <typename ALLOC, typename RAW_ARRAY>
2892
class BitmaskReflectableArray : public ReflectableArrayBase<ALLOC>
2893
{
2894
private:
2895
    using Base = ReflectableArrayBase<ALLOC>;
2896
2897
    using ElementType = typename RAW_ARRAY::value_type;
2898
    using UnderlyingElementType = typename ElementType::underlying_type;
2899
2900
public:
2901
    using Base::getTypeInfo;
2902
2903
    BitmaskReflectableArray(const ALLOC& allocator, RAW_ARRAY& rawArray) :
2904
            Base(ElementType::typeInfo(), allocator),
2905
            m_rawArray(rawArray)
2906
1
    {}
2907
2908
    size_t size() const override
2909
30
    {
2910
30
        return m_rawArray.size();
2911
30
    }
2912
2913
    void resize(size_t size) override
2914
2
    {
2915
2
        m_rawArray.resize(size);
2916
2
    }
2917
2918
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
2919
5
    {
2920
5
        if (index >= size())
2921
2
        {
2922
2
            throw CppRuntimeException("Index ")
2923
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2924
2
                    << "' of size " << size() << "!";
2925
2
        }
2926
2927
3
        return m_rawArray[index].reflectable(Base::get_allocator());
2928
5
    }
2929
2930
    IBasicReflectablePtr<ALLOC> at(size_t index) override
2931
9
    {
2932
9
        if (index >= size())
2933
2
        {
2934
2
            throw CppRuntimeException("Index ")
2935
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2936
2
                    << "' of size " << size() << "!";
2937
2
        }
2938
2939
7
        return m_rawArray[index].reflectable(Base::get_allocator());
2940
9
    }
2941
2942
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
2943
3
    {
2944
3
        if (index >= size())
2945
1
        {
2946
1
            throw CppRuntimeException("Index ")
2947
1
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
2948
1
                    << "' of size " << size() << "!";
2949
1
        }
2950
2951
2
        if (value.template isType<ElementType>())
2952
1
        {
2953
1
            m_rawArray[index] = value.template get<ElementType>();
2954
1
        }
2955
1
        else
2956
1
        {
2957
1
            m_rawArray[index] = ElementType(value.template get<UnderlyingElementType>());
2958
1
        }
2959
2
    }
2960
2961
    void append(const AnyHolder<ALLOC>& value) override
2962
2
    {
2963
2
        if (value.template isType<ElementType>())
2964
1
        {
2965
1
            m_rawArray.push_back(value.template get<ElementType>());
2966
1
        }
2967
1
        else
2968
1
        {
2969
1
            m_rawArray.push_back(ElementType(value.template get<UnderlyingElementType>()));
2970
1
        }
2971
2
    }
2972
2973
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
2974
1
    {
2975
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
2976
1
    }
2977
2978
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
2979
1
    {
2980
1
        return AnyHolder<ALLOC>(std::ref(m_rawArray), allocator);
2981
1
    }
2982
2983
private:
2984
    RAW_ARRAY& m_rawArray;
2985
};
2986
/** \} */
2987
2988
/** Reflectable for arrays of enum types. */
2989
/** \{ */
2990
template <typename ALLOC, typename RAW_ARRAY>
2991
class EnumReflectableConstArray : public ReflectableConstArrayBase<ALLOC>
2992
{
2993
private:
2994
    using Base = ReflectableConstArrayBase<ALLOC>;
2995
2996
    using ElementType = typename RAW_ARRAY::value_type;
2997
2998
public:
2999
    using Base::at;
3000
    using Base::getTypeInfo;
3001
    using Base::operator[];
3002
    using Base::getAnyValue;
3003
3004
    EnumReflectableConstArray(const ALLOC& allocator, const RAW_ARRAY& rawArray) :
3005
            Base(enumTypeInfo<ElementType, ALLOC>(), allocator),
3006
            m_rawArray(rawArray)
3007
1
    {}
3008
3009
    size_t size() const override
3010
8
    {
3011
8
        return m_rawArray.size();
3012
8
    }
3013
3014
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
3015
5
    {
3016
5
        if (index >= size())
3017
2
        {
3018
2
            throw CppRuntimeException("Index ")
3019
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
3020
2
                    << "' of size " << size() << "!";
3021
2
        }
3022
3023
3
        return enumReflectable(m_rawArray[index], Base::get_allocator());
3024
5
    }
3025
3026
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
3027
1
    {
3028
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
3029
1
    }
3030
3031
private:
3032
    const RAW_ARRAY& m_rawArray;
3033
};
3034
3035
template <typename ALLOC, typename RAW_ARRAY>
3036
class EnumReflectableArray : public ReflectableArrayBase<ALLOC>
3037
{
3038
private:
3039
    using Base = ReflectableArrayBase<ALLOC>;
3040
3041
    using ElementType = typename RAW_ARRAY::value_type;
3042
    using UnderlyingElementType = typename std::underlying_type<ElementType>::type;
3043
3044
public:
3045
    using Base::getTypeInfo;
3046
3047
    EnumReflectableArray(const ALLOC& allocator, RAW_ARRAY& rawArray) :
3048
            Base(enumTypeInfo<ElementType, ALLOC>(), allocator),
3049
            m_rawArray(rawArray)
3050
1
    {}
3051
3052
    size_t size() const override
3053
30
    {
3054
30
        return m_rawArray.size();
3055
30
    }
3056
3057
    void resize(size_t size) override
3058
2
    {
3059
2
        m_rawArray.resize(size);
3060
2
    }
3061
3062
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
3063
5
    {
3064
5
        if (index >= size())
3065
2
        {
3066
2
            throw CppRuntimeException("Index ")
3067
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
3068
2
                    << "' of size " << size() << "!";
3069
2
        }
3070
3071
3
        return enumReflectable(m_rawArray[index], Base::get_allocator());
3072
5
    }
3073
3074
    IBasicReflectablePtr<ALLOC> at(size_t index) override
3075
9
    {
3076
9
        if (index >= size())
3077
2
        {
3078
2
            throw CppRuntimeException("Index ")
3079
2
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
3080
2
                    << "' of size " << size() << "!";
3081
2
        }
3082
3083
7
        return enumReflectable(m_rawArray[index], Base::get_allocator());
3084
9
    }
3085
3086
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
3087
3
    {
3088
3
        if (index >= size())
3089
1
        {
3090
1
            throw CppRuntimeException("Index ")
3091
1
                    << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
3092
1
                    << "' of size " << size() << "!";
3093
1
        }
3094
3095
2
        if (value.template isType<ElementType>())
3096
1
        {
3097
1
            m_rawArray[index] = value.template get<ElementType>();
3098
1
        }
3099
1
        else
3100
1
        {
3101
1
            m_rawArray[index] = valueToEnum<ElementType>(value.template get<UnderlyingElementType>());
3102
1
        }
3103
2
    }
3104
3105
    void append(const AnyHolder<ALLOC>& value) override
3106
2
    {
3107
2
        if (value.template isType<ElementType>())
3108
1
        {
3109
1
            m_rawArray.push_back(value.template get<ElementType>());
3110
1
        }
3111
1
        else
3112
1
        {
3113
1
            m_rawArray.push_back(valueToEnum<ElementType>(value.template get<UnderlyingElementType>()));
3114
1
        }
3115
2
    }
3116
3117
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
3118
1
    {
3119
1
        return AnyHolder<ALLOC>(std::cref(m_rawArray), allocator);
3120
1
    }
3121
3122
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
3123
1
    {
3124
1
        return AnyHolder<ALLOC>(std::ref(m_rawArray), allocator);
3125
1
    }
3126
3127
private:
3128
    RAW_ARRAY& m_rawArray;
3129
};
3130
/** \} */
3131
3132
/**
3133
 * Wrapper around reflectable which actually owns the reflected object.
3134
 *
3135
 * This is needed in ZserioTreeCreator to be able to generically create the new instance of a zserio object.
3136
 */
3137
template <typename T, typename ALLOC = typename T::allocator_type>
3138
class ReflectableOwner : public IBasicReflectable<ALLOC>
3139
{
3140
public:
3141
    ReflectableOwner() :
3142
            ReflectableOwner(ALLOC())
3143
    {}
3144
3145
    explicit ReflectableOwner(const ALLOC& allocator) :
3146
            m_object(allocator),
3147
            m_reflectable(m_object.reflectable(allocator))
3148
85
    {}
3149
3150
    const IBasicTypeInfo<ALLOC>& getTypeInfo() const override
3151
2
    {
3152
2
        return m_reflectable->getTypeInfo();
3153
2
    }
3154
3155
    bool isArray() const override
3156
1
    {
3157
1
        return m_reflectable->isArray();
3158
1
    }
3159
3160
    void initializeChildren() override
3161
8
    {
3162
8
        m_reflectable->initializeChildren();
3163
8
    }
3164
3165
    void initialize(const vector<AnyHolder<ALLOC>, ALLOC>& typeArguments) override
3166
6
    {
3167
6
        m_reflectable->initialize(typeArguments);
3168
6
    }
3169
3170
    size_t initializeOffsets(size_t bitPosition) override
3171
1
    {
3172
1
        return m_reflectable->initializeOffsets(bitPosition);
3173
1
    }
3174
3175
    size_t initializeOffsets() override
3176
1
    {
3177
1
        return initializeOffsets(0);
3178
1
    }
3179
3180
    size_t bitSizeOf(size_t bitPosition) const override
3181
2
    {
3182
2
        return m_reflectable->bitSizeOf(bitPosition);
3183
2
    }
3184
3185
    size_t bitSizeOf() const override
3186
2
    {
3187
2
        return bitSizeOf(0);
3188
2
    }
3189
3190
    void write(BitStreamWriter& writer) const override
3191
1
    {
3192
1
        m_reflectable->write(writer);
3193
1
    }
3194
3195
    IBasicReflectableConstPtr<ALLOC> getField(StringView name) const override
3196
1
    {
3197
1
        return m_reflectable->getField(name);
3198
1
    }
3199
3200
    IBasicReflectablePtr<ALLOC> getField(StringView name) override
3201
132
    {
3202
132
        return m_reflectable->getField(name);
3203
132
    }
3204
3205
    IBasicReflectablePtr<ALLOC> createField(StringView name) override
3206
18
    {
3207
18
        return m_reflectable->createField(name);
3208
18
    }
3209
3210
    void setField(StringView name, const AnyHolder<ALLOC>& value) override
3211
62
    {
3212
62
        m_reflectable->setField(name, value);
3213
62
    }
3214
3215
    IBasicReflectableConstPtr<ALLOC> getParameter(StringView name) const override
3216
1
    {
3217
1
        return m_reflectable->getParameter(name);
3218
1
    }
3219
3220
    IBasicReflectablePtr<ALLOC> getParameter(StringView name) override
3221
10
    {
3222
10
        return m_reflectable->getParameter(name);
3223
10
    }
3224
3225
    IBasicReflectableConstPtr<ALLOC> callFunction(StringView name) const override
3226
1
    {
3227
1
        return m_reflectable->callFunction(name);
3228
1
    }
3229
3230
    IBasicReflectablePtr<ALLOC> callFunction(StringView name) override
3231
1
    {
3232
1
        return m_reflectable->callFunction(name);
3233
1
    }
3234
3235
    StringView getChoice() const override
3236
2
    {
3237
2
        return m_reflectable->getChoice();
3238
2
    }
3239
3240
    IBasicReflectableConstPtr<ALLOC> find(StringView path) const override
3241
1
    {
3242
1
        return m_reflectable->find(path);
3243
1
    }
3244
3245
    IBasicReflectablePtr<ALLOC> find(StringView path) override
3246
48
    {
3247
48
        return m_reflectable->find(path);
3248
48
    }
3249
3250
    IBasicReflectableConstPtr<ALLOC> operator[](StringView path) const override
3251
1
    {
3252
1
        return m_reflectable->operator[](path);
3253
1
    }
3254
3255
    IBasicReflectablePtr<ALLOC> operator[](StringView path) override
3256
1
    {
3257
1
        return m_reflectable->operator[](path);
3258
1
    }
3259
3260
    size_t size() const override
3261
1
    {
3262
1
        return m_reflectable->size();
3263
1
    }
3264
3265
    void resize(size_t size) override
3266
1
    {
3267
1
        m_reflectable->resize(size);
3268
1
    }
3269
3270
    IBasicReflectableConstPtr<ALLOC> at(size_t index) const override
3271
1
    {
3272
1
        return m_reflectable->at(index);
3273
1
    }
3274
3275
    IBasicReflectablePtr<ALLOC> at(size_t index) override
3276
1
    {
3277
1
        return m_reflectable->at(index);
3278
1
    }
3279
3280
    IBasicReflectableConstPtr<ALLOC> operator[](size_t index) const override
3281
1
    {
3282
1
        return m_reflectable->operator[](index);
3283
1
    }
3284
3285
    IBasicReflectablePtr<ALLOC> operator[](size_t index) override
3286
1
    {
3287
1
        return m_reflectable->operator[](index);
3288
1
    }
3289
3290
    void setAt(const AnyHolder<ALLOC>& value, size_t index) override
3291
1
    {
3292
1
        m_reflectable->setAt(value, index);
3293
1
    }
3294
3295
    void append(const AnyHolder<ALLOC>& value) override
3296
1
    {
3297
1
        m_reflectable->append(value);
3298
1
    }
3299
3300
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) const override
3301
1
    {
3302
1
        return m_reflectable->getAnyValue(allocator);
3303
1
    }
3304
3305
    AnyHolder<ALLOC> getAnyValue(const ALLOC& allocator) override
3306
17
    {
3307
17
        return m_reflectable->getAnyValue(allocator);
3308
17
    }
3309
3310
    AnyHolder<ALLOC> getAnyValue() const override
3311
1
    {
3312
1
        return getAnyValue(ALLOC());
3313
1
    }
3314
3315
    AnyHolder<ALLOC> getAnyValue() override
3316
1
    {
3317
1
        return getAnyValue(ALLOC());
3318
1
    }
3319
3320
    // exact checked getters
3321
    bool getBool() const override
3322
1
    {
3323
1
        return m_reflectable->getBool();
3324
1
    }
3325
    int8_t getInt8() const override
3326
1
    {
3327
1
        return m_reflectable->getInt8();
3328
1
    }
3329
    int16_t getInt16() const override
3330
1
    {
3331
1
        return m_reflectable->getInt16();
3332
1
    }
3333
    int32_t getInt32() const override
3334
1
    {
3335
1
        return m_reflectable->getInt32();
3336
1
    }
3337
    int64_t getInt64() const override
3338
1
    {
3339
1
        return m_reflectable->getInt64();
3340
1
    }
3341
    uint8_t getUInt8() const override
3342
1
    {
3343
1
        return m_reflectable->getUInt8();
3344
1
    }
3345
    uint16_t getUInt16() const override
3346
1
    {
3347
1
        return m_reflectable->getUInt16();
3348
1
    }
3349
    uint32_t getUInt32() const override
3350
1
    {
3351
1
        return m_reflectable->getUInt32();
3352
1
    }
3353
    uint64_t getUInt64() const override
3354
1
    {
3355
1
        return m_reflectable->getUInt64();
3356
1
    }
3357
    float getFloat() const override
3358
1
    {
3359
1
        return m_reflectable->getFloat();
3360
1
    }
3361
    double getDouble() const override
3362
1
    {
3363
1
        return m_reflectable->getDouble();
3364
1
    }
3365
    Span<const uint8_t> getBytes() const override
3366
1
    {
3367
1
        return m_reflectable->getBytes();
3368
1
    }
3369
    StringView getStringView() const override
3370
1
    {
3371
1
        return m_reflectable->getStringView();
3372
1
    }
3373
    const BasicBitBuffer<ALLOC>& getBitBuffer() const override
3374
1
    {
3375
1
        return m_reflectable->getBitBuffer();
3376
1
    }
3377
3378
    // convenience conversions
3379
    int64_t toInt() const override
3380
1
    {
3381
1
        return m_reflectable->toInt();
3382
1
    }
3383
    uint64_t toUInt() const override
3384
1
    {
3385
1
        return m_reflectable->toUInt();
3386
1
    }
3387
    double toDouble() const override
3388
1
    {
3389
1
        return m_reflectable->toDouble();
3390
1
    }
3391
    string<RebindAlloc<ALLOC, char>> toString(const ALLOC& allocator) const override
3392
1
    {
3393
1
        return m_reflectable->toString(allocator);
3394
1
    }
3395
    string<RebindAlloc<ALLOC, char>> toString() const override
3396
1
    {
3397
1
        return toString(ALLOC());
3398
1
    }
3399
3400
private:
3401
    T m_object;
3402
    IBasicReflectablePtr<ALLOC> m_reflectable;
3403
};
3404
3405
/**
3406
 * Factory used to make it easier to create reflectable instances.
3407
 *
3408
 * Creates reflectables for all builtin types and for arrays.
3409
 */
3410
template <typename ALLOC>
3411
class BasicReflectableFactory
3412
{
3413
public:
3414
    static IBasicReflectablePtr<ALLOC> getBool(bool value, const ALLOC& allocator = ALLOC())
3415
13
    {
3416
13
        return std::allocate_shared<BoolReflectable<ALLOC>>(allocator, value);
3417
13
    }
3418
3419
    static IBasicReflectablePtr<ALLOC> getInt8(int8_t value, const ALLOC& allocator = ALLOC())
3420
16
    {
3421
16
        return std::allocate_shared<Int8Reflectable<ALLOC>>(allocator, value);
3422
16
    }
3423
3424
    static IBasicReflectablePtr<ALLOC> getInt16(int16_t value, const ALLOC& allocator = ALLOC())
3425
12
    {
3426
12
        return std::allocate_shared<Int16Reflectable<ALLOC>>(allocator, value);
3427
12
    }
3428
3429
    static IBasicReflectablePtr<ALLOC> getInt32(int32_t value, const ALLOC& allocator = ALLOC())
3430
15
    {
3431
15
        return std::allocate_shared<Int32Reflectable<ALLOC>>(allocator, value);
3432
15
    }
3433
3434
    static IBasicReflectablePtr<ALLOC> getInt64(int64_t value, const ALLOC& allocator = ALLOC())
3435
11
    {
3436
11
        return std::allocate_shared<Int64Reflectable<ALLOC>>(allocator, value);
3437
11
    }
3438
3439
    static IBasicReflectablePtr<ALLOC> getUInt8(uint8_t value, const ALLOC& allocator = ALLOC())
3440
35
    {
3441
35
        return std::allocate_shared<UInt8Reflectable<ALLOC>>(allocator, value);
3442
35
    }
3443
3444
    static IBasicReflectablePtr<ALLOC> getUInt16(uint16_t value, const ALLOC& allocator = ALLOC())
3445
11
    {
3446
11
        return std::allocate_shared<UInt16Reflectable<ALLOC>>(allocator, value);
3447
11
    }
3448
3449
    static IBasicReflectablePtr<ALLOC> getUInt32(uint32_t value, const ALLOC& allocator = ALLOC())
3450
60
    {
3451
60
        return std::allocate_shared<UInt32Reflectable<ALLOC>>(allocator, value);
3452
60
    }
3453
3454
    static IBasicReflectablePtr<ALLOC> getUInt64(uint64_t value, const ALLOC& allocator = ALLOC())
3455
12
    {
3456
12
        return std::allocate_shared<UInt64Reflectable<ALLOC>>(allocator, value);
3457
12
    }
3458
3459
    template <typename T, typename std::enable_if<std::is_signed<T>::value, int>::type = 0>
3460
    static IBasicReflectablePtr<ALLOC> getFixedSignedBitField(
3461
            T value, uint8_t bitSize, const ALLOC& allocator = ALLOC())
3462
45
    {
3463
45
        return std::allocate_shared<FixedSignedBitFieldReflectable<ALLOC, T>>(allocator, value, bitSize);
3464
45
    }
3465
3466
    template <typename T, typename std::enable_if<std::is_unsigned<T>::value, int>::type = 0>
3467
    static IBasicReflectablePtr<ALLOC> getFixedUnsignedBitField(
3468
            T value, uint8_t bitSize, const ALLOC& allocator = ALLOC())
3469
82
    {
3470
82
        return std::allocate_shared<FixedUnsignedBitFieldReflectable<ALLOC, T>>(allocator, value, bitSize);
3471
82
    }
3472
3473
    template <typename T, typename std::enable_if<std::is_signed<T>::value, int>::type = 0>
3474
    static IBasicReflectablePtr<ALLOC> getDynamicSignedBitField(
3475
            T value, uint8_t maxBitSize, uint8_t dynamicBitSize, const ALLOC& allocator = ALLOC())
3476
16
    {
3477
16
        return std::allocate_shared<DynamicSignedBitFieldReflectable<ALLOC, T>>(
3478
16
                allocator, value, maxBitSize, dynamicBitSize);
3479
16
    }
3480
3481
    // for dynamic signed bit field given by a type reference (e.g. parameter, function return type)
3482
    static IBasicReflectablePtr<ALLOC> getDynamicSignedBitField(
3483
            int64_t value, uint8_t maxBitSize, const ALLOC& allocator = ALLOC())
3484
2
    {
3485
2
        if (maxBitSize != 64)
3486
1
        {
3487
1
            throw CppRuntimeException("ReflectableFactory::getDynamicSignedBitField - ")
3488
1
                    << "maxBitSize != 64 for referenced dynamic bit field!";
3489
1
        }
3490
3491
1
        return getDynamicSignedBitField(value, maxBitSize, maxBitSize, allocator);
3492
2
    }
3493
3494
    template <typename T, typename std::enable_if<std::is_unsigned<T>::value, int>::type = 0>
3495
    static IBasicReflectablePtr<ALLOC> getDynamicUnsignedBitField(
3496
            T value, uint8_t maxBitSize, uint8_t dynamicBitSize, const ALLOC& allocator = ALLOC())
3497
16
    {
3498
16
        return std::allocate_shared<DynamicUnsignedBitFieldReflectable<ALLOC, T>>(
3499
16
                allocator, value, maxBitSize, dynamicBitSize);
3500
16
    }
3501
3502
    // for dynamic unsigned bit field given a by type reference (e.g. parameter, function return type)
3503
    static IBasicReflectablePtr<ALLOC> getDynamicUnsignedBitField(
3504
            uint64_t value, uint8_t maxBitSize, const ALLOC& allocator = ALLOC())
3505
2
    {
3506
2
        if (maxBitSize != 64)
3507
1
        {
3508
1
            throw CppRuntimeException("ReflectableFactory::getDynamicUnsignedBitField - ")
3509
1
                    << "maxBitSize != 64 for referenced dynamic bit field!";
3510
1
        }
3511
3512
1
        return getDynamicUnsignedBitField(value, maxBitSize, maxBitSize, allocator);
3513
2
    }
3514
3515
    static IBasicReflectablePtr<ALLOC> getVarInt16(int16_t value, const ALLOC& allocator = ALLOC())
3516
2
    {
3517
2
        return std::allocate_shared<VarInt16Reflectable<ALLOC>>(allocator, value);
3518
2
    }
3519
3520
    static IBasicReflectablePtr<ALLOC> getVarInt32(int32_t value, const ALLOC& allocator = ALLOC())
3521
2
    {
3522
2
        return std::allocate_shared<VarInt32Reflectable<ALLOC>>(allocator, value);
3523
2
    }
3524
3525
    static IBasicReflectablePtr<ALLOC> getVarInt64(int64_t value, const ALLOC& allocator = ALLOC())
3526
2
    {
3527
2
        return std::allocate_shared<VarInt64Reflectable<ALLOC>>(allocator, value);
3528
2
    }
3529
3530
    static IBasicReflectablePtr<ALLOC> getVarInt(int64_t value, const ALLOC& allocator = ALLOC())
3531
3
    {
3532
3
        return std::allocate_shared<VarIntReflectable<ALLOC>>(allocator, value);
3533
3
    }
3534
3535
    static IBasicReflectablePtr<ALLOC> getVarUInt16(uint16_t value, const ALLOC& allocator = ALLOC())
3536
2
    {
3537
2
        return std::allocate_shared<VarUInt16Reflectable<ALLOC>>(allocator, value);
3538
2
    }
3539
3540
    static IBasicReflectablePtr<ALLOC> getVarUInt32(uint32_t value, const ALLOC& allocator = ALLOC())
3541
2
    {
3542
2
        return std::allocate_shared<VarUInt32Reflectable<ALLOC>>(allocator, value);
3543
2
    }
3544
3545
    static IBasicReflectablePtr<ALLOC> getVarUInt64(uint64_t value, const ALLOC& allocator = ALLOC())
3546
2
    {
3547
2
        return std::allocate_shared<VarUInt64Reflectable<ALLOC>>(allocator, value);
3548
2
    }
3549
3550
    static IBasicReflectablePtr<ALLOC> getVarUInt(uint64_t value, const ALLOC& allocator = ALLOC())
3551
2
    {
3552
2
        return std::allocate_shared<VarUIntReflectable<ALLOC>>(allocator, value);
3553
2
    }
3554
3555
    static IBasicReflectablePtr<ALLOC> getVarSize(uint32_t value, const ALLOC& allocator = ALLOC())
3556
3
    {
3557
3
        return std::allocate_shared<VarSizeReflectable<ALLOC>>(allocator, value);
3558
3
    }
3559
3560
    static IBasicReflectablePtr<ALLOC> getFloat16(float value, const ALLOC& allocator = ALLOC())
3561
7
    {
3562
7
        return std::allocate_shared<Float16Reflectable<ALLOC>>(allocator, value);
3563
7
    }
3564
3565
    static IBasicReflectablePtr<ALLOC> getFloat32(float value, const ALLOC& allocator = ALLOC())
3566
9
    {
3567
9
        return std::allocate_shared<Float32Reflectable<ALLOC>>(allocator, value);
3568
9
    }
3569
3570
    static IBasicReflectablePtr<ALLOC> getFloat64(double value, const ALLOC& allocator = ALLOC())
3571
37
    {
3572
37
        return std::allocate_shared<Float64Reflectable<ALLOC>>(allocator, value);
3573
37
    }
3574
3575
    static IBasicReflectablePtr<ALLOC> getBytes(Span<const uint8_t> value, const ALLOC& allocator = ALLOC())
3576
20
    {
3577
20
        return std::allocate_shared<BytesReflectable<ALLOC>>(allocator, value);
3578
20
    }
3579
3580
    static IBasicReflectablePtr<ALLOC> getString(StringView value, const ALLOC& allocator = ALLOC())
3581
134
    {
3582
134
        return std::allocate_shared<StringReflectable<ALLOC>>(allocator, value);
3583
134
    }
3584
3585
    static IBasicReflectablePtr<ALLOC> getBitBuffer(
3586
            const BasicBitBuffer<ALLOC>& value, const ALLOC& allocator = ALLOC())
3587
20
    {
3588
20
        return std::allocate_shared<BitBufferReflectable<ALLOC>>(allocator, value);
3589
20
    }
3590
3591
    template <typename RAW_ARRAY>
3592
    static IBasicReflectableConstPtr<ALLOC> getBoolArray(
3593
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3594
1
    {
3595
1
        return std::allocate_shared<BoolReflectableConstArray<ALLOC, RAW_ARRAY>>(
3596
1
                allocator, allocator, rawArray);
3597
1
    }
3598
3599
    template <typename RAW_ARRAY>
3600
    static IBasicReflectablePtr<ALLOC> getBoolArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3601
1
    {
3602
1
        return std::allocate_shared<BoolReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3603
1
    }
3604
3605
    template <typename RAW_ARRAY>
3606
    static IBasicReflectableConstPtr<ALLOC> getInt8Array(
3607
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3608
1
    {
3609
1
        return std::allocate_shared<Int8ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3610
1
                allocator, allocator, rawArray);
3611
1
    }
3612
3613
    template <typename RAW_ARRAY>
3614
    static IBasicReflectablePtr<ALLOC> getInt8Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3615
1
    {
3616
1
        return std::allocate_shared<Int8ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3617
1
    }
3618
3619
    template <typename RAW_ARRAY>
3620
    static IBasicReflectableConstPtr<ALLOC> getInt16Array(
3621
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3622
1
    {
3623
1
        return std::allocate_shared<Int16ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3624
1
                allocator, allocator, rawArray);
3625
1
    }
3626
3627
    template <typename RAW_ARRAY>
3628
    static IBasicReflectablePtr<ALLOC> getInt16Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3629
1
    {
3630
1
        return std::allocate_shared<Int16ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3631
1
    }
3632
3633
    template <typename RAW_ARRAY>
3634
    static IBasicReflectableConstPtr<ALLOC> getInt32Array(
3635
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3636
1
    {
3637
1
        return std::allocate_shared<Int32ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3638
1
                allocator, allocator, rawArray);
3639
1
    }
3640
3641
    template <typename RAW_ARRAY>
3642
    static IBasicReflectablePtr<ALLOC> getInt32Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3643
1
    {
3644
1
        return std::allocate_shared<Int32ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3645
1
    }
3646
3647
    template <typename RAW_ARRAY>
3648
    static IBasicReflectableConstPtr<ALLOC> getInt64Array(
3649
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3650
1
    {
3651
1
        return std::allocate_shared<Int64ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3652
1
                allocator, allocator, rawArray);
3653
1
    }
3654
3655
    template <typename RAW_ARRAY>
3656
    static IBasicReflectablePtr<ALLOC> getInt64Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3657
1
    {
3658
1
        return std::allocate_shared<Int64ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3659
1
    }
3660
3661
    template <typename RAW_ARRAY>
3662
    static IBasicReflectableConstPtr<ALLOC> getUInt8Array(
3663
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3664
2
    {
3665
2
        return std::allocate_shared<UInt8ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3666
2
                allocator, allocator, rawArray);
3667
2
    }
3668
3669
    template <typename RAW_ARRAY>
3670
    static IBasicReflectablePtr<ALLOC> getUInt8Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3671
2
    {
3672
2
        return std::allocate_shared<UInt8ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3673
2
    }
3674
3675
    template <typename RAW_ARRAY>
3676
    static IBasicReflectableConstPtr<ALLOC> getUInt16Array(
3677
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3678
1
    {
3679
1
        return std::allocate_shared<UInt16ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3680
1
                allocator, allocator, rawArray);
3681
1
    }
3682
3683
    template <typename RAW_ARRAY>
3684
    static IBasicReflectablePtr<ALLOC> getUInt16Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3685
1
    {
3686
1
        return std::allocate_shared<UInt16ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3687
1
    }
3688
3689
    template <typename RAW_ARRAY>
3690
    static IBasicReflectableConstPtr<ALLOC> getUInt32Array(
3691
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3692
1
    {
3693
1
        return std::allocate_shared<UInt32ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3694
1
                allocator, allocator, rawArray);
3695
1
    }
3696
3697
    template <typename RAW_ARRAY>
3698
    static IBasicReflectablePtr<ALLOC> getUInt32Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3699
10
    {
3700
10
        return std::allocate_shared<UInt32ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3701
10
    }
3702
3703
    template <typename RAW_ARRAY>
3704
    static IBasicReflectableConstPtr<ALLOC> getUInt64Array(
3705
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3706
1
    {
3707
1
        return std::allocate_shared<UInt64ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3708
1
                allocator, allocator, rawArray);
3709
1
    }
3710
3711
    template <typename RAW_ARRAY>
3712
    static IBasicReflectablePtr<ALLOC> getUInt64Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3713
1
    {
3714
1
        return std::allocate_shared<UInt64ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3715
1
    }
3716
3717
    template <typename RAW_ARRAY>
3718
    static IBasicReflectableConstPtr<ALLOC> getFixedSignedBitFieldArray(
3719
            const RAW_ARRAY& rawArray, uint8_t bitSize, const ALLOC& allocator = ALLOC())
3720
1
    {
3721
1
        return std::allocate_shared<FixedSignedBitFieldReflectableConstArray<ALLOC, RAW_ARRAY>>(
3722
1
                allocator, allocator, rawArray, bitSize);
3723
1
    }
3724
3725
    template <typename RAW_ARRAY>
3726
    static IBasicReflectablePtr<ALLOC> getFixedSignedBitFieldArray(
3727
            RAW_ARRAY& rawArray, uint8_t bitSize, const ALLOC& allocator = ALLOC())
3728
1
    {
3729
1
        return std::allocate_shared<FixedSignedBitFieldReflectableArray<ALLOC, RAW_ARRAY>>(
3730
1
                allocator, allocator, rawArray, bitSize);
3731
1
    }
3732
3733
    template <typename RAW_ARRAY>
3734
    static IBasicReflectableConstPtr<ALLOC> getFixedUnsignedBitFieldArray(
3735
            const RAW_ARRAY& rawArray, uint8_t bitSize, const ALLOC& allocator = ALLOC())
3736
1
    {
3737
1
        return std::allocate_shared<FixedUnsignedBitFieldReflectableConstArray<ALLOC, RAW_ARRAY>>(
3738
1
                allocator, allocator, rawArray, bitSize);
3739
1
    }
3740
3741
    template <typename RAW_ARRAY>
3742
    static IBasicReflectablePtr<ALLOC> getFixedUnsignedBitFieldArray(
3743
            RAW_ARRAY& rawArray, uint8_t bitSize, const ALLOC& allocator = ALLOC())
3744
1
    {
3745
1
        return std::allocate_shared<FixedUnsignedBitFieldReflectableArray<ALLOC, RAW_ARRAY>>(
3746
1
                allocator, allocator, rawArray, bitSize);
3747
1
    }
3748
3749
    template <typename RAW_ARRAY>
3750
    static IBasicReflectableConstPtr<ALLOC> getDynamicSignedBitFieldArray(const RAW_ARRAY& rawArray,
3751
            uint8_t maxBitSize, uint8_t dynamicBitSize, const ALLOC& allocator = ALLOC())
3752
1
    {
3753
1
        return std::allocate_shared<DynamicSignedBitFieldReflectableConstArray<ALLOC, RAW_ARRAY>>(
3754
1
                allocator, allocator, rawArray, maxBitSize, dynamicBitSize);
3755
1
    }
3756
3757
    template <typename RAW_ARRAY>
3758
    static IBasicReflectablePtr<ALLOC> getDynamicSignedBitFieldArray(
3759
            RAW_ARRAY& rawArray, uint8_t maxBitSize, uint8_t dynamicBitSize, const ALLOC& allocator = ALLOC())
3760
1
    {
3761
1
        return std::allocate_shared<DynamicSignedBitFieldReflectableArray<ALLOC, RAW_ARRAY>>(
3762
1
                allocator, allocator, rawArray, maxBitSize, dynamicBitSize);
3763
1
    }
3764
3765
    template <typename RAW_ARRAY>
3766
    static IBasicReflectableConstPtr<ALLOC> getDynamicUnsignedBitFieldArray(const RAW_ARRAY& rawArray,
3767
            uint8_t maxBitSize, uint8_t dynamicBitSize, const ALLOC& allocator = ALLOC())
3768
1
    {
3769
1
        return std::allocate_shared<DynamicUnsignedBitFieldReflectableConstArray<ALLOC, RAW_ARRAY>>(
3770
1
                allocator, allocator, rawArray, maxBitSize, dynamicBitSize);
3771
1
    }
3772
3773
    template <typename RAW_ARRAY>
3774
    static IBasicReflectablePtr<ALLOC> getDynamicUnsignedBitFieldArray(
3775
            RAW_ARRAY& rawArray, uint8_t maxBitSize, uint8_t dynamicBitSize, const ALLOC& allocator = ALLOC())
3776
1
    {
3777
1
        return std::allocate_shared<DynamicUnsignedBitFieldReflectableArray<ALLOC, RAW_ARRAY>>(
3778
1
                allocator, allocator, rawArray, maxBitSize, dynamicBitSize);
3779
1
    }
3780
3781
    template <typename RAW_ARRAY>
3782
    static IBasicReflectableConstPtr<ALLOC> getVarInt16Array(
3783
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3784
1
    {
3785
1
        return std::allocate_shared<VarInt16ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3786
1
                allocator, allocator, rawArray);
3787
1
    }
3788
3789
    template <typename RAW_ARRAY>
3790
    static IBasicReflectablePtr<ALLOC> getVarInt16Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3791
1
    {
3792
1
        return std::allocate_shared<VarInt16ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3793
1
    }
3794
3795
    template <typename RAW_ARRAY>
3796
    static IBasicReflectableConstPtr<ALLOC> getVarInt32Array(
3797
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3798
1
    {
3799
1
        return std::allocate_shared<VarInt32ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3800
1
                allocator, allocator, rawArray);
3801
1
    }
3802
3803
    template <typename RAW_ARRAY>
3804
    static IBasicReflectablePtr<ALLOC> getVarInt32Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3805
1
    {
3806
1
        return std::allocate_shared<VarInt32ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3807
1
    }
3808
3809
    template <typename RAW_ARRAY>
3810
    static IBasicReflectableConstPtr<ALLOC> getVarInt64Array(
3811
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3812
1
    {
3813
1
        return std::allocate_shared<VarInt64ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3814
1
                allocator, allocator, rawArray);
3815
1
    }
3816
3817
    template <typename RAW_ARRAY>
3818
    static IBasicReflectablePtr<ALLOC> getVarInt64Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3819
1
    {
3820
1
        return std::allocate_shared<VarInt64ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3821
1
    }
3822
3823
    template <typename RAW_ARRAY>
3824
    static IBasicReflectableConstPtr<ALLOC> getVarIntArray(
3825
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3826
1
    {
3827
1
        return std::allocate_shared<VarIntReflectableConstArray<ALLOC, RAW_ARRAY>>(
3828
1
                allocator, allocator, rawArray);
3829
1
    }
3830
3831
    template <typename RAW_ARRAY>
3832
    static IBasicReflectablePtr<ALLOC> getVarIntArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3833
1
    {
3834
1
        return std::allocate_shared<VarIntReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3835
1
    }
3836
3837
    template <typename RAW_ARRAY>
3838
    static IBasicReflectableConstPtr<ALLOC> getVarUInt16Array(
3839
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3840
1
    {
3841
1
        return std::allocate_shared<VarUInt16ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3842
1
                allocator, allocator, rawArray);
3843
1
    }
3844
3845
    template <typename RAW_ARRAY>
3846
    static IBasicReflectablePtr<ALLOC> getVarUInt16Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3847
1
    {
3848
1
        return std::allocate_shared<VarUInt16ReflectableArray<ALLOC, RAW_ARRAY>>(
3849
1
                allocator, allocator, rawArray);
3850
1
    }
3851
3852
    template <typename RAW_ARRAY>
3853
    static IBasicReflectableConstPtr<ALLOC> getVarUInt32Array(
3854
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3855
1
    {
3856
1
        return std::allocate_shared<VarUInt32ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3857
1
                allocator, allocator, rawArray);
3858
1
    }
3859
3860
    template <typename RAW_ARRAY>
3861
    static IBasicReflectablePtr<ALLOC> getVarUInt32Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3862
1
    {
3863
1
        return std::allocate_shared<VarUInt32ReflectableArray<ALLOC, RAW_ARRAY>>(
3864
1
                allocator, allocator, rawArray);
3865
1
    }
3866
3867
    template <typename RAW_ARRAY>
3868
    static IBasicReflectableConstPtr<ALLOC> getVarUInt64Array(
3869
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3870
1
    {
3871
1
        return std::allocate_shared<VarUInt64ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3872
1
                allocator, allocator, rawArray);
3873
1
    }
3874
3875
    template <typename RAW_ARRAY>
3876
    static IBasicReflectablePtr<ALLOC> getVarUInt64Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3877
1
    {
3878
1
        return std::allocate_shared<VarUInt64ReflectableArray<ALLOC, RAW_ARRAY>>(
3879
1
                allocator, allocator, rawArray);
3880
1
    }
3881
3882
    template <typename RAW_ARRAY>
3883
    static IBasicReflectableConstPtr<ALLOC> getVarUIntArray(
3884
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3885
1
    {
3886
1
        return std::allocate_shared<VarUIntReflectableConstArray<ALLOC, RAW_ARRAY>>(
3887
1
                allocator, allocator, rawArray);
3888
1
    }
3889
3890
    template <typename RAW_ARRAY>
3891
    static IBasicReflectablePtr<ALLOC> getVarUIntArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3892
1
    {
3893
1
        return std::allocate_shared<VarUIntReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3894
1
    }
3895
3896
    template <typename RAW_ARRAY>
3897
    static IBasicReflectableConstPtr<ALLOC> getVarSizeArray(
3898
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3899
1
    {
3900
1
        return std::allocate_shared<VarSizeReflectableConstArray<ALLOC, RAW_ARRAY>>(
3901
1
                allocator, allocator, rawArray);
3902
1
    }
3903
3904
    template <typename RAW_ARRAY>
3905
    static IBasicReflectablePtr<ALLOC> getVarSizeArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3906
1
    {
3907
1
        return std::allocate_shared<VarSizeReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3908
1
    }
3909
3910
    template <typename RAW_ARRAY>
3911
    static IBasicReflectableConstPtr<ALLOC> getFloat16Array(
3912
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3913
1
    {
3914
1
        return std::allocate_shared<Float16ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3915
1
                allocator, allocator, rawArray);
3916
1
    }
3917
3918
    template <typename RAW_ARRAY>
3919
    static IBasicReflectablePtr<ALLOC> getFloat16Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3920
1
    {
3921
1
        return std::allocate_shared<Float16ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3922
1
    }
3923
3924
    template <typename RAW_ARRAY>
3925
    static IBasicReflectableConstPtr<ALLOC> getFloat32Array(
3926
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3927
1
    {
3928
1
        return std::allocate_shared<Float32ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3929
1
                allocator, allocator, rawArray);
3930
1
    }
3931
3932
    template <typename RAW_ARRAY>
3933
    static IBasicReflectablePtr<ALLOC> getFloat32Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3934
1
    {
3935
1
        return std::allocate_shared<Float32ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3936
1
    }
3937
3938
    template <typename RAW_ARRAY>
3939
    static IBasicReflectableConstPtr<ALLOC> getFloat64Array(
3940
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3941
1
    {
3942
1
        return std::allocate_shared<Float64ReflectableConstArray<ALLOC, RAW_ARRAY>>(
3943
1
                allocator, allocator, rawArray);
3944
1
    }
3945
3946
    template <typename RAW_ARRAY>
3947
    static IBasicReflectablePtr<ALLOC> getFloat64Array(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3948
1
    {
3949
1
        return std::allocate_shared<Float64ReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3950
1
    }
3951
3952
    template <typename RAW_ARRAY>
3953
    static IBasicReflectableConstPtr<ALLOC> getBytesArray(
3954
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3955
1
    {
3956
1
        return std::allocate_shared<BytesReflectableConstArray<ALLOC, RAW_ARRAY>>(
3957
1
                allocator, allocator, rawArray);
3958
1
    }
3959
3960
    template <typename RAW_ARRAY>
3961
    static IBasicReflectablePtr<ALLOC> getBytesArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3962
12
    {
3963
12
        return std::allocate_shared<BytesReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3964
12
    }
3965
3966
    template <typename RAW_ARRAY>
3967
    static IBasicReflectableConstPtr<ALLOC> getStringArray(
3968
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3969
1
    {
3970
1
        return std::allocate_shared<StringReflectableConstArray<ALLOC, RAW_ARRAY>>(
3971
1
                allocator, allocator, rawArray);
3972
1
    }
3973
3974
    template <typename RAW_ARRAY>
3975
    static IBasicReflectablePtr<ALLOC> getStringArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3976
20
    {
3977
20
        return std::allocate_shared<StringReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
3978
20
    }
3979
3980
    template <typename RAW_ARRAY>
3981
    static IBasicReflectableConstPtr<ALLOC> getBitBufferArray(
3982
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3983
1
    {
3984
1
        return std::allocate_shared<BitBufferReflectableConstArray<ALLOC, RAW_ARRAY>>(
3985
1
                allocator, allocator, rawArray);
3986
1
    }
3987
3988
    template <typename RAW_ARRAY>
3989
    static IBasicReflectablePtr<ALLOC> getBitBufferArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3990
11
    {
3991
11
        return std::allocate_shared<BitBufferReflectableArray<ALLOC, RAW_ARRAY>>(
3992
11
                allocator, allocator, rawArray);
3993
11
    }
3994
3995
    template <typename RAW_ARRAY>
3996
    static IBasicReflectableConstPtr<ALLOC> getCompoundArray(
3997
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
3998
1
    {
3999
1
        return std::allocate_shared<CompoundReflectableConstArray<ALLOC, RAW_ARRAY>>(
4000
1
                allocator, allocator, rawArray);
4001
1
    }
4002
4003
    template <typename RAW_ARRAY>
4004
    static IBasicReflectablePtr<ALLOC> getCompoundArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
4005
41
    {
4006
41
        return std::allocate_shared<CompoundReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
4007
41
    }
4008
4009
    template <typename RAW_ARRAY>
4010
    static IBasicReflectableConstPtr<ALLOC> getBitmaskArray(
4011
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
4012
1
    {
4013
1
        return std::allocate_shared<BitmaskReflectableConstArray<ALLOC, RAW_ARRAY>>(
4014
1
                allocator, allocator, rawArray);
4015
1
    }
4016
4017
    template <typename RAW_ARRAY>
4018
    static IBasicReflectablePtr<ALLOC> getBitmaskArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
4019
1
    {
4020
1
        return std::allocate_shared<BitmaskReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
4021
1
    }
4022
4023
    template <typename RAW_ARRAY>
4024
    static IBasicReflectableConstPtr<ALLOC> getEnumArray(
4025
            const RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
4026
1
    {
4027
1
        return std::allocate_shared<EnumReflectableConstArray<ALLOC, RAW_ARRAY>>(
4028
1
                allocator, allocator, rawArray);
4029
1
    }
4030
4031
    template <typename RAW_ARRAY>
4032
    static IBasicReflectablePtr<ALLOC> getEnumArray(RAW_ARRAY& rawArray, const ALLOC& allocator = ALLOC())
4033
1
    {
4034
1
        return std::allocate_shared<EnumReflectableArray<ALLOC, RAW_ARRAY>>(allocator, allocator, rawArray);
4035
1
    }
4036
};
4037
4038
/** Typedef to the reflectable factory provided for convenience - using default std::allocator<uint8_t>. */
4039
using ReflectableFactory = BasicReflectableFactory<std::allocator<uint8_t>>;
4040
4041
template <typename ALLOC>
4042
ReflectableBase<ALLOC>::ReflectableBase(const IBasicTypeInfo<ALLOC>& typeInfo) :
4043
        m_typeInfo(typeInfo)
4044
1.68k
{}
4045
4046
template <typename ALLOC>
4047
ReflectableBase<ALLOC>::~ReflectableBase() = default;
4048
4049
template <typename ALLOC>
4050
const IBasicTypeInfo<ALLOC>& ReflectableBase<ALLOC>::getTypeInfo() const
4051
13.3k
{
4052
13.3k
    return m_typeInfo;
4053
13.3k
}
4054
4055
template <typename ALLOC>
4056
bool ReflectableBase<ALLOC>::isArray() const
4057
558
{
4058
558
    return false;
4059
558
}
4060
4061
template <typename ALLOC>
4062
void ReflectableBase<ALLOC>::initializeChildren()
4063
122
{
4064
122
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not a compound type!";
4065
122
}
4066
4067
template <typename ALLOC>
4068
void ReflectableBase<ALLOC>::initialize(const vector<AnyHolder<ALLOC>, ALLOC>&)
4069
123
{
4070
123
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no type arguments!";
4071
123
}
4072
4073
template <typename ALLOC>
4074
size_t ReflectableBase<ALLOC>::initializeOffsets(size_t)
4075
122
{
4076
122
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not a compound type!";
4077
122
}
4078
4079
template <typename ALLOC>
4080
size_t ReflectableBase<ALLOC>::initializeOffsets()
4081
153
{
4082
153
    return initializeOffsets(0);
4083
153
}
4084
4085
template <typename ALLOC>
4086
size_t ReflectableBase<ALLOC>::bitSizeOf(size_t) const
4087
1
{
4088
1
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not implemented!";
4089
1
}
4090
4091
template <typename ALLOC>
4092
size_t ReflectableBase<ALLOC>::bitSizeOf() const
4093
308
{
4094
308
    return bitSizeOf(0);
4095
308
}
4096
4097
template <typename ALLOC>
4098
void ReflectableBase<ALLOC>::write(BitStreamWriter&) const
4099
1
{
4100
1
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not implemented!";
4101
1
}
4102
4103
template <typename ALLOC>
4104
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::getField(StringView) const
4105
175
{
4106
175
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no fields to get!";
4107
175
}
4108
4109
template <typename ALLOC>
4110
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::getField(StringView)
4111
122
{
4112
122
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no fields to get!";
4113
122
}
4114
4115
template <typename ALLOC>
4116
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::createField(StringView)
4117
122
{
4118
122
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no fields to create!";
4119
122
}
4120
4121
template <typename ALLOC>
4122
void ReflectableBase<ALLOC>::setField(StringView, const AnyHolder<ALLOC>&)
4123
122
{
4124
122
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no fields to set!";
4125
122
}
4126
4127
template <typename ALLOC>
4128
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::getParameter(StringView) const
4129
175
{
4130
175
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no parameters to get!";
4131
175
}
4132
4133
template <typename ALLOC>
4134
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::getParameter(StringView)
4135
124
{
4136
124
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no parameters to get!";
4137
124
}
4138
4139
template <typename ALLOC>
4140
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::callFunction(StringView) const
4141
175
{
4142
175
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no functions to call!";
4143
175
}
4144
4145
template <typename ALLOC>
4146
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::callFunction(StringView)
4147
124
{
4148
124
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' has no functions to call!";
4149
124
}
4150
4151
template <typename ALLOC>
4152
StringView ReflectableBase<ALLOC>::getChoice() const
4153
299
{
4154
299
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is neither choice nor union!";
4155
299
}
4156
4157
template <typename ALLOC>
4158
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::find(StringView path) const
4159
520
{
4160
520
    return detail::getFromObject(*this, path, 0);
4161
520
}
4162
4163
template <typename ALLOC>
4164
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::find(StringView path)
4165
399
{
4166
399
    return detail::getFromObject(*this, path, 0);
4167
399
}
4168
4169
template <typename ALLOC>
4170
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::operator[](StringView path) const
4171
247
{
4172
247
    return find(path);
4173
247
}
4174
4175
template <typename ALLOC>
4176
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::operator[](StringView path)
4177
167
{
4178
167
    return find(path);
4179
167
}
4180
4181
template <typename ALLOC>
4182
size_t ReflectableBase<ALLOC>::size() const
4183
309
{
4184
309
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4185
309
}
4186
4187
template <typename ALLOC>
4188
void ReflectableBase<ALLOC>::resize(size_t)
4189
126
{
4190
126
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4191
126
}
4192
4193
template <typename ALLOC>
4194
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::at(size_t) const
4195
308
{
4196
308
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4197
308
}
4198
4199
template <typename ALLOC>
4200
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::at(size_t)
4201
127
{
4202
127
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4203
127
}
4204
4205
template <typename ALLOC>
4206
IBasicReflectableConstPtr<ALLOC> ReflectableBase<ALLOC>::operator[](size_t) const
4207
308
{
4208
308
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4209
308
}
4210
4211
template <typename ALLOC>
4212
IBasicReflectablePtr<ALLOC> ReflectableBase<ALLOC>::operator[](size_t)
4213
127
{
4214
127
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4215
127
}
4216
4217
template <typename ALLOC>
4218
void ReflectableBase<ALLOC>::setAt(const AnyHolder<ALLOC>&, size_t)
4219
126
{
4220
126
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4221
126
}
4222
4223
template <typename ALLOC>
4224
void ReflectableBase<ALLOC>::append(const AnyHolder<ALLOC>&)
4225
1
{
4226
1
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not an array!";
4227
1
}
4228
4229
template <typename ALLOC>
4230
AnyHolder<ALLOC> ReflectableBase<ALLOC>::getAnyValue(const ALLOC&) const
4231
1
{
4232
1
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not implemented!";
4233
1
}
4234
4235
template <typename ALLOC>
4236
AnyHolder<ALLOC> ReflectableBase<ALLOC>::getAnyValue(const ALLOC&)
4237
1
{
4238
1
    throw CppRuntimeException("Type '") << getTypeInfo().getSchemaName() << "' is not implemented!";
4239
1
}
4240
4241
template <typename ALLOC>
4242
AnyHolder<ALLOC> ReflectableBase<ALLOC>::getAnyValue() const
4243
225
{
4244
225
    return getAnyValue(ALLOC());
4245
225
}
4246
4247
template <typename ALLOC>
4248
AnyHolder<ALLOC> ReflectableBase<ALLOC>::getAnyValue()
4249
159
{
4250
159
    return getAnyValue(ALLOC());
4251
159
}
4252
4253
template <typename ALLOC>
4254
bool ReflectableBase<ALLOC>::getBool() const
4255
300
{
4256
300
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not boolean type!";
4257
300
}
4258
4259
template <typename ALLOC>
4260
int8_t ReflectableBase<ALLOC>::getInt8() const
4261
254
{
4262
254
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not int8 type!";
4263
254
}
4264
4265
template <typename ALLOC>
4266
int16_t ReflectableBase<ALLOC>::getInt16() const
4267
289
{
4268
289
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not int16 type!";
4269
289
}
4270
4271
template <typename ALLOC>
4272
int32_t ReflectableBase<ALLOC>::getInt32() const
4273
289
{
4274
289
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not int32 type!";
4275
289
}
4276
4277
template <typename ALLOC>
4278
int64_t ReflectableBase<ALLOC>::getInt64() const
4279
280
{
4280
280
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not int64 type!";
4281
280
}
4282
4283
template <typename ALLOC>
4284
uint8_t ReflectableBase<ALLOC>::getUInt8() const
4285
267
{
4286
267
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not uint8 type!";
4287
267
}
4288
4289
template <typename ALLOC>
4290
uint16_t ReflectableBase<ALLOC>::getUInt16() const
4291
289
{
4292
289
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not uint16 type!";
4293
289
}
4294
4295
template <typename ALLOC>
4296
uint32_t ReflectableBase<ALLOC>::getUInt32() const
4297
280
{
4298
280
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not uint32 type!";
4299
280
}
4300
4301
template <typename ALLOC>
4302
uint64_t ReflectableBase<ALLOC>::getUInt64() const
4303
280
{
4304
280
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not uint64 type!";
4305
280
}
4306
4307
template <typename ALLOC>
4308
float ReflectableBase<ALLOC>::getFloat() const
4309
297
{
4310
297
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not float type!";
4311
297
}
4312
4313
template <typename ALLOC>
4314
double ReflectableBase<ALLOC>::getDouble() const
4315
302
{
4316
302
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not double type!";
4317
302
}
4318
4319
template <typename ALLOC>
4320
Span<const uint8_t> ReflectableBase<ALLOC>::getBytes() const
4321
302
{
4322
302
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not bytes type!";
4323
302
}
4324
4325
template <typename ALLOC>
4326
StringView ReflectableBase<ALLOC>::getStringView() const
4327
298
{
4328
298
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not string type!";
4329
298
}
4330
4331
template <typename ALLOC>
4332
const BasicBitBuffer<ALLOC>& ReflectableBase<ALLOC>::getBitBuffer() const
4333
302
{
4334
302
    throw CppRuntimeException("'") << getTypeInfo().getSchemaName() << "' is not an extern type!";
4335
302
}
4336
4337
template <typename ALLOC>
4338
int64_t ReflectableBase<ALLOC>::toInt() const
4339
185
{
4340
185
    throw CppRuntimeException("Conversion from '")
4341
185
            << getTypeInfo().getSchemaName() << "' to signed integer is not available!";
4342
185
}
4343
4344
template <typename ALLOC>
4345
uint64_t ReflectableBase<ALLOC>::toUInt() const
4346
180
{
4347
180
    throw CppRuntimeException("Conversion from '")
4348
180
            << getTypeInfo().getSchemaName() << "' to unsigned integer is not available!";
4349
180
}
4350
4351
template <typename ALLOC>
4352
double ReflectableBase<ALLOC>::toDouble() const
4353
37
{
4354
37
    throw CppRuntimeException("Conversion from '")
4355
37
            << getTypeInfo().getSchemaName() << "' to double is not available!";
4356
37
}
4357
4358
template <typename ALLOC>
4359
string<ALLOC> ReflectableBase<ALLOC>::toString(const ALLOC&) const
4360
45
{
4361
45
    throw CppRuntimeException("Conversion from '")
4362
45
            << getTypeInfo().getSchemaName() << "' to string is not available!";
4363
45
}
4364
4365
template <typename ALLOC>
4366
string<ALLOC> ReflectableBase<ALLOC>::toString() const
4367
402
{
4368
402
    return toString(ALLOC());
4369
402
}
4370
4371
template <typename ALLOC>
4372
void ReflectableConstAllocatorHolderBase<ALLOC>::initializeChildren()
4373
1
{
4374
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4375
1
}
4376
4377
template <typename ALLOC>
4378
void ReflectableConstAllocatorHolderBase<ALLOC>::initialize(const vector<AnyHolder<ALLOC>, ALLOC>&)
4379
1
{
4380
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4381
1
}
4382
4383
template <typename ALLOC>
4384
size_t ReflectableConstAllocatorHolderBase<ALLOC>::initializeOffsets(size_t)
4385
1
{
4386
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4387
1
}
4388
4389
template <typename ALLOC>
4390
IBasicReflectablePtr<ALLOC> ReflectableConstAllocatorHolderBase<ALLOC>::getField(StringView)
4391
1
{
4392
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4393
1
}
4394
4395
template <typename ALLOC>
4396
void ReflectableConstAllocatorHolderBase<ALLOC>::setField(StringView, const AnyHolder<ALLOC>&)
4397
1
{
4398
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4399
1
}
4400
4401
template <typename ALLOC>
4402
IBasicReflectablePtr<ALLOC> ReflectableConstAllocatorHolderBase<ALLOC>::getParameter(StringView)
4403
1
{
4404
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4405
1
}
4406
4407
template <typename ALLOC>
4408
IBasicReflectablePtr<ALLOC> ReflectableConstAllocatorHolderBase<ALLOC>::callFunction(StringView)
4409
1
{
4410
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4411
1
}
4412
4413
template <typename ALLOC>
4414
AnyHolder<ALLOC> ReflectableConstAllocatorHolderBase<ALLOC>::getAnyValue(const ALLOC&)
4415
1
{
4416
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
4417
1
}
4418
4419
template <typename ALLOC>
4420
void ReflectableArrayBase<ALLOC>::initializeChildren()
4421
31
{
4422
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4423
31
}
4424
4425
template <typename ALLOC>
4426
void ReflectableArrayBase<ALLOC>::initialize(const vector<AnyHolder<ALLOC>, ALLOC>&)
4427
31
{
4428
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4429
31
}
4430
4431
template <typename ALLOC>
4432
size_t ReflectableArrayBase<ALLOC>::initializeOffsets(size_t)
4433
31
{
4434
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4435
31
}
4436
4437
template <typename ALLOC>
4438
size_t ReflectableArrayBase<ALLOC>::bitSizeOf(size_t) const
4439
71
{
4440
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4441
71
}
4442
4443
template <typename ALLOC>
4444
void ReflectableArrayBase<ALLOC>::write(BitStreamWriter&) const
4445
71
{
4446
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4447
71
}
4448
4449
template <typename ALLOC>
4450
IBasicReflectableConstPtr<ALLOC> ReflectableArrayBase<ALLOC>::getField(StringView) const
4451
40
{
4452
40
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4453
40
}
4454
4455
template <typename ALLOC>
4456
IBasicReflectablePtr<ALLOC> ReflectableArrayBase<ALLOC>::getField(StringView)
4457
31
{
4458
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4459
31
}
4460
4461
template <typename ALLOC>
4462
IBasicReflectablePtr<ALLOC> ReflectableArrayBase<ALLOC>::createField(StringView)
4463
31
{
4464
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4465
31
}
4466
4467
template <typename ALLOC>
4468
void ReflectableArrayBase<ALLOC>::setField(StringView, const AnyHolder<ALLOC>&)
4469
31
{
4470
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4471
31
}
4472
4473
template <typename ALLOC>
4474
IBasicReflectableConstPtr<ALLOC> ReflectableArrayBase<ALLOC>::getParameter(StringView) const
4475
40
{
4476
40
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4477
40
}
4478
4479
template <typename ALLOC>
4480
IBasicReflectablePtr<ALLOC> ReflectableArrayBase<ALLOC>::getParameter(StringView)
4481
31
{
4482
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4483
31
}
4484
4485
template <typename ALLOC>
4486
IBasicReflectableConstPtr<ALLOC> ReflectableArrayBase<ALLOC>::callFunction(StringView) const
4487
40
{
4488
40
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4489
40
}
4490
4491
template <typename ALLOC>
4492
IBasicReflectablePtr<ALLOC> ReflectableArrayBase<ALLOC>::callFunction(StringView)
4493
31
{
4494
31
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4495
31
}
4496
4497
template <typename ALLOC>
4498
StringView ReflectableArrayBase<ALLOC>::getChoice() const
4499
71
{
4500
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4501
71
}
4502
4503
template <typename ALLOC>
4504
IBasicReflectableConstPtr<ALLOC> ReflectableArrayBase<ALLOC>::operator[](size_t index) const
4505
105
{
4506
105
    return this->at(index);
4507
105
}
4508
4509
template <typename ALLOC>
4510
IBasicReflectablePtr<ALLOC> ReflectableArrayBase<ALLOC>::operator[](size_t index)
4511
84
{
4512
84
    return this->at(index);
4513
84
}
4514
4515
template <typename ALLOC>
4516
bool ReflectableArrayBase<ALLOC>::getBool() const
4517
71
{
4518
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4519
71
}
4520
4521
template <typename ALLOC>
4522
int8_t ReflectableArrayBase<ALLOC>::getInt8() const
4523
71
{
4524
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4525
71
}
4526
4527
template <typename ALLOC>
4528
int16_t ReflectableArrayBase<ALLOC>::getInt16() const
4529
71
{
4530
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4531
71
}
4532
4533
template <typename ALLOC>
4534
int32_t ReflectableArrayBase<ALLOC>::getInt32() const
4535
71
{
4536
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4537
71
}
4538
4539
template <typename ALLOC>
4540
int64_t ReflectableArrayBase<ALLOC>::getInt64() const
4541
71
{
4542
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4543
71
}
4544
4545
template <typename ALLOC>
4546
uint8_t ReflectableArrayBase<ALLOC>::getUInt8() const
4547
71
{
4548
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4549
71
}
4550
4551
template <typename ALLOC>
4552
uint16_t ReflectableArrayBase<ALLOC>::getUInt16() const
4553
71
{
4554
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4555
71
}
4556
4557
template <typename ALLOC>
4558
uint32_t ReflectableArrayBase<ALLOC>::getUInt32() const
4559
71
{
4560
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4561
71
}
4562
4563
template <typename ALLOC>
4564
uint64_t ReflectableArrayBase<ALLOC>::getUInt64() const
4565
71
{
4566
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4567
71
}
4568
4569
template <typename ALLOC>
4570
float ReflectableArrayBase<ALLOC>::getFloat() const
4571
71
{
4572
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4573
71
}
4574
4575
template <typename ALLOC>
4576
double ReflectableArrayBase<ALLOC>::getDouble() const
4577
71
{
4578
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4579
71
}
4580
4581
template <typename ALLOC>
4582
Span<const uint8_t> ReflectableArrayBase<ALLOC>::getBytes() const
4583
71
{
4584
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4585
71
}
4586
4587
template <typename ALLOC>
4588
StringView ReflectableArrayBase<ALLOC>::getStringView() const
4589
71
{
4590
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4591
71
}
4592
4593
template <typename ALLOC>
4594
const BasicBitBuffer<ALLOC>& ReflectableArrayBase<ALLOC>::getBitBuffer() const
4595
71
{
4596
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4597
71
}
4598
4599
template <typename ALLOC>
4600
int64_t ReflectableArrayBase<ALLOC>::toInt() const
4601
71
{
4602
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4603
71
}
4604
4605
template <typename ALLOC>
4606
uint64_t ReflectableArrayBase<ALLOC>::toUInt() const
4607
71
{
4608
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4609
71
}
4610
4611
template <typename ALLOC>
4612
double ReflectableArrayBase<ALLOC>::toDouble() const
4613
71
{
4614
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4615
71
}
4616
4617
template <typename ALLOC>
4618
string<ALLOC> ReflectableArrayBase<ALLOC>::toString(const ALLOC&) const
4619
71
{
4620
71
    throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
4621
71
}
4622
4623
template <typename ALLOC>
4624
void ReflectableConstArrayBase<ALLOC>::resize(size_t)
4625
1
{
4626
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
4627
1
}
4628
4629
template <typename ALLOC>
4630
IBasicReflectablePtr<ALLOC> ReflectableConstArrayBase<ALLOC>::at(size_t)
4631
1
{
4632
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
4633
1
}
4634
4635
template <typename ALLOC>
4636
IBasicReflectablePtr<ALLOC> ReflectableConstArrayBase<ALLOC>::operator[](size_t)
4637
1
{
4638
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
4639
1
}
4640
4641
template <typename ALLOC>
4642
void ReflectableConstArrayBase<ALLOC>::setAt(const AnyHolder<ALLOC>&, size_t)
4643
1
{
4644
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
4645
1
}
4646
4647
template <typename ALLOC>
4648
void ReflectableConstArrayBase<ALLOC>::append(const AnyHolder<ALLOC>&)
4649
1
{
4650
1
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
4651
1
}
4652
4653
template <typename ALLOC>
4654
AnyHolder<ALLOC> ReflectableConstArrayBase<ALLOC>::getAnyValue(const ALLOC&)
4655
6
{
4656
6
    throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
4657
6
}
4658
4659
} // namespace zserio
4660
4661
#endif // ZSERIO_REFLECTABLE_H_INC