Qpid Proton C++  0.12.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
type_traits.hpp
1 #ifndef TYPE_TRAITS_HPP
2 #define TYPE_TRAITS_HPP
3 
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 
24 
31 
32 #include "proton/config.hpp"
33 #include "proton/types.hpp"
34 
35 namespace proton {
36 
37 class value;
38 
39 template <bool, class T=void> struct enable_if {};
40 template <class T> struct enable_if<true, T> { typedef T type; };
41 
42 struct true_type { static const bool value = true; };
43 struct false_type { static const bool value = false; };
44 
45 template <class T> struct is_integral : public false_type {};
46 
47 template <> struct is_integral<unsigned char> : public true_type {};
48 template <> struct is_integral<unsigned short> : public true_type {};
49 template <> struct is_integral<unsigned int> : public true_type {};
50 template <> struct is_integral<unsigned long> : public true_type {};
51 
52 template <> struct is_integral<signed char> : public true_type {};
53 template <> struct is_integral<signed short> : public true_type {};
54 template <> struct is_integral<signed int> : public true_type {};
55 template <> struct is_integral<signed long> : public true_type {};
56 
57 template <class T> struct is_signed : public false_type {};
58 
59 template <> struct is_signed<unsigned char> : public false_type {};
60 template <> struct is_signed<unsigned short> : public false_type {};
61 template <> struct is_signed<unsigned int> : public false_type {};
62 template <> struct is_signed<unsigned long> : public false_type {};
63 
64 template <> struct is_signed<signed char> : public true_type {};
65 template <> struct is_signed<signed short> : public true_type {};
66 template <> struct is_signed<signed int> : public true_type {};
67 template <> struct is_signed<signed long> : public true_type {};
68 
69 #if PN_HAS_LONG_LONG
70 template <> struct is_integral<unsigned long long> : public true_type {};
71 template <> struct is_integral<signed long long> : public true_type {};
72 template <> struct is_signed<unsigned long long> : public false_type {};
73 template <> struct is_signed<signed long long> : public true_type {};
74 #endif
75 
76 template <class T, class U> struct is_same { static const bool value=false; };
77 template <class T> struct is_same<T,T> { static const bool value=true; };
78 
79 
80 template< class T > struct remove_const { typedef T type; };
81 template< class T > struct remove_const<const T> { typedef T type; };
82 
83 // Metafunction returning AMQP type for scalar C++ types
84 template <class T, class Enable=void> struct type_id_of;
85 template<> struct type_id_of<amqp_null> { static const type_id value=NULL_TYPE; };
86 template<> struct type_id_of<amqp_boolean> { static const type_id value=BOOLEAN; };
87 template<> struct type_id_of<amqp_ubyte> { static const type_id value=UBYTE; };
88 template<> struct type_id_of<amqp_byte> { static const type_id value=BYTE; };
89 template<> struct type_id_of<amqp_ushort> { static const type_id value=USHORT; };
90 template<> struct type_id_of<amqp_short> { static const type_id value=SHORT; };
91 template<> struct type_id_of<amqp_uint> { static const type_id value=UINT; };
92 template<> struct type_id_of<amqp_int> { static const type_id value=INT; };
93 template<> struct type_id_of<amqp_char> { static const type_id value=CHAR; };
94 template<> struct type_id_of<amqp_ulong> { static const type_id value=ULONG; };
95 template<> struct type_id_of<amqp_long> { static const type_id value=LONG; };
96 template<> struct type_id_of<amqp_timestamp> { static const type_id value=TIMESTAMP; };
97 template<> struct type_id_of<amqp_float> { static const type_id value=FLOAT; };
98 template<> struct type_id_of<amqp_double> { static const type_id value=DOUBLE; };
99 template<> struct type_id_of<amqp_decimal32> { static const type_id value=DECIMAL32; };
100 template<> struct type_id_of<amqp_decimal64> { static const type_id value=DECIMAL64; };
101 template<> struct type_id_of<amqp_decimal128> { static const type_id value=DECIMAL128; };
102 template<> struct type_id_of<amqp_uuid> { static const type_id value=UUID; };
103 template<> struct type_id_of<amqp_binary> { static const type_id value=BINARY; };
104 template<> struct type_id_of<amqp_string> { static const type_id value=STRING; };
105 template<> struct type_id_of<amqp_symbol> { static const type_id value=SYMBOL; };
106 
107 template <class T, class Enable=void> struct has_type_id : public false_type {};
108 template <class T> struct has_type_id<T, typename enable_if<!!type_id_of<T>::value>::type> {
109  static const bool value = true;
110 };
111 
112 // Map arbitrary integral types to known AMQP integral types.
113 template<size_t SIZE, bool IS_SIGNED> struct integer_type;
114 template<> struct integer_type<1, true> { typedef amqp_byte type; };
115 template<> struct integer_type<2, true> { typedef amqp_short type; };
116 template<> struct integer_type<4, true> { typedef amqp_int type; };
117 template<> struct integer_type<8, true> { typedef amqp_long type; };
118 template<> struct integer_type<1, false> { typedef amqp_ubyte type; };
119 template<> struct integer_type<2, false> { typedef amqp_ushort type; };
120 template<> struct integer_type<4, false> { typedef amqp_uint type; };
121 template<> struct integer_type<8, false> { typedef amqp_ulong type; };
122 
123 // True if T is an integer type that does not have a type_id mapping.
124 template <class T> struct is_unknown_integer {
125  static const bool value = !has_type_id<T>::value && is_integral<T>::value;
126 };
127 
128 }
129 
131 
132 #endif // TYPE_TRAITS_HPP
Defines C++ types representing AMQP types.