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_HPP__ 47 #define __OPENCV_CUDEV_UTIL_TYPE_TRAITS_HPP__ 48 49 #include "../common.hpp" 50 #include "vec_traits.hpp" 51 #include "detail/type_traits.hpp" 52 53 namespace cv { namespace cudev { 54 55 //! @addtogroup cudev 56 //! @{ 57 58 // NullType 59 60 struct NullType {}; 61 62 // Int2Type 63 64 template <int A> struct Int2Type 65 { 66 enum { value = A }; 67 }; 68 69 // ArrayWrapper 70 71 template <typename T, int COUNT> struct ArrayWrapper 72 { 73 T array[COUNT]; 74 }; 75 76 // Log2 (compile time calculation) 77 78 template <int N, int CURRENT_VAL = N, int COUNT = 0> struct Log2 79 { 80 enum { value = Log2<N, (CURRENT_VAL >> 1), COUNT + 1>::VALUE }; 81 }; 82 template <int N, int COUNT> struct Log2<N, 0, COUNT> 83 { 84 enum { value = (1 << (COUNT - 1) < N) ? COUNT : COUNT - 1 }; 85 }; 86 87 // IsPowerOf2 88 89 template <int N> struct IsPowerOf2 90 { 91 enum { value = ((N != 0) && !(N & (N - 1))) }; 92 }; 93 94 // SelectIf 95 96 template <bool, typename ThenType, typename ElseType> struct SelectIf 97 { 98 typedef ThenType type; 99 }; 100 template <typename ThenType, typename ElseType> struct SelectIf<false, ThenType, ElseType> 101 { 102 typedef ElseType type; 103 }; 104 105 // EnableIf 106 107 template <bool, typename T = void> struct EnableIf {}; 108 template <typename T> struct EnableIf<true, T> { typedef T type; }; 109 110 // DisableIf 111 112 template <bool, typename T = void> struct DisableIf {}; 113 template <typename T> struct DisableIf<false, T> { typedef T type; }; 114 115 // TypesEquals 116 117 template <typename A, typename B> struct TypesEquals 118 { 119 enum { value = 0 }; 120 }; 121 template <typename A> struct TypesEquals<A, A> 122 { 123 enum { value = 1 }; 124 }; 125 126 // TypeTraits 127 128 template <typename T> struct TypeTraits 129 { 130 typedef typename type_traits_detail::UnConst<T>::type non_const_type; 131 typedef typename type_traits_detail::UnVolatile<T>::type non_volatile_type; 132 typedef typename type_traits_detail::UnVolatile<typename type_traits_detail::UnConst<T>::type>::type unqualified_type; 133 typedef typename type_traits_detail::PointerTraits<unqualified_type>::type pointee_type; 134 typedef typename type_traits_detail::ReferenceTraits<T>::type referred_type; 135 136 enum { is_const = type_traits_detail::UnConst<T>::value }; 137 enum { is_volatile = type_traits_detail::UnVolatile<T>::value }; 138 139 enum { is_reference = type_traits_detail::ReferenceTraits<unqualified_type>::value }; 140 enum { is_pointer = type_traits_detail::PointerTraits<typename type_traits_detail::ReferenceTraits<unqualified_type>::type>::value }; 141 142 enum { is_unsigned_int = type_traits_detail::IsUnsignedIntegral<unqualified_type>::value }; 143 enum { is_signed_int = type_traits_detail::IsSignedIntergral<unqualified_type>::value }; 144 enum { is_integral = type_traits_detail::IsIntegral<unqualified_type>::value }; 145 enum { is_float = type_traits_detail::IsFloat<unqualified_type>::value }; 146 enum { is_scalar = is_integral || is_float }; 147 enum { is_vec = type_traits_detail::IsVec<unqualified_type>::value }; 148 149 typedef typename SelectIf<type_traits_detail::IsSimpleParameter<unqualified_type>::value, 150 T, typename type_traits_detail::AddParameterType<T>::type>::type parameter_type; 151 }; 152 153 // LargerType 154 155 template <typename A, typename B> struct LargerType 156 { 157 typedef typename SelectIf< 158 unsigned(VecTraits<A>::cn) != unsigned(VecTraits<B>::cn), 159 void, 160 typename MakeVec< 161 typename type_traits_detail::LargerDepth< 162 typename VecTraits<A>::elem_type, 163 typename VecTraits<B>::elem_type 164 >::type, 165 VecTraits<A>::cn 166 >::type 167 >::type type; 168 }; 169 170 //! @} 171 172 }} 173 174 #endif 175