1 #ifndef ZSERIO_TYPE_INFO_INC_H
2 #define ZSERIO_TYPE_INFO_INC_H
23 template <
typename ALLOC>
93 template <
typename ALLOC = std::allocator<u
int8_t>>
315 template <
typename ALLOC>
441 template <
typename ALLOC>
476 template <
typename ALLOC>
525 template <
typename ALLOC>
550 template <
typename ALLOC>
575 template <
typename ALLOC>
610 template <
typename ALLOC>
637 template <
typename ALLOC>
661 template <
typename ALLOC>
685 template <
typename ALLOC>
714 bool m_isWithoutRowId;
720 template <
typename ALLOC>
741 template <
typename ALLOC>
762 template <
typename ALLOC>
784 template <
typename ALLOC>
797 m_typeInfoFunc(typeInfoFunc)
852 template <
typename ALLOC>
854 m_schemaName(schemaName),
855 m_schemaType(schemaType),
859 template <
typename ALLOC>
862 template <
typename ALLOC>
868 template <
typename ALLOC>
874 template <
typename ALLOC>
880 template <
typename ALLOC>
886 template <
typename ALLOC>
892 template <
typename ALLOC>
898 template <
typename ALLOC>
904 template <
typename ALLOC>
910 template <
typename ALLOC>
916 template <
typename ALLOC>
919 throw CppRuntimeException(
"Type '") << getSchemaName() <<
"' does not have underlying type!";
922 template <
typename ALLOC>
925 throw CppRuntimeException(
"Type '") << getSchemaName() <<
"' does not have underlying type!";
928 template <
typename ALLOC>
934 template <
typename ALLOC>
940 template <
typename ALLOC>
946 template <
typename ALLOC>
952 template <
typename ALLOC>
958 template <
typename ALLOC>
964 template <
typename ALLOC>
970 template <
typename ALLOC>
976 template <
typename ALLOC>
982 template <
typename ALLOC>
988 template <
typename ALLOC>
994 template <
typename ALLOC>
1000 template <
typename ALLOC>
1003 return createInstance(ALLOC());
1006 template <
typename ALLOC>
1011 template <
typename ALLOC>
1017 template <
typename ALLOC>
1023 template <
typename ALLOC>
1029 template <
typename ALLOC>
1035 template <
typename ALLOC>
1041 template <
typename ALLOC>
1047 template <
typename ALLOC>
1053 template <
typename ALLOC>
1059 template <
typename ALLOC>
1065 template <
typename ALLOC>
1069 makeStringView(
"varint16"), SchemaType::VARINT16, CppType::INT16};
1073 template <
typename ALLOC>
1077 makeStringView(
"varint32"), SchemaType::VARINT32, CppType::INT32};
1081 template <
typename ALLOC>
1085 makeStringView(
"varint64"), SchemaType::VARINT64, CppType::INT64};
1089 template <
typename ALLOC>
1097 template <
typename ALLOC>
1101 makeStringView(
"varuint16"), SchemaType::VARUINT16, CppType::UINT16};
1105 template <
typename ALLOC>
1109 makeStringView(
"varuint32"), SchemaType::VARUINT32, CppType::UINT32};
1113 template <
typename ALLOC>
1117 makeStringView(
"varuint64"), SchemaType::VARUINT64, CppType::UINT64};
1121 template <
typename ALLOC>
1125 makeStringView(
"varuint"), SchemaType::VARUINT, CppType::UINT64};
1129 template <
typename ALLOC>
1133 makeStringView(
"varsize"), SchemaType::VARSIZE, CppType::UINT32};
1137 template <
typename ALLOC>
1143 template <
typename ALLOC>
1149 template <
typename ALLOC>
1155 template <
typename ALLOC>
1162 template <
typename ALLOC>
1170 template <
typename ALLOC>
1174 makeStringView(
"extern"), SchemaType::EXTERN, CppType::BIT_BUFFER};
1178 template <
typename ALLOC>
1184 template <
typename ALLOC>
1190 template <
typename ALLOC>
1193 if (maxBitSize == 0 || maxBitSize > 64)
1195 throw CppRuntimeException(
"BuiltinTypeInfo::getDynamicSignedBitField: Invalid max bit size '")
1196 << maxBitSize <<
"'!";
1199 if (maxBitSize <= 8)
1202 "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT8};
1205 else if (maxBitSize <= 16)
1208 "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT16};
1211 else if (maxBitSize <= 32)
1214 "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT32};
1220 "int<>"_sv, SchemaType::DYNAMIC_SIGNED_BITFIELD, CppType::INT64};
1225 template <
typename ALLOC>
1228 if (maxBitSize == 0 || maxBitSize > 64)
1230 throw CppRuntimeException(
"BuiltinTypeInfo::getDynamicUnsignedBitField: Invalid max bit size '")
1231 << maxBitSize <<
"'!";
1234 if (maxBitSize <= 8)
1237 "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT8};
1240 else if (maxBitSize <= 16)
1243 "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT16};
1246 else if (maxBitSize <= 32)
1249 "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT32};
1255 "bit<>"_sv, SchemaType::DYNAMIC_UNSIGNED_BITFIELD, CppType::UINT64};
1260 template <
typename ALLOC>
1267 template <
typename ALLOC>
1273 template <
typename ALLOC>
1281 template <
typename ALLOC>
1289 template <
typename ALLOC>
1297 template <
typename ALLOC>
1305 template <
typename ALLOC>
1313 template <
typename ALLOC>
1321 template <
typename ALLOC>
1329 template <
typename ALLOC>
1337 template <
typename ALLOC>
1345 template <
typename ALLOC>
1353 template <
typename ALLOC>
1361 template <
typename ALLOC>
1369 template <
typename ALLOC>
1372 if (bitSize == 0 || bitSize > 64)
1374 throw CppRuntimeException(
"FixedSizeBuiltinTypeInfo::getFixedSignedBitField: Invalid bit size '")
1378 static const std::array<FixedSizeBuiltinTypeInfo<ALLOC>, 64> bitFieldTypeInfoArray = {
1444 return bitFieldTypeInfoArray[bitSize - 1U];
1447 template <
typename ALLOC>
1450 if (bitSize == 0 || bitSize > 64)
1452 throw CppRuntimeException(
"FixedSizeBuiltinTypeInfo::getFixedUnsignedBitField: Invalid bit size '")
1456 static const std::array<FixedSizeBuiltinTypeInfo<ALLOC>, 64> bitFieldTypeInfoArray = {
1522 return bitFieldTypeInfoArray[
static_cast<size_t>(bitSize - 1)];
1525 template <
typename ALLOC>
1530 m_templateName(templateName),
1531 m_templateArguments(templateArguments)
1534 template <
typename ALLOC>
1537 template <
typename ALLOC>
1540 return m_templateName;
1543 template <
typename ALLOC>
1546 return m_templateArguments;
1549 template <
typename ALLOC>
1556 m_createInstanceFunc(createInstanceFunc),
1558 m_parameters(parameters),
1559 m_functions(functions)
1562 template <
typename ALLOC>
1565 template <
typename ALLOC>
1571 template <
typename ALLOC>
1574 return m_parameters;
1577 template <
typename ALLOC>
1583 template <
typename ALLOC>
1586 if (!m_createInstanceFunc)
1589 << getSchemaName() <<
"': Cannot create instance, "
1590 <<
"either '-withoutWriterCode' or '-withoutReflectionCode' zserio option is used!";
1592 return m_createInstanceFunc(allocator);
1595 template <
typename ALLOC>
1601 templateName, templateArguments, fields, parameters, functions)
1604 template <
typename ALLOC>
1610 templateName, templateArguments, fields, parameters, functions)
1613 template <
typename ALLOC>
1620 templateName, templateArguments, fields, parameters, functions),
1621 m_selector(selector),
1625 template <
typename ALLOC>
1631 template <
typename ALLOC>
1637 template <
typename ALLOC>
1641 bool isWithoutRowId) :
1645 m_sqlConstraint(sqlConstraint),
1646 m_virtualTableUsing(virtualTableUsing),
1647 m_isWithoutRowId(isWithoutRowId)
1650 template <
typename ALLOC>
1656 template <
typename ALLOC>
1659 return m_sqlConstraint;
1662 template <
typename ALLOC>
1665 return m_virtualTableUsing;
1668 template <
typename ALLOC>
1671 return m_isWithoutRowId;
1674 template <
typename ALLOC>
1681 template <
typename ALLOC>
1687 template <
typename ALLOC>
1692 m_underlyingType(underlyingType),
1693 m_underlyingTypeArguments(underlyingTypeArguments)
1696 template <
typename ALLOC>
1699 return m_underlyingType;
1702 template <
typename ALLOC>
1705 return m_underlyingTypeArguments;
1708 template <
typename ALLOC>
1713 m_enumItems(enumItems)
1716 template <
typename ALLOC>
1722 template <
typename ALLOC>
1727 m_bitmaskValues(bitmaskValues)
1730 template <
typename ALLOC>
1733 return m_bitmaskValues;
1736 template <
typename ALLOC>
1739 m_messages(messages)
1742 template <
typename ALLOC>
1748 template <
typename ALLOC>
1754 template <
typename ALLOC>
1760 template <
typename ALLOC>
1763 return m_typeInfoFunc().getSchemaName();
1766 template <
typename ALLOC>
1769 return m_typeInfoFunc().getSchemaType();
1772 template <
typename ALLOC>
1775 return m_typeInfoFunc().getCppType();
1778 template <
typename ALLOC>
1781 return m_typeInfoFunc().getBitSize();
1784 template <
typename ALLOC>
1787 return m_typeInfoFunc().getFields();
1790 template <
typename ALLOC>
1793 return m_typeInfoFunc().getParameters();
1796 template <
typename ALLOC>
1799 return m_typeInfoFunc().getFunctions();
1802 template <
typename ALLOC>
1805 return m_typeInfoFunc().getSelector();
1808 template <
typename ALLOC>
1811 return m_typeInfoFunc().getCases();
1814 template <
typename ALLOC>
1820 template <
typename ALLOC>
1823 return m_typeInfoFunc().getUnderlyingTypeArguments();
1826 template <
typename ALLOC>
1829 return m_typeInfoFunc().getEnumItems();
1832 template <
typename ALLOC>
1835 return m_typeInfoFunc().getBitmaskValues();
1838 template <
typename ALLOC>
1841 return m_typeInfoFunc().getColumns();
1844 template <
typename ALLOC>
1847 return m_typeInfoFunc().getSqlConstraint();
1850 template <
typename ALLOC>
1853 return m_typeInfoFunc().getVirtualTableUsing();
1856 template <
typename ALLOC>
1859 return m_typeInfoFunc().isWithoutRowId();
1862 template <
typename ALLOC>
1865 return m_typeInfoFunc().getTables();
1868 template <
typename ALLOC>
1871 return m_typeInfoFunc().getTemplateName();
1874 template <
typename ALLOC>
1877 return m_typeInfoFunc().getTemplateArguments();
1880 template <
typename ALLOC>
1883 return m_typeInfoFunc().getMessages();
1886 template <
typename ALLOC>
1889 return m_typeInfoFunc().getMethods();
1892 template <
typename ALLOC>
1895 return m_typeInfoFunc().createInstance(allocator);
1898 template <
typename ALLOC>
1901 return createInstance(ALLOC());
Span< const ItemInfo > getBitmaskValues() const override
BitmaskTypeInfo(StringView schemaName, const IBasicTypeInfo< ALLOC > &underlyingType, Span< const StringView > underlyingTypeArguments, Span< const ItemInfo > bitmaskValues)
static const IBasicTypeInfo< ALLOC > & getDynamicUnsignedBitField(uint8_t maxBitSize)
static const IBasicTypeInfo< ALLOC > & getFloat32()
static const IBasicTypeInfo< ALLOC > & getVarUInt64()
static const IBasicTypeInfo< ALLOC > & getUInt32()
static const IBasicTypeInfo< ALLOC > & getBool()
static const IBasicTypeInfo< ALLOC > & getVarInt64()
static const IBasicTypeInfo< ALLOC > & getVarUInt()
static const IBasicTypeInfo< ALLOC > & getVarInt32()
static const IBasicTypeInfo< ALLOC > & getFixedUnsignedBitField(uint8_t bitSize)
static const IBasicTypeInfo< ALLOC > & getInt32()
static const IBasicTypeInfo< ALLOC > & getInt16()
static const IBasicTypeInfo< ALLOC > & getVarInt()
static const IBasicTypeInfo< ALLOC > & getString()
static const IBasicTypeInfo< ALLOC > & getInt8()
static const IBasicTypeInfo< ALLOC > & getVarInt16()
static const IBasicTypeInfo< ALLOC > & getUInt8()
static const IBasicTypeInfo< ALLOC > & getBitBuffer()
BuiltinTypeInfo(StringView schemaName, SchemaType schemaType, CppType cppType)
static const IBasicTypeInfo< ALLOC > & getUInt64()
static const IBasicTypeInfo< ALLOC > & getInt64()
static const IBasicTypeInfo< ALLOC > & getUInt16()
static const IBasicTypeInfo< ALLOC > & getVarSize()
static const IBasicTypeInfo< ALLOC > & getFloat16()
static const IBasicTypeInfo< ALLOC > & getVarUInt32()
static const IBasicTypeInfo< ALLOC > & getBytes()
static const IBasicTypeInfo< ALLOC > & getVarUInt16()
static const IBasicTypeInfo< ALLOC > & getDynamicSignedBitField(uint8_t maxBitSize)
static const IBasicTypeInfo< ALLOC > & getFixedSignedBitField(uint8_t bitSize)
static const IBasicTypeInfo< ALLOC > & getFloat64()
StringView getSelector() const override
Span< const BasicCaseInfo< ALLOC > > getCases() const override
ChoiceTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc, StringView templateName, Span< const BasicTemplateArgumentInfo< ALLOC >> templateArguments, Span< const BasicFieldInfo< ALLOC >> fields, Span< const BasicParameterInfo< ALLOC >> parameters, Span< const BasicFunctionInfo< ALLOC >> functions, StringView selector, Span< const BasicCaseInfo< ALLOC >> cases)
CompoundTypeInfoBase(const CompoundTypeInfoBase &)=default
Span< const BasicFunctionInfo< ALLOC > > getFunctions() const override
~CompoundTypeInfoBase() override=0
CompoundTypeInfoBase(CompoundTypeInfoBase &&)=default
IBasicReflectablePtr< ALLOC >(*)(const ALLOC &) CreateInstanceFunc
CompoundTypeInfoBase & operator=(const CompoundTypeInfoBase &)=default
CompoundTypeInfoBase(StringView schemaName, CreateInstanceFunc createInstanceFunc, SchemaType schemaType, CppType cppType, StringView templateName, Span< const BasicTemplateArgumentInfo< ALLOC >> templateArguments, Span< const BasicFieldInfo< ALLOC >> fields, Span< const BasicParameterInfo< ALLOC >> parameters, Span< const BasicFunctionInfo< ALLOC >> functions)
Span< const BasicParameterInfo< ALLOC > > getParameters() const override
Span< const BasicFieldInfo< ALLOC > > getFields() const override
CompoundTypeInfoBase & operator=(CompoundTypeInfoBase &&)=default
Span< const ItemInfo > getEnumItems() const override
EnumTypeInfo(StringView schemaName, const IBasicTypeInfo< ALLOC > &underlyingType, Span< const StringView > underlyingTypeArguments, Span< const ItemInfo > enumItems)
static const IBasicTypeInfo< ALLOC > & getFloat64()
static const IBasicTypeInfo< ALLOC > & getUInt64()
static const IBasicTypeInfo< ALLOC > & getInt32()
static const IBasicTypeInfo< ALLOC > & getFloat32()
uint8_t getBitSize() const override
static const IBasicTypeInfo< ALLOC > & getUInt16()
static const IBasicTypeInfo< ALLOC > & getFixedSignedBitField(uint8_t bitSize)
static const IBasicTypeInfo< ALLOC > & getBool()
static const IBasicTypeInfo< ALLOC > & getInt64()
static const IBasicTypeInfo< ALLOC > & getFixedUnsignedBitField(uint8_t bitSize)
static const IBasicTypeInfo< ALLOC > & getUInt8()
static const IBasicTypeInfo< ALLOC > & getFloat16()
static const IBasicTypeInfo< ALLOC > & getInt8()
static const IBasicTypeInfo< ALLOC > & getUInt32()
static const IBasicTypeInfo< ALLOC > & getInt16()
FixedSizeBuiltinTypeInfo(StringView schemaName, SchemaType schemaType, CppType cppType, uint8_t bitSize)
virtual const IBasicTypeInfo< ALLOC > & getUnderlyingType() const =0
PubsubTypeInfo(StringView schemaName, Span< const BasicMessageInfo< ALLOC >> messages)
Span< const BasicMessageInfo< ALLOC > > getMessages() const override
Span< const BasicMethodInfo< ALLOC > > getMethods() const override
StringView getTemplateName() const override
Span< const BasicMessageInfo< ALLOC > > getMessages() const override
StringView getSqlConstraint() const override
Span< const BasicTableInfo< ALLOC > > getTables() const override
RecursiveTypeInfo(const RecursiveTypeInfo &)=delete
Span< const BasicFunctionInfo< ALLOC > > getFunctions() const override
RecursiveTypeInfo(const RecursiveTypeInfo &&)=delete
bool isWithoutRowId() const override
StringView getVirtualTableUsing() const override
uint8_t getBitSize() const override
IBasicReflectablePtr< ALLOC > createInstance() const override
StringView getSchemaName() const override
~RecursiveTypeInfo() override=default
Span< const ItemInfo > getEnumItems() const override
StringView getSelector() const override
Span< const BasicColumnInfo< ALLOC > > getColumns() const override
Span< const BasicCaseInfo< ALLOC > > getCases() const override
CppType getCppType() const override
RecursiveTypeInfo & operator=(const RecursiveTypeInfo &&)=delete
SchemaType getSchemaType() const override
const IBasicTypeInfo< ALLOC > & getUnderlyingType() const override
RecursiveTypeInfo & operator=(const RecursiveTypeInfo &)=delete
Span< const BasicFieldInfo< ALLOC > > getFields() const override
RecursiveTypeInfo(TypeInfoFunc typeInfoFunc)
Span< const BasicTemplateArgumentInfo< ALLOC > > getTemplateArguments() const override
Span< const ItemInfo > getBitmaskValues() const override
Span< const StringView > getUnderlyingTypeArguments() const override
Span< const BasicParameterInfo< ALLOC > > getParameters() const override
Span< const BasicMethodInfo< ALLOC > > getMethods() const override
ServiceTypeInfo(StringView schemaName, Span< const BasicMethodInfo< ALLOC >> methods)
SqlDatabaseTypeInfo(StringView schemaName, Span< const BasicTableInfo< ALLOC >> tables)
Span< const BasicTableInfo< ALLOC > > getTables() const override
StringView getVirtualTableUsing() const override
bool isWithoutRowId() const override
SqlTableTypeInfo(StringView schemaName, StringView templateName, Span< const BasicTemplateArgumentInfo< ALLOC >> templateArguments, Span< const BasicColumnInfo< ALLOC >> columns, StringView sqlConstraint, StringView virtualTableUsing, bool isWithoutRowId)
Span< const BasicColumnInfo< ALLOC > > getColumns() const override
StringView getSqlConstraint() const override
StructTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc, StringView templateName, Span< const BasicTemplateArgumentInfo< ALLOC >> templateArguments, Span< const BasicFieldInfo< ALLOC >> fields, Span< const BasicParameterInfo< ALLOC >> parameters, Span< const BasicFunctionInfo< ALLOC >> functions)
TemplatableTypeInfoBase & operator=(TemplatableTypeInfoBase &&)=default
TemplatableTypeInfoBase(StringView schemaName, SchemaType schemaType, CppType cppType, StringView templateName, Span< const BasicTemplateArgumentInfo< ALLOC >> templateArguments)
Span< const BasicTemplateArgumentInfo< ALLOC > > getTemplateArguments() const override
TemplatableTypeInfoBase & operator=(const TemplatableTypeInfoBase &)=default
TemplatableTypeInfoBase(const TemplatableTypeInfoBase &)=default
TemplatableTypeInfoBase(TemplatableTypeInfoBase &&)=default
~TemplatableTypeInfoBase() override=0
StringView getTemplateName() const override
CppType getCppType() const override
Span< const BasicFieldInfo< ALLOC > > getFields() const override
TypeInfoBase & operator=(const TypeInfoBase &&)=delete
const IBasicTypeInfo< ALLOC > & getUnderlyingType() const override
Span< const BasicTableInfo< ALLOC > > getTables() const override
bool isWithoutRowId() const override
TypeInfoBase(const TypeInfoBase &&)=delete
Span< const BasicColumnInfo< ALLOC > > getColumns() const override
StringView getSelector() const override
IBasicReflectablePtr< ALLOC > createInstance(const ALLOC &allocator) const override
Span< const StringView > getUnderlyingTypeArguments() const override
StringView getVirtualTableUsing() const override
Span< const BasicMethodInfo< ALLOC > > getMethods() const override
Span< const ItemInfo > getBitmaskValues() const override
StringView getSqlConstraint() const override
StringView getTemplateName() const override
~TypeInfoBase() override=0
Span< const BasicTemplateArgumentInfo< ALLOC > > getTemplateArguments() const override
Span< const ItemInfo > getEnumItems() const override
Span< const BasicMessageInfo< ALLOC > > getMessages() const override
Span< const BasicCaseInfo< ALLOC > > getCases() const override
SchemaType getSchemaType() const override
TypeInfoBase(StringView schemaName, SchemaType schemaType, CppType cppType)
uint8_t getBitSize() const override
Span< const BasicParameterInfo< ALLOC > > getParameters() const override
TypeInfoBase(const TypeInfoBase &)=delete
Span< const BasicFunctionInfo< ALLOC > > getFunctions() const override
StringView getSchemaName() const override
IBasicReflectablePtr< ALLOC > createInstance() const override
TypeInfoBase & operator=(const TypeInfoBase &)=delete
Span< const StringView > getUnderlyingTypeArguments() const override
TypeInfoWithUnderlyingTypeBase(StringView schemaName, SchemaType schemaType, CppType cppType, const IBasicTypeInfo< ALLOC > &underlyingType, Span< const StringView > underlyingTypeArguments)
const IBasicTypeInfo< ALLOC > & getUnderlyingType() const override
UnionTypeInfo(StringView schemaName, CreateInstanceFunc createInstanceFunc, StringView templateName, Span< const BasicTemplateArgumentInfo< ALLOC >> templateArguments, Span< const BasicFieldInfo< ALLOC >> fields, Span< const BasicParameterInfo< ALLOC >> parameters, Span< const BasicFunctionInfo< ALLOC >> functions)
@ FIXED_UNSIGNED_BITFIELD
constexpr BasicStringView< CharT > makeStringView(const CharT(&str)[N])
typename IBasicReflectable< ALLOC >::Ptr IBasicReflectablePtr