1#ifndef ZSERIO_REFLECTABLE_DATA_H_INC
2#define ZSERIO_REFLECTABLE_DATA_H_INC
19template <
typename ALLOC>
20class ReflectableDataBase :
public IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>
23 using Ptr =
typename IBasicReflectableData<ALLOC>::Ptr;
24 using ConstPtr =
typename IBasicReflectableData<ALLOC>::ConstPtr;
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;
36 explicit ReflectableDataBase(
const IBasicTypeInfo<ALLOC>&
typeInfo);
39 ~ReflectableDataBase()
override = 0;
45 ReflectableDataBase(
const ReflectableDataBase&) =
delete;
46 ReflectableDataBase& operator=(
const ReflectableDataBase&) =
delete;
48 ReflectableDataBase(
const ReflectableDataBase&&) =
delete;
49 ReflectableDataBase& operator=(
const ReflectableDataBase&&) =
delete;
56 void setField(std::string_view name,
const BasicAny<ALLOC>& value)
override;
59 Ptr at(
size_t index)
override;
61 void setAt(
const BasicAny<ALLOC>& value,
size_t index)
override;
62 void append(
const BasicAny<ALLOC>& value)
override;
64 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
override;
68 Ptr find(std::string_view path)
override;
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);
83template <
typename T,
typename ALLOC>
84class BuiltinReflectableDataBase :
public ReflectableDataBase<ALLOC>
87 using Base = ReflectableDataBase<ALLOC>;
88 using ReflectableDataBase<ALLOC>::getAnyValue;
93 BuiltinReflectableDataBase(
const IBasicTypeInfo<ALLOC>&
typeInfo, T value) :
104 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
const override
106 return BasicAny<ALLOC>(m_value, allocator);
109 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
override
111 return BasicAny<ALLOC>(m_value, allocator);
123template <
typename T,
typename ALLOC>
124class IntegralReflectableDataBase :
public BuiltinReflectableDataBase<T, ALLOC>
127 static_assert(std::is_integral_v<typename T::ValueType>,
"T must be a signed integral type!");
129 using Base = BuiltinReflectableDataBase<T, ALLOC>;
132 IntegralReflectableDataBase(
const IBasicTypeInfo<ALLOC>&
typeInfo, T value) :
138 return static_cast<double>(Base::getValue());
141 BasicString<RebindAlloc<ALLOC, char>>
toString(
const ALLOC& allocator)
const override
152template <
typename T,
typename ALLOC>
153class SignedReflectableDataBase :
public IntegralReflectableDataBase<T, ALLOC>
156 static_assert(std::is_signed_v<typename T::ValueType>,
"T must be a signed integral type!");
158 using Base = IntegralReflectableDataBase<T, ALLOC>;
163 int64_t
toInt()
const override
165 return Base::getValue();
174template <
typename T,
typename ALLOC>
175class UnsignedReflectableDataBase :
public IntegralReflectableDataBase<T, ALLOC>
178 static_assert(std::is_unsigned<typename T::ValueType>::value,
"T must be an unsigned integral type!");
180 using Base = IntegralReflectableDataBase<T, ALLOC>;
185 uint64_t
toUInt()
const override
187 return Base::getValue();
194template <
typename ALLOC>
195class BoolReflectableData :
public UnsignedReflectableDataBase<Bool, ALLOC>
198 using Base = UnsignedReflectableDataBase<Bool, ALLOC>;
201 explicit BoolReflectableData(
Bool value) :
207 return Base::getValue();
214template <
typename T,
typename ALLOC>
215class Int8ReflectableData :
public SignedReflectableDataBase<T, ALLOC>
218 using Base = SignedReflectableDataBase<T, ALLOC>;
220 static_assert(std::is_same_v<int8_t, typename T::ValueType>,
"T must be based on int8_t!");
223 explicit Int8ReflectableData(T value) :
227 int8_t
getInt8()
const override
229 return Base::getValue();
236template <
typename T,
typename ALLOC>
237class Int16ReflectableData :
public SignedReflectableDataBase<T, ALLOC>
240 using Base = SignedReflectableDataBase<T, ALLOC>;
242 static_assert(std::is_same_v<int16_t, typename T::ValueType>,
"T must be based on int16_t!");
245 explicit Int16ReflectableData(T value) :
251 return Base::getValue();
258template <
typename T,
typename ALLOC>
259class Int32ReflectableData :
public SignedReflectableDataBase<T, ALLOC>
262 using Base = SignedReflectableDataBase<T, ALLOC>;
264 static_assert(std::is_same_v<int32_t, typename T::ValueType>,
"T must be based on int32_t!");
267 explicit Int32ReflectableData(T value) :
273 return Base::getValue();
280template <
typename T,
typename ALLOC>
281class Int64ReflectableData :
public SignedReflectableDataBase<T, ALLOC>
284 using Base = SignedReflectableDataBase<T, ALLOC>;
286 static_assert(std::is_same_v<int64_t, typename T::ValueType>,
"T must be based on int64_t!");
289 explicit Int64ReflectableData(T value) :
295 return Base::getValue();
302template <
typename T,
typename ALLOC>
303class UInt8ReflectableData :
public UnsignedReflectableDataBase<T, ALLOC>
306 using Base = UnsignedReflectableDataBase<T, ALLOC>;
308 static_assert(std::is_same_v<uint8_t, typename T::ValueType>,
"T must be based on uint8_t!");
311 explicit UInt8ReflectableData(T value) :
317 return Base::getValue();
324template <
typename T,
typename ALLOC>
325class UInt16ReflectableData :
public UnsignedReflectableDataBase<T, ALLOC>
328 using Base = UnsignedReflectableDataBase<T, ALLOC>;
330 static_assert(std::is_same_v<uint16_t, typename T::ValueType>,
"T must be based on uint16_t!");
333 explicit UInt16ReflectableData(T value) :
339 return Base::getValue();
346template <
typename T,
typename ALLOC>
347class UInt32ReflectableData :
public UnsignedReflectableDataBase<T, ALLOC>
350 using Base = UnsignedReflectableDataBase<T, ALLOC>;
352 static_assert(std::is_same_v<uint32_t, typename T::ValueType>,
"T must be based on uint32_t!");
355 explicit UInt32ReflectableData(T value) :
361 return Base::getValue();
368template <
typename T,
typename ALLOC>
369class UInt64ReflectableData :
public UnsignedReflectableDataBase<T, ALLOC>
372 using Base = UnsignedReflectableDataBase<T, ALLOC>;
374 static_assert(std::is_same_v<uint64_t, typename T::ValueType>,
"T must be based on uint64_t!");
377 explicit UInt64ReflectableData(T value) :
383 return Base::getValue();
390template <
typename T,
typename ALLOC>
391class FloatingPointReflectableDataBase :
public BuiltinReflectableDataBase<T, ALLOC>
394 static_assert(std::is_floating_point_v<typename T::ValueType>,
"T must be a floating point type!");
396 using Base = BuiltinReflectableDataBase<T, ALLOC>;
402 return static_cast<double>(Base::getValue());
409template <
typename T,
typename ALLOC>
410class FloatReflectableData :
public FloatingPointReflectableDataBase<T, ALLOC>
413 using Base = FloatingPointReflectableDataBase<T, ALLOC>;
416 explicit FloatReflectableData(T value) :
422 return Base::getValue();
429template <
typename ALLOC>
430class DoubleReflectableData :
public FloatingPointReflectableDataBase<Float64, ALLOC>
433 using Base = FloatingPointReflectableDataBase<Float64, ALLOC>;
436 explicit DoubleReflectableData(
Float64 value) :
442 return Base::getValue();
449template <
typename ALLOC>
450class BytesReflectableData :
public BuiltinReflectableDataBase<BytesView, ALLOC>
453 using Base = BuiltinReflectableDataBase<BytesView, ALLOC>;
456 explicit BytesReflectableData(
BytesView value) :
462 return Base::getValue();
469template <
typename ALLOC>
470class StringReflectableData :
public BuiltinReflectableDataBase<std::string_view, ALLOC>
473 using Base = BuiltinReflectableDataBase<std::string_view, ALLOC>;
476 explicit StringReflectableData(std::string_view value) :
482 return Base::getValue();
485 BasicString<RebindAlloc<ALLOC, char>>
toString(
const ALLOC& allocator)
const override
494template <
typename ALLOC>
495class BitBufferReflectableData
496 :
public BuiltinReflectableDataBase<std::reference_wrapper<const BasicBitBuffer<ALLOC>>, ALLOC>
499 using Base = BuiltinReflectableDataBase<std::reference_wrapper<const BasicBitBuffer<ALLOC>>, ALLOC>;
502 explicit BitBufferReflectableData(std::reference_wrapper<
const BasicBitBuffer<ALLOC>> value) :
503 Base(
typeInfo<BasicBitBuffer<ALLOC>>(), value)
506 const BasicBitBuffer<ALLOC>&
getBitBuffer()
const override
508 return Base::getValue();
515template <
typename ALLOC>
516class ReflectableDataAllocatorHolderBase :
public ReflectableDataBase<ALLOC>,
public AllocatorHolder<ALLOC>
519 ReflectableDataAllocatorHolderBase(
const IBasicTypeInfo<ALLOC>&
typeInfo,
const ALLOC& allocator) :
520 ReflectableDataBase<ALLOC>(
typeInfo),
530template <
typename ALLOC>
531class ReflectableDataConstAllocatorHolderBase :
public ReflectableDataAllocatorHolderBase<ALLOC>
534 using Base = ReflectableDataAllocatorHolderBase<ALLOC>;
540 IBasicReflectableDataPtr<ALLOC>
getField(std::string_view name)
override;
541 void setField(std::string_view name,
const BasicAny<ALLOC>& value)
override;
543 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
override;
551template <
typename ALLOC>
552class ReflectableDataArrayBase :
public ReflectableDataAllocatorHolderBase<ALLOC>
555 using Base = ReflectableDataAllocatorHolderBase<ALLOC>;
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;
571 IBasicReflectableDataConstPtr<ALLOC>
operator[](
size_t index)
const override;
572 IBasicReflectableDataPtr<ALLOC>
operator[](
size_t index)
override;
575 int8_t
getInt8()
const override;
587 const BasicBitBuffer<ALLOC>&
getBitBuffer()
const override;
589 int64_t
toInt()
const override;
590 uint64_t
toUInt()
const override;
592 BasicString<RebindAlloc<ALLOC, char>>
toString(
const ALLOC& allocator)
const override;
600template <
typename ALLOC>
601class ReflectableDataConstArrayBase :
public ReflectableDataArrayBase<ALLOC>
604 using Base = ReflectableDataArrayBase<ALLOC>;
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;
616 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
override;
621template <
typename ALLOC = std::allocator<u
int8_t>>
624 return std::allocate_shared<detail::BoolReflectableData<ALLOC>>(
allocator, value);
627template <BitSize BIT_SIZE,
bool IS_SIGNED,
typename ALLOC = std::allocator<u
int8_t>>
631 using Type = detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED>;
632 using ValueType =
typename Type::ValueType;
634 if constexpr (std::is_signed_v<ValueType>)
636 if constexpr (
sizeof(ValueType) > 4)
638 return std::allocate_shared<detail::Int64ReflectableData<Type, ALLOC>>(
allocator, value);
640 else if constexpr (
sizeof(ValueType) > 2)
642 return std::allocate_shared<detail::Int32ReflectableData<Type, ALLOC>>(
allocator, value);
644 else if constexpr (
sizeof(ValueType) > 1)
646 return std::allocate_shared<detail::Int16ReflectableData<Type, ALLOC>>(
allocator, value);
650 return std::allocate_shared<detail::Int8ReflectableData<Type, ALLOC>>(
allocator, value);
655 if constexpr (
sizeof(ValueType) > 4)
657 return std::allocate_shared<detail::UInt64ReflectableData<Type, ALLOC>>(
allocator, value);
659 else if constexpr (
sizeof(ValueType) > 2)
661 return std::allocate_shared<detail::UInt32ReflectableData<Type, ALLOC>>(
allocator, value);
663 else if constexpr (
sizeof(ValueType) > 1)
665 return std::allocate_shared<detail::UInt16ReflectableData<Type, ALLOC>>(
allocator, value);
669 return std::allocate_shared<detail::UInt8ReflectableData<Type, ALLOC>>(
allocator, value);
674template <
typename T,
typename ALLOC = std::allocator<u
int8_t>>
677 using Type = detail::DynIntWrapper<T>;
679 if constexpr (std::is_signed_v<T>)
681 if constexpr (
sizeof(T) > 4)
683 return std::allocate_shared<detail::Int64ReflectableData<Type, ALLOC>>(
allocator, value);
685 else if constexpr (
sizeof(T) > 2)
687 return std::allocate_shared<detail::Int32ReflectableData<Type, ALLOC>>(
allocator, value);
689 else if constexpr (
sizeof(T) > 1)
691 return std::allocate_shared<detail::Int16ReflectableData<Type, ALLOC>>(
allocator, value);
695 return std::allocate_shared<detail::Int8ReflectableData<Type, ALLOC>>(
allocator, value);
700 if constexpr (
sizeof(T) > 4)
702 return std::allocate_shared<detail::UInt64ReflectableData<Type, ALLOC>>(
allocator, value);
704 else if constexpr (
sizeof(T) > 2)
706 return std::allocate_shared<detail::UInt32ReflectableData<Type, ALLOC>>(
allocator, value);
708 else if constexpr (
sizeof(T) > 1)
710 return std::allocate_shared<detail::UInt16ReflectableData<Type, ALLOC>>(
allocator, value);
714 return std::allocate_shared<detail::UInt8ReflectableData<Type, ALLOC>>(
allocator, value);
719template <
typename ALLOC = std::allocator<u
int8_t>>
722 return std::allocate_shared<detail::Int16ReflectableData<VarInt16, ALLOC>>(
allocator, value);
725template <
typename ALLOC = std::allocator<u
int8_t>>
726IBasicReflectableDataPtr<ALLOC>
reflectable(
VarInt32 value,
const ALLOC& allocator = ALLOC())
728 return std::allocate_shared<detail::Int32ReflectableData<VarInt32, ALLOC>>(allocator, value);
731template <
typename ALLOC = std::allocator<u
int8_t>>
732IBasicReflectableDataPtr<ALLOC>
reflectable(
VarInt64 value,
const ALLOC& allocator = ALLOC())
734 return std::allocate_shared<detail::Int64ReflectableData<VarInt64, ALLOC>>(allocator, value);
737template <
typename ALLOC = std::allocator<u
int8_t>>
738IBasicReflectableDataPtr<ALLOC>
reflectable(
VarInt value,
const ALLOC& allocator = ALLOC())
740 return std::allocate_shared<detail::Int64ReflectableData<VarInt, ALLOC>>(allocator, value);
743template <
typename ALLOC = std::allocator<u
int8_t>>
746 return std::allocate_shared<detail::UInt16ReflectableData<VarUInt16, ALLOC>>(allocator, value);
749template <
typename ALLOC = std::allocator<u
int8_t>>
752 return std::allocate_shared<detail::UInt32ReflectableData<VarUInt32, ALLOC>>(allocator, value);
755template <
typename ALLOC = std::allocator<u
int8_t>>
758 return std::allocate_shared<detail::UInt64ReflectableData<VarUInt64, ALLOC>>(allocator, value);
761template <
typename ALLOC = std::allocator<u
int8_t>>
762IBasicReflectableDataPtr<ALLOC>
reflectable(
VarUInt value,
const ALLOC& allocator = ALLOC())
764 return std::allocate_shared<detail::UInt64ReflectableData<VarUInt, ALLOC>>(allocator, value);
767template <
typename ALLOC = std::allocator<u
int8_t>>
768IBasicReflectableDataPtr<ALLOC>
reflectable(
VarSize value,
const ALLOC& allocator = ALLOC())
770 return std::allocate_shared<detail::UInt32ReflectableData<VarSize, ALLOC>>(allocator, value);
773template <
typename ALLOC = std::allocator<u
int8_t>>
776 return std::allocate_shared<detail::FloatReflectableData<Float16, ALLOC>>(
allocator, value);
779template <
typename ALLOC = std::allocator<u
int8_t>>
780IBasicReflectableDataPtr<ALLOC>
reflectable(
Float32 value,
const ALLOC& allocator = ALLOC())
782 return std::allocate_shared<detail::FloatReflectableData<Float32, ALLOC>>(allocator, value);
785template <
typename ALLOC = std::allocator<u
int8_t>>
786IBasicReflectableDataPtr<ALLOC>
reflectable(
Float64 value,
const ALLOC& allocator = ALLOC())
788 return std::allocate_shared<detail::DoubleReflectableData<ALLOC>>(allocator, value);
791template <
typename ALLOC = std::allocator<u
int8_t>>
794 return std::allocate_shared<detail::BytesReflectableData<ALLOC>>(
allocator, value);
797template <
typename ALLOC = std::allocator<u
int8_t>>
800 return std::allocate_shared<detail::BytesReflectableData<ALLOC>>(
allocator, value);
803template <
typename STRING_ALLOC,
typename ALLOC = std::allocator<u
int8_t>>
807 return std::allocate_shared<detail::StringReflectableData<ALLOC>>(
allocator, value);
810template <
typename ALLOC = std::allocator<u
int8_t>>
813 return std::allocate_shared<detail::StringReflectableData<ALLOC>>(
allocator, value);
816template <
typename ALLOC = std::allocator<u
int8_t>>
819 return std::allocate_shared<detail::BitBufferReflectableData<ALLOC>>(
allocator, value);
822template <
typename ALLOC = std::allocator<u
int8_t>>
826 return std::allocate_shared<detail::BitBufferReflectableData<ALLOC>>(
allocator, value);
836template <
typename RAW_ARRAY,
typename ALLOC>
837class ReflectableDataConstArray :
public ReflectableDataConstArrayBase<ALLOC>
840 using Base = ReflectableDataConstArrayBase<ALLOC>;
845 using Base::operator[];
846 using Base::getAnyValue;
848 explicit ReflectableDataConstArray(
const RAW_ARRAY& rawArray,
const ALLOC& allocator = {}) :
849 Base(
typeInfo<typename RAW_ARRAY::value_type, ALLOC>(), allocator),
853 size_t size()
const override
855 return m_rawArray.size();
858 IBasicReflectableDataConstPtr<ALLOC>
at(
size_t index)
const override
862 throw CppRuntimeException(
"Index ")
863 << index <<
" out of range for reflectable array '" <<
getTypeInfo().getSchemaName()
864 <<
"' of size " <<
size() <<
"!";
870 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
const override
872 return BasicAny<ALLOC>(std::cref(m_rawArray), allocator);
876 const RAW_ARRAY& m_rawArray;
879template <
typename RAW_ARRAY,
typename ALLOC>
880class ReflectableDataArray :
public ReflectableDataArrayBase<ALLOC>
883 using Base = ReflectableDataArrayBase<ALLOC>;
886 using Base::getAnyValue;
889 explicit ReflectableDataArray(RAW_ARRAY& rawArray,
const ALLOC& allocator = {}) :
890 Base(
typeInfo<typename RAW_ARRAY::value_type, ALLOC>(), allocator),
894 size_t size()
const override
896 return m_rawArray.size();
899 void resize(
size_t size)
override
901 m_rawArray.resize(size);
904 IBasicReflectableDataConstPtr<ALLOC>
at(
size_t index)
const override
908 throw CppRuntimeException(
"Index ")
909 << index <<
" out of range for reflectable array '" <<
getTypeInfo().getSchemaName()
910 <<
"' of size " << size() <<
"!";
916 IBasicReflectableDataPtr<ALLOC>
at(
size_t index)
override
920 throw CppRuntimeException(
"Index ")
921 << index <<
" out of range for reflectable array '" <<
getTypeInfo().getSchemaName()
922 <<
"' of size " << size() <<
"!";
928 void setAt(
const BasicAny<ALLOC>& value,
size_t index)
override
932 throw CppRuntimeException(
"Index ")
933 << index <<
" out of range for reflectable array '" <<
getTypeInfo().getSchemaName()
934 <<
"' of size " << size() <<
"!";
937 m_rawArray[index] = ReflectableUtil::fromAny<typename RAW_ARRAY::value_type>(value);
940 void append(
const BasicAny<ALLOC>& value)
override
942 m_rawArray.push_back(ReflectableUtil::fromAny<typename RAW_ARRAY::value_type>(value));
945 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
const override
947 return BasicAny<ALLOC>(std::cref(m_rawArray), allocator);
950 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
override
952 return BasicAny<ALLOC>(std::ref(m_rawArray), allocator);
956 RAW_ARRAY& m_rawArray;
964template <
typename T,
typename ALLOC =
typename T::allocator_type>
965class ReflectableDataOwner :
public IBasicReflectableData<ALLOC>
968 ReflectableDataOwner() :
969 ReflectableDataOwner(ALLOC())
972 explicit ReflectableDataOwner(
const ALLOC& allocator) :
977 const IBasicTypeInfo<ALLOC>&
getTypeInfo()
const override
979 return m_reflectable->getTypeInfo();
984 return m_reflectable->isArray();
987 IBasicReflectableDataConstPtr<ALLOC>
getField(std::string_view name)
const override
989 return m_reflectable->getField(name);
992 IBasicReflectableDataPtr<ALLOC>
getField(std::string_view name)
override
994 return m_reflectable->getField(name);
997 IBasicReflectableDataPtr<ALLOC>
createField(std::string_view name)
override
999 return m_reflectable->createField(name);
1002 void setField(std::string_view name,
const BasicAny<ALLOC>& value)
override
1004 m_reflectable->setField(name, value);
1007 IBasicReflectableDataConstPtr<ALLOC>
find(std::string_view path)
const override
1009 return m_reflectable->find(path);
1012 IBasicReflectableDataPtr<ALLOC>
find(std::string_view path)
override
1014 return m_reflectable->find(path);
1017 IBasicReflectableDataConstPtr<ALLOC>
operator[](std::string_view path)
const override
1019 return m_reflectable->operator[](path);
1022 IBasicReflectableDataPtr<ALLOC>
operator[](std::string_view path)
override
1024 return m_reflectable->operator[](path);
1027 std::string_view
getChoice()
const override
1029 return m_reflectable->getChoice();
1032 size_t size()
const override
1034 return m_reflectable->size();
1037 void resize(
size_t size)
override
1039 m_reflectable->resize(size);
1042 IBasicReflectableDataConstPtr<ALLOC>
at(
size_t index)
const override
1044 return m_reflectable->at(index);
1047 IBasicReflectableDataPtr<ALLOC>
at(
size_t index)
override
1049 return m_reflectable->at(index);
1052 IBasicReflectableDataConstPtr<ALLOC>
operator[](
size_t index)
const override
1054 return m_reflectable->operator[](index);
1057 IBasicReflectableDataPtr<ALLOC>
operator[](
size_t index)
override
1059 return m_reflectable->operator[](index);
1062 void setAt(
const BasicAny<ALLOC>& value,
size_t index)
override
1064 m_reflectable->setAt(value, index);
1067 void append(
const BasicAny<ALLOC>& value)
override
1069 m_reflectable->append(value);
1072 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
const override
1074 return m_reflectable->getAnyValue(allocator);
1077 BasicAny<ALLOC>
getAnyValue(
const ALLOC& allocator)
override
1079 return m_reflectable->getAnyValue(allocator);
1095 return m_reflectable->getBool();
1097 int8_t
getInt8()
const override
1099 return m_reflectable->getInt8();
1103 return m_reflectable->getInt16();
1107 return m_reflectable->getInt32();
1111 return m_reflectable->getInt64();
1115 return m_reflectable->getUInt8();
1119 return m_reflectable->getUInt16();
1123 return m_reflectable->getUInt32();
1127 return m_reflectable->getUInt64();
1131 return m_reflectable->getFloat();
1135 return m_reflectable->getDouble();
1137 Span<const uint8_t>
getBytes()
const override
1139 return m_reflectable->getBytes();
1143 return m_reflectable->getStringView();
1145 const BasicBitBuffer<ALLOC>&
getBitBuffer()
const override
1147 return m_reflectable->getBitBuffer();
1151 int64_t
toInt()
const override
1153 return m_reflectable->toInt();
1155 uint64_t
toUInt()
const override
1157 return m_reflectable->toUInt();
1161 return m_reflectable->toDouble();
1163 BasicString<RebindAlloc<ALLOC, char>>
toString(
const ALLOC& allocator)
const override
1165 return m_reflectable->toString(allocator);
1167 BasicString<RebindAlloc<ALLOC, char>>
toString()
const override
1174 IBasicReflectableDataPtr<ALLOC> m_reflectable;
1179template <
typename ALLOC>
1180ReflectableDataBase<ALLOC>::ReflectableDataBase(
const IBasicTypeInfo<ALLOC>&
typeInfo) :
1181 IntrospectableDataBase<IBasicReflectableData<ALLOC>, ALLOC>(
typeInfo)
1184template <
typename ALLOC>
1185ReflectableDataBase<ALLOC>::~ReflectableDataBase() =
default;
1187template <
typename ALLOC>
1188typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::getField(std::string_view)
1190 throw CppRuntimeException(
"Type '")
1191 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' has no fields to get!";
1194template <
typename ALLOC>
1195typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::createField(std::string_view)
1197 throw CppRuntimeException(
"Type '")
1198 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' has no fields to create!";
1201template <
typename ALLOC>
1202void ReflectableDataBase<ALLOC>::setField(std::string_view,
const BasicAny<ALLOC>&)
1204 throw CppRuntimeException(
"Type '")
1205 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' has no fields to set!";
1208template <
typename ALLOC>
1209void ReflectableDataBase<ALLOC>::resize(
size_t)
1211 throw CppRuntimeException(
"Type '")
1212 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' is not an array!";
1215template <
typename ALLOC>
1216typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::at(
size_t)
1218 throw CppRuntimeException(
"Type '")
1219 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' is not an array!";
1222template <
typename ALLOC>
1223typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::operator[](
size_t)
1225 throw CppRuntimeException(
"Type '")
1226 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' is not an array!";
1229template <
typename ALLOC>
1230void ReflectableDataBase<ALLOC>::setAt(
const BasicAny<ALLOC>&,
size_t)
1232 throw CppRuntimeException(
"Type '")
1233 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' is not an array!";
1236template <
typename ALLOC>
1237void ReflectableDataBase<ALLOC>::append(
const BasicAny<ALLOC>&)
1239 throw CppRuntimeException(
"Type '")
1240 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' is not an array!";
1243template <
typename ALLOC>
1244BasicAny<ALLOC> ReflectableDataBase<ALLOC>::getAnyValue(
const ALLOC&)
1246 throw CppRuntimeException(
"Type '")
1247 << ReflectableDataBase<ALLOC>::getTypeInfo().getSchemaName() <<
"' is not implemented!";
1250template <
typename ALLOC>
1251BasicAny<ALLOC> ReflectableDataBase<ALLOC>::getAnyValue()
1253 return getAnyValue(ALLOC());
1256template <
typename ALLOC>
1257typename ReflectableDataBase<ALLOC>::ConstPtr ReflectableDataBase<ALLOC>::find(std::string_view path)
const
1259 return getFromObject(*
this, path, 0);
1262template <
typename ALLOC>
1263typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::find(std::string_view path)
1265 return getFromObject(*
this, path, 0);
1268template <
typename ALLOC>
1269typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::operator[](std::string_view path)
1274template <
typename ALLOC>
1275typename ReflectableDataBase<ALLOC>::ConstPtr ReflectableDataBase<ALLOC>::getFieldFromObject(
1276 const IBasicReflectableData<ALLOC>&
object, std::string_view name)
const
1278 const auto&
typeInfo =
object.getTypeInfo();
1279 if (TypeInfoUtil::isCompound(
typeInfo.getSchemaType()))
1281 const auto& fields =
typeInfo.getFields();
1283 std::find_if(fields.begin(), fields.end(), [name](
const BasicFieldInfo<ALLOC>& fieldInfo) {
1284 return fieldInfo.schemaName == name;
1286 if (fieldsIt != fields.end())
1288 return object.getField(name);
1295template <
typename ALLOC>
1296typename ReflectableDataBase<ALLOC>::ConstPtr ReflectableDataBase<ALLOC>::getFromObject(
1297 const IBasicReflectableData<ALLOC>&
object, std::string_view path,
size_t pos)
const
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);
1306 auto field = getFieldFromObject(
object, name);
1309 return isLast ? std::move(field) : getFromObject(*field, path, dotPos + 1);
1312 catch (
const CppRuntimeException&)
1318template <
typename ALLOC>
1319typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::getFieldFromObject(
1320 IBasicReflectableData<ALLOC>&
object, std::string_view name)
1322 const auto&
typeInfo =
object.getTypeInfo();
1323 if (TypeInfoUtil::isCompound(
typeInfo.getSchemaType()))
1325 const auto& fields =
typeInfo.getFields();
1327 std::find_if(fields.begin(), fields.end(), [name](
const BasicFieldInfo<ALLOC>& fieldInfo) {
1328 return fieldInfo.schemaName == name;
1330 if (fieldsIt != fields.end())
1332 return object.getField(name);
1339template <
typename ALLOC>
1340typename ReflectableDataBase<ALLOC>::Ptr ReflectableDataBase<ALLOC>::getFromObject(
1341 IBasicReflectableData<ALLOC>&
object, std::string_view path,
size_t pos)
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);
1350 auto field = getFieldFromObject(
object, name);
1353 return isLast ? std::move(field) : getFromObject(*field, path, dotPos + 1);
1356 catch (
const CppRuntimeException&)
1362template <
typename ALLOC>
1363IBasicReflectableDataPtr<ALLOC> ReflectableDataConstAllocatorHolderBase<ALLOC>::getField(std::string_view)
1365 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is constant!";
1368template <
typename ALLOC>
1369void ReflectableDataConstAllocatorHolderBase<ALLOC>::setField(std::string_view,
const BasicAny<ALLOC>&)
1371 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is constant!";
1374template <
typename ALLOC>
1375BasicAny<ALLOC> ReflectableDataConstAllocatorHolderBase<ALLOC>::getAnyValue(
const ALLOC&)
1377 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is constant!";
1380template <
typename ALLOC>
1381IBasicReflectableDataConstPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::getField(std::string_view)
const
1383 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1386template <
typename ALLOC>
1387IBasicReflectableDataPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::getField(std::string_view)
1389 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1392template <
typename ALLOC>
1393IBasicReflectableDataPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::createField(std::string_view)
1395 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1398template <
typename ALLOC>
1399void ReflectableDataArrayBase<ALLOC>::setField(std::string_view,
const BasicAny<ALLOC>&)
1401 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1404template <
typename ALLOC>
1405IBasicReflectableDataConstPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::operator[](
size_t index)
const
1407 return this->at(index);
1410template <
typename ALLOC>
1411IBasicReflectableDataPtr<ALLOC> ReflectableDataArrayBase<ALLOC>::operator[](
size_t index)
1413 return this->at(index);
1416template <
typename ALLOC>
1417bool ReflectableDataArrayBase<ALLOC>::getBool()
const
1419 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1422template <
typename ALLOC>
1423int8_t ReflectableDataArrayBase<ALLOC>::getInt8()
const
1425 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1428template <
typename ALLOC>
1429int16_t ReflectableDataArrayBase<ALLOC>::getInt16()
const
1431 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1434template <
typename ALLOC>
1435int32_t ReflectableDataArrayBase<ALLOC>::getInt32()
const
1437 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1440template <
typename ALLOC>
1441int64_t ReflectableDataArrayBase<ALLOC>::getInt64()
const
1443 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1446template <
typename ALLOC>
1447uint8_t ReflectableDataArrayBase<ALLOC>::getUInt8()
const
1449 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1452template <
typename ALLOC>
1453uint16_t ReflectableDataArrayBase<ALLOC>::getUInt16()
const
1455 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1458template <
typename ALLOC>
1459uint32_t ReflectableDataArrayBase<ALLOC>::getUInt32()
const
1461 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1464template <
typename ALLOC>
1465uint64_t ReflectableDataArrayBase<ALLOC>::getUInt64()
const
1467 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1470template <
typename ALLOC>
1471float ReflectableDataArrayBase<ALLOC>::getFloat()
const
1473 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1476template <
typename ALLOC>
1477double ReflectableDataArrayBase<ALLOC>::getDouble()
const
1479 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1482template <
typename ALLOC>
1483BytesView ReflectableDataArrayBase<ALLOC>::getBytes()
const
1485 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1488template <
typename ALLOC>
1489std::string_view ReflectableDataArrayBase<ALLOC>::getStringView()
const
1491 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1494template <
typename ALLOC>
1495const BasicBitBuffer<ALLOC>& ReflectableDataArrayBase<ALLOC>::getBitBuffer()
const
1497 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1500template <
typename ALLOC>
1501int64_t ReflectableDataArrayBase<ALLOC>::toInt()
const
1503 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1506template <
typename ALLOC>
1507uint64_t ReflectableDataArrayBase<ALLOC>::toUInt()
const
1509 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1512template <
typename ALLOC>
1513double ReflectableDataArrayBase<ALLOC>::toDouble()
const
1515 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1518template <
typename ALLOC>
1519BasicString<RebindAlloc<ALLOC, char>> ReflectableDataArrayBase<ALLOC>::toString(
const ALLOC&)
const
1521 throw CppRuntimeException(
"Reflectable is an array '") << getTypeInfo().getSchemaName() <<
"[]'!";
1524template <
typename ALLOC>
1525void ReflectableDataConstArrayBase<ALLOC>::resize(
size_t)
1527 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is a constant array!";
1530template <
typename ALLOC>
1531IBasicReflectableDataPtr<ALLOC> ReflectableDataConstArrayBase<ALLOC>::at(
size_t)
1533 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is a constant array!";
1536template <
typename ALLOC>
1537IBasicReflectableDataPtr<ALLOC> ReflectableDataConstArrayBase<ALLOC>::operator[](
size_t)
1539 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is a constant array!";
1542template <
typename ALLOC>
1543void ReflectableDataConstArrayBase<ALLOC>::setAt(
const BasicAny<ALLOC>&,
size_t)
1545 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is a constant array!";
1548template <
typename ALLOC>
1549void ReflectableDataConstArrayBase<ALLOC>::append(
const BasicAny<ALLOC>&)
1551 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is a constant array!";
1554template <
typename ALLOC>
1555BasicAny<ALLOC> ReflectableDataConstArrayBase<ALLOC>::getAnyValue(
const ALLOC&)
1557 throw CppRuntimeException(
"Reflectable '") << getTypeInfo().getSchemaName() <<
"' is a constant array!";
1562template <
typename T,
typename VECTOR_ALLOC,
typename ALLOC = std::allocator<u
int8_t>>
1566 return std::allocate_shared<detail::ReflectableDataConstArray<std::vector<T, VECTOR_ALLOC>,
ALLOC>>(
1570template <
typename T,
typename VECTOR_ALLOC,
typename ALLOC = std::allocator<u
int8_t>>
1574 return std::allocate_shared<detail::ReflectableDataArray<std::vector<T, VECTOR_ALLOC>,
ALLOC>>(
allocator_type get_allocator() const
typename IIntrospectableData< IBasicReflectableData< ALLOC >, ALLOC >::ConstPtr ConstPtr
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 BasicAny< ALLOC > getAnyValue(const ALLOC &allocator)=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 BasicString< RebindAlloc< ALLOC, char > > toString() const=0
virtual std::string_view getStringView() const=0
virtual int32_t getInt32() const=0
virtual uint8_t getUInt8() const=0
virtual float getFloat() const=0
virtual int8_t getInt8() const=0
virtual const BasicBitBuffer< ALLOC > & getBitBuffer() const=0
virtual bool isArray() const=0
virtual double getDouble() const=0
virtual size_t size() const=0
virtual BytesView getBytes() const=0
virtual int64_t toInt() const=0
virtual uint64_t toUInt() const=0
virtual uint32_t getUInt32() const=0
virtual int64_t getInt64() const=0
virtual uint64_t getUInt64() const=0
virtual int16_t getInt16() const=0
virtual uint16_t getUInt16() const=0
virtual bool getBool() const=0
virtual const IBasicTypeInfo< ALLOC > & getTypeInfo() const=0
virtual BasicString< RebindAlloc< ALLOC, char > > toString(const ALLOC &allocator) const =0
virtual std::string_view getChoice() const =0
virtual double toDouble() const=0
Span< const uint8_t > BytesView
const IBasicTypeInfo< ALLOC > & typeInfo()
IBasicReflectableDataConstPtr< ALLOC > reflectableArray(const std::vector< T, VECTOR_ALLOC > &array, const ALLOC &allocator=ALLOC())
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR > VarUInt
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
detail::FloatWrapper< float, detail::FloatType::FLOAT16 > Float16
std::vector< uint8_t, ALLOC > BasicBytes
detail::FloatWrapper< float, detail::FloatType::FLOAT32 > Float32
detail::VarIntWrapper< int32_t, detail::VarIntType::VAR32 > VarInt32
typename std::allocator_traits< ALLOC >::template rebind_alloc< T > RebindAlloc
detail::VarIntWrapper< uint16_t, detail::VarIntType::VAR16 > VarUInt16
detail::VarIntWrapper< uint64_t, detail::VarIntType::VAR64 > VarUInt64
BasicString< RebindAlloc< ALLOC, char > > toString(T value, const ALLOC &allocator=ALLOC())
detail::VarIntWrapper< int16_t, detail::VarIntType::VAR16 > VarInt16
IBasicReflectableDataConstPtr< ALLOC > reflectable(const T &value, const ALLOC &allocator=ALLOC())
detail::FloatWrapper< double, detail::FloatType::FLOAT64 > Float64
detail::VarIntWrapper< uint32_t, detail::VarIntType::VAR32 > VarUInt32
detail::VarIntWrapper< int64_t, detail::VarIntType::VAR > VarInt
detail::VarIntWrapper< int64_t, detail::VarIntType::VAR64 > VarInt64
detail::VarIntWrapper< uint32_t, detail::VarIntType::VARSIZE > VarSize