1 // ========================================================================== 2 // SeqAn - The Library for Sequence Analysis 3 // ========================================================================== 4 // Copyright (c) 2006-2015, Knut Reinert, FU Berlin 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 Knut Reinert or the FU Berlin 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 KNUT REINERT OR THE FU BERLIN 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: David Weese <david.weese@fu-berlin.de> 33 // ========================================================================== 34 35 #ifndef SEQAN_HEADER_PIPE_CASTER_H 36 #define SEQAN_HEADER_PIPE_CASTER_H 37 38 namespace SEQAN_NAMESPACE_MAIN 39 { 40 41 //namespace SEQAN_NAMESPACE_PIPELINING 42 //{ 43 44 struct CasterReinterpret; 45 struct CasterConvert; 46 47 template < typename TValue, typename TSpec = CasterReinterpret > 48 struct Caster; 49 50 template < typename TInput, typename TValue, typename TSpec > 51 struct Value< Pipe< TInput, Caster<TValue, TSpec> > > { 52 typedef TValue Type; 53 }; 54 55 /*! 56 * @class Caster 57 * @extends Pipe 58 * @headerfile <seqan/pipe.h> 59 * @brief Casts the input type in a specific output type. 60 * 61 * @signature template <typename TInput, typename TValue[, typename TSpec]> 62 * class Pipe<TInput, Caster<TValue, TSpec> >; 63 * 64 * @tparam TInput The type of the pipeline module this module reads from. 65 * @tparam TValue The new output type. 66 * @tparam TSpec <tt>CasterReinterpret</tt> (default) or <tt>CasterConvert</tt>. 67 * 68 * The input stream is casted using <tt>reinterpret_cast<TValue></tt>. 69 */ 70 71 ////////////////////////////////////////////////////////////////////////////// 72 // caster pipe 73 template <typename TInput, typename TValue > 74 struct Pipe< TInput, Caster<TValue, CasterReinterpret> > 75 { 76 TInput ∈ 77 78 Pipe(TInput& _in): 79 in(_in) {} 80 81 inline TValue const & operator*() const { 82 return reinterpret_cast<TValue const &>(*in); 83 } 84 85 Pipe& operator++() { 86 ++in; 87 return *this; 88 } 89 }; 90 91 template <typename TInput, typename TValue > 92 struct Pipe< TInput, Caster<TValue, CasterConvert> > 93 { 94 TInput ∈ 95 96 Pipe(TInput& _in): 97 in(_in) {} 98 99 inline TValue operator*() const { 100 return TValue(*in); 101 } 102 103 Pipe& operator++() { 104 ++in; 105 return *this; 106 } 107 }; 108 //} 109 110 } 111 112 #endif 113