ClickHouse/dbms/src/Core/Types.h

78 lines
3.2 KiB
C++
Raw Normal View History

2011-08-28 00:31:30 +00:00
#pragma once
2010-03-01 16:59:51 +00:00
#include <string>
#include <vector>
2010-03-01 16:59:51 +00:00
#include <Poco/Types.h>
2015-09-29 19:19:54 +00:00
#include <common/strong_typedef.h>
2010-03-01 16:59:51 +00:00
namespace DB
{
/** Data types for representing values from a database in RAM.
2010-03-01 16:59:51 +00:00
*/
STRONG_TYPEDEF(char, Null);
2010-03-01 16:59:51 +00:00
using UInt8 = Poco::UInt8;
using UInt16 = Poco::UInt16;
using UInt32 = Poco::UInt32;
using UInt64 = Poco::UInt64;
2010-03-01 16:59:51 +00:00
using Int8 = Poco::Int8;
using Int16 = Poco::Int16;
using Int32 = Poco::Int32;
using Int64 = Poco::Int64;
2010-03-01 16:59:51 +00:00
using Float32 = float;
using Float64 = double;
2010-03-01 16:59:51 +00:00
using String = std::string;
using Strings = std::vector<String>;
2010-03-01 16:59:51 +00:00
/// Ordinary types with nullability.
template <typename T> struct Nullable { using Type = T; };
2010-03-01 16:59:51 +00:00
2016-08-04 23:10:35 +00:00
/// Get a non-nullable type.
template <typename T> struct RemoveNullable { using Type = T; };
2016-08-04 23:10:35 +00:00
template <typename T> struct RemoveNullable<Nullable<T>> { using Type = T; };
2011-08-28 00:31:30 +00:00
2016-08-04 23:10:35 +00:00
/// Check if a type is nullable.
template <typename T> struct IsNullable { static constexpr bool value = false; };
template <typename T> struct IsNullable<Nullable<T>> { static constexpr bool value = true; };
template <typename T> struct IsNumber { static constexpr bool value = false; };
2017-08-30 18:13:32 +00:00
template <typename T> struct IsNumber<Nullable<T>> { static constexpr bool value = IsNumber<T>::value; };
template <> struct IsNumber<UInt8> { static constexpr bool value = true; };
template <> struct IsNumber<UInt16> { static constexpr bool value = true; };
template <> struct IsNumber<UInt32> { static constexpr bool value = true; };
template <> struct IsNumber<UInt64> { static constexpr bool value = true; };
template <> struct IsNumber<Int8> { static constexpr bool value = true; };
template <> struct IsNumber<Int16> { static constexpr bool value = true; };
template <> struct IsNumber<Int32> { static constexpr bool value = true; };
template <> struct IsNumber<Int64> { static constexpr bool value = true; };
template <> struct IsNumber<Float32> { static constexpr bool value = true; };
template <> struct IsNumber<Float64> { static constexpr bool value = true; };
2011-08-28 00:31:30 +00:00
template <typename T> struct TypeName;
template <typename T> struct TypeName<Nullable<T>> { static const char * get() { return "Nullable"; } };
template <> struct TypeName<Null> { static const char * get() { return "Null"; } };
2016-08-04 23:10:35 +00:00
template <> struct TypeName<Nullable<void>> : TypeName<Null> {};
2011-08-28 00:31:30 +00:00
template <> struct TypeName<UInt8> { static const char * get() { return "UInt8"; } };
template <> struct TypeName<UInt16> { static const char * get() { return "UInt16"; } };
template <> struct TypeName<UInt32> { static const char * get() { return "UInt32"; } };
template <> struct TypeName<UInt64> { static const char * get() { return "UInt64"; } };
template <> struct TypeName<Int8> { static const char * get() { return "Int8"; } };
template <> struct TypeName<Int16> { static const char * get() { return "Int16"; } };
template <> struct TypeName<Int32> { static const char * get() { return "Int32"; } };
template <> struct TypeName<Int64> { static const char * get() { return "Int64"; } };
template <> struct TypeName<Float32> { static const char * get() { return "Float32"; } };
template <> struct TypeName<Float64> { static const char * get() { return "Float64"; } };
template <> struct TypeName<String> { static const char * get() { return "String"; } };
2011-08-28 00:31:30 +00:00
}