1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 // Third party copyrights are property of their respective owners. 17 // 18 // Redistribution and use in source and binary forms, with or without modification, 19 // are permitted provided that the following conditions are met: 20 // 21 // * Redistribution's of source code must retain the above copyright notice, 22 // this list of conditions and the following disclaimer. 23 // 24 // * Redistribution's in binary form must reproduce the above copyright notice, 25 // this list of conditions and the following disclaimer in the documentation 26 // and/or other materials provided with the distribution. 27 // 28 // * The name of the copyright holders may not be used to endorse or promote products 29 // derived from this software without specific prior written permission. 30 // 31 // This software is provided by the copyright holders and contributors "as is" and 32 // any express or implied warranties, including, but not limited to, the implied 33 // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 // In no event shall the Intel Corporation or contributors be liable for any direct, 35 // indirect, incidental, special, exemplary, or consequential damages 36 // (including, but not limited to, procurement of substitute goods or services; 37 // loss of use, data, or profits; or business interruption) however caused 38 // and on any theory of liability, whether in contract, strict liability, 39 // or tort (including negligence or otherwise) arising in any way out of 40 // the use of this software, even if advised of the possibility of such damage. 41 // 42 //M*/ 43 44 #pragma once 45 46 #ifndef __OPENCV_CUDEV_UTIL_TYPE_TRAITS_DETAIL_HPP__ 47 #define __OPENCV_CUDEV_UTIL_TYPE_TRAITS_DETAIL_HPP__ 48 49 #include "../../common.hpp" 50 51 namespace cv { namespace cudev { 52 53 namespace type_traits_detail 54 { 55 template <typename T> struct IsSignedIntergral { enum {value = 0}; }; 56 template <> struct IsSignedIntergral<schar> { enum {value = 1}; }; 57 template <> struct IsSignedIntergral<short> { enum {value = 1}; }; 58 template <> struct IsSignedIntergral<int> { enum {value = 1}; }; 59 60 template <typename T> struct IsUnsignedIntegral { enum {value = 0}; }; 61 template <> struct IsUnsignedIntegral<uchar> { enum {value = 1}; }; 62 template <> struct IsUnsignedIntegral<ushort> { enum {value = 1}; }; 63 template <> struct IsUnsignedIntegral<uint> { enum {value = 1}; }; 64 65 template <typename T> struct IsIntegral { enum {value = IsSignedIntergral<T>::value || IsUnsignedIntegral<T>::value}; }; 66 template <> struct IsIntegral<char> { enum {value = 1}; }; 67 template <> struct IsIntegral<bool> { enum {value = 1}; }; 68 69 template <typename T> struct IsFloat { enum {value = 0}; }; 70 template <> struct IsFloat<float> { enum {value = 1}; }; 71 template <> struct IsFloat<double> { enum {value = 1}; }; 72 73 template <typename T> struct IsVec { enum {value = 0}; }; 74 template <> struct IsVec<uchar1> { enum {value = 1}; }; 75 template <> struct IsVec<uchar2> { enum {value = 1}; }; 76 template <> struct IsVec<uchar3> { enum {value = 1}; }; 77 template <> struct IsVec<uchar4> { enum {value = 1}; }; 78 template <> struct IsVec<char1> { enum {value = 1}; }; 79 template <> struct IsVec<char2> { enum {value = 1}; }; 80 template <> struct IsVec<char3> { enum {value = 1}; }; 81 template <> struct IsVec<char4> { enum {value = 1}; }; 82 template <> struct IsVec<ushort1> { enum {value = 1}; }; 83 template <> struct IsVec<ushort2> { enum {value = 1}; }; 84 template <> struct IsVec<ushort3> { enum {value = 1}; }; 85 template <> struct IsVec<ushort4> { enum {value = 1}; }; 86 template <> struct IsVec<short1> { enum {value = 1}; }; 87 template <> struct IsVec<short2> { enum {value = 1}; }; 88 template <> struct IsVec<short3> { enum {value = 1}; }; 89 template <> struct IsVec<short4> { enum {value = 1}; }; 90 template <> struct IsVec<uint1> { enum {value = 1}; }; 91 template <> struct IsVec<uint2> { enum {value = 1}; }; 92 template <> struct IsVec<uint3> { enum {value = 1}; }; 93 template <> struct IsVec<uint4> { enum {value = 1}; }; 94 template <> struct IsVec<int1> { enum {value = 1}; }; 95 template <> struct IsVec<int2> { enum {value = 1}; }; 96 template <> struct IsVec<int3> { enum {value = 1}; }; 97 template <> struct IsVec<int4> { enum {value = 1}; }; 98 template <> struct IsVec<float1> { enum {value = 1}; }; 99 template <> struct IsVec<float2> { enum {value = 1}; }; 100 template <> struct IsVec<float3> { enum {value = 1}; }; 101 template <> struct IsVec<float4> { enum {value = 1}; }; 102 template <> struct IsVec<double1> { enum {value = 1}; }; 103 template <> struct IsVec<double2> { enum {value = 1}; }; 104 template <> struct IsVec<double3> { enum {value = 1}; }; 105 template <> struct IsVec<double4> { enum {value = 1}; }; 106 107 template <class U> struct AddParameterType { typedef const U& type; }; 108 template <class U> struct AddParameterType<U&> { typedef U& type; }; 109 template <> struct AddParameterType<void> { typedef void type; }; 110 111 // ReferenceTraits 112 113 template <class U> struct ReferenceTraits 114 { 115 enum { value = 0 }; 116 typedef U type; 117 }; 118 template <class U> struct ReferenceTraits<U&> 119 { 120 enum { value = 1 }; 121 typedef U type; 122 }; 123 124 // PointerTraits 125 126 template <class U> struct PointerTraits 127 { 128 enum { value = 0 }; 129 typedef void type; 130 }; 131 template <class U> struct PointerTraits<U*> 132 { 133 enum { value = 1 }; 134 typedef U type; 135 }; 136 template <class U> struct PointerTraits<U*&> 137 { 138 enum { value = 1 }; 139 typedef U type; 140 }; 141 142 // UnConst 143 144 template <class U> struct UnConst 145 { 146 typedef U type; 147 enum { value = 0 }; 148 }; 149 template <class U> struct UnConst<const U> 150 { 151 typedef U type; 152 enum { value = 1 }; 153 }; 154 template <class U> struct UnConst<const U&> 155 { 156 typedef U& type; 157 enum { value = 1 }; 158 }; 159 160 // UnVolatile 161 162 template <class U> struct UnVolatile 163 { 164 typedef U type; 165 enum { value = 0 }; 166 }; 167 template <class U> struct UnVolatile<volatile U> 168 { 169 typedef U type; 170 enum { value = 1 }; 171 }; 172 template <class U> struct UnVolatile<volatile U&> 173 { 174 typedef U& type; 175 enum { value = 1 }; 176 }; 177 178 // IsSimpleParameter 179 180 template <typename T> struct IsSimpleParameter 181 { 182 enum { value = IsIntegral<T>::value 183 || IsFloat<T>::value 184 || PointerTraits<typename ReferenceTraits<T>::type>::value}; 185 }; 186 187 // LargerDepth 188 189 template <bool, typename ThenType, typename ElseType> struct SelectIf 190 { 191 typedef ThenType type; 192 }; 193 template <typename ThenType, typename ElseType> struct SelectIf<false, ThenType, ElseType> 194 { 195 typedef ElseType type; 196 }; 197 198 template <typename A, typename B> struct LargerDepth 199 { 200 typedef typename SelectIf<sizeof(A) >= sizeof(B), A, B>::type type; 201 }; 202 template <typename A> struct LargerDepth<A, float> 203 { 204 typedef float type; 205 }; 206 template <typename A> struct LargerDepth<float, A> 207 { 208 typedef float type; 209 }; 210 template <typename A> struct LargerDepth<A, double> 211 { 212 typedef double type; 213 }; 214 template <typename A> struct LargerDepth<double, A> 215 { 216 typedef double type; 217 }; 218 template <> struct LargerDepth<float, float> 219 { 220 typedef float type; 221 }; 222 template <> struct LargerDepth<float, double> 223 { 224 typedef double type; 225 }; 226 template <> struct LargerDepth<double, float> 227 { 228 typedef double type; 229 }; 230 template <> struct LargerDepth<double, double> 231 { 232 typedef double type; 233 }; 234 } 235 236 }} 237 238 #endif 239