Class RecordReader
Buffer management when reading from streams.

All Subcl's DoublePassRecordReader, SinglePassRecordReader, StringDoublePassRecordReader, StringSinglePassRecordReader
Defined in <seqan/stream.h>
Signature template <typename TStream, typename TSpec> class RecordReader;

Template Parameters

TStream The StreamConcept to read from.
TSpec The record reader specialization type.

Member Function Overview

Interface Function Overview

Interface Metafunction Overview

Detailed Description

Examples

#include <fstream>
#include <iostream>

#include <seqan/seq_io.h>
#include <seqan/sequence.h>

int main()
{
    seqan::CharString path = SEQAN_PATH_TO_ROOT();
    append(path, "/core/demos/input_output/example.fa");

    // Open file and create RecordReader.
    std::fstream in(toCString(path), std::ios::binary | std::ios::in);
    seqan::RecordReader<std::fstream, seqan::SinglePass<> > reader(in);

    // Read file record-wise.
    seqan::CharString id;
    seqan::Dna5String seq;
    while (!atEnd(reader))
    {
        if (readRecord(id, seq, reader, seqan::Fasta()) != 0)
            return 1;  // Could not read record from file.

        std::cout << id << "\t" << seq << "\n";
    }
    
    return 0;
}

The output is as follows:

one	CGATCGAT
two	TTTTTTTTTTTTTCGATAAAAAAAAAAAAA

Member Functions Detail

RecordReader::RecordReader(); RecordReader::RecordReader(stream[, bufferSize]);

Constructor.

Parameters

stream The StreamConcept to read from.
bufferSize The size of the buffer to use. Type: unsigned.

Interface Functions Detail

bool atEnd(reader);

Returns true if there is no more data to be read.

Parameters

reader The RecordReader to query the state of.

Returns

bool 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 resultCode to get the result to return from your parsing function.

See Also

int countLine(num, reader);

Count characters in a line excluding '\r' and '\n'.

Parameters

num The unsigned to increment.
reader The RecordReader to read from.

Returns

int 0 if there was no error on reading or non-0 if there were errors. A special value is EOF_BEFORE_SUCCESS.

Remarks

This function stops on the beginning of the next line, if there is a next line (even though newline characters are not counted).

Works on ANSI EOL and on Unix EOL.

bool goNext(reader);

Advance to the next position in the stream.

Parameters

reader The RecordReader to advance.

Returns

bool true on success, false on failure.

bool nextIs(reader, tag)

Query whether the next record is of a given type.

Parameters

reader The RecordReader to peek into. Remains unchanged.
tag Tag to select the given record type.

Returns

bool Indicating whether the next record in reader is of type given by tag.

Remarks

The checks are mostly heuristic, mostly looking at one or few characters from reader.

TPosition position(reader);

Returns the current position of the reader.

Parameters

reader The RecordReader to query.

Returns

TPosition The resulting position. Use Position to retrieve.

int read2(OUTPUT, reader, tag);

Reads an entire document from a StreamConcept by the means of a RecordReader.

Parameters

OUTPUT A format-specific value with records, can also be multiple parameters.
reader A RecordReader to read from.
tag A format-specific tag.

Returns

int A return code. 0 on success, non-0 value on error.

Remarks

If not noted otherwise, only a Single-Pass implementation is available for the given format.

int readRecord(OUTPUT, reader, tag);

Reads one records (e.g. a single DNA sequence and its meta data) from a StreamConcept by the means of a RecordReader.

Parameters

OUTPUT A format-specific value for one record, can also be multiple parameters.
reader A RecordReader to read from.
tag A format-specific tag.

Returns

int A return code. 0 on success, non-0 value on error.

Remarks

If not noted otherwise, only a Single-Pass implementation is available for the given format.

int resultCode(reader);

Return current status code of the reader/underlying stream.

Parameters

reader The RecordReader to query for its status code.

Returns

int The status code, 0 for no errors, non-0 value for errors.

void setPosition(reader, pos);

Sets the current position of the reader.

Parameters

reader The RecordReader to set the position of.
pos The position to set.

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 Also

char value(reader);

Return the current value (character) of the reader.

Parameters

reader The RecordReader to read from.

Returns

char The resulting character.

This is undefined if the reader is at the end or an error occured.

Interface Metafunctions Detail

Position<TReader>::Type;

Returns the position tpye to use in position and setPosition.

Template Parameters

TReader The RecordReader to query for its position type.

Returns

Type The resulting position type.