next up previous contents index
Next: Coder Pipes ( CoderPipe2 Up: Lossless Compression Previous: Encoding File Stream (   Contents   Index


Decoding File Stream ( decoding_ifstream )

Definition

The type decoding_ifstream<Coder> is the decoding counterpart of the type ifstream from the C++ iostream library. Each instance is of type decoding_ifstream<Coder> is associated with a file. Whenever data is requested from an instance is of type decoding_ifstream<Coder>, is reads some data from the associated file and then decodes it on-the-fly with an intance of type Coder. All operations and all operators (») defined for C++ istreams can be applied to decoding_ifstream as well.

decoding_ifstream supports random access read operations by providing seek operations. For this purpose it maintains a so-called get pointer. This pointer specifies the position in the decoded data stream from which the next read operation will extract its data. After the operation the get pointer refers to the position immediately behind the last extracted character. E.g., if you are not interested in the first 5000 characters and you want to extract the 10 characters in positions 5000 - 5009, you can perform a seek operation which moves the get pointer to position 5000 and then read 10 characters. (After that the get pointer will refer to position 5010.) This seek operation will usually be faster than skipping 5000 characters by hand.
Seek operations are supported no matter which coder is plugged into decoding_ifstream. However, some coders (like checksummers) provide fast seek operations. This manual mentions these coders explicitly. Moreover, we provide a class called BlockCoder (in Section Block Coder) which allows you to speed up seeks for any coder.

#include < LEDA/coding/coder_util.h >

Creation

decoding_ifstream<Coder> is(const char* file_name = 0, ios::openmode mode = ios::in)
    creates an instance is. If file_name is specified, the stream is attached to the file with the given name.

Operations

bool is.is_open() returns if is is attached to an open file.

void is.open(const char* file_name = 0, ios::openmode mode = ios::in)
    opens a file and attaches is to it.

void is.close() closes the attached file and detaches is from it.

void is.finish() reads till the end of the stream and then closes is. (This is useful if Coder is a checksummer; the checksum is only verified after EOF has been read.)

streampos is.tellg() queries the position of the (internal) get pointer. This pointer determines the position in the (decoded) stream from which the next character is read.

istream& is.seekg(streampos pos) sets the position of the get pointer to pos.

istream& is.seekg(streamoff off, ios::seekdir dir)
    moves the get pointer by off relative to the position determined by dir. dir can be ios::beg (beginning), ios::cur (current position) or ios::end (last position).

Coder* is.get_coder() returns the instance of Coder which is used for decoding.


next up previous contents index
Next: Coder Pipes ( CoderPipe2 Up: Lossless Compression Previous: Encoding File Stream (   Contents   Index