00001 #ifndef PROTON_INTERNAL_TYPE_TRAITS_HPP
00002 #define PROTON_INTERNAL_TYPE_TRAITS_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00029
00030 #include "./config.hpp"
00031 #include "../types_fwd.hpp"
00032 #include "../type_id.hpp"
00033
00034 namespace proton {
00035 namespace internal {
00036
00037 class decoder;
00038 class encoder;
00039
00040 template <bool, class T=void> struct enable_if {};
00041 template <class T> struct enable_if<true, T> { typedef T type; };
00042
00043 struct true_type { static const bool value = true; };
00044 struct false_type { static const bool value = false; };
00045
00046 template <class T> struct is_integral : public false_type {};
00047 template <class T> struct is_signed : public false_type {};
00048
00049 template <> struct is_integral<char> : public true_type {};
00050 template <> struct is_signed<char> : public false_type {};
00051
00052 template <> struct is_integral<unsigned char> : public true_type {};
00053 template <> struct is_integral<unsigned short> : public true_type {};
00054 template <> struct is_integral<unsigned int> : public true_type {};
00055 template <> struct is_integral<unsigned long> : public true_type {};
00056
00057 template <> struct is_integral<signed char> : public true_type {};
00058 template <> struct is_integral<signed short> : public true_type {};
00059 template <> struct is_integral<signed int> : public true_type {};
00060 template <> struct is_integral<signed long> : public true_type {};
00061
00062 template <> struct is_signed<unsigned short> : public false_type {};
00063 template <> struct is_signed<unsigned int> : public false_type {};
00064 template <> struct is_signed<unsigned long> : public false_type {};
00065
00066 template <> struct is_signed<signed char> : public true_type {};
00067 template <> struct is_signed<signed short> : public true_type {};
00068 template <> struct is_signed<signed int> : public true_type {};
00069 template <> struct is_signed<signed long> : public true_type {};
00070
00071 #if PN_CPP_HAS_LONG_LONG
00072 template <> struct is_integral<unsigned long long> : public true_type {};
00073 template <> struct is_integral<signed long long> : public true_type {};
00074 template <> struct is_signed<unsigned long long> : public false_type {};
00075 template <> struct is_signed<signed long long> : public true_type {};
00076 #endif
00077
00078 template <class T, class U> struct is_same { static const bool value=false; };
00079 template <class T> struct is_same<T,T> { static const bool value=true; };
00080
00081 template< class T > struct remove_const { typedef T type; };
00082 template< class T > struct remove_const<const T> { typedef T type; };
00083
00084 template <type_id ID, class T> struct type_id_constant {
00085 typedef T type;
00086 static const type_id value = ID;
00087 };
00088
00091 template <class T> struct type_id_of;
00092 template<> struct type_id_of<bool> : public type_id_constant<BOOLEAN, bool> {};
00093 template<> struct type_id_of<uint8_t> : public type_id_constant<UBYTE, uint8_t> {};
00094 template<> struct type_id_of<int8_t> : public type_id_constant<BYTE, int8_t> {};
00095 template<> struct type_id_of<uint16_t> : public type_id_constant<USHORT, uint16_t> {};
00096 template<> struct type_id_of<int16_t> : public type_id_constant<SHORT, int16_t> {};
00097 template<> struct type_id_of<uint32_t> : public type_id_constant<UINT, uint32_t> {};
00098 template<> struct type_id_of<int32_t> : public type_id_constant<INT, int32_t> {};
00099 template<> struct type_id_of<uint64_t> : public type_id_constant<ULONG, uint64_t> {};
00100 template<> struct type_id_of<int64_t> : public type_id_constant<LONG, int64_t> {};
00101 template<> struct type_id_of<wchar_t> : public type_id_constant<CHAR, wchar_t> {};
00102 template<> struct type_id_of<float> : public type_id_constant<FLOAT, float> {};
00103 template<> struct type_id_of<double> : public type_id_constant<DOUBLE, double> {};
00104 template<> struct type_id_of<timestamp> : public type_id_constant<TIMESTAMP, timestamp> {};
00105 template<> struct type_id_of<decimal32> : public type_id_constant<DECIMAL32, decimal32> {};
00106 template<> struct type_id_of<decimal64> : public type_id_constant<DECIMAL64, decimal64> {};
00107 template<> struct type_id_of<decimal128> : public type_id_constant<DECIMAL128, decimal128> {};
00108 template<> struct type_id_of<uuid> : public type_id_constant<UUID, uuid> {};
00109 template<> struct type_id_of<std::string> : public type_id_constant<STRING, std::string> {};
00110 template<> struct type_id_of<symbol> : public type_id_constant<SYMBOL, symbol> {};
00111 template<> struct type_id_of<binary> : public type_id_constant<BINARY, binary> {};
00113
00115 template <class T, class Enable=void> struct has_type_id : public false_type {};
00116 template <class T> struct has_type_id<T, typename type_id_of<T>::type> : public true_type {};
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 template<size_t SIZE, bool IS_SIGNED> struct integer_type;
00133 template<> struct integer_type<1, true> { typedef int8_t type; };
00134 template<> struct integer_type<2, true> { typedef int16_t type; };
00135 template<> struct integer_type<4, true> { typedef int32_t type; };
00136 template<> struct integer_type<8, true> { typedef int64_t type; };
00137 template<> struct integer_type<1, false> { typedef uint8_t type; };
00138 template<> struct integer_type<2, false> { typedef uint16_t type; };
00139 template<> struct integer_type<4, false> { typedef uint32_t type; };
00140 template<> struct integer_type<8, false> { typedef uint64_t type; };
00141
00142
00143 template <class T> struct is_unknown_integer {
00144 static const bool value = !has_type_id<T>::value && is_integral<T>::value;
00145 };
00146
00147 template<class T, class = typename enable_if<is_unknown_integer<T>::value>::type>
00148 struct known_integer : public integer_type<sizeof(T), is_signed<T>::value> {};
00149
00150
00151
00152 struct sfinae {
00153 typedef char yes;
00154 typedef double no;
00155 struct wildcard { wildcard(...); };
00156 };
00157
00158 template <class From, class To> struct is_convertible : public sfinae {
00159 static yes test(const To&);
00160 static no test(...);
00161 static const From& from;
00162
00163
00164
00165 #ifdef _WIN32
00166 #pragma warning( push )
00167 #pragma warning( disable : 4244 )
00168 #endif
00169 static bool const value = sizeof(test(from)) == sizeof(yes);
00170 #ifdef _WIN32
00171 #pragma warning( pop )
00172 #endif
00173 };
00174
00175 }
00176 }
00177
00178 #endif // PROTON_INTERNAL_TYPE_TRAITS_HPP