SctArchiving::ZlibStringCompressor Class Reference

Uses zlib to compress a string into another (hopefully shorter!) string. More...

#include <ZlibStringCompressor.h>


Public Member Functions

 ZlibStringCompressor (unsigned long bufferSize=0)
 constructor, with optional bufferSizeArgument;
const string compress (const string &toCompress, int level)
 Compress a string.
const string inflate (const string &compressed)
 Uncompress a string.
unsigned long getBufferSize ()
 Find the size of the buffer in bytes (for information);.
void setDebugLevel (int level)
 Level of 0 produces no output.
int getDebugLevel ()
 return the value of the debug level.
Bytef * setBufferSize (unsigned long size)
 set the buffer size (in bytes)

Static Private Member Functions

static void checkZlibResult (const int result, const char *file, const int line)
 Check return result number from zlib, throwing InvalidArgument if necessary.
static unsigned long findSizeInBytes (const string &s)
 Find the length in bytes of a string.
static unsigned long findRequiredBufferSize (const unsigned long uncompressedSize)
 Find the minimum buffer size for compresses string.

Private Attributes

long unsigned m_bufferSize
 size in bytes of the buffer
Bytef * m_buffer
int m_debugLevel


Detailed Description

Uses zlib to compress a string into another (hopefully shorter!) string.

Can also extract a compressed string. The extraction step requires a buffer, so the class has an interal buffer, which it increases in size if necessary, to fit the uncompressed string. Sends mrs messages if it encounters problems with zlib. Designed so that a single instance of this class should be re-used many times, so clients should initiate one and then continue to re-use it for best use of the buffering. Note that returned `strings' are actually references to data held in internal buffers.

Note:
the buffer size required for extraction cannot be known in advanced. So the buffer can dynamically increase its size, to allow for bigger `original sized' strings.

Definition at line 22 of file ZlibStringCompressor.h.


Constructor & Destructor Documentation

SctArchiving::ZlibStringCompressor::ZlibStringCompressor unsigned long  bufferSize = 0  ) 
 

constructor, with optional bufferSizeArgument;

Definition at line 12 of file ZlibStringCompressor.cpp.

References setBufferSize().

Here is the call graph for this function:


Member Function Documentation

void SctArchiving::ZlibStringCompressor::checkZlibResult const int  result,
const char *  file,
const int  line
[static, private]
 

Check return result number from zlib, throwing InvalidArgument if necessary.

Definition at line 35 of file ZlibStringCompressor.cpp.

Referenced by compress(), and inflate().

const string SctArchiving::ZlibStringCompressor::compress const string &  toCompress,
int  level
 

Compress a string.

Parameters:
reference to string to compress
gzip compression level 1->9;
Returns:
compressed string (actual string is stored in buffer.)

Definition at line 50 of file ZlibStringCompressor.cpp.

References checkZlibResult(), findRequiredBufferSize(), findSizeInBytes(), getBufferSize(), m_buffer, and setBufferSize().

Here is the call graph for this function:

static unsigned long SctArchiving::ZlibStringCompressor::findRequiredBufferSize const unsigned long  uncompressedSize  )  [static, private]
 

Find the minimum buffer size for compresses string.

Parameters:
uncompressed size

Referenced by compress().

unsigned long SctArchiving::ZlibStringCompressor::findSizeInBytes const string &  s  )  [inline, static, private]
 

Find the length in bytes of a string.

Definition at line 83 of file ZlibStringCompressor.h.

Referenced by compress(), and inflate().

unsigned long SctArchiving::ZlibStringCompressor::getBufferSize  ) 
 

Find the size of the buffer in bytes (for information);.

Definition at line 17 of file ZlibStringCompressor.cpp.

References m_bufferSize.

Referenced by compress(), and inflate().

int SctArchiving::ZlibStringCompressor::getDebugLevel  )  [inline]
 

return the value of the debug level.

Definition at line 96 of file ZlibStringCompressor.h.

References m_debugLevel.

Referenced by setBufferSize().

const string SctArchiving::ZlibStringCompressor::inflate const string &  compressed  ) 
 

Uncompress a string.

Parameters:
reference to compressed string.
Returns:
uncompressed equivalent (actual string is stored in buffer.)

Definition at line 76 of file ZlibStringCompressor.cpp.

References checkZlibResult(), findSizeInBytes(), getBufferSize(), m_buffer, and setBufferSize().

Here is the call graph for this function:

Bytef * SctArchiving::ZlibStringCompressor::setBufferSize unsigned long  size  ) 
 

set the buffer size (in bytes)

Definition at line 21 of file ZlibStringCompressor.cpp.

References getDebugLevel(), m_buffer, and m_bufferSize.

Referenced by compress(), inflate(), and ZlibStringCompressor().

Here is the call graph for this function:

void SctArchiving::ZlibStringCompressor::setDebugLevel int  level  )  [inline]
 

Level of 0 produces no output.

Higher levels produce more output.

Definition at line 92 of file ZlibStringCompressor.h.

References m_debugLevel.


Field Documentation

long unsigned SctArchiving::ZlibStringCompressor::m_bufferSize [private]
 

size in bytes of the buffer

Definition at line 65 of file ZlibStringCompressor.h.

Referenced by getBufferSize(), and setBufferSize().


The documentation for this class was generated from the following files:
Generated on Mon Feb 6 14:05:14 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6