Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SmallBlockUncompressor Class Reference

#include <SmallUncompress.hpp>

Inheritance diagram for SmallBlockUncompressor::

Uncompressor List of all members.

Public Methods

void UncompressMore (unsigned long *len)
 SmallBlockUncompressor (Input *myinput)
 ~SmallBlockUncompressor ()
void Init ()
unsigned char * GetCurPtr ()
unsigned long GetCurDataSize ()
unsigned char * LoadData (unsigned long len)
unsigned long LoadUInt32 ()
unsigned long LoadSInt32 (char *isneg)
unsigned long LoadString (char **str)

Constructor & Destructor Documentation

SmallBlockUncompressor::SmallBlockUncompressor Input   myinput [inline]
 

Definition at line 113 of file SmallUncompress.hpp.

00114    {
00115       curdatasize=0;
00116       bufsize=0;
00117       input=myinput;
00118       curptr=buf=NULL;
00119    }

SmallBlockUncompressor::~SmallBlockUncompressor   [inline]
 

Definition at line 121 of file SmallUncompress.hpp.

00122    {
00123       if(buf!=NULL)
00124          free(buf);
00125    }


Member Function Documentation

unsigned long SmallBlockUncompressor::GetCurDataSize   [inline]
 

Definition at line 138 of file SmallUncompress.hpp.

00138 {  return curdatasize;  }

unsigned char* SmallBlockUncompressor::GetCurPtr   [inline]
 

Definition at line 137 of file SmallUncompress.hpp.

00137 {  return curptr; }

void SmallBlockUncompressor::Init   [inline]
 

Definition at line 127 of file SmallUncompress.hpp.

00128    {
00129       // We initialize the buffer with a size of 65536L
00130       buf=(unsigned char *)malloc(65536L);
00131       if(buf==0)
00132          ExitNoMem();
00133       bufsize=65536L;
00134       curptr=buf;
00135    }

unsigned char* SmallBlockUncompressor::LoadData unsigned long    len [inline]
 

Definition at line 141 of file SmallUncompress.hpp.

00144    {
00145       unsigned long resultlen=len;
00146 
00147       UncompressMore(&resultlen);
00148       if(resultlen!=len)
00149       {
00150          Error("Corrupt file!");
00151          Exit();
00152       }
00153       curptr+=len;
00154       curdatasize-=len;
00155 
00156       return curptr-len;
00157    }

unsigned long SmallBlockUncompressor::LoadSInt32 char *    isneg [inline]
 

Definition at line 199 of file SmallUncompress.hpp.

00201    {
00202       unsigned long saveval;
00203       if(curdatasize<4)
00204       {
00205          saveval=1;
00206          UncompressMore(&saveval);
00207       }
00208       if(*curptr<128)
00209       {
00210          *isneg=((*curptr & 64) ? 1 : 0);
00211 
00212          curptr++;
00213          curdatasize--;
00214          return (unsigned long)(curptr[-1]&63);
00215       }
00216       else
00217       {
00218          *isneg=((*curptr & 32) ? 1 : 0);
00219 
00220          if(*curptr<192)
00221          {
00222             saveval=2;
00223             UncompressMore(&saveval);
00224             curptr+=2;
00225             curdatasize-=2;
00226             return ((unsigned)(curptr[-2]&31)<<8)+(unsigned)curptr[-1];
00227          }
00228          else
00229          {
00230             saveval=4;
00231             UncompressMore(&saveval);
00232             curptr+=4;
00233             curdatasize-=4;
00234             return   ((unsigned)(curptr[-4]&31)<<24)+
00235                      ((unsigned)curptr[-3]<<16)+
00236                      ((unsigned)curptr[-2]<<8)+
00237                      (unsigned)curptr[-1];
00238          }
00239       }
00240    }

unsigned long SmallBlockUncompressor::LoadString char **    str [inline]
 

Definition at line 242 of file SmallUncompress.hpp.

00247    {
00248       unsigned long len=LoadUInt32();
00249       unsigned long mylen=len;
00250 
00251       UncompressMore(&mylen);
00252       *str=(char *)curptr;
00253       curptr+=len;
00254       curdatasize-=len;
00255       return len;
00256    }

unsigned long SmallBlockUncompressor::LoadUInt32   [inline]
 

Definition at line 159 of file SmallUncompress.hpp.

00161    {
00162       unsigned long saveval;
00163 
00164       if(curdatasize<4)
00165       {
00166          saveval=1;
00167          UncompressMore(&saveval);
00168       }
00169       if(*curptr<128)
00170       {
00171          curptr++;
00172          curdatasize--;
00173          return (unsigned long)curptr[-1];
00174       }
00175       else
00176       {
00177          if(*curptr<192)
00178          {
00179             saveval=2;
00180             UncompressMore(&saveval);
00181             curptr+=2;
00182             curdatasize-=2;
00183             return ((unsigned)(curptr[-2]-128)<<8)+(unsigned)curptr[-1];
00184          }
00185          else
00186          {
00187             saveval=4;
00188             UncompressMore(&saveval);
00189             curptr+=4;
00190             curdatasize-=4;
00191             return   ((unsigned)(curptr[-4]-192)<<24)+
00192                      ((unsigned)curptr[-3]<<16)+
00193                      ((unsigned)curptr[-2]<<8)+
00194                      (unsigned)curptr[-1];
00195          }
00196       }
00197    }

void SmallBlockUncompressor::UncompressMore unsigned long *    len [inline]
 

Definition at line 56 of file SmallUncompress.hpp.

00058    {
00059       if(curdatasize>=*len) // Already enough data in the buffer?
00060          return;
00061 
00062       if(*len>bufsize)
00063          // Do we need more space than we have in the buffer?
00064       {
00065          // We take 'len' as the new buffer size.
00066 
00067          // But we allocate at least 30000 bytes!
00068          if(*len<30000)
00069             *len=30000;
00070 
00071          unsigned char *newbuf=(unsigned char *)malloc(*len);
00072          if(newbuf==NULL)
00073             ExitNoMem();
00074 
00075          // Copy the already existing data
00076          if(curdatasize>0)
00077             memcpy(newbuf,curptr,curdatasize);
00078 
00079          if(buf!=NULL)  // Release the old buffer
00080             free(buf);
00081 
00082          bufsize=*len;
00083          buf=newbuf;
00084          curptr=newbuf;
00085       }
00086       else
00087       {
00088          // We have enough space in the buffer
00089          // ==> Move existing data to the beginning
00090          if(curdatasize>0)
00091             memmove(buf,curptr,curdatasize);
00092 
00093          curptr=buf;
00094       }
00095 
00096       // Now we can load more data from the decompressor
00097       // and store it in the buffer
00098 
00099       // We try to read as mu
00100       unsigned long maxlen=bufsize-curdatasize;
00101 
00102       Uncompress(input,buf+curdatasize,&maxlen);
00103 
00104       curdatasize+=maxlen;
00105 
00106       // We didn't read everything that was requested?
00107       if(curdatasize<*len)
00108          *len=curdatasize;
00109    }


The documentation for this class was generated from the following file:
Generated on Sat Oct 13 16:08:55 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001