⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compress.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: compress.hpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:39:20  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * PRODUCTION * =========================================================================== */#ifndef UTIL_COMPRESS__COMPRESS__HPP#define UTIL_COMPRESS__COMPRESS__HPP/*  $Id: compress.hpp,v 1000.2 2004/06/01 19:39:20 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Author:  Vladimir Ivanov * * File Description:  The Compression API * */#include <corelib/ncbistd.hpp>/** @addtogroup Compression * * @{ */BEGIN_NCBI_SCOPE// Default compression I/O stream buffer sizeconst streamsize kCompressionDefaultBufSize = 16*1024;///////////////////////////////////////////////////////////////////////////////// CCompressionException////  Exceptions generated by CCompresson and derived classes//class NCBI_XUTIL_EXPORT CCompressionException : public CCoreException{public:    enum EErrCode {        eCompression,      // Compression/decompression error        eCompressionFile   // Compression/decompression file error    };    virtual const char* GetErrCodeString(void) const    {        switch (GetErrCode()) {        case eCompression     : return "eCompression";        case eCompressionFile : return "eCompressionFile";        default               : return CException::GetErrCodeString();        }    }    NCBI_EXCEPTION_DEFAULT(CCompressionException,CCoreException);};// Forward declarationclass CCompressionFile;class CCompressionStreambuf;////////////////////////////////////////////////////////////////////////////////// CCompression -- abstract base class//class NCBI_XUTIL_EXPORT CCompression{public:    // Compression level.    // It is in range [0..9]. Increase of level might mean better compression    // and usualy greater time of compression. Usualy 1 gives best speed,    // 9 gives best compression, 0 gives no compression at all.    // eDefault value requests a compromise between speed and compression    // (according to developers of the corresponding compression algorithm).    enum ELevel {        eLevel_Default       = -1,  // default        eLevel_NoCompression =  0,  // just store data        eLevel_Lowest        =  1,        eLevel_VeryLow       =  2,        eLevel_Low           =  3,        eLevel_MediumLow     =  4,        eLevel_Medium        =  5,        eLevel_MediumHigh    =  6,        eLevel_High          =  7,        eLevel_VeryHigh      =  8,        eLevel_Best          =  9    };    // Compression flags. The flag selection depends from realization.    typedef int TFlags;    // 'ctors    CCompression(ELevel level = eLevel_Default);    virtual ~CCompression(void);    // Get/set compression level.    // NOTE 1:  Changing compression level after compression has begun will    //          be ignored.    // NOTE 2:  If the level is not supported by the underlying algorithm,    //          then it will be translated to the nearest supported value.    void SetLevel(ELevel level);    virtual ELevel GetLevel(void) const;    // Return the default compression level for current compression algorithm    virtual ELevel GetDefaultLevel(void) const = 0;    // Get compressor's internal status/error code and description    // for the last operation.    int    GetErrorCode(void) const;    string GetErrorDescription(void) const;    // Get/set flags    TFlags GetFlags(void) const;    void SetFlags(TFlags flags);    //    // Utility functions     //    // (De)compress the source buffer into the destination buffer.    // Return TRUE on success, FALSE on error.    // The compressor error code can be acquired via GetLastError() call.    // Notice that altogether the total size of the destination buffer must    // be little more then size of the source buffer.     virtual bool CompressBuffer(        const void* src_buf, unsigned int  src_len,        void*       dst_buf, unsigned int  dst_size,        /* out */            unsigned int* dst_len    ) = 0;    virtual bool DecompressBuffer(        const void* src_buf, unsigned int  src_len,        void*       dst_buf, unsigned int  dst_size,        /* out */            unsigned int* dst_len    ) = 0;        // (De)compress file "src_file" and put result to file "dst_file".    // Return TRUE on success, FALSE on error.    virtual bool CompressFile(        const string&     src_file,        const string&     dst_file,        size_t            buf_size = kCompressionDefaultBufSize    ) = 0;    virtual bool DecompressFile(        const string&     src_file,        const string&     dst_file,         size_t            buf_size = kCompressionDefaultBufSize    ) = 0;protected:    // Set last compressor's action error/status code and description    void SetError(int status, const char* description = 0);protected:    // Universal file compression/decompression functions.    // Return TRUE on success, FALSE on error.    virtual bool x_CompressFile(        const string&     src_file,        CCompressionFile& dst_file,        size_t            buf_size = kCompressionDefaultBufSize    );    virtual bool x_DecompressFile(        CCompressionFile& src_file,        const string&     dst_file,        size_t            buf_size = kCompressionDefaultBufSize    );private:    ELevel  m_Level;      // Compression level    int     m_ErrorCode;  // Last compressor action error/status    string  m_ErrorMsg;   // Last compressor action error message    TFlags  m_Flags;      // Bitwise OR of flags     // Friend classes    friend class CCompressionStreambuf;};////////////////////////////////////////////////////////////////////////////////// CCompressionFile -- abstract base class//// Class for support work with compressed files.// Assumed that file on hard disk is always compressed and data in memory// is uncompressed. //class NCBI_XUTIL_EXPORT CCompressionFile{public:    // Compression file hadler    typedef void* TFile;    // File open mode    enum EMode {        eMode_Read,   // for reading from compressed file        eMode_Write   // for writing compressed data to file    };    // 'ctors    CCompressionFile(void);    //CCompressionFile(const string& path, EMode mode) = 0;     virtual ~CCompressionFile(void);    // Opens a compressed file for reading or writing.    // Return NULL if error has been occurred.    virtual bool Open(const string& path, EMode mode) = 0;     // Read up to "len" uncompressed bytes from the compressed file "file"    // into the buffer "buf". Return the number of bytes actually read    // (0 for end of file, -1 for error)    virtual int Read(void* buf, int len) = 0;    // Writes the given number of uncompressed bytes into the compressed file.    // Return the number of bytes actually written or -1 for error.    virtual int Write(const void* buf, int len) = 0;    // Flushes all pending output if necessary, closes the compressed file.    // Return TRUE on success, FALSE on error.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -