00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "compressor_statistical.hpp"
00017
00018 using namespace std;
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 OctaneCompressor_Statistical::OctaneCompressor_Statistical(bool registerme)
00033 :OctaneCompressor(registerme)
00034 {
00035
00036 parserp=NULL;
00037 modelerp=NULL;
00038 coderp=NULL;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 }
00049
00050 OctaneCompressor_Statistical::~OctaneCompressor_Statistical()
00051 {
00052
00053
00054 if (coderp!=NULL)
00055 delete coderp;
00056 if (modelerp!=NULL)
00057 delete modelerp;
00058 if (parserp!=NULL)
00059 delete parserp;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069 string OctaneCompressor_Statistical::GetHelpInformation()
00070 {
00071
00072 string helpinfo;
00073
00074
00075 helpinfo += PrefixNonEmptyString("Parser Help:\n-------------------------\n",parserp->GetHelpInformation());
00076 helpinfo += PrefixNonEmptyString("Modeler Help:\n-------------------------\n",modelerp->GetHelpInformation());
00077 helpinfo += PrefixNonEmptyString("Coder Help:\n-------------------------\n",coderp->GetHelpInformation());
00078
00079
00080 return helpinfo;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089 void OctaneCompressor_Statistical::ShowDebuggingInfo()
00090 {
00091
00092 parserp->ShowDebuggingInfo();
00093 modelerp->ShowDebuggingInfo();
00094 coderp->ShowDebuggingInfo();
00095 }
00096
00097 unsigned int OctaneCompressor_Statistical::GetMemoryUsed()
00098 {
00099
00100 return (unsigned int)(sizeof(this)+parserp->GetMemoryUsed()+modelerp->GetMemoryUsed()+coderp->GetMemoryUsed());
00101 }
00102
00103 unsigned int OctaneCompressor_Statistical::GetDiskspaceUsed(bool fortempdecompressiononly)
00104 {
00105
00106 return (parserp->GetDiskspaceUsed(fortempdecompressiononly)+modelerp->GetDiskspaceUsed(fortempdecompressiononly)+coderp->GetDiskspaceUsed(fortempdecompressiononly));
00107 }
00108
00109 std::string OctaneCompressor_Statistical::GetParametersInformation()
00110 {
00111
00112 string parameterinfo;
00113
00114
00115 parameterinfo += PrefixNonEmptyString("Parser Parameters:\n-------------------------\n",parserp->GetParametersInformation());
00116 parameterinfo += PrefixNonEmptyString("Modeler Parameters:\n-------------------------\n",modelerp->GetParametersInformation());
00117 parameterinfo += PrefixNonEmptyString("Coder Parameters:\n-------------------------\n",coderp->GetParametersInformation());
00118
00119
00120 return parameterinfo;
00121 }
00122
00123 void OctaneCompressor_Statistical::SetDefaultParameters()
00124 {
00125
00126 parserp->SetDefaultParameters();
00127 modelerp->SetDefaultParameters();
00128 coderp->SetDefaultParameters();
00129 }
00130
00131 bool OctaneCompressor_Statistical::SetParameter(const std::string ¶metername,const std::string ¶metervalue)
00132 {
00135 bool bretv;
00136
00137 bretv=parserp->SetParameter(parametername,parametervalue);
00138 if (!bretv)
00139 bretv=modelerp->SetParameter(parametername,parametervalue);
00140 if (!bretv)
00141 bretv=coderp->SetParameter(parametername,parametervalue);
00142 return bretv;
00143 }
00144
00145 bool OctaneCompressor_Statistical::DoProtectedSaveState(bitwriter &to,bool fortempdecompressiononly)
00146 {
00147
00148 bool bretv;
00149 bretv=parserp->SaveState(to,fortempdecompressiononly);
00150 if (bretv)
00151 bretv=modelerp->SaveState(to,fortempdecompressiononly);
00152 if (bretv)
00153 bretv=coderp->SaveState(to,fortempdecompressiononly);
00154 return bretv;
00155 }
00156
00157 bool OctaneCompressor_Statistical::DoProtectedLoadState(bitreader &from)
00158 {
00159
00160 bool bretv;
00161 bretv=parserp->LoadState(from);
00162 if (bretv)
00163 bretv=modelerp->LoadState(from);
00164 if (bretv)
00165 {
00166 bretv=coderp->LoadState(from);
00168 coderp->ReceiveNotification_ModelChange_AllSymbolWeights(modelerp);
00169 }
00170 return bretv;
00171 }
00172
00173
00174
00175
00176
00177
00178 void OctaneCompressor_Statistical::ResetState()
00179 {
00180
00181 parserp->ResetState();
00182 modelerp->ResetState();
00183 coderp->ResetState();
00184 }
00185
00186
00187 void OctaneCompressor_Statistical::SetupAnyDefaultParser()
00188 {
00189
00190 if (parserp->IsReadyToParse())
00191 {
00192 modelerp->CreateModelUsingParser(parserp);
00193 if (modelerp->IsReadyToModel())
00194 {
00196 coderp->ReceiveNotification_ModelChange_AllSymbolWeights(modelerp);
00197 }
00198 }
00199 }
00200
00201
00202 bool OctaneCompressor_Statistical::DoProtectedCreateSymbolsAndModelsUsingStream(bitreader &from)
00203 {
00204
00205 bool bretv;
00206
00207
00208
00209
00210
00211 size_t fromstartpos=from.tell_bit();
00212
00213
00214 bretv = parserp->CreateSymbolSetUsingStream(from);
00215
00216 if (bretv)
00217 {
00218
00219 from.seek_bit(fromstartpos);
00220
00221 bretv = modelerp->CreateModelUsingStream(parserp,from);
00222 if (bretv)
00223 {
00225 coderp->ReceiveNotification_ModelChange_AllSymbolWeights(modelerp);
00226 }
00227 }
00228
00229
00230 return bretv;
00231 }
00232
00233 bool OctaneCompressor_Statistical::PrepareForCompression()
00234 {
00235
00236 bool bretv;
00237
00238
00239 bretv=parserp->PrepareForParsing();
00240
00241 if (bretv)
00242 modelerp->PrepareForModeling(parserp);
00243
00244 if (bretv)
00245 coderp->PrepareForCoding(modelerp);
00246
00247
00248 return bretv;
00249 }
00250
00251 bool OctaneCompressor_Statistical::IsReadyToCompress()
00252 {
00253
00254 bool bretv1,bretv2,bretv3;
00255
00256 if (!(bretv1=parserp->IsReadyToParse()))
00257 cout << "the parser is not ready."<<endl;
00258 if (!(bretv2=modelerp->IsReadyToModel()))
00259 cout << "the modeler is not ready."<<endl;
00260 if (!(bretv3=coderp->IsReadyToCode()))
00261 cout << "the coder is not ready."<<endl;
00262 return (bretv1 && bretv2 && bretv3);
00263 }
00264
00265 void OctaneCompressor_Statistical::SynchronizeStateForNewStream()
00266 {
00267
00268
00269 parserp->SynchronizeStateForNewStream();
00270 modelerp->SynchronizeStateForNewStream();
00271 coderp->SynchronizeStateForNewStream();
00272 }
00273
00274
00275
00276
00277
00278
00279
00280 bool OctaneCompressor_Statistical::DoProtectedCompress(bitreader &from, bitwriter &to)
00281 {
00282
00283
00284
00285 bool bretv=true;
00286 int symbolnumber;
00287
00288
00289 SynchronizeStateForNewStream();
00290
00291
00292 while (parserp->ParseNextSymbolFromInput(from,symbolnumber))
00293 {
00294
00295
00296
00297 if (!(bretv=coderp->WriteSymbolBits(symbolnumber,to)))
00298 break;
00299
00300
00301 if (!(bretv=modelerp->UpdateModelAfterReceivingSymbol(symbolnumber,coderp)))
00302 break;
00303 }
00304
00305
00306
00307
00308 coderp->AlignOutputStreamToByteBoundry(to);
00309
00310
00311 return bretv;
00312 }
00313
00314 bool OctaneCompressor_Statistical::DoProtectedDecompress(bitreader &from, bitwriter &to)
00315 {
00316
00317
00318
00319 bool bretv=true;
00320 int symbolnumber;
00321 bool isendofstreamsymbol;
00322
00323
00324 SynchronizeStateForNewStream();
00325
00326
00327 while (coderp->DecodeSymbolFromInput(symbolnumber,from))
00328 {
00329
00330
00331
00332 if (!(bretv=parserp->WriteSymbolText(to,symbolnumber,isendofstreamsymbol)))
00333 break;
00334
00335 if (isendofstreamsymbol)
00336 {
00337
00338
00339
00340 coderp->AlignInputStreamToByteBoundry(from);
00341
00342 }
00343
00344
00345 if (!(bretv=modelerp->UpdateModelAfterReceivingSymbol(symbolnumber,coderp)))
00346 break;
00347 }
00348
00349
00350 return bretv;
00351 }
00352