next up previous contents index
Next: Block Coder ( BlockCoder Up: Lossless Compression Previous: Coder Pipes ( CoderPipe2   Contents   Index

Automatic Decoder ( AutoDecoder )


An instance C of AutoDecoder can be used for decoding any stream that has been encoded with a LEDA coder or a pipe of LEDA coders. Thus this class is useful if you want to decode a stream and have forgotten which combination of coders you have used to encode it. This class is also helpful if the encoding method is not known at compile-time. Then the decoding method cannot be fixed at compile-time either but it has to be determined at run-time.

#include < LEDA/coding/auto_decoder.h >


In order to facilitate the usage of AutoDecoder with decoding_istream we provide the typedef autodecoding_istream as a shorthand for decoding_istream<AutoDecoder>.


AutoDecoder 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.

AutoDecoder C(const char* src_file_name, const char* tgt_file_name)
    creates an instance C which uses file-streams for input and output.


Standard Operations

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

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

uint32 C.decode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    decodes 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 decoded data the failure flag will be set (see below).

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() puts C in exactly the same state as the default constructor.

bool C.failed() returns true if an error occured.

bool C.finished() returns true if decoding is finished.

string C.get_description() provides a description for C. After decoding this includes a description of the coder that has been used for encoding the stream.

Additional Operations

coder_base* C.get_coder() after decoding this function returns the coder that has actually been used to decode the stream. E.g., if the original source stream has been encoded with an instance of type A0Coder then the function returns an instance of A0Coder.

next up previous contents index
Next: Block Coder ( BlockCoder Up: Lossless Compression Previous: Coder Pipes ( CoderPipe2   Contents   Index