1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2013, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>
// ==========================================================================
#ifndef SEQAN_STREAM_RECORD_READER_BASE_H_
#define SEQAN_STREAM_RECORD_READER_BASE_H_
namespace seqan {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
struct StringReader_;
typedef Tag<StringReader_> StringReader;
template <typename TSpec = void>
struct SinglePass {};
template <typename TSpec = void>
struct DoublePass {};
/*!
* @class RecordReader
* @headerfile <seqan/stream.h>
* @brief Buffer management when reading from @link StreamConcept streams @endlink.
*
* @signature template <typename TStream, typename TSpec>
* class RecordReader;
*
* @tparam TStream The @link ConceptStream @endlink to read from.
* @tparam TSpec The record reader specialization type.
*
* @section Examples
*
* @include demos/input_output/record_reader.cpp
*
* The output is as follows:
*
* @include demos/input_output/record_reader.cpp.stdout
*/
/*!
* @fn RecordReader::RecordReader
* @brief Constructor.
*
* @signature RecordReader::RecordReader();
* @signature RecordReader::RecordReader(stream[, bufferSize]);
*
* @param[in] stream The @link StreamConcept @endlink to read from.
* @param[in] bufferSize The size of the buffer to use. Type: <tt>unsigned</tt>.
*/
/**
.Class.RecordReader
..cat:Input/Output
..summary:Buffer management for streams.
..signature:RecordReader<TStream, TSpec>
..param.TStream:The @Concept.StreamConcept@ type to work on.
..param.TSpec:The record reader specialization to chose.
..see:Concept.StreamConcept
..example.file:demos/input_output/record_reader.cpp
..include:seqan/stream.h
.Memfunc.RecordReader#RecordReader
..class:Class.RecordReader
..summary:Constructor
..signature:RecordReader()
..signature:RecordReader(file[, bufferSize])
..param.file:The file/String to use for reading.
...type:nolink:The $TFile$ type of $RecordReader$.
..param.bufferSize:The size of the buffer to use.
...type:nolink:$unsigned$
*/
template <typename TStream, typename TSpec>
class RecordReader;
// ============================================================================
// Metafunctions
// ============================================================================
// ----------------------------------------------------------------------------
// Metafuction Position
// ----------------------------------------------------------------------------
/*!
* @mfn RecordReader#Position
* @brief Returns the position tpye to use in @link RecordReader#position @endlink and @link RecordReader#setPosition @endlink.
*
* @signature Position<TReader>::Type;
*
* @tparam TReader The RecordReader to query for its position type.
*
* @return Type The resulting position type.
*
* @see RecordReader#position
* @see RecordReader#setPosition
*/
/**
.Metafunction.RecordReader#Position
..class:Class.RecordReader
..cat:Input/Output
..summary:Returns the position type to use in @Function.RecordReader#position@ and @Function.RecordReader#setPosition@.
..signature:Position<TReader>::Type
..param.TReader:The @Class.RecordReader@ type to query for its position type.
..returns:The position type related to the record reader type.
..include:seqan/stream.h
..see:Function.RecordReader#position
..see:Function.RecordReader#setPosition
*/
template <typename TStream, typename TSpec>
struct Position<RecordReader<TStream, TSpec> >
{
typedef typename Position<TStream>::Type Type;
};
template <typename TStream, typename TSpec>
struct Position<RecordReader<TStream, TSpec> const> :
Position<RecordReader<TStream, TSpec> >
{};
// ============================================================================
// Functions
// ============================================================================
/*!
* @fn RecordReader#resultCode
* @brief Return current status code of the reader/underlying stream.
*
* @signature int resultCode(reader);
*
* @param[in] reader The RecordReader to query for its status code.
*
* @return int The status code, 0 for no errors, non-0 value for errors.
*/
/*!
* @fn RecordReader#value
* @brief Return the current value (character) of the reader.
*
* This is undefined if the reader is at the end or an error occured.
*
* @signature char value(reader);
*
* @param[in] reader The RecordReader to read from.
*
* @return char The resulting character.
*/
/*!
* @fn RecordReader#goNext
* @brief Advance to the next position in the stream.
*
* @signature bool goNext(reader);
*
* @param[in,out] reader The RecordReader to advance.
*
* @return bool <tt>true</tt> on success, <tt>false</tt> on failure.
*/
/*!
* @fn RecordReader#nextIs
* @brief Query whether the next record is of a given type.
*
* @signature bool nextIs(reader, tag)
*
* @param[in,out] reader The @link RecordReader @endlink to peek into. Remains unchanged.
* @param[in] tag Tag to select the given record type.
*
* @return bool Indicating whether the next record in <tt>reader</tt> is of type given by tag.
*
* @section Remarks
*
* The checks are mostly heuristic, mostly looking at one or few characters from reader.
*/
/*!
* @fn RecordReader#atEnd
* @brief Returns <tt>true</tt> if there is no more data to be read.
*
* @signature bool atEnd(reader);
*
* @param reader The @link RecordReader @endlink to query the state of.
*
* @return bool This function returns <tt>true</tt> if the file is at end or there was an error reading. It returns
* <tt>false</tt> if there is more data to read. In parsing functions, you can use @link
* RecordReader#resultCode @endlink to get the result to return from your parsing function.
*
* @see RecordReader#value
* @see RecordReader#resultCode
*/
/*!
* @fn RecordReader#position
* @brief Returns the current position of the reader.
*
* @signature TPosition position(reader);
*
* @param[in] reader The RecordReader to query.
*
* @return TPosition The resulting position. Use @link RecordReader#Position @endlink to retrieve.
*/
/*!
* @fn RecordReader#setPosition
* @brief Sets the current position of the reader.
*
* @signature void setPosition(reader, pos);
*
* @param[in,out] reader The RecordReader to set the position of.
* @param[in] pos The position to set.
*
* @section Remarks
*
* The underlying data source has to support setting the position. For RecordReader objects reading from strings this
* always works. When reading from streams, setting the position must be supported by the underlying stream
*
* @see RecordReader#position
*/
/**
.Function.RecordReader#resultCode
..cat:Input/Output
..class:Class.RecordReader
..signature:int resultCode(reader)
..summary:Returns $int$ current status code for reader (0 on success).
..param.reader:The @Class.RecordReader@ to query the state of.
...type:Class.RecordReader
..returns:$int$, zero if there was no error reading, non-zero value on errors. Note that zero is also returned on EOF.
..include:seqan/stream.h
.Function.RecordReader#value
..summary:Returns the current value of the reader.
..cat:Input/Output
..class:Class.RecordReader
..signature:char value(reader)
..param.reader:The @Class.RecordReader@ to get the current value from.
...type:Class.RecordReader
..include:seqan/stream.h
.Function.RecordReader#goNext
..cat:Input/Output
..class:Class.RecordReader
..signature:bool goNext(recordReader)
..summary:Advance record reader to next position.
..param.recordReader:The @Class.RecordReader@ to advance the position in.
...type:Class.RecordReader
..include:seqan/stream.h
.Function.RecordReader#nextIs
..class:Class.RecordReader
..cat:Input/Output
..signature:bool nextIs(recordReader, tag)
..summary:Query whether the next record is of a given type.
..param.recordReader:The @Class.RecordReader@ to peek into.
...type:Class.RecordReader
...remarks:Stays unchanged.
..param.tag:Tag to select the given record type.
..returns:$bool$ indicating whether the next record in $recordReader$ is of type given by tag.
..remarks:The checks are mostly heuristic, mostly looking at one or few characters from recordReader.
..include:seqan/stream.h
.Function.RecordReader#atEnd
..cat:Input/Output
..class:Class.RecordReader
..summary:Returns $true$ if there is no more data to be read.
..signature:bool atEnd(recordReader)
..param.recordReader:The @Class.RecordReader@ to query the state of.
...type:Class.RecordReader
..returns:This function returns $true$ if the file is at end or there was an error reading. It returns $false$ if there is more data to read. In parsing functions, you can use @Function.RecordReader#resultCode@ to get the result to return from your parsing function.
..see:Function.RecordReader#value
..see:Function.RecordReader#resultCode
..include:seqan/stream.h
.Function.RecordReader#position
..cat:Input/Output
..class:Class.RecordReader
..summary:Returns the current position of the reader.
..signature:TPosition position(reader)
..param.reader:The @Class.RecordReader@ to query for its position.
...type:Class.RecordReader
..param.TPosition:The @Metafunction.RecordReader#Position@ of the reader.
..returns:The current position of the record reader.
..see:Metafunction.RecordReader#Position
..include:seqan/stream.h
.Function.RecordReader#setPosition
..cat:Input/Output
..class:Class.RecordReader
..summary:Returns the current position of the reader.
..remarks:
The underlying data source has to support setting the position.
For String RecordReader objects, this works nicely, when reading from streams, setting the position of the record reader is supported if the underlying string supports it.
..signature:void setPosition(reader, pos)
..param.reader:The @Class.RecordReader@ to query for its position.
...type:Class.RecordReader
..param.pos:The position to set the reader to.
...type:Metafunction.RecordReader#Position
..returns:$void$
..see:Metafunction.RecordReader#Position
..see:Function.RecordReader#position
..include:seqan/stream.h
*/
} // namespace seqan
#endif // #ifndef SEQAN_STREAM_RECORD_READER_BASE_H_
|