include/corelib/impl/rwstreambuf.hpp

Go to the documentation of this file.
00001 #ifndef CORELIB___RWSTREAMBUF__HPP
00002 #define CORELIB___RWSTREAMBUF__HPP
00003 
00004 /*  $Id: rwstreambuf.hpp 129455 2008-06-02 16:51:02Z lavr $
00005  * ===========================================================================
00006  *
00007  *                            PUBLIC DOMAIN NOTICE
00008  *               National Center for Biotechnology Information
00009  *
00010  *  This software/database is a "United States Government Work" under the
00011  *  terms of the United States Copyright Act.  It was written as part of
00012  *  the author's official duties as a United States Government employee and
00013  *  thus cannot be copyrighted.  This software/database is freely available
00014  *  to the public for use. The National Library of Medicine and the U.S.
00015  *  Government have not placed any restriction on its use or reproduction.
00016  *
00017  *  Although all reasonable efforts have been taken to ensure the accuracy
00018  *  and reliability of the software and data, the NLM and the U.S.
00019  *  Government do not and cannot warrant the performance or results that
00020  *  may be obtained by using this software or data. The NLM and the U.S.
00021  *  Government disclaim all warranties, express or implied, including
00022  *  warranties of performance, merchantability or fitness for any particular
00023  *  purpose.
00024  *
00025  *  Please cite the author in any work or product based on this material.
00026  *
00027  * ===========================================================================
00028  *
00029  * Authors:  Anton Lavrentiev
00030  *
00031  * File Description:
00032  *   Reader-writer based stream buffer
00033  *
00034  */
00035 
00036 /// @file rwstreambuf.hpp
00037 /// Reader-writer based stream buffer
00038 /// @sa IReader, IWriter, IReaderWriter
00039 
00040 #include <corelib/ncbistre.hpp>
00041 #include <corelib/reader_writer.hpp>
00042 
00043 #ifdef NCBI_COMPILER_MIPSPRO
00044 #  define CRWStreambufBase CMIPSPRO_ReadsomeTolerantStreambuf
00045 #else
00046 #  define CRWStreambufBase CNcbiStreambuf
00047 #endif //NCBI_COMPILER_MIPSPRO
00048 
00049 
00050 BEGIN_NCBI_SCOPE
00051 
00052 
00053 /// Reader-writer based stream buffer
00054 
00055 class  CRWStreambuf : public CRWStreambufBase
00056 {
00057 public:
00058     /// Which of the objects (passed in the constructor) should be
00059     /// deleted on this object's destruction.
00060     /// NOTE:  if the reader and writer are in fact the same object,
00061     ///        it will _not_ be deleted twice.
00062     enum EFlags {
00063         fOwnReader     = 1 << 1,    // own the underlying reader
00064         fOwnWriter     = 1 << 2,    // own the underlying writer
00065         fOwnAll        = fOwnReader + fOwnWriter,
00066         fLogExceptions = 1 << 8
00067     };
00068     typedef int TFlags;             // bitwise OR of EFlags
00069 
00070 
00071     CRWStreambuf(IReaderWriter* rw       = 0,
00072                  streamsize     buf_size = 0,
00073                  CT_CHAR_TYPE*  buf      = 0,
00074                  TFlags         flags    = 0);
00075 
00076     CRWStreambuf(IReader*       r,
00077                  IWriter*       w,
00078                  streamsize     buf_size = 0,
00079                  CT_CHAR_TYPE*  buf      = 0,
00080                  TFlags         flags    = 0);
00081 
00082     virtual ~CRWStreambuf();
00083 
00084 protected:
00085     virtual CT_INT_TYPE overflow(CT_INT_TYPE c);
00086     virtual streamsize  xsputn(const CT_CHAR_TYPE* buf, streamsize n);
00087 
00088     virtual CT_INT_TYPE underflow(void);
00089     virtual streamsize  xsgetn(CT_CHAR_TYPE* s, streamsize n);
00090     virtual streamsize  showmanyc(void);
00091 
00092     virtual int         sync(void);
00093 
00094     /// Note: setbuf(0, 0) has no effect
00095     virtual CNcbiStreambuf* setbuf(CT_CHAR_TYPE* buf, streamsize buf_size);
00096 
00097     // only seekoff(0, IOS_BASE::cur, *) is permitted
00098     virtual CT_POS_TYPE seekoff(CT_OFF_TYPE off, IOS_BASE::seekdir whence,
00099                                 IOS_BASE::openmode which =
00100                                 IOS_BASE::in | IOS_BASE::out);
00101 protected:
00102     CT_POS_TYPE    x_GetGPos(void)
00103     { return x_GPos - (CT_OFF_TYPE)(gptr() ? egptr() - gptr() : 0); }
00104     CT_POS_TYPE    x_GetPPos(void)
00105     { return x_GPos - (CT_OFF_TYPE)(gptr() ? egptr() - gptr() : 0); }
00106 
00107 protected:
00108     TFlags         m_Flags;
00109 
00110     IReader*       m_Reader;
00111     IWriter*       m_Writer;
00112 
00113     streamsize     m_BufSize;
00114     CT_CHAR_TYPE*  m_ReadBuf;
00115     CT_CHAR_TYPE*  m_WriteBuf;
00116 
00117     CT_CHAR_TYPE*  m_pBuf;
00118     CT_CHAR_TYPE   x_Buf;
00119 
00120     CT_POS_TYPE    x_GPos;      //< get position [for istream.tellg()]
00121     CT_POS_TYPE    x_PPos;      //< put position [for ostream.tellp()]
00122 
00123     bool           x_Err;       //< whether there was a write error
00124     CT_POS_TYPE    x_ErrPos;    //< position of write error (if x_Error)
00125 };
00126 
00127 
00128 END_NCBI_SCOPE
00129 
00130 #endif /* CORELIB___RWSTREAMBUF__HPP */
00131 
00132 

Generated on Sun Oct 12 02:45:45 2008 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Sun Oct 12 18:15:26 2008 by modify_doxy.py rev. 117643