1 #ifndef ZSERIO_INTROSPECTABLE_DATA_BASE_H_INC
2 #define ZSERIO_INTROSPECTABLE_DATA_BASE_H_INC
14 template <
typename I,
typename ALLOC>
15 class IntrospectableDataBase :
public I
19 using ConstPtr =
typename I::ConstPtr;
32 explicit IntrospectableDataBase(
const IBasicTypeInfo<ALLOC>&
typeInfo);
35 ~IntrospectableDataBase()
override =
default;
41 IntrospectableDataBase(
const IntrospectableDataBase&) =
delete;
42 IntrospectableDataBase& operator=(
const IntrospectableDataBase&) =
delete;
44 IntrospectableDataBase(
const IntrospectableDataBase&&) =
delete;
45 IntrospectableDataBase& operator=(
const IntrospectableDataBase&&) =
delete;
50 const IBasicTypeInfo<ALLOC>& getTypeInfo()
const override;
51 bool isArray()
const override;
53 ConstPtr getField(std::string_view name)
const override;
54 std::string_view getChoice()
const override;
56 size_t size()
const override;
57 ConstPtr at(
size_t index)
const override;
58 ConstPtr operator[](
size_t index)
const override;
60 BasicAny<ALLOC> getAnyValue(
const ALLOC& allocator)
const override;
61 BasicAny<ALLOC> getAnyValue()
const override;
64 bool getBool()
const override;
65 int8_t getInt8()
const override;
66 int16_t getInt16()
const override;
67 int32_t getInt32()
const override;
68 int64_t getInt64()
const override;
69 uint8_t getUInt8()
const override;
70 uint16_t getUInt16()
const override;
71 uint32_t getUInt32()
const override;
72 uint64_t getUInt64()
const override;
73 float getFloat()
const override;
74 double getDouble()
const override;
76 std::string_view getStringView()
const override;
77 const BasicBitBuffer<ALLOC>& getBitBuffer()
const override;
80 int64_t toInt()
const override;
81 uint64_t toUInt()
const override;
82 double toDouble()
const override;
83 BasicString<RebindAlloc<ALLOC, char>>
toString(
const ALLOC& allocator)
const override;
84 BasicString<RebindAlloc<ALLOC, char>>
toString()
const override;
86 ConstPtr find(std::string_view path)
const override;
87 ConstPtr operator[](std::string_view path)
const override;
90 const IBasicTypeInfo<ALLOC>& m_typeInfo;
95 template <
typename I,
typename ALLOC>
96 IntrospectableDataBase<I, ALLOC>::IntrospectableDataBase(
const IBasicTypeInfo<ALLOC>&
typeInfo) :
100 template <
typename I,
typename ALLOC>
101 const IBasicTypeInfo<ALLOC>& IntrospectableDataBase<I, ALLOC>::getTypeInfo()
const
106 template <
typename I,
typename ALLOC>
107 bool IntrospectableDataBase<I, ALLOC>::isArray()
const
112 template <
typename I,
typename ALLOC>
113 typename IntrospectableDataBase<I, ALLOC>::ConstPtr IntrospectableDataBase<I, ALLOC>::getField(
114 std::string_view)
const
116 throw CppRuntimeException(
"Type '") << m_typeInfo.getSchemaName() <<
"' has no fields to get!";
119 template <
typename I,
typename ALLOC>
120 std::string_view IntrospectableDataBase<I, ALLOC>::getChoice()
const
122 throw CppRuntimeException(
"Type '") << m_typeInfo.getSchemaName() <<
"' is neither choice nor union!";
125 template <
typename I,
typename ALLOC>
126 size_t IntrospectableDataBase<I, ALLOC>::size()
const
128 throw CppRuntimeException(
"Type '") << m_typeInfo.getSchemaName() <<
"' is not an array!";
131 template <
typename I,
typename ALLOC>
132 typename IntrospectableDataBase<I, ALLOC>::ConstPtr IntrospectableDataBase<I, ALLOC>::at(
size_t)
const
134 throw CppRuntimeException(
"Type '") << m_typeInfo.getSchemaName() <<
"' is not an array!";
137 template <
typename I,
typename ALLOC>
138 typename IntrospectableDataBase<I, ALLOC>::ConstPtr IntrospectableDataBase<I, ALLOC>::operator[](
size_t)
const
140 throw CppRuntimeException(
"Type '") << m_typeInfo.getSchemaName() <<
"' is not an array!";
143 template <
typename I,
typename ALLOC>
144 BasicAny<ALLOC> IntrospectableDataBase<I, ALLOC>::getAnyValue(
const ALLOC&)
const
146 throw CppRuntimeException(
"Type '") << m_typeInfo.getSchemaName() <<
"' is not implemented!";
149 template <
typename I,
typename ALLOC>
150 BasicAny<ALLOC> IntrospectableDataBase<I, ALLOC>::getAnyValue()
const
152 return getAnyValue(ALLOC());
155 template <
typename I,
typename ALLOC>
156 bool IntrospectableDataBase<I, ALLOC>::getBool()
const
158 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not boolean type!";
161 template <
typename I,
typename ALLOC>
162 int8_t IntrospectableDataBase<I, ALLOC>::getInt8()
const
164 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not int8 type!";
167 template <
typename I,
typename ALLOC>
168 int16_t IntrospectableDataBase<I, ALLOC>::getInt16()
const
170 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not int16 type!";
173 template <
typename I,
typename ALLOC>
174 int32_t IntrospectableDataBase<I, ALLOC>::getInt32()
const
176 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not int32 type!";
179 template <
typename I,
typename ALLOC>
180 int64_t IntrospectableDataBase<I, ALLOC>::getInt64()
const
182 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not int64 type!";
185 template <
typename I,
typename ALLOC>
186 uint8_t IntrospectableDataBase<I, ALLOC>::getUInt8()
const
188 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not uint8 type!";
191 template <
typename I,
typename ALLOC>
192 uint16_t IntrospectableDataBase<I, ALLOC>::getUInt16()
const
194 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not uint16 type!";
197 template <
typename I,
typename ALLOC>
198 uint32_t IntrospectableDataBase<I, ALLOC>::getUInt32()
const
200 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not uint32 type!";
203 template <
typename I,
typename ALLOC>
204 uint64_t IntrospectableDataBase<I, ALLOC>::getUInt64()
const
206 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not uint64 type!";
209 template <
typename I,
typename ALLOC>
210 float IntrospectableDataBase<I, ALLOC>::getFloat()
const
212 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not float type!";
215 template <
typename I,
typename ALLOC>
216 double IntrospectableDataBase<I, ALLOC>::getDouble()
const
218 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not double type!";
221 template <
typename I,
typename ALLOC>
222 BytesView IntrospectableDataBase<I, ALLOC>::getBytes()
const
224 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not bytes type!";
227 template <
typename I,
typename ALLOC>
228 std::string_view IntrospectableDataBase<I, ALLOC>::getStringView()
const
230 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not string type!";
233 template <
typename I,
typename ALLOC>
234 const BasicBitBuffer<ALLOC>& IntrospectableDataBase<I, ALLOC>::getBitBuffer()
const
236 throw CppRuntimeException(
"'") << m_typeInfo.getSchemaName() <<
"' is not an extern type!";
239 template <
typename I,
typename ALLOC>
240 int64_t IntrospectableDataBase<I, ALLOC>::toInt()
const
242 throw CppRuntimeException(
"Conversion from '")
243 << m_typeInfo.getSchemaName() <<
"' to signed integer is not available!";
246 template <
typename I,
typename ALLOC>
247 uint64_t IntrospectableDataBase<I, ALLOC>::toUInt()
const
249 throw CppRuntimeException(
"Conversion from '")
250 << m_typeInfo.getSchemaName() <<
"' to unsigned integer is not available!";
253 template <
typename I,
typename ALLOC>
254 double IntrospectableDataBase<I, ALLOC>::toDouble()
const
256 throw CppRuntimeException(
"Conversion from '")
257 << m_typeInfo.getSchemaName() <<
"' to double is not available!";
260 template <
typename I,
typename ALLOC>
263 throw CppRuntimeException(
"Conversion from '")
264 << m_typeInfo.getSchemaName() <<
"' to string is not available!";
267 template <
typename I,
typename ALLOC>
273 template <
typename I,
typename ALLOC>
274 typename IntrospectableDataBase<I, ALLOC>::ConstPtr IntrospectableDataBase<I, ALLOC>::find(
275 std::string_view)
const
277 throw CppRuntimeException(
"Find is not available for '") << m_typeInfo.getSchemaName() <<
"'!";
280 template <
typename I,
typename ALLOC>
281 typename IntrospectableDataBase<I, ALLOC>::ConstPtr IntrospectableDataBase<I, ALLOC>::operator[](
282 std::string_view path)
const
Span< const uint8_t > BytesView
const IBasicTypeInfo< ALLOC > & typeInfo()
BasicString< RebindAlloc< ALLOC, char > > toString(T value, const ALLOC &allocator=ALLOC())