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

UnCompCont.hpp

Go to the documentation of this file.
00001 /*
00002 This product contains certain software code or other information
00003 ("AT&T Software") proprietary to AT&T Corp. ("AT&T").  The AT&T
00004 Software is provided to you "AS IS".  YOU ASSUME TOTAL RESPONSIBILITY
00005 AND RISK FOR USE OF THE AT&T SOFTWARE.  AT&T DOES NOT MAKE, AND
00006 EXPRESSLY DISCLAIMS, ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND
00007 WHATSOEVER, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00008 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WARRANTIES OF
00009 TITLE OR NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS, ANY
00010 WARRANTIES ARISING BY USAGE OF TRADE, COURSE OF DEALING OR COURSE OF
00011 PERFORMANCE, OR ANY WARRANTY THAT THE AT&T SOFTWARE IS "ERROR FREE" OR
00012 WILL MEET YOUR REQUIREMENTS.
00013 
00014 Unless you accept a license to use the AT&T Software, you shall not
00015 reverse compile, disassemble or otherwise reverse engineer this
00016 product to ascertain the source code for any AT&T Software.
00017 
00018 (c) AT&T Corp. All rights reserved.  AT&T is a registered trademark of AT&T Corp.
00019 
00020 ***********************************************************************
00021 
00022 History:
00023 
00024       24/11/99  - initial release by Hartmut Liefke, liefke@seas.upenn.edu
00025                                      Dan Suciu,      suciu@research.att.com
00026 */
00027 
00028 //**************************************************************************
00029 //**************************************************************************
00030 
00031 // This module contains the container manager for the decompressor
00032 
00033 #include "Load.hpp"
00034 #include "MemStreamer.hpp"
00035 #include "VPathExprMan.hpp"
00036 
00037 extern MemStreamer blockmem;
00038 
00039 class VPathExpr;
00040 class Input;
00041 class UserUncompressor;
00042 
00043 class UncompressContainer
00044    // This class represents a single decompressor container
00045    // Each decompressor container has a fixed pointer to some data space
00046    // that contains the data
00047 {
00048    unsigned char        *dataptr;   // The pointer to the data
00049    unsigned long        size;       // The size of the container
00050    unsigned char        *curptr;    // The current position in the container
00051 
00052 public:
00053 
00054    void *operator new(size_t size)  {  return blockmem.GetByteBlock(size); }
00055    void operator delete(void *ptr)  {}
00056 
00057    void SetSize(unsigned long mysize)
00058       // This sets the initial size - the memory is allocated later
00059       // and the data is loaded later
00060    {
00061       dataptr=curptr=NULL;
00062       size=mysize;
00063    }
00064    unsigned long GetSize() {  return size;   }
00065 
00066    void AllocateContMem(unsigned long mincontsize);
00067       // Allocates the memory - but only if the size is larger than 'mincontsize'
00068       // This will allows us to allocate memory starting with the largest
00069       // containers. Then, smaller containers can be allocated.
00070 
00071    void ReleaseContMem();
00072       // Releases the container manager
00073 
00074       // Decompresses the container data and stores
00075       // it in the data buffer
00076    void UncompressSmallContainer(SmallBlockUncompressor *uncompressor);
00077    void UncompressLargeContainer(Input *input);
00078 
00079    unsigned char *GetDataPtr()   {  return curptr; }
00080 
00081    unsigned char *GetDataPtr(int len)
00082    {
00083       curptr+=len;
00084       return curptr-len;
00085    }
00086 
00087    // Some auxiliary functions for reading integers and strings
00088    unsigned long LoadUInt32()
00089    {
00090       return ::LoadUInt32(curptr);
00091    }
00092 
00093    unsigned long LoadSInt32(char *isneg)
00094    {
00095       return ::LoadSInt32(curptr,isneg);
00096    }
00097 
00098    long LoadSInt32()
00099    {
00100       char isneg;
00101       long val=::LoadSInt32(curptr,&isneg);
00102       if(isneg)
00103          return 0L-val;
00104       else
00105          return val;
00106    }
00107 
00108    char LoadChar()
00109    {
00110       return ::LoadChar(curptr);
00111    }
00112 
00113    unsigned char *LoadString(unsigned *len)
00114    {
00115       *len=LoadUInt32();
00116 
00117       curptr+=*len;
00118       return curptr-*len;
00119    }
00120 };
00121 
00122 //**************************************************************************
00123 //**************************************************************************
00124 
00125 class UncompressContainerBlock
00126    // Containers a grouped in container blocks
00127    // Each container block has a path expression (with user decompressor)
00128    // that takes care of the decompression
00129 {
00130    VPathExpr            *pathexpr;  // The path expression
00131    UncompressContainer  *contarray; // The array of containers
00132    unsigned long        contnum;    // The number of containers in the array
00133 
00134    // Note: The state space for the user compressor is stored *directly*
00135    // after the container array space !
00136 
00137 public:
00138 
00139    void *operator new(size_t size)  {  return blockmem.GetByteBlock(size); }
00140    void operator delete(void *ptr)  {}
00141 
00142    void Load(SmallBlockUncompressor *uncompressor);
00143       // Loads the container block information (number+size of containers)
00144       // from the small decompressor object
00145 
00146    void AllocateContMem(unsigned long mincontsize);
00147       // Allocates the memory for those containers with size>mincontsize
00148    void ReleaseContMem();
00149       // Release the container memory
00150 
00151       // Decompresses the container data and stores
00152       // it in the containers
00153    void UncompressSmallContainers(SmallBlockUncompressor *uncompressor);
00154    void UncompressLargeContainers(Input *input);
00155 
00156    UncompressContainer  *GetContainer(unsigned idx)   {  return contarray+idx;   }
00157 
00158    UserUncompressor *GetUserUncompressor()
00159    {
00160       return pathexpr->GetUserUncompressor();
00161    }
00162 
00163    char *GetUserDataPtr()
00164       // Returns the pointer to the user decompressor state data
00165    {
00166       return (char *)(contarray+contnum);
00167    }
00168 
00169    void Init()
00170       // Initializes the decompress container block
00171       // This initializes the decompressor state data
00172    {
00173       if(pathexpr!=NULL)
00174          GetUserUncompressor()->InitUncompress(GetContainer(0),GetUserDataPtr());
00175    }
00176 
00177    void UncompressText(XMLOutput *output)
00178       // Decompresses a text item and prints it to 'output'
00179    {
00180       GetUserUncompressor()->UncompressItem(GetContainer(0),GetUserDataPtr(),output);
00181    }
00182 
00183    void FinishUncompress()
00184       // After all items have been read, this function cleans
00185       // up the user decompressor states
00186    {
00187       if(pathexpr!=NULL)
00188          pathexpr->GetUserUncompressor()->FinishUncompress(GetContainer(0),GetUserDataPtr());
00189    }
00190 };
00191 
00192 class UncompressContainerMan
00193    // The decompressor container manager handles the set of container blocks
00194    // and their containers
00195 {
00196    UncompressContainerBlock   *blockarray;   // The array of container blocks
00197    unsigned long              blocknum;      // The number of container blocks
00198 
00199 public:
00200    void Load(SmallBlockUncompressor *uncompress);
00201       // Loads the structural information from the small block decompressor
00202 
00203    void AllocateContMem();
00204       // Allocates the memory for the container sequentially.
00205       // Loads the container block information (number+size+structure of container blocks)
00206       // from the small decompressor object
00207       // This function starts with large containers and then allocates
00208       // memory for smaller containers
00209 
00210    void ReleaseContMem();
00211       // Release the container memory
00212 
00213       // Decompresses the container data and stores
00214       // it in the containers
00215    void UncompressLargeContainers(Input *input);
00216    void UncompressSmallContainers(SmallBlockUncompressor *uncompressor);
00217 
00218    void Init();   // Initializes the state data for all container blocks
00219 
00220    UncompressContainerBlock  *GetContBlock(unsigned idx)   {  return blockarray+idx;   }
00221 
00222    void FinishUncompress();
00223       // Finishes the decompression
00224 };

Generated on Sat Oct 13 16:08:41 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001