CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
Public Types | Public Member Functions

claw::lzw_encoder< InputBuffer, OutputBuffer > Class Template Reference

A class to help encoding a stream with Lempel-Ziv-Welch (LZW) compression algorithm. More...

#include <lzw_encoder.hpp>

List of all members.

Public Types

typedef InputBuffer input_buffer_type
 The type of the input buffer.
typedef OutputBuffer output_buffer_type
 The type of the output buffer.

Public Member Functions

void encode (input_buffer_type &input, output_buffer_type &output) const
 Encode a sequence of datas.

Detailed Description

template<typename InputBuffer, typename OutputBuffer>
class claw::lzw_encoder< InputBuffer, OutputBuffer >

A class to help encoding a stream with Lempel-Ziv-Welch (LZW) compression algorithm.

Template parameters:

The InputBuffer type must have the following methods:

The OutputBuffer type must have the following methods:

Author:
Julien Jorge

Definition at line 60 of file lzw_encoder.hpp.


Member Typedef Documentation

template<typename InputBuffer , typename OutputBuffer >
typedef InputBuffer claw::lzw_encoder< InputBuffer, OutputBuffer >::input_buffer_type

The type of the input buffer.

Definition at line 64 of file lzw_encoder.hpp.

template<typename InputBuffer , typename OutputBuffer >
typedef OutputBuffer claw::lzw_encoder< InputBuffer, OutputBuffer >::output_buffer_type

The type of the output buffer.

Definition at line 67 of file lzw_encoder.hpp.


Member Function Documentation

template<typename InputBuffer , typename OutputBuffer >
void claw::lzw_encoder< InputBuffer, OutputBuffer >::encode ( input_buffer_type input,
output_buffer_type output 
) const

Encode a sequence of datas.

Parameters:
inputWhere we read the uncompressed data.
outputWhere we write compressed data.

Definition at line 16 of file lzw_encoder.tpp.

{
  typedef std::pair<unsigned int, unsigned int> word;

  if ( !input.end_of_data() )
    {
      std::map<word, unsigned int> table;
      
      unsigned int symbol = input.get_next();
      unsigned int prefix_code = symbol;
      unsigned int next_code = input.symbols_count();

      while ( !input.end_of_data() && (next_code != output.max_code()) )
        {
          symbol = input.get_next();

          word new_word(prefix_code, symbol);

          if ( table.find(new_word) != table.end() )
            prefix_code = table[new_word];
          else
            {
              output.write(prefix_code);
              output.new_code(next_code);
              table[new_word] = next_code;
              prefix_code = symbol;

              ++next_code;
            }
        }

      output.write(prefix_code);
    }
} // lzw_encoder::encode()

The documentation for this class was generated from the following files: