Octane v1.01.20 - The Open Compression Toolkit for C++ | http://octane.sourceforge.net/ |
#include <compressor_statistical.hpp>
Inheritance diagram for OctaneCompressor_Statistical:
Definition at line 39 of file compressor_statistical.hpp.
Public Member Functions | |
OctaneCompressor_Statistical (bool registerme=false) | |
constructor | |
virtual | ~OctaneCompressor_Statistical () |
destructor | |
virtual std::string | GetClassName () |
Get the assigned name of an instantiated compressor. | |
virtual std::string | GetDescription () |
optionally provide a longer (maybe 20-60 characters) description | |
virtual std::string | GetHelpInformation () |
optionally provide more information about the object on request for help | |
virtual void | ShowDebuggingInfo () |
show any debugging info on request (used by various derived classes) [optional] | |
virtual unsigned int | GetMemoryUsed () |
Report actual current memory usage (in bytes). | |
virtual unsigned int | GetDiskspaceUsed (bool fortempdecompressiononly) |
Report disk space (in bytes) that would be used when saving state to file (in bytes). | |
virtual std::string | GetParametersInformation () |
Reports information about any parameters available. | |
virtual void | SetDefaultParameters () |
Reset any parameters to their default values. | |
virtual bool | SetParameter (const std::string ¶metername, const std::string ¶metervalue) |
virtual void | ResetState () |
Reset the state of the compressor to its initial state. | |
virtual void | SynchronizeStateForNewStream () |
Synchronize state for a new stream - this will be called each time before beginning a new parsing stream. | |
virtual bool | PrepareForCompression () |
Prepare for parsing mode, this will be called parsing begins. | |
virtual void | SetupAnyDefaultParser () |
virtual bool | IsReadyToCompress () |
is the compressor ready to compress? Normally this is false until a dictionary is built or loaded. | |
Protected Member Functions | |
virtual bool | DoProtectedCompress (bitreader &from, bitwriter &to) |
This is the member function which does the actual compression, and this is the function that should be subclasses by derived classes. | |
virtual bool | DoProtectedDecompress (bitreader &from, bitwriter &to) |
This is the member function which does the actual decompression, and this is the function that should be subclasses by derived classes. | |
virtual bool | DoProtectedCreateSymbolsAndModelsUsingStream (bitreader &from) |
virtual bool | DoProtectedSaveState (bitwriter &to, bool fortempdecompressiononly) |
This is the member function which does the actual saving of state, and this is the function that should be subclasses by derived classes. | |
virtual bool | DoProtectedLoadState (bitreader &from) |
Protected Attributes | |
OctaneParser * | parserp |
Pointer to the derived (and dynamically allocated) statistical parser. | |
OctaneModeler * | modelerp |
Pointer to the derived (and dynamically allocated) statistical modeler. | |
OctaneCoder * | coderp |
Pointer to the derived (and dynamically allocated) statistical coder. |
|
optionally provide a longer (maybe 20-60 characters) description
Reimplemented from OctaneCompressor. Reimplemented in SampleStatCompressor, and SubStrHuffCompressor. Definition at line 58 of file compressor_statistical.hpp.
00058 {return "Statistical Compressor Base Class";} |
|
optionally provide more information about the object on request for help
Reimplemented from OctaneCompressor. Definition at line 69 of file compressor_statistical.cpp. References coderp, OctaneCoder::GetHelpInformation(), OctaneModeler::GetHelpInformation(), OctaneParser::GetHelpInformation(), modelerp, parserp, and OctaneClass::PrefixNonEmptyString().
00070 { 00071 // show help info from our parser,model,coder 00072 string helpinfo; 00073 00074 // generic help information for children 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 // return amalgamated string 00080 return helpinfo; 00081 } |
|
Reimplemented from OctaneClass. Definition at line 131 of file compressor_statistical.cpp. References coderp, modelerp, parserp, and OctaneClass::SetParameter().
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 } |
|
Prepare for parsing mode, this will be called parsing begins.
Reimplemented from OctaneCompressor. Definition at line 233 of file compressor_statistical.cpp. References coderp, modelerp, parserp, OctaneCoder::PrepareForCoding(), OctaneModeler::PrepareForModeling(), and OctaneParser::PrepareForParsing().
00234 { 00235 // prepare for parsing mode, must be called after zero or more Updating calls, and before parsing begins; returns true on success 00236 bool bretv; 00237 00238 // first prepare the parser (this should ensure we have a valid symbol set) 00239 bretv=parserp->PrepareForParsing(); 00240 // now prepare the model (give it parser info in case it wants it) 00241 if (bretv) 00242 modelerp->PrepareForModeling(parserp); 00243 // now build coder based on modeler 00244 if (bretv) 00245 coderp->PrepareForCoding(modelerp); 00246 00247 // return success 00248 return bretv; 00249 } |
|
now tell the coder that all the weights on symbols have changed Reimplemented from OctaneCompressor. Definition at line 187 of file compressor_statistical.cpp. References coderp, OctaneModeler::CreateModelUsingParser(), OctaneModeler::IsReadyToModel(), OctaneParser::IsReadyToParse(), modelerp, parserp, and OctaneCoder::ReceiveNotification_ModelChange_AllSymbolWeights(). Referenced by SampleStatCompressor::SampleStatCompressor(), and SubStrHuffCompressor::SubStrHuffCompressor().
00188 { 00189 // if a parser starts out ready to parse, we might need to build a model/coder from it 00190 if (parserp->IsReadyToParse()) 00191 { 00192 modelerp->CreateModelUsingParser(parserp); 00193 if (modelerp->IsReadyToModel()) 00194 { 00196 coderp->ReceiveNotification_ModelChange_AllSymbolWeights(modelerp); 00197 } 00198 } 00199 } |
|
is the compressor ready to compress? Normally this is false until a dictionary is built or loaded.
Reimplemented from OctaneCompressor. Definition at line 251 of file compressor_statistical.cpp. References coderp, OctaneCoder::IsReadyToCode(), OctaneModeler::IsReadyToModel(), OctaneParser::IsReadyToParse(), modelerp, and parserp.
00252 { 00253 // is the compressor ready to compress? Normally this is false until a dictionary is built or loaded. 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 } |
|
This is the member function which does the actual compression, and this is the function that should be subclasses by derived classes. It is wrapped by the public API call Compress() which performs some measurements on compression speed and streamsize.
Implements OctaneCompressor. Definition at line 280 of file compressor_statistical.cpp. References OctaneCoder::AlignOutputStreamToByteBoundry(), coderp, modelerp, OctaneParser::ParseNextSymbolFromInput(), parserp, SynchronizeStateForNewStream(), OctaneModeler::UpdateModelAfterReceivingSymbol(), and OctaneCoder::WriteSymbolBits().
00281 { 00282 // compress all of from and send to to 00283 // ATTN: the only thing slightly troubling about this otherwise elegant routine, is the 00284 // fact that there is no way for the components to change the symbol set during compression 00285 bool bretv=true; 00286 int symbolnumber; 00287 00288 // we *must* inform our components that we are about to compress or decompress a new stream 00289 SynchronizeStateForNewStream(); 00290 00291 // loop parsing a symbol from parser until we hit end (note the last symbol will be an End-Of-Stream) 00292 while (parserp->ParseNextSymbolFromInput(from,symbolnumber)) 00293 { 00294 // debug show some info? 00295 // cout << "$READ SYMBOL "<<symbolnumber<<": '"<<parserp->LookupSymbolText(symbolnumber)<<"'."<<endl; 00296 // code the symbol given current model and codes 00297 if (!(bretv=coderp->WriteSymbolBits(symbolnumber,to))) 00298 break; 00299 // now update the model based on this symbol (pass coderp so it can inform it if probabilities change). 00300 // note that for four zero-order model this doesn't do anything, but we call it for completeness. 00301 if (!(bretv=modelerp->UpdateModelAfterReceivingSymbol(symbolnumber,coderp))) 00302 break; 00303 } 00304 00305 // when we finish coding a stream we want to align to byte boundary in the output 00306 // this will happen automatically if we close the output stream now, but we do it manually in case we want to pack multiple 00307 // input streams into the same output. 00308 coderp->AlignOutputStreamToByteBoundry(to); 00309 00310 // return success 00311 return bretv; 00312 } |
|
This is the member function which does the actual decompression, and this is the function that should be subclasses by derived classes. It is wrapped by the public API call Decompress() which performs some measurements on decompression speed and streamsize.
Implements OctaneCompressor. Definition at line 314 of file compressor_statistical.cpp. References OctaneCoder::AlignInputStreamToByteBoundry(), coderp, OctaneCoder::DecodeSymbolFromInput(), modelerp, parserp, SynchronizeStateForNewStream(), OctaneModeler::UpdateModelAfterReceivingSymbol(), and OctaneParser::WriteSymbolText().
00315 { 00316 // decompress all of from and send to to 00317 // ATTN: the only thing slightly troubling about this otherwise elegant routine, is the 00318 // fact that there is no way for the components to change the symbol set during compression 00319 bool bretv=true; 00320 int symbolnumber; 00321 bool isendofstreamsymbol; 00322 00323 // we *must* inform our components that we are about to compress or decompress a new stream 00324 SynchronizeStateForNewStream(); 00325 00326 // loop decoding a symbol from coder until we hit end 00327 while (coderp->DecodeSymbolFromInput(symbolnumber,from)) 00328 { 00329 // debug show some info? 00330 // cout << "$DECODED SYMBOL "<<symbolnumber<<": '"<<parserp->LookupSymbolText(symbolnumber)<<"'."<<endl; 00331 // deParse the symbol given current model and symbol set 00332 if (!(bretv=parserp->WriteSymbolText(to,symbolnumber,isendofstreamsymbol))) 00333 break; 00334 // did we just parse an EOS(end-of-stream) symbol? if so we need to align input to byte boundary (normally its end of file) 00335 if (isendofstreamsymbol) 00336 { 00337 // when we finish coding a stream we want to align to byte boundary in the output 00338 // this will happen automatically if we close the output stream now, but we do it manually in case we want to pack multiple 00339 // input streams into the same output. note that this we will almost always be leaving this loop after this symbol. 00340 coderp->AlignInputStreamToByteBoundry(from); 00341 // cout << "$DEBUG aligning input."<<endl; 00342 } 00343 // now update the model based on this symbol (pass coderp so it can inform it if probabilities change). 00344 // note that for four zero-order model this doesn't do anything, but we call it for completeness. 00345 if (!(bretv=modelerp->UpdateModelAfterReceivingSymbol(symbolnumber,coderp))) 00346 break; 00347 } 00348 00349 // return success 00350 return bretv; 00351 } |
|
now tell the coder that all the weights on symbols have changed Reimplemented from OctaneCompressor. Definition at line 202 of file compressor_statistical.cpp. References coderp, OctaneModeler::CreateModelUsingStream(), OctaneParser::CreateSymbolSetUsingStream(), modelerp, parserp, OctaneCoder::ReceiveNotification_ModelChange_AllSymbolWeights(), bitreader::seek_bit(), and bitreader::tell_bit().
00203 { 00204 // optionally (pre)process an input stream to update/create a symbol set from it; returns true on success 00205 bool bretv; 00206 // build parser symbol set using stream 00207 // HOWEVER this can be a bit tricky, because we have 2 structures (parser and modeler) which may want to process from stream 00208 // so we need to rewind it after the parser gets done with it. 00209 00210 // record starting position of from stream (probably 0) 00211 size_t fromstartpos=from.tell_bit(); 00212 00213 // give it to parser 00214 bretv = parserp->CreateSymbolSetUsingStream(from); 00215 // now build the model using the symbols created by the parser, and again on the stream from 00216 if (bretv) 00217 { 00218 // reset from stream to start 00219 from.seek_bit(fromstartpos); 00220 // now have model process it 00221 bretv = modelerp->CreateModelUsingStream(parserp,from); 00222 if (bretv) 00223 { 00225 coderp->ReceiveNotification_ModelChange_AllSymbolWeights(modelerp); 00226 } 00227 } 00228 00229 // return success 00230 return bretv; 00231 } |
|
This is the member function which does the actual saving of state, and this is the function that should be subclasses by derived classes. It is wrapped by the public API call SaveState() which performs some measurements on speed and streamsize.
Reimplemented from OctaneCompressor. Definition at line 145 of file compressor_statistical.cpp. References coderp, modelerp, parserp, and OctaneClass::SaveState().
00146 { 00147 // save state; returns true on success 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 } |
|
now tell the coder that the modeler (the weights on symbols) have changed Reimplemented from OctaneCompressor. Definition at line 157 of file compressor_statistical.cpp. References coderp, OctaneClass::LoadState(), modelerp, parserp, and OctaneCoder::ReceiveNotification_ModelChange_AllSymbolWeights().
00158 { 00159 // save state; returns true on success 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 } |