Coverage Report

Created: 2023-12-13 14:58

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