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.h,v 1.1 2008/08/25 16:20:04 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_STREAM_H
22 #define SEQAN_HEADER_STREAM_H
26 namespace SEQAN_NAMESPACE_MAIN
28 //////////////////////////////////////////////////////////////////////////////
30 .Adaption."std::iostream":
31 ..summary:Standard library stream classes.
34 //////////////////////////////////////////////////////////////////////////////
36 template <typename TValue, typename TTraits>
37 struct Position< ::std::basic_ios<TValue, TTraits> >
39 typedef typename ::std::basic_ios<TValue, TTraits>::pos_type Type;
41 template <typename TValue, typename TTraits>
42 struct Position< ::std::basic_streambuf<TValue, TTraits> >
44 typedef typename ::std::basic_streambuf<TValue, TTraits>::pos_type Type;
46 template <typename TValue, typename TTraits>
47 struct Position< ::std::basic_istream<TValue, TTraits> >
49 typedef typename ::std::basic_istream<TValue, TTraits>::pos_type Type;
51 template <typename TValue, typename TTraits>
52 struct Position< ::std::basic_ostream<TValue, TTraits> >
54 typedef typename ::std::basic_ostream<TValue, TTraits>::pos_type Type;
56 template <typename TValue, typename TTraits>
57 struct Position< ::std::basic_iostream<TValue, TTraits> >
59 typedef typename ::std::basic_iostream<TValue, TTraits>::pos_type Type;
61 template <typename TValue, typename TTraits>
62 struct Position< ::std::basic_stringbuf<TValue, TTraits> >
64 typedef typename ::std::basic_stringbuf<TValue, TTraits>::pos_type Type;
66 template <typename TValue, typename TTraits>
67 struct Position< ::std::basic_istringstream<TValue, TTraits> >
69 typedef typename ::std::basic_istringstream<TValue, TTraits>::pos_type Type;
71 template <typename TValue, typename TTraits>
72 struct Position< ::std::basic_ostringstream<TValue, TTraits> >
74 typedef typename ::std::basic_ostringstream<TValue, TTraits>::pos_type Type;
76 template <typename TValue, typename TTraits>
77 struct Position< ::std::basic_stringstream<TValue, TTraits> >
79 typedef typename ::std::basic_stringstream<TValue, TTraits>::pos_type Type;
81 template <typename TValue, typename TTraits>
82 struct Position< ::std::basic_filebuf<TValue, TTraits> >
84 typedef typename ::std::basic_filebuf<TValue, TTraits>::pos_type Type;
86 template <typename TValue, typename TTraits>
87 struct Position< ::std::basic_ifstream<TValue, TTraits> >
89 typedef typename ::std::basic_ifstream<TValue, TTraits>::pos_type Type;
91 template <typename TValue, typename TTraits>
92 struct Position< ::std::basic_ofstream<TValue, TTraits> >
94 typedef typename ::std::basic_ofstream<TValue, TTraits>::pos_type Type;
96 template <typename TValue, typename TTraits>
97 struct Position< ::std::basic_fstream<TValue, TTraits> >
99 typedef typename ::std::basic_fstream<TValue, TTraits>::pos_type Type;
102 //////////////////////////////////////////////////////////////////////////////
104 template <typename TValue, typename TTraits>
105 struct Value< ::std::basic_ios<TValue, TTraits> >
107 typedef typename ::std::basic_ios<TValue, TTraits>::char_type Type;
109 template <typename TValue, typename TTraits>
110 struct Value< ::std::basic_streambuf<TValue, TTraits> >
112 typedef typename ::std::basic_streambuf<TValue, TTraits>::char_type Type;
114 template <typename TValue, typename TTraits>
115 struct Value< ::std::basic_istream<TValue, TTraits> >
117 typedef typename ::std::basic_istream<TValue, TTraits>::char_type Type;
119 template <typename TValue, typename TTraits>
120 struct Value< ::std::basic_ostream<TValue, TTraits> >
122 typedef typename ::std::basic_ostream<TValue, TTraits>::char_type Type;
124 template <typename TValue, typename TTraits>
125 struct Value< ::std::basic_iostream<TValue, TTraits> >
127 typedef typename ::std::basic_iostream<TValue, TTraits>::char_type Type;
129 template <typename TValue, typename TTraits>
130 struct Value< ::std::basic_stringbuf<TValue, TTraits> >
132 typedef typename ::std::basic_stringbuf<TValue, TTraits>::char_type Type;
134 template <typename TValue, typename TTraits>
135 struct Value< ::std::basic_istringstream<TValue, TTraits> >
137 typedef typename ::std::basic_istringstream<TValue, TTraits>::char_type Type;
139 template <typename TValue, typename TTraits>
140 struct Value< ::std::basic_ostringstream<TValue, TTraits> >
142 typedef typename ::std::basic_ostringstream<TValue, TTraits>::char_type Type;
144 template <typename TValue, typename TTraits>
145 struct Value< ::std::basic_stringstream<TValue, TTraits> >
147 typedef typename ::std::basic_stringstream<TValue, TTraits>::char_type Type;
149 template <typename TValue, typename TTraits>
150 struct Value< ::std::basic_filebuf<TValue, TTraits> >
152 typedef typename ::std::basic_filebuf<TValue, TTraits>::char_type Type;
154 template <typename TValue, typename TTraits>
155 struct Value< ::std::basic_ifstream<TValue, TTraits> >
157 typedef typename ::std::basic_ifstream<TValue, TTraits>::char_type Type;
159 template <typename TValue, typename TTraits>
160 struct Value< ::std::basic_ofstream<TValue, TTraits> >
162 typedef typename ::std::basic_ofstream<TValue, TTraits>::char_type Type;
164 template <typename TValue, typename TTraits>
165 struct Value< ::std::basic_fstream<TValue, TTraits> >
167 typedef typename ::std::basic_fstream<TValue, TTraits>::char_type Type;
170 //////////////////////////////////////////////////////////////////////////////
172 /**.interal._IsTellSeekStream:
173 ..summary:Determines whether stream supports tell and seek functions.
177 template <typename T>
178 struct _IsTellSeekStream
184 template <typename TValue, typename TTraits>
185 struct _IsTellSeekStream< ::std::basic_ifstream<TValue, TTraits> >
189 template <typename TValue, typename TTraits>
190 struct _IsTellSeekStream< ::std::basic_fstream<TValue, TTraits> >
195 //////////////////////////////////////////////////////////////////////////////
198 .Internal._streamEOF:
199 ..summary:Test stream for being in eof or error state.
201 ..signature:_streamEOF(stream)
202 ..param.stream:A stream object.
203 ...type:Adaption."std::iostream"
204 ..returns:$true$, if stream is at end of file or was set to error state, $false$ otherwise.
206 template <typename TValue, typename TTraits>
208 _streamEOF(::std::basic_ios<TValue, TTraits> const & me)
211 return me.eof() || me.fail();
214 //////////////////////////////////////////////////////////////////////////////
217 .Internal._streamRead:
218 ..summary:Read some characters from stream into a buffer.
220 ..signature:_streamRead(target, stream, limit)
221 ..param.target:A buffer that is filled.
222 ..param.stream:An input stream.
223 ...type:Adaption."std::iostream"
224 ..param.limit:The maximal number of characters that is read from $stream$.
225 ..returns:The number of characters read from $stream$.
227 template <typename TValue, typename TTraits>
228 inline ::std::streamsize
229 _streamRead(TValue * target,
230 ::std::basic_istream<TValue, TTraits> & source,
231 ::std::streamsize limit)
234 source.read(target, limit);
235 return source.gcount();
238 //////////////////////////////////////////////////////////////////////////////
241 .Internal._streamGet:
242 ..summary:Read one character from stream.
244 ..signature:_streamGet(stream)
245 ..param.stream:An input stream.
246 ...type:Adaption."std::iostream"
247 ..returns:The character read.
250 template <typename TValue, typename TTraits>
252 _streamGet(::std::basic_istream<TValue, TTraits> & source)
258 //////////////////////////////////////////////////////////////////////////////
261 .Internal._streamPeek:
262 ..summary:Return the next character to be read from stream.
264 ..signature:_streamPeek(stream)
265 ..param.stream:An input stream.
266 ...type:Adaption."std::iostream"
267 ..returns:The character to be read.
270 template <typename TValue, typename TTraits>
272 _streamPeek(::std::basic_istream<TValue, TTraits> & source)
275 return source.peek();
278 //////////////////////////////////////////////////////////////////////////////
281 .Internal._streamUnget:
282 ..summary:Put the last read character back into stream.
284 ..signature:_streamUnget(stream)
285 ..param.stream:An input stream.
286 ...type:Adaption."std::iostream"
289 template <typename TValue, typename TTraits>
291 _streamUnget(::std::basic_istream<TValue, TTraits> & source)
297 //////////////////////////////////////////////////////////////////////////////
300 .Internal._streamPut:
301 ..summary:Writes one character to stream.
303 ..signature:_streamPut(stream, character)
304 ..param.stream:An input stream.
305 ...type:Adaption."std::iostream"
306 ..param.character:A character that is written to $stream$.
309 template <typename TValue, typename TTraits, typename TChar>
311 _streamPut(::std::basic_ostream<TValue, TTraits> & target,
315 target.put(convert<TValue>(character));
318 //////////////////////////////////////////////////////////////////////////////
321 .Internal._streamTellG:
323 ..summary:Gets current position of input stream.
324 ..signature:_streamTellG(stream)
325 ..param.stream:An input stream.
326 ...type:Adaption."std::iostream"
327 ..returns:The current position in $stream$.
329 template <typename TValue, typename TTraits>
330 inline typename Position< ::std::basic_istream<TValue, TTraits> >::Type
331 _streamTellG(::std::basic_istream<TValue, TTraits> & me)
337 //////////////////////////////////////////////////////////////////////////////
339 .Internal._streamTellP:
341 ..summary:Gets current position of output stream.
342 ..signature:_streamTellP(stream)
343 ..param.stream:An ouput stream.
344 ...type:Adaption."std::iostream"
345 ..returns:The current position in $stream$.
346 ..see:Internal._streamTellG
348 template <typename TValue, typename TTraits>
349 inline typename Position< ::std::basic_ostream<TValue, TTraits> >::Type
350 _streamTellP(::std::basic_ostream<TValue, TTraits> & me)
356 //////////////////////////////////////////////////////////////////////////////
359 .Internal._streamSeekG:
360 ..summary:Moves input stream to a position.
362 ..signature:_streamSeekG(stream, position)
363 ..param.stream:An input stream.
364 ...type:Adaption."std::iostream"
365 ..param.position:A position within the stream.
366 ...remarks:Use @Function._streamTellG@ to get valid stream positions.
367 ..see:Internal._streamTellG
369 template <typename TValue, typename TTraits>
371 _streamSeekG(::std::basic_istream<TValue, TTraits> & me,
372 typename Position< ::std::basic_istream<TValue, TTraits> >::Type pos)
379 //////////////////////////////////////////////////////////////////////////////
382 .Internal._streamSeekP:
383 ..summary:Moves output stream to a position.
385 ..signature:_streamSeekP(stream, position)
386 ..param.stream:An output stream.
387 ...type:Adaption."std::iostream"
388 ..param.position:A position within the stream.
389 ...remarks:Use @Function._streamTellP@ to get valid stream positions.
390 ..see:Internal._streamTellP
391 ..see:Internal._streamSeekG
393 template <typename TValue, typename TTraits>
395 _streamSeekP(::std::basic_ostream<TValue, TTraits> & me,
396 typename Position< ::std::basic_ostream<TValue, TTraits> >::Type pos)
403 //////////////////////////////////////////////////////////////////////////////
406 .Internal._streamSeek2G:
407 ..summary:Moves input stream position relative to current position.
409 ..signature:_streamSeek2G(stream, offset)
410 ..param.stream:An input stream.
411 ...type:Adaption."std::iostream"
412 ..param.offset:The amout the position is changed.
413 ...remarks:If this value is negative.
414 ..see:Internal._streamSeekG
416 template <typename TValue, typename TTraits>
418 _streamSeek2G(::std::basic_istream<TValue, TTraits> & me,
422 me.seekg(off, ::std::ios_base::cur);
426 //////////////////////////////////////////////////////////////////////////////
428 } //namespace SEQAN_NAMESPACE_MAIN
430 #endif //#ifndef SEQAN_HEADER_...