next up previous contents index
Next: CRC32 Checksum ( CRC32Coder Up: Lossless Compression Previous: RLE for Runs of   Contents   Index


Checksummers ( checksummer_base )

Definition

The class checksummer_base is the base class for all LEDA checksummers. It cannot be instantiated. In order to avoid repeating this documentation for each derived class below we will discuss its members here.

When a checksummer is used in encoding mode it can add checksums to the output stream. This is controlled by the checksums_in_stream flag. If this flag is set and the block size is zero (default setting) then one checksum is appended at the end of the stream. If the flag is switched on and the block size b is positive then a checksum is written for every block of b characters.
When the checksummer is used in decoding mode this flag specifies whether the source stream contains checksums. If so, they will be compared against the computed checksum for the stream (or for the respective block if the block size is positive).

If you use a checksummer in a coder pipe (cf. Section Coder Pipes) then it should be the first coder in the pipe. This ensures that the checksum is computed for the original input.
Finally, we want to point out that all checksummers provide fast seek operations (cf. Section Decoding File Stream).

#include < LEDA/coding/checksum.h >

Creation

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

checksummer_base C(const char* src_file_name, const char* tgt_file_name = 0)
    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 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

string C.check() checks the source stream and returns the computed checksum. No target stream needs to be set. (If a target stream is set, check coincides with decode).

bool C.checksum_is_valid() returns whether C has a valid checksum.

string C.get_checksum_as_hex_string()
    returns the checksum for the stream that has been processed last as hexadecimal string.

string C.check(string str) computes a checksum for a string. (Sets source and target stream to nil.)

void C.set_checksums_in_stream_flag(bool sums_in_stream, uint32 blocksize = 0)
    sets the checksums_in_stream flag and the block size.

bool C.get_checksums_in_stream_flag()
    returns the checksums_in_stream flag.

uint32 C.get_block_size() returns the current block size.


next up previous contents index
Next: CRC32 Checksum ( CRC32Coder Up: Lossless Compression Previous: RLE for Runs of   Contents   Index
root 2008-01-09