1 /*==========================================================================
2 SeqAn - The Library for Sequence Analysis
4 ============================================================================
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 ============================================================================
18 $Id: stream_algorithms.h,v 1.1 2008/08/25 16:20:04 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_STREAM_ALGORITHMS_H
22 #define SEQAN_HEADER_STREAM_ALGORITHMS_H
25 namespace SEQAN_NAMESPACE_MAIN
27 //////////////////////////////////////////////////////////////////////////////
31 .Internal._streamPutInt:
32 ..summary:Converts an integer to a character and writes it to stream.
34 ..signature:_streamPutInt(stream, number [, format_string])
35 ..param.target:An output stream.
36 ...type:Adaption."std::iostream"
37 ..param.number:A number that is written to $stream$.
39 template <typename TStream>
41 _streamPutInt(TStream & target,
43 char const * format_string)
46 char str[BitsPerValue<int>::VALUE];
47 sprintf(str, format_string, number);
48 _streamWrite(target, str);
50 template <typename TStream>
52 _streamPutInt(TStream & target,
56 _streamPutInt(target, number, "%d");
60 .Internal._streamPutFloat:
61 ..summary:Converts a float to a character and writes it to stream.
63 ..signature:_streamPutFloat(stream, number [, format_string])
64 ..param.target:An output stream.
65 ...type:Adaption."std::iostream"
66 ..param.number:A number that is written to $stream$.
68 template <typename TStream>
70 _streamPutFloat(TStream & target,
72 char const * format_string)
75 char str[BitsPerValue<float>::VALUE];
76 sprintf(str, format_string, number);
77 _streamWrite(target, str);
79 template <typename TStream>
81 _streamPutFloat(TStream & target,
85 _streamPutFloat(target, number, "%f");
88 //////////////////////////////////////////////////////////////////////////////
90 template <typename TTarget, typename T1, typename T2, typename TCompression>
92 _streamWrite(TTarget & target,
93 Pair<T1, T2, TCompression> const & source)
96 _streamWrite(target, getValueI1(source));
97 _streamWrite(target, getValueI2(source));
100 template <typename TTarget, typename T1, typename T2, typename T3, typename TCompression>
102 _streamWrite(TTarget & target,
103 Triple<T1, T2, T3, TCompression> const & source)
106 _streamWrite(target, getValueI1(source));
107 _streamWrite(target, getValueI2(source));
108 _streamWrite(target, getValueI3(source));
111 //////////////////////////////////////////////////////////////////////////////
116 .Internal._streamWrite:
117 ..summary:Writes a sequence to stream.
119 ..signature:_streamWrite(stream, sequence)
120 ..param.stream:An input stream.
121 ..param.sequence:A sequence that is written to $stream$.
124 template <typename TTarget, typename TSource>
126 _streamWrite(TTarget & target,
127 TSource const & source)
130 _streamWriteSeq(target, source, typename IsSequence<TSource const>::Type());
133 //____________________________________________________________________________
135 template <typename TTarget, typename TSource>
137 _streamWriteSeq(TTarget & target,
138 TSource const & source,
141 _streamPut(target, source);
144 //____________________________________________________________________________
146 template <typename TTarget, typename TSource>
148 _streamWriteSeq(TTarget & target,
149 TSource const & source,
153 typename Iterator<TSource const, Standard>::Type it = begin(source, Standard());
154 typename Iterator<TSource const, Standard>::Type it_end = end(source, Standard());
156 for (; it < it_end; ++it)
158 typename GetValue<TSource const>::Type val_ = getValue(it);
159 _streamWrite(target, val_);
163 template <typename TTarget, typename TSourceValue>
165 _streamWriteSeq(TTarget & target,
166 TSourceValue const * source,
171 for (; !atEnd(source); ++source)
173 _streamWrite(target, *source);
177 //////////////////////////////////////////////////////////////////////////////
180 .Internal._streamWriteRange:
181 ..summary:Writes a range to stream.
183 ..signature:_streamWriteRange(stream, begin_iterator, end_iterator)
184 ..param.stream:An input stream.
185 ..param.sequence:A sequence that is written to $stream$.
188 template <typename TTarget, typename TIterator>
190 _streamWriteRange(TTarget & target,
195 for (; begin_ != end_; ++begin_)
197 _streamPut(target, *begin_);
204 //////////////////////////////////////////////////////////////////////////////
206 } //namespace SEQAN_NAMESPACE_MAIN
208 #endif //#ifndef SEQAN_HEADER_...