#pragma once #include #include #include namespace DB { /// Data types for representing elementary values from a database in RAM. struct Null {}; using UInt8 = uint8_t; using UInt16 = uint16_t; using UInt32 = uint32_t; using UInt64 = uint64_t; using Int8 = int8_t; using Int16 = int16_t; using Int32 = int32_t; using Int64 = int64_t; using Float32 = float; using Float64 = double; using String = std::string; /** Note that for types not used in DB, IsNumber is false. */ template constexpr bool IsNumber = false; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template <> constexpr bool IsNumber = true; template struct TypeName; template <> struct TypeName { static const char * get() { return "UInt8"; } }; template <> struct TypeName { static const char * get() { return "UInt16"; } }; template <> struct TypeName { static const char * get() { return "UInt32"; } }; template <> struct TypeName { static const char * get() { return "UInt64"; } }; template <> struct TypeName { static const char * get() { return "Int8"; } }; template <> struct TypeName { static const char * get() { return "Int16"; } }; template <> struct TypeName { static const char * get() { return "Int32"; } }; template <> struct TypeName { static const char * get() { return "Int64"; } }; template <> struct TypeName { static const char * get() { return "Float32"; } }; template <> struct TypeName { static const char * get() { return "Float64"; } }; template <> struct TypeName { static const char * get() { return "String"; } }; template struct TypeNumber; /// 0 reserved for types without number template <> struct TypeNumber { static constexpr const size_t value = 1; }; template <> struct TypeNumber { static constexpr const size_t value = 2; }; template <> struct TypeNumber { static constexpr const size_t value = 3; }; template <> struct TypeNumber { static constexpr const size_t value = 4; }; /// 5 reserved for TypeNumber template <> struct TypeNumber { static constexpr const size_t value = 7; }; template <> struct TypeNumber { static constexpr const size_t value = 8; }; template <> struct TypeNumber { static constexpr const size_t value = 9; }; template <> struct TypeNumber { static constexpr const size_t value = 10; }; template <> struct TypeNumber { static constexpr const size_t value = 11; }; template <> struct TypeNumber { static constexpr const size_t value = 12; }; /// 13 reserved for TypeNumber /// Not a data type in database, defined just for convenience. using Strings = std::vector; } #if 1 /// __int128 namespace DB { using Int128 = __int128; template <> constexpr bool IsNumber = true; template <> struct TypeName { static const char * get() { return "Int128"; } }; template <> struct TypeNumber { static constexpr const size_t value = 13; }; } namespace std { template <> struct is_signed<__int128> { static constexpr bool value = true; }; template <> struct is_unsigned<__int128> { static constexpr bool value = false; }; template <> struct is_integral<__int128> { static constexpr bool value = true; }; template <> struct is_arithmetic<__int128> { static constexpr bool value = true; }; } #endif namespace DB { /// Own FieldType for Decimal template class Dec { public: using NativeType = T; Dec() = default; Dec(Dec &&) = default; Dec(const Dec &) = default; Dec(const T & value_) : value(value_) {} template Dec(const Dec & x) : value(x) {} constexpr Dec & operator = (Dec &&) = default; constexpr Dec & operator = (const Dec &) = default; operator T () const { return value; } const Dec & operator += (const T & x) { value += x; return *this; } const Dec & operator -= (const T & x) { value -= x; return *this; } const Dec & operator *= (const T & x) { value *= x; return *this; } const Dec & operator /= (const T & x) { value /= x; return *this; } const Dec & operator %= (const T & x) { value %= x; return *this; } private: T value; }; using Dec32 = Dec; using Dec64 = Dec; using Dec128 = Dec; template <> struct TypeName { static const char * get() { return "Dec32"; } }; template <> struct TypeName { static const char * get() { return "Dec64"; } }; template <> struct TypeName { static const char * get() { return "Dec128"; } }; template <> struct TypeNumber { static constexpr const size_t value = 16; }; template <> struct TypeNumber { static constexpr const size_t value = 17; }; template <> struct TypeNumber { static constexpr const size_t value = 18; }; }