ZlibStringCompressor.h

00001 #ifndef SCTARCHIVING_ZLIBSTRINGCOMPRESSOR_H
00002 #define SCTARCHIVING_ZLIBSTRINGCOMPRESSOR_H
00003 #include <zlib.h>
00004 #include <string>
00005 using std::string;
00006 
00007 namespace SctArchiving{
00022 class ZlibStringCompressor{
00023  public:
00027   ZlibStringCompressor(unsigned long bufferSize=0);
00034   const string compress(const string& toCompress, int level);
00040   const string inflate(const string& compressed);
00044   unsigned long getBufferSize();
00048   void setDebugLevel(int level);
00052   int getDebugLevel();
00056   Bytef* setBufferSize(unsigned long size);
00057 private:
00061   static void checkZlibResult(const int result, const char* file, const int line);
00065   long unsigned m_bufferSize;
00066   /*
00067     pointer to start of buffer
00068   */
00069   Bytef* m_buffer;
00073   static unsigned long findSizeInBytes(const string& s);
00078   static unsigned long findRequiredBufferSize(const unsigned long uncompressedSize);
00079   int m_debugLevel;
00080 };
00081 
00082 
00083 inline unsigned long ZlibStringCompressor::findSizeInBytes(const string&s ){
00084   return sizeof(char)*s.size();
00085 }
00086 
00087 // buffer size myst be at least original size + 0.1% + 12 bytes
00088 inline unsigned long ZlibStringCompressor::findRequiredBufferSize(long unsigned unbufferedSize){
00089   return unbufferedSize + unbufferedSize/1000 + 12;
00090 }
00091 
00092 inline void ZlibStringCompressor::setDebugLevel(int level){
00093   m_debugLevel=level;
00094 }
00095 
00096 inline int ZlibStringCompressor::getDebugLevel(){
00097   return m_debugLevel;
00098 }
00099 
00100 }
00101 
00102 #endif //  SCTARCHIVING_ZLIBSTRINGCOMPRESSOR_H

Generated on Mon Feb 6 14:01:37 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6