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

📄 bytesrc.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: bytesrc.hpp,v $ * PRODUCTION Revision 1000.2  2004/02/12 21:57:36  gouriano * PRODUCTION PRODUCTION: UPGRADED [CORE_001] Dev-tree R1.23 * PRODUCTION * =========================================================================== */#ifndef UTIL___BYTESRC__HPP#define UTIL___BYTESRC__HPP/*  $Id: bytesrc.hpp,v 1000.2 2004/02/12 21:57:36 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: Eugene Vasilchenko * *//// @file bytesrc.hpp///#include <corelib/ncbistd.hpp>#include <corelib/ncbiobj.hpp>#include <util/reader_writer.hpp>/** @addtogroup StreamSupport * * @{ */BEGIN_NCBI_SCOPEclass CByteSource;class CByteSourceReader;class CSubSourceCollector;class CIStreamBuffer;class NCBI_XUTIL_EXPORT CByteSource : public CObject{public:    CByteSource(void);    virtual ~CByteSource(void);    virtual CRef<CByteSourceReader> Open(void) = 0;};class NCBI_XUTIL_EXPORT CByteSourceReader : public CObject{public:    CByteSourceReader(void);    virtual ~CByteSourceReader(void);    /// Read up to bufferLength bytes into buffer    /// return amount of bytes read (if zero - see EndOfData())    virtual size_t Read(char* buffer, size_t bufferLength) = 0;    /// Call this method after Read returned zero to determine whether    /// end of data reached or error occurred    virtual bool EndOfData(void) const;    virtual CRef<CSubSourceCollector>         SubSource(size_t prepend, CRef<CSubSourceCollector> parent);    // push back some data in source, return true if successful    virtual bool Pushback(const char* data, size_t size);    // Set reader current position, when possible    // (default implementation throws an exception)    virtual void Seekg(size_t pos);private:    CByteSourceReader(const CByteSourceReader&);    CByteSourceReader& operator=(const CByteSourceReader&);};/// Abstract class for implementing "sub collectors".////// Sub source collectors can accumulate data in memory, disk/// or uany other media. This is used to temporarily /// store fragments of binary streams or BLOBs. /// Typically such collected data can be re-read by provided /// CByteSource interface.class NCBI_XUTIL_EXPORT CSubSourceCollector : public CObject{public:    /// Constructor.    ///    /// @param parent_collector    ///   Pointer on parent(chained) collector.    ///   CSubSourceCollector relays all AddChunk calls to the parent object    ///   making possible having several sub-sources chained together.    CSubSourceCollector(CRef<CSubSourceCollector> parent);    // Destructor.    virtual ~CSubSourceCollector(void);    /// Add data to the sub-source. If parent pointer is    /// set(m_ParentSubSource) call is redirected to the parent chain.    virtual void AddChunk(const char* buffer, size_t bufferLength);    /// Get CByteSource implementation.    ///    /// Calling program can try to re-read collected data using CByteSource and    /// CByteSourceReader interfaces, though it is legal to return NULL pointer    /// if CSubSourceCollector implementation does not support re-reading    /// (for example if collector sends data away using network or just writes    /// down logs to a write-only database).    /// @sa    ///   CByteSource, CByteSourceReader    virtual CRef<CByteSource> GetSource(void) = 0;protected:    /// Pointer on parent (or chained) collector.    CRef<CSubSourceCollector> m_ParentSubSource;};class NCBI_XUTIL_EXPORT CStreamByteSource : public CByteSource{public:    CStreamByteSource(CNcbiIstream& in);    ~CStreamByteSource(void);    CRef<CByteSourceReader> Open(void);protected:    CNcbiIstream* m_Stream;};class NCBI_XUTIL_EXPORT CFStreamByteSource : public CStreamByteSource{public:    CFStreamByteSource(CNcbiIstream& in);    CFStreamByteSource(const string& fileName, bool binary);    ~CFStreamByteSource(void);};class NCBI_XUTIL_EXPORT CFileByteSource : public CByteSource{public:    CFileByteSource(const string& name, bool binary);    CFileByteSource(const CFileByteSource& file);    ~CFileByteSource(void);    CRef<CByteSourceReader> Open(void);    const string& GetFileName(void) const        { return m_FileName; }    bool IsBinary(void) const        { return m_Binary; }private:    string m_FileName;    bool   m_Binary;};class NCBI_XUTIL_EXPORT CStreamByteSourceReader : public CByteSourceReader{public:    CStreamByteSourceReader(const CByteSource* source, CNcbiIstream* stream);    ~CStreamByteSourceReader(void);    size_t Read(char* buffer, size_t bufferLength);    bool EndOfData(void) const;    bool Pushback(const char* data, size_t size);    virtual void Seekg(size_t pos);protected:    CConstRef<CByteSource> m_Source;    CNcbiIstream*          m_Stream;};/// Class adapter from IReader to CByteSourceReader.///class NCBI_XUTIL_EXPORT CIRByteSourceReader : public CByteSourceReader{public:    CIRByteSourceReader(IReader* reader);    ~CIRByteSourceReader(void);    size_t Read(char* buffer, size_t bufferLength);    bool EndOfData(void) const;protected:    IReader*   m_Reader;    bool       m_EOF;};/// Stream based byte source reader./// /// Class works as a virtual class factory to create CWriterSourceCollector.////// One of the projected uses is to update local BLOB cache./// @sa///   SubSource().class NCBI_XUTIL_EXPORT CWriterByteSourceReader     : public CStreamByteSourceReader{public:    /// Constructor.    ///    /// @param stream    ///   Readers source.    /// @param writer    ///   Destination interface pointer.    CWriterByteSourceReader(CNcbiIstream* stream, IWriter* writer);    ~CWriterByteSourceReader(void);    /// Create CWriterSourceCollector.    virtual CRef<CSubSourceCollector>         SubSource(size_t prepend, CRef<CSubSourceCollector> parent);protected:    IWriter* m_Writer;};class NCBI_XUTIL_EXPORT CWriterCopyByteSourceReader     : public CByteSourceReader{public:    /// Constructor.    ///    /// @param reader    ///   Source reader.    /// @param writer    ///   Destination interface pointer.    CWriterCopyByteSourceReader(CByteSourceReader* reader, IWriter* writer);    ~CWriterCopyByteSourceReader(void);    /// Just call Read method on source reader.    size_t Read(char* buffer, size_t bufferLength);    /// Just call EndOfData method on source reader.    bool EndOfData(void) const;    /// Create CWriterSourceCollector.    virtual CRef<CSubSourceCollector>         SubSource(size_t prepend, CRef<CSubSourceCollector> parent);protected:    CRef<CByteSourceReader> m_Reader;    IWriter* m_Writer;};

⌨️ 快捷键说明

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