📄 compress.hpp
字号:
virtual bool Close(void) = 0;protected: TFile m_File; // File handler EMode m_Mode; // File open mode};////////////////////////////////////////////////////////////////////////////////// CCompressionProcessor -- abstract base class//// Contains a functions for service a compression/decompression session.//class NCBI_XUTIL_EXPORT CCompressionProcessor{public: // Type of the result of all basic functions enum EStatus { // Everything is fine, no errors occurred eStatus_Success, // Special case of eStatus_Success. // Logical end of (compressed) stream is detected, no errors occurred. // All subsequent inquiries about data processing should be ignored. eStatus_EndOfData, // Error has occurred. The error code can be acquired by GetLastError. eStatus_Error, // Output buffer overflow - not enough output space. // Buffer must be emptied and the last action repeated. eStatus_Overflow }; // 'ctors CCompressionProcessor(void); virtual ~CCompressionProcessor(void); // Return compressor's busy flag. If returns value is true that // the current compression object already have being use in other // compression session. bool IsBusy(void) const; // Return number of processed/output bytes. unsigned long GetProcessedSize(void); unsigned long GetOutputSize(void);protected: // Initialize the internal stream state for compression/decompression. // It does not perform any compression, this will be done by Process(). virtual EStatus Init(void) = 0; // Compress/decompress as much data as possible, and stops when the input // buffer becomes empty or the output buffer becomes full. It may // introduce some output latency (reading input without producing any // output). virtual EStatus Process (const char* in_buf, // [in] input buffer unsigned long in_len, // [in] input data length char* out_buf, // [in] output buffer unsigned long out_size, // [in] output buffer size unsigned long* in_avail, // [out] count unproc.bytes in input buffer unsigned long* out_avail // [out] count bytes putted into out buffer ) = 0; // Flush compressed/decompressed data from the output buffer. // Flushing may degrade compression for some compression algorithms // and so it should be used only when necessary. virtual EStatus Flush (char* out_buf, // [in] output buffer unsigned long out_size, // [in] output buffer size unsigned long* out_avail // [out] count bytes putted into out buffer ) = 0; // Finish the compression/decompression process. // Process pending input, flush pending output. // This function slightly like to Flush(), but it must be called only // at the end of compression process before End(). virtual EStatus Finish (char* out_buf, // [in] output buffer unsigned long out_size, // [in] output buffer size unsigned long* out_avail // [out] count bytes putted into out buffer ) = 0; // Free all dynamically allocated data structures. // This function discards any unprocessed input and does not flush // any pending output. virtual EStatus End(void) = 0;protected: // Reset internal state void Reset(void); // Set/unset compressor busy flag void SetBusy(bool busy = true); // Increase number of processed/output bytes. void IncreaseProcessedSize(unsigned long n_bytes); void IncreaseOutputSize(unsigned long n_bytes);private: unsigned long m_ProcessedSize; //< The number of processed bytes unsigned long m_OutputSize; //< The number of output bytes bool m_Busy; //< Is true if compressor is ready to begin //< next session // Friend classes friend class CCompressionStream; friend class CCompressionStreambuf;};/* @} *///// Inline functions//inlinevoid CCompression::SetLevel(ELevel level){ m_Level = level;}inlineint CCompression::GetErrorCode(void) const{ return m_ErrorCode;}inlinestring CCompression::GetErrorDescription(void) const{ return m_ErrorMsg;}inlinevoid CCompression::SetError(int errcode, const char* description){ m_ErrorCode = errcode; m_ErrorMsg = description ? description : kEmptyStr;}inlineCCompression::TFlags CCompression::GetFlags(void) const{ return m_Flags;}inlinevoid CCompression::SetFlags(TFlags flags){ m_Flags = flags;}inlinevoid CCompressionProcessor::Reset(void){ m_ProcessedSize = 0; m_OutputSize = 0; m_Busy = false;}inlinebool CCompressionProcessor::IsBusy(void) const{ return m_Busy;}inlinevoid CCompressionProcessor::SetBusy(bool busy){ if ( busy && m_Busy ) { NCBI_THROW(CCompressionException, eCompression, "CCompression::SetBusy(): The compressor is busy now"); } m_Busy = busy;}inlinevoid CCompressionProcessor::IncreaseProcessedSize(unsigned long n_bytes){ if (n_bytes > 0) { m_ProcessedSize += n_bytes; }}inlinevoid CCompressionProcessor::IncreaseOutputSize(unsigned long n_bytes){ if (n_bytes > 0) { m_OutputSize += n_bytes; }}inlineunsigned long CCompressionProcessor::GetProcessedSize(void){ return m_ProcessedSize;}inlineunsigned long CCompressionProcessor::GetOutputSize(void){ return m_OutputSize;}END_NCBI_SCOPE/* * =========================================================================== * $Log: compress.hpp,v $ * Revision 1000.2 2004/06/01 19:39:20 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * * Revision 1.8 2004/05/10 11:56:24 ivanov * Added gzip file format support * * Revision 1.7 2004/04/01 14:14:02 lavr * Spell "occurred", "occurrence", and "occurring" * * Revision 1.6 2003/07/15 15:50:00 ivanov * Improved error diagnostics. Renamed GetLastError() -> GetErrorCode(). * Added GetErrorDescription(). Added second parameter for SetError(). * Added new status value - eStatus_EndOfData. * * Revision 1.5 2003/07/10 16:19:25 ivanov * Added kCompressionDefaultBufSize definition from stream.hpp. * Added auxiliary file compression/decompression functions. * * Revision 1.4 2003/06/03 20:09:54 ivanov * The Compression API redesign. Added some new classes, rewritten old. * * Revision 1.3 2003/04/11 19:57:25 ivanov * Move streambuf.hpp from 'include/...' to 'src/...' * * Revision 1.2 2003/04/08 20:48:51 ivanov * Added class-key declaration for friend classes in the CCompression * * Revision 1.1 2003/04/07 20:42:11 ivanov * Initial revision * * =========================================================================== */#endif /* UTIL_COMPRESS__COMPRESS__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -