NCBI C++ ToolKit
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
CRWStreambuf Class Reference

Search Toolkit Book for CRWStreambuf

Reader-writer-based stream buffer. More...

#include <corelib/impl/rwstreambuf.hpp>

+ Inheritance diagram for CRWStreambuf:
+ Collaboration diagram for CRWStreambuf:

Public Types

enum  EFlags {
  fOwnReader = 1 << 0 , fOwnWriter = 1 << 1 , fOwnAll = fOwnReader + fOwnWriter , fUntie = 1 << 2 ,
  fNoStatusLog = 1 << 3 , fLogExceptions = 1 << 4 , fLeakExceptions = 1 << 5
}
 Which of the objects (passed in the constructor) must be deleted on this object's destruction, whether to tie I/O, and how to process exceptions thrown at lower levels... More...
 
typedef int TFlags
 Bitwise OR of EFlags. More...
 

Public Member Functions

 CRWStreambuf (IReaderWriter *rw=0, streamsize buf_size=0, CT_CHAR_TYPE *buf=0, TFlags flags=0)
 
 CRWStreambuf (IReader *r, IWriter *w, streamsize buf_size=0, CT_CHAR_TYPE *buf=0, TFlags flags=0)
 NOTE: if both reader and writer have actually happened to be the same object, then when owned, it will _not_ be deleted twice. More...
 
virtual ~CRWStreambuf ()
 

Protected Member Functions

virtual CT_INT_TYPE overflow (CT_INT_TYPE c)
 
virtual streamsize xsputn (const CT_CHAR_TYPE *buf, streamsize n)
 
virtual CT_INT_TYPE underflow (void)
 
virtual streamsize xsgetn (CT_CHAR_TYPE *s, streamsize n)
 
virtual streamsize showmanyc (void)
 
virtual int sync (void)
 
virtual CNcbiStreambufsetbuf (CT_CHAR_TYPE *buf, streamsize buf_size)
 Per the standard, setbuf(0, 0) makes I/O unbuffered. More...
 
virtual CT_POS_TYPE seekoff (CT_OFF_TYPE off, IOS_BASE::seekdir whence, IOS_BASE::openmode which=IOS_BASE::in|IOS_BASE::out)
 Only seekoff(0, IOS_BASE::cur, *) to obtain current position, and input skip-forward are permitted: seekoff(off, IOS_BASE::cur or IOS_BASE::beg, IOS_BASE::in) when the requested stream position is past the current input position (so the stream can read forward internally to reach that position). More...
 
virtual streamsize _Xsgetn_s (CT_CHAR_TYPE *buf, size_t, streamsize n)
 
CT_POS_TYPE x_GetGPos (void)
 
CT_POS_TYPE x_GetPPos (void)
 
int x_Sync (void)
 
streamsize x_Read (CT_CHAR_TYPE *s, streamsize n)
 
ERW_Result x_Pushback (void)
 

Protected Attributes

TFlags m_Flags
 
AutoPtr< IReaderm_Reader
 
AutoPtr< IWriterm_Writer
 
size_t m_BufSize
 
CT_CHAR_TYPEm_ReadBuf
 
CT_CHAR_TYPEm_WriteBuf
 
CT_CHAR_TYPEm_pBuf
 
CT_CHAR_TYPE x_Buf
 
CT_POS_TYPE x_GPos
 get position [for istream::tellg()] More...
 
CT_POS_TYPE x_PPos
 put position [for ostream::tellp()] More...
 
bool x_Eof
 whether at EOF More...
 
bool x_Err
 whether there was a _write_ error More...
 
CT_POS_TYPE x_ErrPos
 position of the _write_ error (if x_Err) More...
 

Private Member Functions

 CRWStreambuf (const CRWStreambuf &)
 
CRWStreambuf operator= (const CRWStreambuf &)
 

Detailed Description

Reader-writer-based stream buffer.

Definition at line 59 of file rwstreambuf.hpp.

Member Typedef Documentation

◆ TFlags

Bitwise OR of EFlags.

Definition at line 74 of file rwstreambuf.hpp.

Member Enumeration Documentation

◆ EFlags

Which of the objects (passed in the constructor) must be deleted on this object's destruction, whether to tie I/O, and how to process exceptions thrown at lower levels...

Enumerator
fOwnReader 

Own the underlying reader.

fOwnWriter 

Own the underlying writer.

fOwnAll 
fUntie 

Do not flush before reading.

fNoStatusLog 

Do not log unsuccessful I/O.

fLogExceptions 

Exceptions logged only.

fLeakExceptions 

Exceptions leaked out.

Definition at line 65 of file rwstreambuf.hpp.

Constructor & Destructor Documentation

◆ CRWStreambuf() [1/3]

CRWStreambuf::CRWStreambuf ( IReaderWriter rw = 0,
streamsize  buf_size = 0,
CT_CHAR_TYPE buf = 0,
CRWStreambuf::TFlags  f = 0 
)

Definition at line 165 of file rwstreambuf.cpp.

References kDefaultBufSize, n, and setbuf().

◆ CRWStreambuf() [2/3]

CRWStreambuf::CRWStreambuf ( IReader r,
IWriter w,
streamsize  buf_size = 0,
CT_CHAR_TYPE buf = 0,
CRWStreambuf::TFlags  f = 0 
)

NOTE: if both reader and writer have actually happened to be the same object, then when owned, it will _not_ be deleted twice.

Definition at line 180 of file rwstreambuf.cpp.

References kDefaultBufSize, m_Reader, m_Writer, n, and setbuf().

◆ ~CRWStreambuf()

CRWStreambuf::~CRWStreambuf ( )
virtual

◆ CRWStreambuf() [3/3]

CRWStreambuf::CRWStreambuf ( const CRWStreambuf )
private

Member Function Documentation

◆ _Xsgetn_s()

virtual streamsize CRWStreambuf::_Xsgetn_s ( CT_CHAR_TYPE buf,
size_t  ,
streamsize  n 
)
inlineprotectedvirtual

Definition at line 129 of file rwstreambuf.hpp.

References buf, n, and xsgetn().

◆ operator=()

CRWStreambuf CRWStreambuf::operator= ( const CRWStreambuf )
private

◆ overflow()

CT_INT_TYPE CRWStreambuf::overflow ( CT_INT_TYPE  c)
protectedvirtual

◆ seekoff()

CT_POS_TYPE CRWStreambuf::seekoff ( CT_OFF_TYPE  off,
IOS_BASE::seekdir  whence,
IOS_BASE::openmode  which = IOS_BASE::in | IOS_BASE::out 
)
protectedvirtual

Only seekoff(0, IOS_BASE::cur, *) to obtain current position, and input skip-forward are permitted: seekoff(off, IOS_BASE::cur or IOS_BASE::beg, IOS_BASE::in) when the requested stream position is past the current input position (so the stream can read forward internally to reach that position).

Definition at line 654 of file rwstreambuf.cpp.

References CT_OFF_TYPE, CT_POS_TYPE, in(), m_Reader, out(), x_GetGPos(), x_GetPPos(), and x_Read().

◆ setbuf()

CNcbiStreambuf * CRWStreambuf::setbuf ( CT_CHAR_TYPE buf,
streamsize  buf_size 
)
protectedvirtual

Per the standard, setbuf(0, 0) makes I/O unbuffered.

Other behavior is implementation-dependent: "buf_size" == 1 makes I/O unbuffered ("buf", if provided, may still be used internally as a one-char un-get location). Special case: setbuf(non-NULL, 0) creates an internal buffer of some predefined size, which will be automatically deallocated in dtor; the value of the first argument is ignored (can be any non-NULL pointer). Otherwise, setbuf() sets I/O arena of size "buf_size" located at "buf", and halved between the I/O directions, if both are used. If "buf" is provided as NULL, the buffer of the requested size gets allocated internally, and gets automatically freed upon CRWStreambuf destruction. Before replacing the buffer, this call first attempts to flush any pending output (sync) to the output device, and return any pending input sequence (internal read buffer) to the input device (pushback).

Definition at line 243 of file rwstreambuf.cpp.

References _ASSERT, Critical(), CT_CHAR_TYPE, ERR_POST_X, eRW_Success, kDefaultBufSize, m_BufSize, m_pBuf, m_ReadBuf, m_Reader, m_WriteBuf, m_Writer, n, x_Buf, x_Pushback(), and x_Sync().

Referenced by CRWStreambuf().

◆ showmanyc()

streamsize CRWStreambuf::showmanyc ( void  )
protectedvirtual

◆ sync()

int CRWStreambuf::sync ( void  )
protectedvirtual

Definition at line 645 of file rwstreambuf.cpp.

References _ASSERT, CT_EOF, CT_EQ_INT_TYPE, and overflow().

Referenced by x_Sync().

◆ underflow()

CT_INT_TYPE CRWStreambuf::underflow ( void  )
protectedvirtual

◆ x_GetGPos()

CT_POS_TYPE CRWStreambuf::x_GetGPos ( void  )
inlineprotected

Definition at line 134 of file rwstreambuf.hpp.

References CT_OFF_TYPE, and x_GPos.

Referenced by seekoff().

◆ x_GetPPos()

CT_POS_TYPE CRWStreambuf::x_GetPPos ( void  )
inlineprotected

Definition at line 137 of file rwstreambuf.hpp.

References CT_OFF_TYPE, and x_PPos.

Referenced by overflow(), seekoff(), xsputn(), and ~CRWStreambuf().

◆ x_Pushback()

ERW_Result CRWStreambuf::x_Pushback ( void  )
protected

◆ x_Read()

streamsize CRWStreambuf::x_Read ( CT_CHAR_TYPE s,
streamsize  n 
)
protected

◆ x_Sync()

int CRWStreambuf::x_Sync ( void  )
inlineprotected

Definition at line 140 of file rwstreambuf.hpp.

References sync().

Referenced by setbuf(), showmanyc(), underflow(), x_Read(), and ~CRWStreambuf().

◆ xsgetn()

streamsize CRWStreambuf::xsgetn ( CT_CHAR_TYPE s,
streamsize  n 
)
protectedvirtual

Definition at line 603 of file rwstreambuf.cpp.

References _ASSERT, buf, AutoPtr< X, Del >::get(), m_Reader, x_CheckRW(), and x_Read().

Referenced by _Xsgetn_s().

◆ xsputn()

streamsize CRWStreambuf::xsputn ( const CT_CHAR_TYPE buf,
streamsize  n 
)
protectedvirtual

Member Data Documentation

◆ m_BufSize

size_t CRWStreambuf::m_BufSize
protected

Definition at line 153 of file rwstreambuf.hpp.

Referenced by setbuf(), underflow(), and x_Read().

◆ m_Flags

TFlags CRWStreambuf::m_Flags
protected

Definition at line 148 of file rwstreambuf.hpp.

Referenced by showmanyc(), underflow(), and x_Read().

◆ m_pBuf

CT_CHAR_TYPE* CRWStreambuf::m_pBuf
protected

Definition at line 157 of file rwstreambuf.hpp.

Referenced by setbuf(), x_Pushback(), and ~CRWStreambuf().

◆ m_ReadBuf

CT_CHAR_TYPE* CRWStreambuf::m_ReadBuf
protected

Definition at line 154 of file rwstreambuf.hpp.

Referenced by setbuf(), underflow(), and x_Read().

◆ m_Reader

AutoPtr<IReader> CRWStreambuf::m_Reader
protected

◆ m_WriteBuf

CT_CHAR_TYPE* CRWStreambuf::m_WriteBuf
protected

Definition at line 155 of file rwstreambuf.hpp.

Referenced by setbuf().

◆ m_Writer

AutoPtr<IWriter> CRWStreambuf::m_Writer
protected

Definition at line 151 of file rwstreambuf.hpp.

Referenced by CRWStreambuf(), overflow(), setbuf(), and xsputn().

◆ x_Buf

CT_CHAR_TYPE CRWStreambuf::x_Buf
protected

Definition at line 158 of file rwstreambuf.hpp.

Referenced by setbuf().

◆ x_Eof

bool CRWStreambuf::x_Eof
protected

whether at EOF

Definition at line 163 of file rwstreambuf.hpp.

Referenced by showmanyc(), underflow(), x_Pushback(), and x_Read().

◆ x_Err

bool CRWStreambuf::x_Err
protected

whether there was a _write_ error

Definition at line 164 of file rwstreambuf.hpp.

Referenced by overflow(), xsputn(), and ~CRWStreambuf().

◆ x_ErrPos

CT_POS_TYPE CRWStreambuf::x_ErrPos
protected

position of the _write_ error (if x_Err)

Definition at line 165 of file rwstreambuf.hpp.

Referenced by overflow(), xsputn(), and ~CRWStreambuf().

◆ x_GPos

CT_POS_TYPE CRWStreambuf::x_GPos
protected

get position [for istream::tellg()]

Definition at line 160 of file rwstreambuf.hpp.

Referenced by underflow(), x_GetGPos(), and x_Read().

◆ x_PPos

CT_POS_TYPE CRWStreambuf::x_PPos
protected

put position [for ostream::tellp()]

Definition at line 161 of file rwstreambuf.hpp.

Referenced by overflow(), x_GetPPos(), and xsputn().


The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:57:50 2024 by modify_doxy.py rev. 669887