]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/type_traits/type_name.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / type_traits / type_name.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_TYPE_TRAITS_TYPE_NAME_HPP
12 #define BOOST_COMPUTE_TYPE_TRAITS_TYPE_NAME_HPP
13
14 #include <boost/preprocessor/cat.hpp>
15 #include <boost/preprocessor/stringize.hpp>
16
17 #include <boost/compute/types/fundamental.hpp>
18
19 namespace boost {
20 namespace compute {
21 namespace detail {
22
23 template<class T>
24 struct type_name_trait;
25
26 /// \internal_
27 #define BOOST_COMPUTE_DEFINE_SCALAR_TYPE_NAME_FUNCTION(type) \
28 template<> \
29 struct type_name_trait<BOOST_PP_CAT(type, _)> \
30 { \
31 static const char* value() \
32 { \
33 return BOOST_PP_STRINGIZE(type); \
34 } \
35 };
36
37 /// \internal_
38 #define BOOST_COMPUTE_DEFINE_VECTOR_TYPE_NAME_FUNCTION(scalar, n) \
39 template<> \
40 struct type_name_trait<BOOST_PP_CAT(BOOST_PP_CAT(scalar, n), _)> \
41 { \
42 static const char* value() \
43 { \
44 return BOOST_PP_STRINGIZE(BOOST_PP_CAT(scalar, n)); \
45 } \
46 };
47
48 /// \internal_
49 #define BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(scalar) \
50 BOOST_COMPUTE_DEFINE_SCALAR_TYPE_NAME_FUNCTION(scalar) \
51 BOOST_COMPUTE_DEFINE_VECTOR_TYPE_NAME_FUNCTION(scalar, 2) \
52 BOOST_COMPUTE_DEFINE_VECTOR_TYPE_NAME_FUNCTION(scalar, 4) \
53 BOOST_COMPUTE_DEFINE_VECTOR_TYPE_NAME_FUNCTION(scalar, 8) \
54 BOOST_COMPUTE_DEFINE_VECTOR_TYPE_NAME_FUNCTION(scalar, 16)
55
56 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(char)
57 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(uchar)
58 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(short)
59 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(ushort)
60 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(int)
61 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(uint)
62 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(long)
63 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(ulong)
64 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(float)
65 BOOST_COMPUTE_DEFINE_TYPE_NAME_FUNCTIONS(double)
66
67 /// \internal_
68 #define BOOST_COMPUTE_DEFINE_BUILTIN_TYPE_NAME_FUNCTION(type) \
69 template<> \
70 struct type_name_trait<type> \
71 { \
72 static const char* value() \
73 { \
74 return #type; \
75 } \
76 };
77
78 BOOST_COMPUTE_DEFINE_BUILTIN_TYPE_NAME_FUNCTION(bool)
79 BOOST_COMPUTE_DEFINE_BUILTIN_TYPE_NAME_FUNCTION(char)
80 BOOST_COMPUTE_DEFINE_BUILTIN_TYPE_NAME_FUNCTION(void)
81
82 } // end detail namespace
83
84 /// Returns the OpenCL type name for the type \c T as a string.
85 ///
86 /// \return a string containing the type name for \c T
87 ///
88 /// For example:
89 /// \code
90 /// type_name<float>() == "float"
91 /// type_name<float4_>() == "float4"
92 /// \endcode
93 ///
94 /// \see type_definition<T>()
95 template<class T>
96 inline const char* type_name()
97 {
98 return detail::type_name_trait<T>::value();
99 }
100
101 } // end compute namespace
102 } // end boost namespace
103
104 /// Registers the OpenCL type for the C++ \p type to \p name.
105 ///
106 /// For example, the following will allow Eigen's \c Vector2f type
107 /// to be used with Boost.Compute algorithms and containers as the
108 /// built-in \c float2 type.
109 /// \code
110 /// BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2f, float2)
111 /// \endcode
112 ///
113 /// This macro should be invoked in the global namespace.
114 ///
115 /// \see type_name()
116 #define BOOST_COMPUTE_TYPE_NAME(type, name) \
117 namespace boost { namespace compute { \
118 template<> \
119 inline const char* type_name<type>() \
120 { \
121 return #name; \
122 }}}
123
124 #endif // BOOST_COMPUTE_TYPE_TRAITS_TYPE_NAME_HPP