next up previous contents index
Next: Automatic Decoder ( AutoDecoder Up: Lossless Compression Previous: Decoding File Stream (   Contents   Index


Coder Pipes ( CoderPipe2 )

Definition

The type CoderPipe2< Coder1, Coder2 > can be used to combine two coders of type Coder1 and Coder2 into one single coder. This works in an analogous way as a pipe of the operating system: In encoding mode the original input is processed by Coder1. Its output is fed into Coder2. The output of Coder2 becomes the output of the pipe. In decoding mode the situation is reversed: The data is sent through Coder2 first and then through Coder1.

We also provide pipes for combining more than two coders (up to six): CoderPipe3,..., CoderPipe6. (Since these classes have a similar interface as CoderPipe2, we do not include manual pages for them.)

#include < LEDA/coding/coder_util.h >

Types

CoderPipe2< Coder1, Coder2 >::coder1 the type Coder1.

CoderPipe2< Coder1, Coder2 >::coder2 the type Coder2.

Creation

CoderPipe2< Coder1, Coder2 > C(streambuf* src_stream = 0, streambuf* tgt_stream = 0, bool own_streams = false)
    creates an instance C which uses the given source and target streams. If own_streams is set, then C is responsible for the destruction of the streams, otherwise the pointers src_stream and tgt_stream must be valid during the life-time of C.

CoderPipe2< Coder1, Coder2 > C(const char* src_file_name, const char* tgt_file_name)
    creates an instance C which uses file-streams for input and output.

Operations

Standard Operations

void C.encode() encodes the source stream and writes the output to the target stream.

void C.decode() decodes the source stream and writes the output to the target stream.

uint32 C.encode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    encodes the memory chunk starting at in_buf with size in_len into the buffer starting at out_buf with size out_len. The function returns actual length of the encoded chunk which may be smaller than out_len. If the output buffer is too small for the encoded data the failure flag will be set (see below).

uint32 C.decode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    decodes a memory chunk. The meaning of the parameters and the return value is the same as in the previous function.

streambuf* C.get_src_stream() returns the current source stream.

void C.set_src_stream(streambuf* src_stream, bool own_stream = false)
    sets the source stream (cf. constructor).

void C.set_src_file(const char* file_name)
    sets a file as source stream.

streambuf* C.get_tgt_stream() returns the current target stream.

void C.set_tgt_stream(streambuf* tgt_stream, bool own_Stream = false)
    sets the target stream (cf. constructor).

void C.set_tgt_file(const char* file_name)
    sets a file as target stream.

void C.reset(bool keep_parameters = true)
    puts C in the same state as the default constructor. If keep_parameters is false the parameters of all coders in the pipe are set to their default values.

bool C.failed() returns true if an error occured or a checksum in the stream does not match the computed checksum.

bool C.finished() returns true if the coding is finished.

string C.get_description() provides a description for C.

Additional Operations

Coder1* C.get_coder1() returns the currently used instance of Coder1.

void C.set_coder1(Coder1* c1, bool own_coder = false)
    sets the instance of Coder1. If own_coder is true, then the c1 is deleted by C. Otherwise c1 is not deleted by C and the pointer c1 must be valid during the life-time of C.

Coder2* C.get_coder2() returns the currently used instance of Coder2.

void C.set_coder2(Coder2* c2, bool own_coder = false)
    sets the instance of Coder2. The paramter own_coder is explained above.


next up previous contents index
Next: Automatic Decoder ( AutoDecoder Up: Lossless Compression Previous: Decoding File Stream (   Contents   Index