Concept StreamConcept
Concept for I/O streams.

Defined in <seqan/stream.h>
Signature concept StreamConcept;

Interface Function Overview

Interface Metafunction Overview

Interface Functions Detail

bool streamEof(stream);

Check end-of-file state of a StreamConcept.

Parameters

stream The stream object to check.

Returns

bool true if the stream is in end-of-file state, false otherwise.

Remarks

Note that the exact behaviour depends on the underlying implementation. With FILE * streams, the stream can be in the end-of-file state from the point where the last character was read or from the point where the user tried to read beyond the end of the file.

int streamError(stream);

Return the stream's error code.

Parameters

stream The stream object to query.

Returns

int An error code, 0 is used for "no errors."

int streamFlush(stream);

Flush the underlying stream.

Parameters

stream The stream object to flush.

Returns

int with an error code, 0 on success.

int streamPeek(c, stream);

Read next character from stream without advancing current position.

Parameters

c The read character is written here. Type: char &.
stream The stream object to read from.

Returns

int 0 on success, otherwise the error value from the underlying string system.

Remarks

Note that this might involve two calls into the stream library, e.g. for cstdio streams, it involves a call to both getc() and ungetc().

See Also

int streamPut(stream, source);

Write different types to stream

Parameters

stream The stream object to write to. Types: StreamConcept
source The data to write to the stream.

Returns

int A status code, 0 on success, non-0 value on errors.

Remarks

Implementation note: for some specializations of StreamConcept certain conversions take place through stringstream and a buffer of size 1023. It follows that the result of the conversion cannot be longer. However this should only effect numericals right now. If you still encounter truncated strings with another type, convert to const char* manually before writing.

See Also

TSize streamReadBlock(target, stream, maxLen)

Read a block of bytes into a buffer.

Parameters

maxLen maximal number of characters to read (size_t).
target The buffer to read into. There has to be enough space for maxLen bytes (char *).
stream The stream to read from.

Returns

TSize Number of read bytes (Metafunction: Size).

Examples

Copying data from a std::fstream into another std::fstream using SeqAn's stream adaption.

#include <fstream>
#include <seqan/sequence.h>
#include <seqan/stream.h>
 
int main()
{
    std::fstream in("in.txt", std::ios::binary | std::ios::in);
    std::fstream out("out.txt", std::ios::binary | std::ios::in);
 
    seqan::CharString buffer;
    resize(buffer, 1000);
 
    while (!seqan::atEnd(in) && seqan::streamError(in) == 0)
    {
        int num = seqan::streamReadBlock(&buffer[0], in, length(buffer));
        seqan::streamWriteBlock(out, &buffer[0], num);
    }
 
    return 0;
}

See Also

int streamReadChar(c, stream);

Read next character from stream and advance the current position.

Parameters

c The read character is written here. Types: char &
stream The stream object to read from.

Returns

TReturn int, 0 on success, otherwise the error value from the underlying string system.

See Also

int streamSeek(stream, delta, origin);

Perform a seek operation on the stream.

Parameters

stream The stream object to seek on.
delta The (relative) position. Type: __int64
origin Where to seek from, we use the integers from <cstdio>. Possible values are SEEK_SET, SEEK_CUR, and SEEK_END. Type: int

Returns

int A status code, 0 on success, non-0 value on errors.

See Also

TPos streamTell(stream);

Get the position in the current stream.

Parameters

stream The stream object to query the current position for.

Returns

TPos The position within the stream.

See Also

TReturn streamWriteBlock(stream, source, count);

Write a block of bytes from a buffer into a stream.

Parameters

stream The stream object to write to. Types: StreamConcept
source The data to write to the stream. Types: nolink:char *
count The number of bytes to write to the stream.

Returns

TSize The number of successfully written objects (Metafunction: Size).

Examples

Copying data from a std::fstream into another std::fstream using SeqAn's stream adaption.

#include <fstream>
#include <seqan/sequence.h>
#include <seqan/stream.h>
 
int main()
{
    std::fstream in("in.txt", std::ios::binary | std::ios::in);
    std::fstream out("out.txt", std::ios::binary | std::ios::in);
 
    seqan::CharString buffer;
    resize(buffer, 1000);
 
    while (!seqan::atEnd(in) && seqan::streamError(in) == 0)
    {
        int num = seqan::streamReadBlock(&buffer[0], in, length(buffer));
        seqan::streamWriteBlock(out, &buffer[0], num);
    }
 
    return 0;
}

See Also

int streamWriteChar(stream, c);

Write one character to the stream.

Parameters

stream The stream object to write to.
c The character to write to the stream. Types: char

Returns

int Error code, 0 on success.

See Also

write2(stream, DOCUMENT, tag);

Writes an entire document to a StreamConcept.

Parameters

stream The Stream object to write to. Types: StreamConcept
DOCUMENT Format specific possibly multiple StringSets (e.g. of meta and sequences).
tag The file format tag

Status

Should be renamed to "write" once the old IO-Code is removed

See Also

int writeRecord(stream, RECORD, tag);

Write one record (e.g. a single DNA-sequence and its meta data) to a StreamConcept

Parameters

RECORD possibly multiple fields (e.g. meta and sequence)
tag The file format tag
stream The Stream object to write to. Type: StreamConcept

Returns

int An integer with the status code (0 on success).

See Also

Interface Metafunctions Detail

HasStreamFeature<TStream, TTag>::Type;

Query features of a stream type.

Template Parameters

TStream The strema type to query the property of.
TTag A tag to select a feature.

Returns

Type Either True or False.

Remarks

Note that this only checks whether the type principally has this feature. For example, if a stream wraps a Unix pipe internally, seek might always fail.

Size<TStream>::Type;

Return the size type for a stream.

Template Parameters

TStream The stream to query for its size type.

Returns

Type The size type of TStream.