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 151833 2009-02-08 16:21:40Z 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 #  ifdef NCBI_COMPILER_MSVC
00048 #    pragma warning(push)
00049 #    pragma warning(disable:4996)
00050 #  endif //NCBI_COMPILER_MSVC
00051 #endif //NCBI_COMPILER_MIPSPRO
00052 
00053 
00054 BEGIN_NCBI_SCOPE
00055 
00056 
00057 /// Reader-writer based stream buffer
00058 
00059 class  CRWStreambuf : public CRWStreambufBase
00060 {
00061 public:
00062     /// Which of the objects (passed in the constructor) should be
00063     /// deleted on this object's destruction.
00064     /// NOTE:  if the reader and writer are in fact the same object,
00065     ///        it will _not_ be deleted twice.
00066     enum EFlags {
00067         fOwnReader     = 1 << 1,    // own the underlying reader
00068         fOwnWriter     = 1 << 2,    // own the underlying writer
00069         fOwnAll        = fOwnReader + fOwnWriter,
00070         fLogExceptions = 1 << 8
00071     };
00072     typedef int TFlags;             // bitwise OR of EFlags
00073 
00074 
00075     CRWStreambuf(IReaderWriter* rw       = 0,
00076                  streamsize     buf_size = 0,
00077                  CT_CHAR_TYPE*  buf      = 0,
00078                  TFlags         flags    = 0);
00079 
00080     CRWStreambuf(IReader*       r,
00081                  IWriter*       w,
00082                  streamsize     buf_size = 0,
00083                  CT_CHAR_TYPE*  buf      = 0,
00084                  TFlags         flags    = 0);
00085 
00086     virtual ~CRWStreambuf();
00087 
00088 protected:
00089     virtual CT_INT_TYPE overflow(CT_INT_TYPE c);
00090     virtual streamsize  xsputn(const CT_CHAR_TYPE* buf, streamsize n);
00091 
00092     virtual CT_INT_TYPE underflow(void);
00093     virtual streamsize  xsgetn(CT_CHAR_TYPE* s, streamsize n);
00094     virtual streamsize  showmanyc(void);
00095 
00096     virtual int         sync(void);
00097 
00098     /// Note: setbuf(0, 0) has no effect
00099     virtual CNcbiStreambuf* setbuf(CT_CHAR_TYPE* buf, streamsize buf_size);
00100 
00101     // only seekoff(0, IOS_BASE::cur, *) is permitted
00102     virtual CT_POS_TYPE seekoff(CT_OFF_TYPE off, IOS_BASE::seekdir whence,
00103                                 IOS_BASE::openmode which =
00104                                 IOS_BASE::in | IOS_BASE::out);
00105 protected:
00106     CT_POS_TYPE    x_GetGPos(void)
00107     { return x_GPos - (CT_OFF_TYPE)(gptr() ? egptr() - gptr() : 0); }
00108     CT_POS_TYPE    x_GetPPos(void)
00109     { return x_PPos + (CT_OFF_TYPE)(pptr() ? pbase() - pptr() : 0); }
00110 
00111 protected:
00112     TFlags         m_Flags;
00113 
00114     IReader*       m_Reader;
00115     IWriter*       m_Writer;
00116 
00117     streamsize     m_BufSize;
00118     CT_CHAR_TYPE*  m_ReadBuf;
00119     CT_CHAR_TYPE*  m_WriteBuf;
00120 
00121     CT_CHAR_TYPE*  m_pBuf;
00122     CT_CHAR_TYPE   x_Buf;
00123 
00124     CT_POS_TYPE    x_GPos;      //< get position [for istream.tellg()]
00125     CT_POS_TYPE    x_PPos;      //< put position [for ostream.tellp()]
00126 
00127     bool           x_Err;       //< whether there was a write error
00128     CT_POS_TYPE    x_ErrPos;    //< position of write error (if x_Error)
00129 };
00130 
00131 
00132 END_NCBI_SCOPE
00133 
00134 
00135 #ifdef NCBI_COMPILER_MSVC
00136 #  pragma warning(pop)
00137 #endif //NCBI_COMPILER_MSVC
00138 
00139 #endif /* CORELIB___RWSTREAMBUF__HPP */
00140 
00141 

Generated on Sun Dec 6 21:58:42 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:20:35 2009 by modify_doxy.py rev. 173732