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

CompressMan.cpp

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 compressor manager, which manages the set
00032 // of compressor factories and the (de)compressor instantiation
00033 // process
00034 
00035 #include "CompressMan.hpp"
00036 
00037 
00038 // The global user-compressor manager
00039 CompressMan compressman;
00040 
00041 
00042 //***********************************************************************
00043 
00044 inline void CompressMan::AddCompressFactory(UserCompressorFactory *compressor)
00045    // Adds a new user compressor factory
00046 {
00047    // We need to be a little careful here
00048    // It is possible that the AddCompressFactory is called *before*
00049    // the constructore CompressMan::CompressMan is called
00050    // Therefore, we do some potential initalization of lastref,
00051    // if nexessary:
00052    if(lastref==NULL)
00053       lastref=&compressorlist;
00054 
00055    *lastref=compressor;
00056    lastref=&(compressor->next);
00057    *lastref=NULL;
00058 }
00059 
00060 UserCompressorFactory::UserCompressorFactory()
00061    // The default constructor for adding a new user-compressor factory
00062 {
00063    compressman.AddCompressFactory(this);
00064 }
00065 
00066 //***********************************************************************
00067 //***********************************************************************
00068 
00069 char *FindEndOfParamString(char *str,char *endptr)
00070    // This function analyses the parameter string between 'str' and 'endptr' and finds the
00071    // ending ')' of the parameter string. most importantly, '(' and ')' can occur
00072    // in a nested fashion - thus we keep a parenthesis count.
00073 {
00074    int   parenthesiscount=0;
00075    char  *startptr=str;
00076    char  *saveptr;
00077 
00078    while(str<endptr)
00079    {
00080       switch(*str)
00081       {
00082       case '"':
00083          saveptr=str;
00084          str++;
00085          while(str<endptr)
00086          {
00087             if(*str=='\\')
00088             {
00089                str++;
00090                continue;
00091             }
00092             if(*str=='"')
00093                break;
00094             str++;
00095          }
00096          if(str==endptr)
00097          {
00098             Error("Could not find closing '\"' in string '");
00099             ErrorCont(saveptr,endptr-saveptr);
00100             ErrorCont("'");
00101             Exit();
00102          }
00103          break;
00104 
00105       case '(':
00106          parenthesiscount++;
00107          break;
00108 
00109       case ')':
00110          if(parenthesiscount==0) // We found the closing bracket ?
00111             return str;
00112          parenthesiscount--;
00113          break;
00114       }
00115       str++;
00116    }
00117    Error("Could not find closing parenthesis for parameter '");
00118    ErrorCont(startptr,endptr-startptr);
00119    ErrorCont("'");
00120    Exit();
00121    return NULL;
00122 }
00123 
00124 // We need to keep an external reference to the constant compressor factory,
00125 // so that we can access it directly.
00126 extern UserCompressorFactory *constantcompressfactoryptr;
00127 
00128 //**********************************************************************
00129 
00130 #ifdef XMILL
00131 
00132 UserCompressor *CompressMan::CreateCompressorInstance(char * &compressorname,char *endptr)
00133    // Finds a specific user compressor factory that is specified by
00134    // 'compressorname' (the length is given by 'endptr-compressorname')
00135    // The compressor name might have parameters and after the operation,
00136    // the 'compressorname' is set to the next character following the
00137    // compressor name.
00138 {
00139    char  *ptr1=compressorname,
00140          *ptr2;
00141 
00142    if(*compressorname=='"')
00143       // Do we have a string ??
00144    {
00145       ptr2=ParseString(ptr1,endptr);
00146 
00147       compressorname=ptr2+1;
00148 
00149       return constantcompressfactoryptr->InstantiateCompressor(ptr1,ptr2-ptr1+1);
00150    }
00151 
00152    // First, let's find the end of the compressor name
00153    while(ptr1<endptr)
00154    {
00155       if((*ptr1=='(')||(*ptr1==')')||(*ptr1==',')||
00156          (*ptr1==' ')||(*ptr1=='\n')||(*ptr1=='\r')||(*ptr1=='\t'))
00157          break;
00158       ptr1++;
00159    }
00160 
00161    UserCompressorFactory *compressor=FindCompressorFactory(compressorname,ptr1-compressorname);
00162 
00163    if(compressor==NULL)
00164    {
00165       Error("Compressor '");
00166       ErrorCont(compressorname,ptr1-compressorname);
00167       ErrorCont("' is not defined");
00168       Exit();
00169    }
00170 
00171    // Do we have a parameter coming afterwards ?
00172    if(*ptr1=='(')
00173    {
00174       // Let's find the end of the parameter string
00175       ptr2=FindEndOfParamString(ptr1+1,endptr);
00176 
00177       compressorname=ptr2+1;
00178 
00179       return compressor->InstantiateCompressor(ptr1+1,ptr2-1-ptr1);
00180    }
00181    else
00182    {
00183       compressorname=ptr1;
00184       return compressor->InstantiateCompressor(NULL,0);
00185    }
00186 }
00187 #endif
00188 
00189 //**********************************************************************
00190 
00191 #ifdef XDEMILL
00192 UserUncompressor *CompressMan::CreateUncompressorInstance(char * &compressorname,char *endptr)
00193    // Finds a specific user decompressor factory that is specified by
00194    // 'compressorname' (the length is given by 'endptr-compressorname')
00195    // The compressor name might have parameters and after the operation,
00196    // the 'compressorname' is set to the next character following the
00197    // compressor name.
00198 {
00199    char  *ptr1=compressorname,
00200          *ptr2;
00201 
00202    if(*compressorname=='"')
00203       // Do we have a string ? ==> We must use the constant compressor
00204    {
00205       // Let's find the end of the string
00206       ptr2=ParseString(ptr1,endptr);
00207 
00208       compressorname=ptr2+1;
00209 
00210       return constantcompressfactoryptr->InstantiateUncompressor(ptr1,ptr2-ptr1+1);
00211    }
00212 
00213    // First, let's find the end of the compressor name
00214    while(ptr1<endptr)
00215    {
00216       if((*ptr1=='(')||(*ptr1==')')||(*ptr1==',')||
00217          (*ptr1==' ')||(*ptr1=='\n')||(*ptr1=='\r')||(*ptr1=='\t'))
00218          break;
00219       ptr1++;
00220    }
00221 
00222    // Let's find the compressor factory
00223    UserCompressorFactory *compressor=FindCompressorFactory(compressorname,ptr1-compressorname);
00224 
00225    if(compressor==NULL)
00226    {
00227       Error("Compressor '");
00228       ErrorCont(compressorname,ptr1-compressorname);
00229       ErrorCont("' is not defined");
00230       Exit();
00231    }
00232 
00233    // Do we have a parameter coming afterwards ?
00234    if(*ptr1=='(')
00235    {
00236       ptr2=FindEndOfParamString(ptr1+1,endptr);
00237       
00238       compressorname=ptr2+1;
00239 
00240       return compressor->InstantiateUncompressor(ptr1+1,ptr2-1-ptr1);
00241    }
00242    else
00243    {
00244       compressorname=ptr1;
00245       return compressor->InstantiateUncompressor(NULL,0);
00246    }
00247 }
00248 #endif
00249 
00250 UserCompressorFactory *CompressMan::FindCompressorFactory(char *name,int len)
00251    // Finds a certain user compressor factory with a given name
00252    // If it doesn't find such a compressor, we exit
00253 {
00254    UserCompressorFactory   *compressor=compressorlist;
00255    int                     namelen;
00256 
00257    while(compressor!=NULL)
00258    {
00259       namelen=strlen(compressor->GetName());
00260       if((namelen==len)&&
00261          (memcmp(compressor->GetName(),name,len)==0))
00262          return compressor;
00263       compressor=compressor->next;
00264    }
00265    Error("Could not find compressor '");
00266    ErrorCont(name,len);
00267    ErrorCont("'!");
00268    Exit();
00269    return NULL;
00270 }
00271 
00272 //**********************************************************************
00273 
00274 #ifdef XMILL
00275 
00276 void CompressMan::PrintCompressorInfo()
00277    // Prints information about the compressors
00278 {
00279    UserCompressorFactory   *compressor=compressorlist;
00280    int                     maxnamelen=0,namelen;
00281 
00282    // First, let's determine the longest compressor name
00283    while(compressor!=NULL)
00284    {
00285       namelen=strlen(compressor->GetName());
00286       if(maxnamelen<namelen)
00287          maxnamelen=namelen;
00288 
00289       compressor=compressor->next;
00290    }
00291 
00292    // Now we print each compressor name and its description
00293 
00294    compressor=compressorlist;
00295 
00296    while(compressor!=NULL)
00297    {
00298       printf("    ");
00299       printf(compressor->GetName());
00300       namelen=strlen(compressor->GetName());
00301 
00302       while(namelen<maxnamelen)
00303       {
00304          printf(" ");
00305          namelen++;
00306       }
00307       printf("  - ");
00308       printf(compressor->GetDescription());
00309       printf("\n");
00310 
00311       compressor=compressor->next;
00312    }
00313 }
00314 
00315 //**********************************************************************
00316 //**********************************************************************
00317 
00318 unsigned long CompressMan::GetDataSize()
00319    // Each compressor is allowed to store own data
00320    // This function determines how much space is needed by all user compressors
00321 {
00322    UserCompressorFactory   *compressor=compressorlist;
00323    unsigned long           size=0;
00324 
00325    while(compressor!=NULL)
00326    {
00327       size+=compressor->GetGlobalDataSize();
00328       compressor=compressor->next;
00329    }
00330    return size;
00331 }
00332 
00333 void CompressMan::CompressSmallGlobalData(Compressor *compress)
00334    // Stores own data (only the small pieces!) of the user compressor factories
00335    // in the output stream described by 'compressor'.
00336 {
00337    UserCompressorFactory *compressor=compressorlist;
00338 
00339    while(compressor!=NULL)
00340    {
00341       compressor->CompressSmallGlobalData(compress);
00342       compressor=compressor->next;
00343    }
00344 }
00345 
00346 void CompressMan::CompressLargeGlobalData(Output *output)
00347    // Stores own data (only the large pieces!) of the user compressor factories
00348    // in the output stream described by 'compressor'.
00349 {
00350    UserCompressorFactory *compressor=compressorlist;
00351 
00352    while(compressor!=NULL)
00353    {
00354       compressor->CompressLargeGlobalData(output);
00355       compressor=compressor->next;
00356    }
00357 }
00358 
00359 #endif
00360 
00361 //**********************************************************************
00362 
00363 #ifdef XDEMILL
00364 
00365 void CompressMan::UncompressSmallGlobalData(SmallBlockUncompressor *uncompressor)
00366    // Reads the own (small) data from the source described by 'uncompressor' and
00367    // initializes the user compressor factories.
00368 {
00369    UserCompressorFactory *compressor=compressorlist;
00370 
00371    // Simply iterates over all user compressor factories and
00372    // invokes 'UncompressSmallGlobalData'.
00373    while(compressor!=NULL)
00374    {
00375       compressor->UncompressSmallGlobalData(uncompressor);
00376       compressor=compressor->next;
00377    }
00378 }
00379 
00380 void CompressMan::UncompressLargeGlobalData(Input *input)
00381    // Reads the own (large) data from the source described by 'uncompressor' and
00382    // initializes the user compressor factories.
00383 {
00384    UserCompressorFactory *compressor=compressorlist;
00385 
00386    // Simply iterates over all user compressor factories and
00387    // invokes 'UncompressLargeGlobalData'.
00388 
00389    while(compressor!=NULL)
00390    {
00391       compressor->UncompressLargeGlobalData(input);
00392       compressor=compressor->next;
00393    }
00394 }
00395 
00396 void CompressMan::FinishUncompress()
00397    // This is called after all user compressor data has been decompressed
00398 {
00399    UserCompressorFactory *compressor=compressorlist;
00400 
00401    // Simply iterates over all user compressor factories and
00402    // invokes 'FinishUncompress'.
00403    while(compressor!=NULL)
00404    {
00405       compressor->FinishUncompress();
00406       compressor=compressor->next;
00407    }
00408 }
00409 
00410 void CompressMan::DebugPrint()
00411 {
00412    UserCompressorFactory *compressor=compressorlist;
00413    while(compressor!=NULL)
00414    {
00415       printf("%lu =>",compressor);
00416       printf("%s\n",compressor->GetName());
00417       compressor=compressor->next;
00418    }
00419 }
00420 
00421 #endif

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