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: cstream.h,v 1.2 2009/03/03 18:47:37 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_CSTREAM_H
22 #define SEQAN_HEADER_CSTREAM_H
26 namespace SEQAN_NAMESPACE_MAIN
28 //////////////////////////////////////////////////////////////////////////////
30 .Adaption."std::FILE *":
31 ..summary:Standard library C style streams.
34 //////////////////////////////////////////////////////////////////////////////
35 // Position is now defined in file/file_cstyle.h
38 struct Position<FILE *>
43 //////////////////////////////////////////////////////////////////////////////
51 //////////////////////////////////////////////////////////////////////////////
54 struct Position<FILE *>
56 typedef ::std::fpos_t Type;
60 //////////////////////////////////////////////////////////////////////////////
63 struct _IsTellSeekStream;
66 struct _IsTellSeekStream<FILE *>
71 //////////////////////////////////////////////////////////////////////////////
74 _streamOpen(::std::FILE * & me, String<char> path, bool for_read = true)
77 size_t plen = length(path);
78 char *s = new char[plen + 1];
79 for(size_t i = 0; i < plen; i++) {
96 //////////////////////////////////////////////////////////////////////////////
99 _streamClose(::std::FILE * & me)
109 //////////////////////////////////////////////////////////////////////////////
111 ///.Internal._streamEOF.param.stream.type:Adaption."std::FILE *"
114 _streamEOF(::std::FILE * me)
117 return feof(me) || ferror(me);
120 //////////////////////////////////////////////////////////////////////////////
122 ///.Internal._streamRead.param.stream.type:Adaption."std::FILE *"
124 template <typename TValue>
126 _streamRead(TValue * target,
127 ::std::FILE * source,
131 return ::std::fread(target, sizeof(TValue), limit, source);
134 //////////////////////////////////////////////////////////////////////////////
136 ///.Internal._streamGet.param.stream.type:Adaption."std::FILE *"
139 _streamGet(::std::FILE * source)
145 //////////////////////////////////////////////////////////////////////////////
147 ///.Internal._streamPut.param.stream.type:Adaption."std::FILE *"
150 _streamPut(::std::FILE * target,
154 putc(character, target);
158 //////////////////////////////////////////////////////////////////////////////
160 ///.Internal._streamPut.param.stream.type:Adaption."std::FILE *"
162 //////////////////////////////////////////////////////////////////////////////
164 ///.Internal._streamTellG.param.stream.type:Adaption."std::FILE *"
166 inline Position<FILE *>::Type
167 _streamTellG(FILE * me)
170 return ::std::ftell(me);
173 //////////////////////////////////////////////////////////////////////////////
175 ///.Internal._streamTellP.param.stream.type:Adaption."std::FILE *"
177 inline Position<FILE *>::Type
178 _streamTellP(FILE * me)
181 return ::std::ftell(me);
184 //////////////////////////////////////////////////////////////////////////////
186 ///.Internal._streamSeekG.param.stream.type:Adaption."std::FILE *"
189 _streamSeekG(FILE * me,
190 Position<FILE *>::Type pos)
193 ::std::fseek(me, pos, SEEK_SET);
196 //////////////////////////////////////////////////////////////////////////////
198 ///.Internal._streamSeekP.param.stream.type:Adaption."std::FILE *"
201 _streamSeekP(FILE * me,
202 Position<FILE *>::Type pos)
205 ::std::fseek(me, pos, SEEK_SET);
208 //////////////////////////////////////////////////////////////////////////////
210 ///.Internal._streamSeek2G.param.stream.type:Adaption."std::FILE *"
213 _streamSeek2G(FILE * me,
217 ::std::fseek(me, off, SEEK_CUR);
220 //////////////////////////////////////////////////////////////////////////////
222 ///.Internal._streamUnget.param.stream.type:Adaption."std::FILE *"
225 _streamUnget(::std::FILE * stream)
228 _streamSeek2G(stream, -1);
231 //////////////////////////////////////////////////////////////////////////////
232 // Stream operators for FILE *
233 //////////////////////////////////////////////////////////////////////////////
235 // ISO C++ operators are only allowed for classes, not for pointers
238 template <typename TSource>
240 operator << (FILE * target,
244 write(target, source);
247 template <typename TSource>
249 operator << (FILE * target,
250 TSource const & source)
253 write(target, source);
257 //____________________________________________________________________________
259 template <typename TTarget>
261 operator >> (FILE * source,
265 read(source, target);
268 template <typename TTarget>
270 operator >> (FILE * source,
271 TTarget const & target)
274 read(source, target);
279 //////////////////////////////////////////////////////////////////////////////
281 } //namespace SEQAN_NAMESPACE_MAIN
283 #endif //#ifndef SEQAN_HEADER_...