Zserio C++17 runtime library  0.5.0
Built for Zserio 2.17.0
ReflectableData.h
Go to the documentation of this file.
1 #ifndef ZSERIO_REFLECTABLE_DATA_H_INC
2 #define ZSERIO_REFLECTABLE_DATA_H_INC
3 
4 #include "zserio/Enums.h"
8 #include "zserio/TypeInfoUtil.h"
9 
10 namespace zserio
11 {
12 
13 namespace detail
14 {
15 
19 template <typename ALLOC>
20 class ReflectableDataBase : public IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>
21 {
22 public:
23  using Ptr = typename IBasicReflectableData<ALLOC>::Ptr;
25 
26  using IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>::getField;
27  using IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>::at;
28  using IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>::operator[];
29  using IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>::getAnyValue;
30 
36  explicit ReflectableDataBase(const IBasicTypeInfo<ALLOC>& typeInfo);
37 
39  ~ReflectableDataBase() override = 0;
40 
45  ReflectableDataBase(const ReflectableDataBase&) = delete;
46  ReflectableDataBase& operator=(const ReflectableDataBase&) = delete;
47 
48  ReflectableDataBase(const ReflectableDataBase&&) = delete;
49  ReflectableDataBase& operator=(const ReflectableDataBase&&) = delete;
54  Ptr getField(std::string_view name) override;
55  Ptr createField(std::string_view name) override;
56  void setField(std::string_view name, const BasicAny<ALLOC>& value) override;
57 
58  void resize(size_t size) override;
59  Ptr at(size_t index) override;
60  Ptr operator[](size_t index) override;
61  void setAt(const BasicAny<ALLOC>& value, size_t index) override;
62  void append(const BasicAny<ALLOC>& value) override;
63 
64  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) override;
65  BasicAny<ALLOC> getAnyValue() override;
66 
67  ConstPtr find(std::string_view path) const override;
68  Ptr find(std::string_view path) override;
69  Ptr operator[](std::string_view path) override;
70 
71 private:
72  ConstPtr getFieldFromObject(const IBasicReflectableData<ALLOC>& object, std::string_view name) const;
73  ConstPtr getFromObject(const IBasicReflectableData<ALLOC>& object, std::string_view path, size_t pos) const;
74  Ptr getFieldFromObject(IBasicReflectableData<ALLOC>& object, std::string_view name);
75  Ptr getFromObject(IBasicReflectableData<ALLOC>& object, std::string_view path, size_t pos);
76 };
77 
83 template <typename T, typename ALLOC>
84 class BuiltinReflectableDataBase : public ReflectableDataBase<ALLOC>
85 {
86 private:
87  using Base = ReflectableDataBase<ALLOC>;
88  using ReflectableDataBase<ALLOC>::getAnyValue;
89 
90 protected:
91  using Type = T;
92 
93  BuiltinReflectableDataBase(const IBasicTypeInfo<ALLOC>& typeInfo, T value) :
94  Base(typeInfo),
95  m_value(value)
96  {}
97 
98  T getValue() const
99  {
100  return m_value;
101  }
102 
103 public:
104  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) const override
105  {
106  return BasicAny<ALLOC>(m_value, allocator);
107  }
108 
109  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) override
110  {
111  return BasicAny<ALLOC>(m_value, allocator);
112  }
113 
114 private:
115  T m_value;
116 };
117 
123 template <typename T, typename ALLOC>
124 class IntegralReflectableDataBase : public BuiltinReflectableDataBase<T, ALLOC>
125 {
126 protected:
127  static_assert(std::is_integral_v<typename T::ValueType>, "T must be a signed integral type!");
128 
129  using Base = BuiltinReflectableDataBase<T, ALLOC>;
130 
131 public:
132  IntegralReflectableDataBase(const IBasicTypeInfo<ALLOC>& typeInfo, T value) :
133  Base(typeInfo, value)
134  {}
135 
136  double toDouble() const override
137  {
138  return static_cast<double>(Base::getValue());
139  }
140 
141  BasicString<RebindAlloc<ALLOC, char>> toString(const ALLOC& allocator) const override
142  {
143  return zserio::toString<ALLOC>(Base::getValue(), allocator);
144  }
145 };
146 
152 template <typename T, typename ALLOC>
153 class SignedReflectableDataBase : public IntegralReflectableDataBase<T, ALLOC>
154 {
155 protected:
156  static_assert(std::is_signed_v<typename T::ValueType>, "T must be a signed integral type!");
157 
158  using Base = IntegralReflectableDataBase<T, ALLOC>;
159 
160  using Base::Base;
161 
162 public:
163  int64_t toInt() const override
164  {
165  return Base::getValue();
166  }
167 };
168 
174 template <typename T, typename ALLOC>
175 class UnsignedReflectableDataBase : public IntegralReflectableDataBase<T, ALLOC>
176 {
177 protected:
178  static_assert(std::is_unsigned<typename T::ValueType>::value, "T must be an unsigned integral type!");
179 
180  using Base = IntegralReflectableDataBase<T, ALLOC>;
181 
182  using Base::Base;
183 
184 public:
185  uint64_t toUInt() const override
186  {
187  return Base::getValue();
188  }
189 };
190 
194 template <typename ALLOC>
195 class BoolReflectableData : public UnsignedReflectableDataBase<Bool, ALLOC>
196 {
197 private:
198  using Base = UnsignedReflectableDataBase<Bool, ALLOC>;
199 
200 public:
201  explicit BoolReflectableData(Bool value) :
202  Base(typeInfo<zserio::Bool, ALLOC>(), value)
203  {}
204 
205  bool getBool() const override
206  {
207  return Base::getValue();
208  }
209 };
210 
214 template <typename T, typename ALLOC>
215 class Int8ReflectableData : public SignedReflectableDataBase<T, ALLOC>
216 {
217 private:
218  using Base = SignedReflectableDataBase<T, ALLOC>;
219 
220  static_assert(std::is_same_v<int8_t, typename T::ValueType>, "T must be based on int8_t!");
221 
222 public:
223  explicit Int8ReflectableData(T value) :
224  Base(typeInfo<T, ALLOC>(), value)
225  {}
226 
227  int8_t getInt8() const override
228  {
229  return Base::getValue();
230  }
231 };
232 
236 template <typename T, typename ALLOC>
237 class Int16ReflectableData : public SignedReflectableDataBase<T, ALLOC>
238 {
239 private:
240  using Base = SignedReflectableDataBase<T, ALLOC>;
241 
242  static_assert(std::is_same_v<int16_t, typename T::ValueType>, "T must be based on int16_t!");
243 
244 public:
245  explicit Int16ReflectableData(T value) :
246  Base(typeInfo<T, ALLOC>(), value)
247  {}
248 
249  int16_t getInt16() const override
250  {
251  return Base::getValue();
252  }
253 };
254 
258 template <typename T, typename ALLOC>
259 class Int32ReflectableData : public SignedReflectableDataBase<T, ALLOC>
260 {
261 private:
262  using Base = SignedReflectableDataBase<T, ALLOC>;
263 
264  static_assert(std::is_same_v<int32_t, typename T::ValueType>, "T must be based on int32_t!");
265 
266 public:
267  explicit Int32ReflectableData(T value) :
268  Base(typeInfo<T, ALLOC>(), value)
269  {}
270 
271  int32_t getInt32() const override
272  {
273  return Base::getValue();
274  }
275 };
276 
280 template <typename T, typename ALLOC>
281 class Int64ReflectableData : public SignedReflectableDataBase<T, ALLOC>
282 {
283 private:
284  using Base = SignedReflectableDataBase<T, ALLOC>;
285 
286  static_assert(std::is_same_v<int64_t, typename T::ValueType>, "T must be based on int64_t!");
287 
288 public:
289  explicit Int64ReflectableData(T value) :
290  Base(typeInfo<T, ALLOC>(), value)
291  {}
292 
293  int64_t getInt64() const override
294  {
295  return Base::getValue();
296  }
297 };
298 
302 template <typename T, typename ALLOC>
303 class UInt8ReflectableData : public UnsignedReflectableDataBase<T, ALLOC>
304 {
305 private:
306  using Base = UnsignedReflectableDataBase<T, ALLOC>;
307 
308  static_assert(std::is_same_v<uint8_t, typename T::ValueType>, "T must be based on uint8_t!");
309 
310 public:
311  explicit UInt8ReflectableData(T value) :
312  Base(typeInfo<T, ALLOC>(), value)
313  {}
314 
315  uint8_t getUInt8() const override
316  {
317  return Base::getValue();
318  }
319 };
320 
324 template <typename T, typename ALLOC>
325 class UInt16ReflectableData : public UnsignedReflectableDataBase<T, ALLOC>
326 {
327 private:
328  using Base = UnsignedReflectableDataBase<T, ALLOC>;
329 
330  static_assert(std::is_same_v<uint16_t, typename T::ValueType>, "T must be based on uint16_t!");
331 
332 public:
333  explicit UInt16ReflectableData(T value) :
334  Base(typeInfo<T, ALLOC>(), value)
335  {}
336 
337  uint16_t getUInt16() const override
338  {
339  return Base::getValue();
340  }
341 };
342 
346 template <typename T, typename ALLOC>
347 class UInt32ReflectableData : public UnsignedReflectableDataBase<T, ALLOC>
348 {
349 private:
350  using Base = UnsignedReflectableDataBase<T, ALLOC>;
351 
352  static_assert(std::is_same_v<uint32_t, typename T::ValueType>, "T must be based on uint32_t!");
353 
354 public:
355  explicit UInt32ReflectableData(T value) :
356  Base(typeInfo<T, ALLOC>(), value)
357  {}
358 
359  uint32_t getUInt32() const override
360  {
361  return Base::getValue();
362  }
363 };
364 
368 template <typename T, typename ALLOC>
369 class UInt64ReflectableData : public UnsignedReflectableDataBase<T, ALLOC>
370 {
371 private:
372  using Base = UnsignedReflectableDataBase<T, ALLOC>;
373 
374  static_assert(std::is_same_v<uint64_t, typename T::ValueType>, "T must be based on uint64_t!");
375 
376 public:
377  explicit UInt64ReflectableData(T value) :
378  Base(typeInfo<T, ALLOC>(), value)
379  {}
380 
381  uint64_t getUInt64() const override
382  {
383  return Base::getValue();
384  }
385 };
386 
390 template <typename T, typename ALLOC>
391 class FloatingPointReflectableDataBase : public BuiltinReflectableDataBase<T, ALLOC>
392 {
393 protected:
394  static_assert(std::is_floating_point_v<typename T::ValueType>, "T must be a floating point type!");
395 
396  using Base = BuiltinReflectableDataBase<T, ALLOC>;
397  using Base::Base;
398 
399 public:
400  double toDouble() const override
401  {
402  return static_cast<double>(Base::getValue());
403  }
404 };
405 
409 template <typename T, typename ALLOC>
410 class FloatReflectableData : public FloatingPointReflectableDataBase<T, ALLOC>
411 {
412 private:
413  using Base = FloatingPointReflectableDataBase<T, ALLOC>;
414 
415 public:
416  explicit FloatReflectableData(T value) :
417  Base(typeInfo<T, ALLOC>(), value)
418  {}
419 
420  float getFloat() const override
421  {
422  return Base::getValue();
423  }
424 };
425 
429 template <typename ALLOC>
430 class DoubleReflectableData : public FloatingPointReflectableDataBase<Float64, ALLOC>
431 {
432 private:
433  using Base = FloatingPointReflectableDataBase<Float64, ALLOC>;
434 
435 public:
436  explicit DoubleReflectableData(Float64 value) :
437  Base(typeInfo<Float64, ALLOC>(), value)
438  {}
439 
440  double getDouble() const override
441  {
442  return Base::getValue();
443  }
444 };
445 
449 template <typename ALLOC>
450 class BytesReflectableData : public BuiltinReflectableDataBase<BytesView, ALLOC>
451 {
452 private:
453  using Base = BuiltinReflectableDataBase<BytesView, ALLOC>;
454 
455 public:
456  explicit BytesReflectableData(BytesView value) :
457  Base(typeInfo<BasicBytes<ALLOC>>(), value)
458  {}
459 
460  BytesView getBytes() const override
461  {
462  return Base::getValue();
463  }
464 };
465 
469 template <typename ALLOC>
470 class StringReflectableData : public BuiltinReflectableDataBase<std::string_view, ALLOC>
471 {
472 private:
473  using Base = BuiltinReflectableDataBase<std::string_view, ALLOC>;
474 
475 public:
476  explicit StringReflectableData(std::string_view value) :
477  Base(typeInfo<BasicString<RebindAlloc<ALLOC, char>>>(), value)
478  {}
479 
480  std::string_view getStringView() const override
481  {
482  return Base::getValue();
483  }
484 
485  BasicString<RebindAlloc<ALLOC, char>> toString(const ALLOC& allocator) const override
486  {
487  return zserio::toString(Base::getValue(), allocator);
488  }
489 };
490 
494 template <typename ALLOC>
495 class BitBufferReflectableData
496  : public BuiltinReflectableDataBase<std::reference_wrapper<const BasicBitBuffer<ALLOC>>, ALLOC>
497 {
498 private:
499  using Base = BuiltinReflectableDataBase<std::reference_wrapper<const BasicBitBuffer<ALLOC>>, ALLOC>;
500 
501 public:
502  explicit BitBufferReflectableData(std::reference_wrapper<const BasicBitBuffer<ALLOC>> value) :
503  Base(typeInfo<BasicBitBuffer<ALLOC>>(), value)
504  {}
505 
506  const BasicBitBuffer<ALLOC>& getBitBuffer() const override
507  {
508  return Base::getValue();
509  }
510 };
511 
515 template <typename ALLOC>
516 class ReflectableDataAllocatorHolderBase : public ReflectableDataBase<ALLOC>, public AllocatorHolder<ALLOC>
517 {
518 public:
519  ReflectableDataAllocatorHolderBase(const IBasicTypeInfo<ALLOC>& typeInfo, const ALLOC& allocator) :
520  ReflectableDataBase<ALLOC>(typeInfo),
521  AllocatorHolder<ALLOC>(allocator)
522  {}
523 };
524 
530 template <typename ALLOC>
531 class ReflectableDataConstAllocatorHolderBase : public ReflectableDataAllocatorHolderBase<ALLOC>
532 {
533 private:
534  using Base = ReflectableDataAllocatorHolderBase<ALLOC>;
535 
536 public:
537  using Base::Base;
538  using Base::getTypeInfo;
539 
540  IBasicReflectableDataPtr<ALLOC> getField(std::string_view name) override;
541  void setField(std::string_view name, const BasicAny<ALLOC>& value) override;
542 
543  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) override;
544 };
545 
551 template <typename ALLOC>
552 class ReflectableDataArrayBase : public ReflectableDataAllocatorHolderBase<ALLOC>
553 {
554 private:
555  using Base = ReflectableDataAllocatorHolderBase<ALLOC>;
556 
557 public:
558  using Base::Base;
559  using Base::getTypeInfo;
560 
561  bool isArray() const override
562  {
563  return true;
564  }
565 
566  IBasicReflectableDataConstPtr<ALLOC> getField(std::string_view name) const override;
567  IBasicReflectableDataPtr<ALLOC> getField(std::string_view name) override;
568  IBasicReflectableDataPtr<ALLOC> createField(std::string_view name) override;
569  void setField(std::string_view name, const BasicAny<ALLOC>& value) override;
570 
571  IBasicReflectableDataConstPtr<ALLOC> operator[](size_t index) const override;
572  IBasicReflectableDataPtr<ALLOC> operator[](size_t index) override;
573 
574  bool getBool() const override;
575  int8_t getInt8() const override;
576  int16_t getInt16() const override;
577  int32_t getInt32() const override;
578  int64_t getInt64() const override;
579  uint8_t getUInt8() const override;
580  uint16_t getUInt16() const override;
581  uint32_t getUInt32() const override;
582  uint64_t getUInt64() const override;
583  float getFloat() const override;
584  double getDouble() const override;
585  BytesView getBytes() const override;
586  std::string_view getStringView() const override;
587  const BasicBitBuffer<ALLOC>& getBitBuffer() const override;
588 
589  int64_t toInt() const override;
590  uint64_t toUInt() const override;
591  double toDouble() const override;
592  BasicString<RebindAlloc<ALLOC, char>> toString(const ALLOC& allocator) const override;
593 };
594 
600 template <typename ALLOC>
601 class ReflectableDataConstArrayBase : public ReflectableDataArrayBase<ALLOC>
602 {
603 private:
604  using Base = ReflectableDataArrayBase<ALLOC>;
605 
606 public:
607  using Base::Base;
608  using Base::getTypeInfo;
609 
610  void resize(size_t index) override;
611  IBasicReflectableDataPtr<ALLOC> at(size_t index) override;
612  IBasicReflectableDataPtr<ALLOC> operator[](size_t index) override;
613  void setAt(const BasicAny<ALLOC>& value, size_t index) override;
614  void append(const BasicAny<ALLOC>& value) override;
615 
616  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) override;
617 };
618 
619 } // namespace detail
620 
621 template <typename ALLOC = std::allocator<uint8_t>>
622 IBasicReflectableDataPtr<ALLOC> reflectable(Bool value, const ALLOC& allocator = ALLOC())
623 {
624  return std::allocate_shared<detail::BoolReflectableData<ALLOC>>(allocator, value);
625 }
626 
627 template <BitSize BIT_SIZE, bool IS_SIGNED, typename ALLOC = std::allocator<uint8_t>>
629  detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED> value, const ALLOC& allocator = ALLOC())
630 {
631  using Type = detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED>;
632  using ValueType = typename Type::ValueType;
633 
634  if constexpr (std::is_signed_v<ValueType>)
635  {
636  if constexpr (sizeof(ValueType) > 4)
637  {
638  return std::allocate_shared<detail::Int64ReflectableData<Type, ALLOC>>(allocator, value);
639  }
640  else if constexpr (sizeof(ValueType) > 2)
641  {
642  return std::allocate_shared<detail::Int32ReflectableData<Type, ALLOC>>(allocator, value);
643  }
644  else if constexpr (sizeof(ValueType) > 1)
645  {
646  return std::allocate_shared<detail::Int16ReflectableData<Type, ALLOC>>(allocator, value);
647  }
648  else
649  {
650  return std::allocate_shared<detail::Int8ReflectableData<Type, ALLOC>>(allocator, value);
651  }
652  }
653  else
654  {
655  if constexpr (sizeof(ValueType) > 4)
656  {
657  return std::allocate_shared<detail::UInt64ReflectableData<Type, ALLOC>>(allocator, value);
658  }
659  else if constexpr (sizeof(ValueType) > 2)
660  {
661  return std::allocate_shared<detail::UInt32ReflectableData<Type, ALLOC>>(allocator, value);
662  }
663  else if constexpr (sizeof(ValueType) > 1)
664  {
665  return std::allocate_shared<detail::UInt16ReflectableData<Type, ALLOC>>(allocator, value);
666  }
667  else
668  {
669  return std::allocate_shared<detail::UInt8ReflectableData<Type, ALLOC>>(allocator, value);
670  }
671  }
672 }
673 
674 template <typename T, typename ALLOC = std::allocator<uint8_t>>
675 IBasicReflectableDataPtr<ALLOC> reflectable(detail::DynIntWrapper<T> value, const ALLOC& allocator = ALLOC())
676 {
677  using Type = detail::DynIntWrapper<T>;
678 
679  if constexpr (std::is_signed_v<T>)
680  {
681  if constexpr (sizeof(T) > 4)
682  {
683  return std::allocate_shared<detail::Int64ReflectableData<Type, ALLOC>>(allocator, value);
684  }
685  else if constexpr (sizeof(T) > 2)
686  {
687  return std::allocate_shared<detail::Int32ReflectableData<Type, ALLOC>>(allocator, value);
688  }
689  else if constexpr (sizeof(T) > 1)
690  {
691  return std::allocate_shared<detail::Int16ReflectableData<Type, ALLOC>>(allocator, value);
692  }
693  else
694  {
695  return std::allocate_shared<detail::Int8ReflectableData<Type, ALLOC>>(allocator, value);
696  }
697  }
698  else
699  {
700  if constexpr (sizeof(T) > 4)
701  {
702  return std::allocate_shared<detail::UInt64ReflectableData<Type, ALLOC>>(allocator, value);
703  }
704  else if constexpr (sizeof(T) > 2)
705  {
706  return std::allocate_shared<detail::UInt32ReflectableData<Type, ALLOC>>(allocator, value);
707  }
708  else if constexpr (sizeof(T) > 1)
709  {
710  return std::allocate_shared<detail::UInt16ReflectableData<Type, ALLOC>>(allocator, value);
711  }
712  else
713  {
714  return std::allocate_shared<detail::UInt8ReflectableData<Type, ALLOC>>(allocator, value);
715  }
716  }
717 }
718 
719 template <typename ALLOC = std::allocator<uint8_t>>
720 IBasicReflectableDataPtr<ALLOC> reflectable(VarInt16 value, const ALLOC& allocator = ALLOC())
721 {
722  return std::allocate_shared<detail::Int16ReflectableData<VarInt16, ALLOC>>(allocator, value);
723 }
724 
725 template <typename ALLOC = std::allocator<uint8_t>>
726 IBasicReflectableDataPtr<ALLOC> reflectable(VarInt32 value, const ALLOC& allocator = ALLOC())
727 {
728  return std::allocate_shared<detail::Int32ReflectableData<VarInt32, ALLOC>>(allocator, value);
729 }
730 
731 template <typename ALLOC = std::allocator<uint8_t>>
732 IBasicReflectableDataPtr<ALLOC> reflectable(VarInt64 value, const ALLOC& allocator = ALLOC())
733 {
734  return std::allocate_shared<detail::Int64ReflectableData<VarInt64, ALLOC>>(allocator, value);
735 }
736 
737 template <typename ALLOC = std::allocator<uint8_t>>
738 IBasicReflectableDataPtr<ALLOC> reflectable(VarInt value, const ALLOC& allocator = ALLOC())
739 {
740  return std::allocate_shared<detail::Int64ReflectableData<VarInt, ALLOC>>(allocator, value);
741 }
742 
743 template <typename ALLOC = std::allocator<uint8_t>>
744 IBasicReflectableDataPtr<ALLOC> reflectable(VarUInt16 value, const ALLOC& allocator = ALLOC())
745 {
746  return std::allocate_shared<detail::UInt16ReflectableData<VarUInt16, ALLOC>>(allocator, value);
747 }
748 
749 template <typename ALLOC = std::allocator<uint8_t>>
750 IBasicReflectableDataPtr<ALLOC> reflectable(VarUInt32 value, const ALLOC& allocator = ALLOC())
751 {
752  return std::allocate_shared<detail::UInt32ReflectableData<VarUInt32, ALLOC>>(allocator, value);
753 }
754 
755 template <typename ALLOC = std::allocator<uint8_t>>
756 IBasicReflectableDataPtr<ALLOC> reflectable(VarUInt64 value, const ALLOC& allocator = ALLOC())
757 {
758  return std::allocate_shared<detail::UInt64ReflectableData<VarUInt64, ALLOC>>(allocator, value);
759 }
760 
761 template <typename ALLOC = std::allocator<uint8_t>>
762 IBasicReflectableDataPtr<ALLOC> reflectable(VarUInt value, const ALLOC& allocator = ALLOC())
763 {
764  return std::allocate_shared<detail::UInt64ReflectableData<VarUInt, ALLOC>>(allocator, value);
765 }
766 
767 template <typename ALLOC = std::allocator<uint8_t>>
768 IBasicReflectableDataPtr<ALLOC> reflectable(VarSize value, const ALLOC& allocator = ALLOC())
769 {
770  return std::allocate_shared<detail::UInt32ReflectableData<VarSize, ALLOC>>(allocator, value);
771 }
772 
773 template <typename ALLOC = std::allocator<uint8_t>>
774 IBasicReflectableDataPtr<ALLOC> reflectable(Float16 value, const ALLOC& allocator = ALLOC())
775 {
776  return std::allocate_shared<detail::FloatReflectableData<Float16, ALLOC>>(allocator, value);
777 }
778 
779 template <typename ALLOC = std::allocator<uint8_t>>
780 IBasicReflectableDataPtr<ALLOC> reflectable(Float32 value, const ALLOC& allocator = ALLOC())
781 {
782  return std::allocate_shared<detail::FloatReflectableData<Float32, ALLOC>>(allocator, value);
783 }
784 
785 template <typename ALLOC = std::allocator<uint8_t>>
786 IBasicReflectableDataPtr<ALLOC> reflectable(Float64 value, const ALLOC& allocator = ALLOC())
787 {
788  return std::allocate_shared<detail::DoubleReflectableData<ALLOC>>(allocator, value);
789 }
790 
791 template <typename ALLOC = std::allocator<uint8_t>>
792 IBasicReflectableDataPtr<ALLOC> reflectable(const BasicBytes<ALLOC>& value, const ALLOC& allocator = ALLOC())
793 {
794  return std::allocate_shared<detail::BytesReflectableData<ALLOC>>(allocator, value);
795 }
796 
797 template <typename ALLOC = std::allocator<uint8_t>>
798 IBasicReflectableDataPtr<ALLOC> reflectable(BytesView value, const ALLOC& allocator = ALLOC())
799 {
800  return std::allocate_shared<detail::BytesReflectableData<ALLOC>>(allocator, value);
801 }
802 
803 template <typename STRING_ALLOC, typename ALLOC = std::allocator<uint8_t>>
805  const BasicString<STRING_ALLOC>& value, const ALLOC& allocator = ALLOC())
806 {
807  return std::allocate_shared<detail::StringReflectableData<ALLOC>>(allocator, value);
808 }
809 
810 template <typename ALLOC = std::allocator<uint8_t>>
811 IBasicReflectableDataPtr<ALLOC> reflectable(std::string_view value, const ALLOC& allocator = ALLOC())
812 {
813  return std::allocate_shared<detail::StringReflectableData<ALLOC>>(allocator, value);
814 }
815 
816 template <typename ALLOC = std::allocator<uint8_t>>
817 IBasicReflectableDataPtr<ALLOC> reflectable(BasicBitBuffer<ALLOC>& value, const ALLOC& allocator = ALLOC())
818 {
819  return std::allocate_shared<detail::BitBufferReflectableData<ALLOC>>(allocator, value);
820 }
821 
822 template <typename ALLOC = std::allocator<uint8_t>>
824  const BasicBitBuffer<ALLOC>& value, const ALLOC& allocator = ALLOC())
825 {
826  return std::allocate_shared<detail::BitBufferReflectableData<ALLOC>>(allocator, value);
827 }
828 
829 namespace detail
830 {
831 
836 template <typename RAW_ARRAY, typename ALLOC>
837 class ReflectableDataConstArray : public ReflectableDataConstArrayBase<ALLOC>
838 {
839 private:
840  using Base = ReflectableDataConstArrayBase<ALLOC>;
841 
842 public:
843  using Base::at;
844  using Base::getTypeInfo;
845  using Base::operator[];
846  using Base::getAnyValue;
847 
848  explicit ReflectableDataConstArray(const RAW_ARRAY& rawArray, const ALLOC& allocator = {}) :
849  Base(typeInfo<typename RAW_ARRAY::value_type, ALLOC>(), allocator),
850  m_rawArray(rawArray)
851  {}
852 
853  size_t size() const override
854  {
855  return m_rawArray.size();
856  }
857 
858  IBasicReflectableDataConstPtr<ALLOC> at(size_t index) const override
859  {
860  if (index >= size())
861  {
862  throw CppRuntimeException("Index ")
863  << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
864  << "' of size " << size() << "!";
865  }
866 
867  return reflectable(m_rawArray[index], Base::get_allocator());
868  }
869 
870  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) const override
871  {
872  return BasicAny<ALLOC>(std::cref(m_rawArray), allocator);
873  }
874 
875 private:
876  const RAW_ARRAY& m_rawArray;
877 };
878 
879 template <typename RAW_ARRAY, typename ALLOC>
880 class ReflectableDataArray : public ReflectableDataArrayBase<ALLOC>
881 {
882 private:
883  using Base = ReflectableDataArrayBase<ALLOC>;
884 
885 public:
886  using Base::getAnyValue;
887  using Base::getTypeInfo;
888 
889  explicit ReflectableDataArray(RAW_ARRAY& rawArray, const ALLOC& allocator = {}) :
890  Base(typeInfo<typename RAW_ARRAY::value_type, ALLOC>(), allocator),
891  m_rawArray(rawArray)
892  {}
893 
894  size_t size() const override
895  {
896  return m_rawArray.size();
897  }
898 
899  void resize(size_t size) override
900  {
901  m_rawArray.resize(size);
902  }
903 
904  IBasicReflectableDataConstPtr<ALLOC> at(size_t index) const override
905  {
906  if (index >= size())
907  {
908  throw CppRuntimeException("Index ")
909  << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
910  << "' of size " << size() << "!";
911  }
912 
913  return reflectable(m_rawArray[index], Base::get_allocator());
914  }
915 
916  IBasicReflectableDataPtr<ALLOC> at(size_t index) override
917  {
918  if (index >= size())
919  {
920  throw CppRuntimeException("Index ")
921  << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
922  << "' of size " << size() << "!";
923  }
924 
925  return reflectable(m_rawArray[index], Base::get_allocator());
926  }
927 
928  void setAt(const BasicAny<ALLOC>& value, size_t index) override
929  {
930  if (index >= size())
931  {
932  throw CppRuntimeException("Index ")
933  << index << " out of range for reflectable array '" << getTypeInfo().getSchemaName()
934  << "' of size " << size() << "!";
935  }
936 
937  m_rawArray[index] = ReflectableUtil::fromAny<typename RAW_ARRAY::value_type>(value);
938  }
939 
940  void append(const BasicAny<ALLOC>& value) override
941  {
942  m_rawArray.push_back(ReflectableUtil::fromAny<typename RAW_ARRAY::value_type>(value));
943  }
944 
945  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) const override
946  {
947  return BasicAny<ALLOC>(std::cref(m_rawArray), allocator);
948  }
949 
950  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) override
951  {
952  return BasicAny<ALLOC>(std::ref(m_rawArray), allocator);
953  }
954 
955 private:
956  RAW_ARRAY& m_rawArray;
957 };
958 
964 template <typename T, typename ALLOC = typename T::allocator_type>
965 class ReflectableDataOwner : public IBasicReflectableData<ALLOC>
966 {
967 public:
968  ReflectableDataOwner() :
969  ReflectableDataOwner(ALLOC())
970  {}
971 
972  explicit ReflectableDataOwner(const ALLOC& allocator) :
973  m_object(allocator),
974  m_reflectable(reflectable(m_object, allocator))
975  {}
976 
977  const IBasicTypeInfo<ALLOC>& getTypeInfo() const override
978  {
979  return m_reflectable->getTypeInfo();
980  }
981 
982  bool isArray() const override
983  {
984  return m_reflectable->isArray();
985  }
986 
987  IBasicReflectableDataConstPtr<ALLOC> getField(std::string_view name) const override
988  {
989  return m_reflectable->getField(name);
990  }
991 
992  IBasicReflectableDataPtr<ALLOC> getField(std::string_view name) override
993  {
994  return m_reflectable->getField(name);
995  }
996 
997  IBasicReflectableDataPtr<ALLOC> createField(std::string_view name) override
998  {
999  return m_reflectable->createField(name);
1000  }
1001 
1002  void setField(std::string_view name, const BasicAny<ALLOC>& value) override
1003  {
1004  m_reflectable->setField(name, value);
1005  }
1006 
1007  IBasicReflectableDataConstPtr<ALLOC> find(std::string_view path) const override
1008  {
1009  return m_reflectable->find(path);
1010  }
1011 
1012  IBasicReflectableDataPtr<ALLOC> find(std::string_view path) override
1013  {
1014  return m_reflectable->find(path);
1015  }
1016 
1017  IBasicReflectableDataConstPtr<ALLOC> operator[](std::string_view path) const override
1018  {
1019  return m_reflectable->operator[](path);
1020  }
1021 
1022  IBasicReflectableDataPtr<ALLOC> operator[](std::string_view path) override
1023  {
1024  return m_reflectable->operator[](path);
1025  }
1026 
1027  std::string_view getChoice() const override
1028  {
1029  return m_reflectable->getChoice();
1030  }
1031 
1032  size_t size() const override
1033  {
1034  return m_reflectable->size();
1035  }
1036 
1037  void resize(size_t size) override
1038  {
1039  m_reflectable->resize(size);
1040  }
1041 
1042  IBasicReflectableDataConstPtr<ALLOC> at(size_t index) const override
1043  {
1044  return m_reflectable->at(index);
1045  }
1046 
1047  IBasicReflectableDataPtr<ALLOC> at(size_t index) override
1048  {
1049  return m_reflectable->at(index);
1050  }
1051 
1052  IBasicReflectableDataConstPtr<ALLOC> operator[](size_t index) const override
1053  {
1054  return m_reflectable->operator[](index);
1055  }
1056 
1057  IBasicReflectableDataPtr<ALLOC> operator[](size_t index) override
1058  {
1059  return m_reflectable->operator[](index);
1060  }
1061 
1062  void setAt(const BasicAny<ALLOC>& value, size_t index) override
1063  {
1064  m_reflectable->setAt(value, index);
1065  }
1066 
1067  void append(const BasicAny<ALLOC>& value) override
1068  {
1069  m_reflectable->append(value);
1070  }
1071 
1072  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) const override
1073  {
1074  return m_reflectable->getAnyValue(allocator);
1075  }
1076 
1077  BasicAny<ALLOC> getAnyValue(const ALLOC& allocator) override
1078  {
1079  return m_reflectable->getAnyValue(allocator);
1080  }
1081 
1082  BasicAny<ALLOC> getAnyValue() const override
1083  {
1084  return getAnyValue(ALLOC());
1085  }
1086 
1087  BasicAny<ALLOC> getAnyValue() override
1088  {
1089  return getAnyValue(ALLOC());
1090  }
1091 
1092  // exact checked getters
1093  bool getBool() const override
1094  {
1095  return m_reflectable->getBool();
1096  }
1097  int8_t getInt8() const override
1098  {
1099  return m_reflectable->getInt8();
1100  }
1101  int16_t getInt16() const override
1102  {
1103  return m_reflectable->getInt16();
1104  }
1105  int32_t getInt32() const override
1106  {
1107  return m_reflectable->getInt32();
1108  }
1109  int64_t getInt64() const override
1110  {
1111  return m_reflectable->getInt64();
1112  }
1113  uint8_t getUInt8() const override
1114  {
1115  return m_reflectable->getUInt8();
1116  }
1117  uint16_t getUInt16() const override
1118  {
1119  return m_reflectable->getUInt16();
1120  }
1121  uint32_t getUInt32() const override
1122  {
1123  return m_reflectable->getUInt32();
1124  }
1125  uint64_t getUInt64() const override
1126  {
1127  return m_reflectable->getUInt64();
1128  }
1129  float getFloat() const override
1130  {
1131  return m_reflectable->getFloat();
1132  }
1133  double getDouble() const override
1134  {
1135  return m_reflectable->getDouble();
1136  }
1137  Span<const uint8_t> getBytes() const override
1138  {
1139  return m_reflectable->getBytes();
1140  }
1141  std::string_view getStringView() const override
1142  {
1143  return m_reflectable->getStringView();
1144  }
1145  const BasicBitBuffer<ALLOC>& getBitBuffer() const override
1146  {
1147  return m_reflectable->getBitBuffer();
1148  }
1149 
1150  // convenience conversions
1151  int64_t toInt() const override
1152  {
1153  return m_reflectable->toInt();
1154  }
1155  uint64_t toUInt() const override
1156  {
1157  return m_reflectable->toUInt();
1158  }
1159  double toDouble() const override
1160  {
1161  return m_reflectable->toDouble();
1162  }
1163  BasicString<RebindAlloc<ALLOC, char>> toString(const ALLOC& allocator) const override
1164  {
1165  return m_reflectable->toString(allocator);
1166  }
1167  BasicString<RebindAlloc<ALLOC, char>> toString() const override
1168  {
1169  return toString(ALLOC());
1170  }
1171 
1172 private:
1173  T m_object;
1174  IBasicReflectableDataPtr<ALLOC> m_reflectable;
1175 };
1176 
1177 // implementation of base classes methods
1178 
1179 template <typename ALLOC>
1180 ReflectableDataBase<ALLOC>::ReflectableDataBase(const IBasicTypeInfo<ALLOC>& typeInfo) :
1181  IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>(typeInfo)
1182 {}
1183 
1184 template <typename ALLOC>
1185 ReflectableDataBase<ALLOC>::~ReflectableDataBase() = default;
1186 
1187 template <typename ALLOC>
1188 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::getField(std::string_view)
1189 {
1190  throw CppRuntimeException("Type '")
1191  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' has no fields to get!";
1192 }
1193 
1194 template <typename ALLOC>
1195 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::createField(std::string_view)
1196 {
1197  throw CppRuntimeException("Type '")
1198  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' has no fields to create!";
1199 }
1200 
1201 template <typename ALLOC>
1202 void ReflectableDataBase<ALLOC>::setField(std::string_view, const BasicAny<ALLOC>&)
1203 {
1204  throw CppRuntimeException("Type '")
1205  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' has no fields to set!";
1206 }
1207 
1208 template <typename ALLOC>
1209 void ReflectableDataBase<ALLOC>::resize(size_t)
1210 {
1211  throw CppRuntimeException("Type '")
1212  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' is not an array!";
1213 }
1214 
1215 template <typename ALLOC>
1216 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::at(size_t)
1217 {
1218  throw CppRuntimeException("Type '")
1219  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' is not an array!";
1220 }
1221 
1222 template <typename ALLOC>
1223 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::operator[](size_t)
1224 {
1225  throw CppRuntimeException("Type '")
1226  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' is not an array!";
1227 }
1228 
1229 template <typename ALLOC>
1230 void ReflectableDataBase<ALLOC>::setAt(const BasicAny<ALLOC>&, size_t)
1231 {
1232  throw CppRuntimeException("Type '")
1233  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' is not an array!";
1234 }
1235 
1236 template <typename ALLOC>
1237 void ReflectableDataBase<ALLOC>::append(const BasicAny<ALLOC>&)
1238 {
1239  throw CppRuntimeException("Type '")
1240  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' is not an array!";
1241 }
1242 
1243 template <typename ALLOC>
1244 BasicAny<ALLOC> ReflectableDataBase<ALLOC>::getAnyValue(const ALLOC&)
1245 {
1246  throw CppRuntimeException("Type '")
1247  << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() << "' is not implemented!";
1248 }
1249 
1250 template <typename ALLOC>
1251 BasicAny<ALLOC> ReflectableDataBase<ALLOC>::getAnyValue()
1252 {
1253  return getAnyValue(ALLOC());
1254 }
1255 
1256 template <typename ALLOC>
1257 typename ReflectableDataBase<ALLOC>::ConstPtr ReflectableDataBase<ALLOC>::find(std::string_view path) const
1258 {
1259  return getFromObject(*this, path, 0);
1260 }
1261 
1262 template <typename ALLOC>
1263 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::find(std::string_view path)
1264 {
1265  return getFromObject(*this, path, 0);
1266 }
1267 
1268 template <typename ALLOC>
1269 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::operator[](std::string_view path)
1270 {
1271  return find(path);
1272 }
1273 
1274 template <typename ALLOC>
1275 typename ReflectableDataBase<ALLOC>::ConstPtr ReflectableDataBase<ALLOC>::getFieldFromObject(
1276  const IBasicReflectableData<ALLOC>& object, std::string_view name) const
1277 {
1278  const auto& typeInfo = object.getTypeInfo();
1279  if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1280  {
1281  const auto& fields = typeInfo.getFields();
1282  auto fieldsIt =
1283  std::find_if(fields.begin(), fields.end(), [name](const BasicFieldInfo<ALLOC>& fieldInfo) {
1284  return fieldInfo.schemaName == name;
1285  });
1286  if (fieldsIt != fields.end())
1287  {
1288  return object.getField(name);
1289  }
1290  }
1291 
1292  return nullptr;
1293 }
1294 
1295 template <typename ALLOC>
1296 typename ReflectableDataBase<ALLOC>::ConstPtr ReflectableDataBase<ALLOC>::getFromObject(
1297  const IBasicReflectableData<ALLOC>& object, std::string_view path, size_t pos) const
1298 {
1299  try
1300  {
1301  const size_t dotPos = path.find('.', pos);
1302  const bool isLast = dotPos == std::string_view::npos;
1303  const std::string_view name =
1304  path.substr(pos, dotPos == std::string_view::npos ? std::string_view::npos : dotPos - pos);
1305 
1306  auto field = getFieldFromObject(object, name);
1307  if (field)
1308  {
1309  return isLast ? std::move(field) : getFromObject(*field, path, dotPos + 1);
1310  }
1311  }
1312  catch (const CppRuntimeException&)
1313  {}
1314 
1315  return nullptr;
1316 }
1317 
1318 template <typename ALLOC>
1319 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::getFieldFromObject(
1320  IBasicReflectableData<ALLOC>& object, std::string_view name)
1321 {
1322  const auto& typeInfo = object.getTypeInfo();
1323  if (TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
1324  {
1325  const auto& fields = typeInfo.getFields();
1326  auto fieldsIt =
1327  std::find_if(fields.begin(), fields.end(), [name](const BasicFieldInfo<ALLOC>& fieldInfo) {
1328  return fieldInfo.schemaName == name;
1329  });
1330  if (fieldsIt != fields.end())
1331  {
1332  return object.getField(name);
1333  }
1334  }
1335 
1336  return nullptr;
1337 }
1338 
1339 template <typename ALLOC>
1340 typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::getFromObject(
1341  IBasicReflectableData<ALLOC>& object, std::string_view path, size_t pos)
1342 {
1343  try
1344  {
1345  const size_t dotPos = path.find('.', pos);
1346  const bool isLast = dotPos == std::string_view::npos;
1347  const std::string_view name =
1348  path.substr(pos, dotPos == std::string_view::npos ? std::string_view::npos : dotPos - pos);
1349 
1350  auto field = getFieldFromObject(object, name);
1351  if (field)
1352  {
1353  return isLast ? std::move(field) : getFromObject(*field, path, dotPos + 1);
1354  }
1355  }
1356  catch (const CppRuntimeException&)
1357  {}
1358 
1359  return nullptr;
1360 }
1361 
1362 template <typename ALLOC>
1363 IBasicReflectableDataPtr<ALLOC> ReflectableDataConstAllocatorHolderBase<ALLOC>::getField(std::string_view)
1364 {
1365  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
1366 }
1367 
1368 template <typename ALLOC>
1369 void ReflectableDataConstAllocatorHolderBase<ALLOC>::setField(std::string_view, const BasicAny<ALLOC>&)
1370 {
1371  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
1372 }
1373 
1374 template <typename ALLOC>
1375 BasicAny<ALLOC> ReflectableDataConstAllocatorHolderBase<ALLOC>::getAnyValue(const ALLOC&)
1376 {
1377  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is constant!";
1378 }
1379 
1380 template <typename ALLOC>
1381 IBasicReflectableDataConstPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::getField(std::string_view) const
1382 {
1383  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1384 }
1385 
1386 template <typename ALLOC>
1387 IBasicReflectableDataPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::getField(std::string_view)
1388 {
1389  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1390 }
1391 
1392 template <typename ALLOC>
1393 IBasicReflectableDataPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::createField(std::string_view)
1394 {
1395  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1396 }
1397 
1398 template <typename ALLOC>
1399 void ReflectableDataArrayBase<ALLOC>::setField(std::string_view, const BasicAny<ALLOC>&)
1400 {
1401  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1402 }
1403 
1404 template <typename ALLOC>
1405 IBasicReflectableDataConstPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::operator[](size_t index) const
1406 {
1407  return this->at(index);
1408 }
1409 
1410 template <typename ALLOC>
1411 IBasicReflectableDataPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::operator[](size_t index)
1412 {
1413  return this->at(index);
1414 }
1415 
1416 template <typename ALLOC>
1417 bool ReflectableDataArrayBase<ALLOC>::getBool() const
1418 {
1419  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1420 }
1421 
1422 template <typename ALLOC>
1423 int8_t ReflectableDataArrayBase<ALLOC>::getInt8() const
1424 {
1425  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1426 }
1427 
1428 template <typename ALLOC>
1429 int16_t ReflectableDataArrayBase<ALLOC>::getInt16() const
1430 {
1431  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1432 }
1433 
1434 template <typename ALLOC>
1435 int32_t ReflectableDataArrayBase<ALLOC>::getInt32() const
1436 {
1437  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1438 }
1439 
1440 template <typename ALLOC>
1441 int64_t ReflectableDataArrayBase<ALLOC>::getInt64() const
1442 {
1443  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1444 }
1445 
1446 template <typename ALLOC>
1447 uint8_t ReflectableDataArrayBase<ALLOC>::getUInt8() const
1448 {
1449  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1450 }
1451 
1452 template <typename ALLOC>
1453 uint16_t ReflectableDataArrayBase<ALLOC>::getUInt16() const
1454 {
1455  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1456 }
1457 
1458 template <typename ALLOC>
1459 uint32_t ReflectableDataArrayBase<ALLOC>::getUInt32() const
1460 {
1461  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1462 }
1463 
1464 template <typename ALLOC>
1465 uint64_t ReflectableDataArrayBase<ALLOC>::getUInt64() const
1466 {
1467  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1468 }
1469 
1470 template <typename ALLOC>
1471 float ReflectableDataArrayBase<ALLOC>::getFloat() const
1472 {
1473  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1474 }
1475 
1476 template <typename ALLOC>
1477 double ReflectableDataArrayBase<ALLOC>::getDouble() const
1478 {
1479  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1480 }
1481 
1482 template <typename ALLOC>
1483 BytesView ReflectableDataArrayBase<ALLOC>::getBytes() const
1484 {
1485  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1486 }
1487 
1488 template <typename ALLOC>
1489 std::string_view ReflectableDataArrayBase<ALLOC>::getStringView() const
1490 {
1491  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1492 }
1493 
1494 template <typename ALLOC>
1495 const BasicBitBuffer<ALLOC>& ReflectableDataArrayBase<ALLOC>::getBitBuffer() const
1496 {
1497  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1498 }
1499 
1500 template <typename ALLOC>
1501 int64_t ReflectableDataArrayBase<ALLOC>::toInt() const
1502 {
1503  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1504 }
1505 
1506 template <typename ALLOC>
1507 uint64_t ReflectableDataArrayBase<ALLOC>::toUInt() const
1508 {
1509  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1510 }
1511 
1512 template <typename ALLOC>
1513 double ReflectableDataArrayBase<ALLOC>::toDouble() const
1514 {
1515  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1516 }
1517 
1518 template <typename ALLOC>
1519 BasicString<RebindAlloc<ALLOC, char>> ReflectableDataArrayBase<ALLOC>::toString(const ALLOC&) const
1520 {
1521  throw CppRuntimeException("Reflectable is an array '") << getTypeInfo().getSchemaName() << "[]'!";
1522 }
1523 
1524 template <typename ALLOC>
1525 void ReflectableDataConstArrayBase<ALLOC>::resize(size_t)
1526 {
1527  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
1528 }
1529 
1530 template <typename ALLOC>
1531 IBasicReflectableDataPtr<ALLOC> ReflectableDataConstArrayBase<ALLOC>::at(size_t)
1532 {
1533  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
1534 }
1535 
1536 template <typename ALLOC>
1537 IBasicReflectableDataPtr<ALLOC> ReflectableDataConstArrayBase<ALLOC>::operator[](size_t)
1538 {
1539  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
1540 }
1541 
1542 template <typename ALLOC>
1543 void ReflectableDataConstArrayBase<ALLOC>::setAt(const BasicAny<ALLOC>&, size_t)
1544 {
1545  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
1546 }
1547 
1548 template <typename ALLOC>
1549 void ReflectableDataConstArrayBase<ALLOC>::append(const BasicAny<ALLOC>&)
1550 {
1551  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
1552 }
1553 
1554 template <typename ALLOC>
1555 BasicAny<ALLOC> ReflectableDataConstArrayBase<ALLOC>::getAnyValue(const ALLOC&)
1556 {
1557  throw CppRuntimeException("Reflectable '") << getTypeInfo().getSchemaName() << "' is a constant array!";
1558 }
1559 
1560 } // namespace detail
1561 
1562 template <typename T, typename VECTOR_ALLOC, typename ALLOC = std::allocator<uint8_t>>
1564  const std::vector<T, VECTOR_ALLOC>& array, const ALLOC& allocator = ALLOC())
1565 {
1566  return std::allocate_shared<detail::ReflectableDataConstArray<std::vector<T, VECTOR_ALLOC>, ALLOC>>(
1567  allocator, array);
1568 }
1569 
1570 template <typename T, typename VECTOR_ALLOC, typename ALLOC = std::allocator<uint8_t>>
1572  std::vector<T, VECTOR_ALLOC>& array, const ALLOC& allocator = ALLOC())
1573 {
1574  return std::allocate_shared<detail::ReflectableDataArray<std::vector<T, VECTOR_ALLOC>, ALLOC>>(
1575  allocator, array);
1576 }
1577 
1578 } // namespace zserio
1579 
1580 #endif // ZSERIO_REFLECTABLE_DATA_H_INC
typename IIntrospectableData< IBasicReflectableData< ALLOC >, ALLOC >::ConstPtr ConstPtr
virtual BasicAny< ALLOC > getAnyValue(const ALLOC &allocator)=0
virtual Ptr createField(std::string_view name)=0
virtual Ptr find(std::string_view path)=0
virtual void append(const BasicAny< ALLOC > &value)=0
virtual Ptr at(size_t index)=0
virtual void setAt(const BasicAny< ALLOC > &value, size_t index)=0
virtual void resize(size_t size)=0
virtual Ptr operator[](size_t index)=0
std::shared_ptr< IBasicReflectableData > Ptr
virtual void setField(std::string_view name, const BasicAny< ALLOC > &value)=0
virtual Ptr getField(std::string_view name)=0
virtual Span< const BasicFieldInfo< ALLOC > > getFields() const =0
virtual SchemaType getSchemaType() const =0
virtual std::string_view getSchemaName() const =0
virtual const IBasicTypeInfo< std::allocator< uint8_t > > & getTypeInfo() const=0
virtual const BasicBitBuffer< std::allocator< uint8_t > > & getBitBuffer() const=0
virtual std::string_view getChoice() const =0
typename IBasicReflectableData< ALLOC >::ConstPtr IBasicReflectableDataConstPtr
Span< const uint8_t > BytesView
Definition: Bytes.h:30
detail::BoolWrapper Bool
Definition: Types.h:732
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR > VarUInt
Definition: Types.h:888
typename IBasicReflectableData< ALLOC >::Ptr IBasicReflectableDataPtr
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
Definition: String.h:17
detail::FloatWrapper< float, detail::FloatType::FLOAT16 > Float16
Definition: Types.h:892
IBasicReflectableDataConstPtr< ALLOC > reflectable(const T &value, const ALLOC &allocator=ALLOC())
std::vector< uint8_t, ALLOC > BasicBytes
Definition: Bytes.h:20
detail::FloatWrapper< float, detail::FloatType::FLOAT32 > Float32
Definition: Types.h:893
IBasicReflectableDataPtr< ALLOC > reflectableArray(std::vector< T, VECTOR_ALLOC > &array, const ALLOC &allocator=ALLOC())
detail::VarIntWrapper< int32_t, detail::VarIntType::VAR32 > VarInt32
Definition: Types.h:881
typename std::allocator_traits< ALLOC >::template rebind_alloc< T > RebindAlloc
Definition: RebindAlloc.h:10
detail::VarIntWrapper< uint16_t, detail::VarIntType::VAR16 > VarUInt16
Definition: Types.h:885
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR64 > VarUInt64
Definition: Types.h:887
const IBasicTypeInfo< ALLOC > & typeInfo()
Definition: ITypeInfo.h:668
BasicString< RebindAlloc< ALLOC, char > > toString(T value, const ALLOC &allocator=ALLOC())
detail::VarIntWrapper< int16_t, detail::VarIntType::VAR16 > VarInt16
Definition: Types.h:880
detail::FloatWrapper< double, detail::FloatType::FLOAT64 > Float64
Definition: Types.h:894
detail::VarIntWrapper< uint32_t, detail::VarIntType::VAR32 > VarUInt32
Definition: Types.h:886
detail::VarIntWrapper< int64_t, detail::VarIntType::VAR > VarInt
Definition: Types.h:883
detail::VarIntWrapper< int64_t, detail::VarIntType::VAR64 > VarInt64
Definition: Types.h:882
detail::VarIntWrapper< uint32_t, detail::VarIntType::VARSIZE > VarSize
Definition: Types.h:890