Octane v1.01.20 - The Open Compression Toolkit for C++ | http://octane.sourceforge.net/ |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 //--------------------------------------------------------------------------- 00016 00017 //--------------------------------------------------------------------------- 00018 // recursive header protection 00019 #ifndef HuffmanCoderH 00020 #define HuffmanCoderH 00021 //--------------------------------------------------------------------------- 00022 00023 //--------------------------------------------------------------------------- 00024 // application includes 00025 #include "huffmannodes.hpp" 00026 #include "../coder.hpp" 00027 #include "../../modelers/modeler.hpp" 00028 // system includes 00029 //--------------------------------------------------------------------------- 00030 00031 00032 00033 00034 //--------------------------------------------------------------------------- 00049 class HuffmanCoder : public OctaneCoder 00050 { 00051 protected: 00054 THuffmanNodePriorityQueue symbolsetpq; 00056 vector<HuffNode_Leaf*> symbolvector; 00058 vector<HuffNode_Leaf*>::iterator symbolvector_pos; 00059 public: 00060 //--------------------------------------------------------------------------- 00062 HuffmanCoder() { ; } 00064 virtual ~HuffmanCoder() { ; } 00065 //--------------------------------------------------------------------------- 00066 public: 00067 //--------------------------------------------------------------------------- 00068 // OCTANE PUBLIC API - RTTI FUNCTIONS - these are supported by all derived classes 00069 virtual std::string GetName() {return "HuffmanCoder";} 00070 virtual std::string GetDescription() {return "Huffman Coder";} 00071 virtual std::string GetHelpInformation() { return ""; } 00072 //--------------------------------------------------------------------------- 00073 public: 00074 //--------------------------------------------------------------------------- 00075 // OCTANE PUBLIC API - AUXILIARY FUNCTIONS - these are supported by all derived classes 00076 virtual void ShowDebuggingInfo(); 00077 virtual unsigned int GetMemoryUsed(); 00078 //--------------------------------------------------------------------------- 00079 public: 00080 //--------------------------------------------------------------------------- 00081 // CODER PUBLIC API - PARSING FUNCTIONS 00082 virtual bool WriteSymbolBits(int symbolnum,bitwriter &bw); 00083 virtual bool DecodeSymbolFromInput(int &symbolnum, bitreader &br); 00084 //--------------------------------------------------------------------------- 00085 public: 00086 //--------------------------------------------------------------------------- 00087 // CODER PUBLIC API - STATE PREPARATION 00088 virtual void ResetState() {;}; 00089 virtual void SynchronizeStateForNewStream() {;}; 00090 virtual bool IsReadyToCode() {if (symbolvector.size()>0) return true; else return false;}; 00091 //--------------------------------------------------------------------------- 00092 public: 00093 //--------------------------------------------------------------------------- 00094 // CODER PUBLIC API - MODEL CHANGE NOTIFICATION 00095 virtual void ReceiveNotification_ModelChange_AllSymbolWeights(OctaneModeler *modelerp) {BuildUpdateHuffmanTreeAndBitcodes(modelerp);}; 00096 virtual void ReceiveNotification_ModelChange_SingleSymbolWeight(OctaneModeler *modelerp,int symbolnum) {BuildUpdateHuffmanTreeAndBitcodes(modelerp);}; 00097 //--------------------------------------------------------------------------- 00098 protected: 00099 // priority queue huffman-tree stuff 00101 bool BuildUpdateHuffmanTreeAndBitcodes(OctaneModeler *modelerp); 00103 void TraverseHuffmanTreeBuildBitcodes(); 00105 void FreeSymbols(); 00107 void ShowBitStrings(); 00108 }; 00109 //--------------------------------------------------------------------------- 00110 00111 00112 00113 //--------------------------------------------------------------------------- 00114 #endif 00115 //--------------------------------------------------------------------------- 00116