StringCompressor Class Reference

Writes and reads strings to and from bitstreams. More...

#include <StringCompressor.h>

List of all members.

Public Member Functions

 ~StringCompressor ()
 Destructor.
void GenerateTreeFromStrings (unsigned char *input, unsigned inputLength)
void EncodeString (char *input, int maxCharsToWrite, RakNet::BitStream *output)
bool DecodeString (char *output, int maxCharsToWrite, RakNet::BitStream *input)

Static Public Member Functions

static StringCompressorInstance ()
static void AddReference (void)
 Used so I can allocate and deallocate this singleton at runtime.
static void RemoveReference (void)
 Used so I can allocate and deallocate this singleton at runtime.

Private Member Functions

void GenerateHuffmanEncodingTree (void)
 Create the huffman encoding tree (obviously).
 StringCompressor ()
 Private Constructor.

Private Attributes

HuffmanEncodingTreehuffmanEncodingTree
 Pointer to the huffman encoding tree.

Static Private Attributes

static StringCompressorinstance = 0
 Singleton instance.
static int referenceCount = 0
 How many instance of RakPeer have been instantiated.


Detailed Description

Writes and reads strings to and from bitstreams.

Only works with ASCII strings. The default compression is for English. You can call GenerateTreeFromStrings to compress and decompress other languages efficiently as well.


Member Function Documentation

bool StringCompressor::DecodeString char *  output,
int  maxCharsToWrite,
RakNet::BitStream input
 

Writes input to output, uncompressed. Takes care of the null terminator for you.

Parameters:
[out] output A block of bytes to receive the output
[in] maxCharsToWrite Size, in bytes, of output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated.
[in] input The bitstream containing the compressed string

void StringCompressor::EncodeString char *  input,
int  maxCharsToWrite,
RakNet::BitStream output
 

Writes input to output, compressed. Takes care of the null terminator for you.

Parameters:
[in] input Pointer to an ASCII string
[in] maxCharsToWrite The size of input
[out] output The bitstream to write the compressed string to

void StringCompressor::GenerateTreeFromStrings unsigned char *  input,
unsigned  inputLength
 

Given an array of strings, such as a chat log, generate the optimal encoding tree for it. This function is optional and if it is not called a default tree will be used instead.

Parameters:
[in] input An array of bytes which should point to text.
[in] inputLength Length of input

static StringCompressor* StringCompressor::Instance  )  [inline, static]
 

static function because only static functions can access static members

Returns:
the unique instance of the StringCompressor


The documentation for this class was generated from the following files:
Generated on Mon Mar 20 20:32:57 2006 for RakNet by  doxygen 1.4.6-NO