1 // ========================================================================== 2 // SeqAn - The Library for Sequence Analysis 3 // ========================================================================== 4 // Copyright (c) 2013 NVIDIA Corporation 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions are met: 9 // 10 // * Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // * Redistributions in binary form must reproduce the above copyright 13 // notice, this list of conditions and the following disclaimer in the 14 // documentation and/or other materials provided with the distribution. 15 // * Neither the name of NVIDIA Corporation nor the names of 16 // its contributors may be used to endorse or promote products derived 17 // from this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 // ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE 23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 // DAMAGE. 30 // 31 // ========================================================================== 32 // Author: Enrico Siragusa <enrico.siragusa@fu-berlin.de> 33 // ========================================================================== 34 35 #ifndef SEQAN_BASIC_VIEW_H 36 #define SEQAN_BASIC_VIEW_H 37 38 namespace seqan { 39 40 // ============================================================================ 41 // Metafunctions 42 // ============================================================================ 43 44 // ---------------------------------------------------------------------------- 45 // Metafunction View 46 // ---------------------------------------------------------------------------- 47 48 /*! 49 * @mfn View 50 * @headerfile <seqan/basic.h> 51 * @brief Converts a given type into its view type. 52 * 53 * @signature View<TObject>::Type; 54 * 55 * @tparam TObject The type to be converted into a view type. 56 * @return Type The resulting view type. 57 * 58 * This metafunction is used to convert device containers into views of device containers. 59 * Subsequently, the view of a device container can be safely passed to and used in device space. 60 * On the host, a view of a @link String @endlink is equivalent to an @link SegmentableConcept#Infix @endlink of the complete string. 61 * @link RemoveView @endlink is the inverse of this metafunction. 62 * 63 * @see RemoveView 64 * @see Device 65 * @see SegmentableConcept#Infix 66 */ 67 68 template <typename TObject> 69 struct View 70 { 71 typedef TObject Type; 72 }; 73 74 template <typename TObject> 75 struct View<TObject const> 76 { 77 typedef typename View<TObject>::Type const Type; 78 }; 79 80 // ---------------------------------------------------------------------------- 81 // Metafunction RemoveView 82 // ---------------------------------------------------------------------------- 83 84 /*! 85 * @mfn RemoveView 86 * @headerfile <seqan/basic.h> 87 * @brief Converts a given view type into its original type. 88 * 89 * @signature RemoveView<TObject>::Type; 90 * 91 * @tparam TObject The view type to be converted into its original type. 92 * @return Type The resulting original type. 93 * 94 * @link View @endlink is the inverse of this metafunction. 95 * 96 * @see View 97 */ 98 99 template <typename TObject> 100 struct RemoveView 101 { 102 typedef TObject Type; 103 }; 104 105 template <typename TObject> 106 struct RemoveView<TObject const> 107 { 108 typedef typename RemoveView<TObject>::Type const Type; 109 }; 110 111 // ---------------------------------------------------------------------------- 112 // Metafunction IsView 113 // ---------------------------------------------------------------------------- 114 115 /*! 116 * @mfn IsView 117 * @headerfile <seqan/basic.h> 118 * @brief Tests if a given type is a view type. 119 * 120 * @signature IsView<TObject>::Type; 121 * 122 * @tparam TObject The type to be tested for being a view type. 123 * @return Type @link LogicalValuesTags#True @endlink or @link LogicalValuesTags#False @endlink. 124 * 125 * @see View 126 * @see RemoveView 127 */ 128 129 template <typename TObject> 130 struct IsView : public False {}; 131 132 template <typename TObject> 133 struct IsView<TObject const> : public IsView<TObject> {}; 134 135 // ---------------------------------------------------------------------------- 136 // Metafunction IfView 137 // ---------------------------------------------------------------------------- 138 139 template <typename TObject, typename T1, typename T2> 140 struct IfView 141 { 142 typedef typename If<IsView<TObject>, T1, T2>::Type Type; 143 }; 144 145 // ============================================================================ 146 // Functions 147 // ============================================================================ 148 149 // ---------------------------------------------------------------------------- 150 // Function view() 151 // ---------------------------------------------------------------------------- 152 153 /*! 154 * @fn TView view 155 * @headerfile <seqan/basic.h> 156 * @brief Returns the view of a given object. 157 * 158 * @signature TView view(object); 159 * 160 * @param[in] object A generic object. 161 * @return TView The @link View @endlink type of the given object. 162 * 163 * @see View 164 * @see IsView 165 */ 166 167 template <typename TObject> 168 inline typename View<TObject>::Type 169 view(TObject & object) 170 { 171 return typename View<TObject>::Type(object); 172 } 173 174 template <typename TObject> 175 inline typename View<TObject const>::Type 176 view(TObject const & object) 177 { 178 return typename View<TObject const>::Type(object); 179 } 180 181 template <typename TObject> 182 inline typename View<TObject>::Type 183 view(TObject * object) 184 { 185 return typename View<TObject>::Type(value(object)); 186 } 187 188 } // namespace seqan 189 190 #endif // #ifndef SEQAN_BASIC_VIEW_H 191