41 #define NCBI_USE_ERRCODE_X Corelib_StreamBuf
44 #define RWSTREAMBUF_HANDLE_EXCEPTIONS(call, subcode, message, action) \
46 switch (m_Flags & (fLogExceptions | fLeakExceptions)) { \
47 case fLeakExceptions: \
65 catch (CException& e) { \
67 NCBI_REPORT_EXCEPTION_X(subcode, message, e); \
70 if (m_Flags & fLeakExceptions) \
73 catch (exception& e) { \
75 ERR_POST_X(subcode, Error \
77 << "] Exception: " << e.what()); \
80 if (m_Flags & fLeakExceptions) \
85 ERR_POST_X(subcode, Error \
86 << '[' << message << "] Unknown exception"); \
89 if (m_Flags & fLeakExceptions) \
95 if (result != eRW_Success && result != eRW_NotImplemented \
96 && !(m_Flags & fNoStatusLog)) { \
97 bool trace = (result == eRW_Timeout || \
98 result == eRW_Eof ? true : false); \
100 Message << (trace ? Trace : Info) << message \
101 << ": " << &g_RW_ResultToString(result)[4
]); \
111 "eRW_NotImplemented",
156 #if !defined(NCBI_COMPILER_GCC) || NCBI_COMPILER_VERSION >= 700
206 size_t count = (size_t)(egptr() - ptr);
211 14,
"CRWStreambuf::Pushback(): IReader::Pushback()",
230 ERR_POST_X(13,
"CRWStreambuf::~CRWStreambuf():"
231 " Read data pending");
254 size_t n = (size_t) m;
289 _ASSERT(pbase() <= pptr() && pptr() <= epptr());
295 size_t n_towrite = (size_t)(pptr() - pbase());
305 5,
"CRWStreambuf::overflow(): IWriter::Write()",
307 _ASSERT(n_written <= n_towrite);
313 memmove(pbase(), pbase() + n_written, n_towrite - n_written);
315 pbump(-
int(n_written));
322 n_towrite -= n_written;
338 6,
"CRWStreambuf::overflow(): IWriter::Write(1)",
357 7,
"CRWStreambuf::overflow(): IWriter::Flush()",
377 _ASSERT(pbase() <= pptr() && pptr() <= epptr());
383 size_t n = (size_t) m;
384 size_t n_written = 0;
392 if (
n && pbase() +
n < epptr()) {
394 x_written = (size_t)(epptr() - pptr());
398 memcpy(pptr(),
buf, x_written);
399 pbump(
int(x_written));
400 n_written += x_written;
403 return (streamsize) n_written;
408 size_t x_towrite = (size_t)(pptr() - pbase());
413 8,
"CRWStreambuf::xsputn(): IWriter::Write()",
415 _ASSERT(x_written <= x_towrite);
422 memmove(pbase(), pbase() + x_written, x_towrite - x_written);
424 pbump(-
int(x_written));
432 9,
"CRWStreambuf::xsputn(): IWriter::Write()",
435 if (!x_written &&
n) {
442 n_written += x_written;
445 return (streamsize) n_written;
452 x_written = (size_t)(epptr() - pptr());
456 memcpy(pptr(),
buf, x_written);
457 n_written += x_written;
458 pbump(
int(x_written));
464 return (streamsize) n_written;
482 #ifdef NCBI_COMPILER_MIPSPRO
483 if (m_MIPSPRO_ReadsomeGptrSetLevel && m_MIPSPRO_ReadsomeGptr != gptr())
494 10,
"CRWStreambuf::underflow(): IReader::Read()",
532 size_t n = (size_t) m;
537 n_read = (size_t)(egptr() - gptr());
541 memcpy(
buf, gptr(), n_read);
545 return (streamsize) n_read;
552 return (streamsize) n_read;
564 11,
"CRWStreambuf::xsgetn(): IReader::Read()",
574 size_t xx_read = x_read;
599 return (streamsize) n_read;
629 12,
"CRWStreambuf::showmanyc(): IReader::PendingCount()",
655 IOS_BASE::openmode which)
657 if (whence == IOS_BASE::cur && off == 0) {
668 && ((whence == IOS_BASE::cur && (off > 0)) ||
669 (whence == IOS_BASE::beg && (off -=
x_GetGPos()) >= 0))){
virtual streamsize xsgetn(CT_CHAR_TYPE *s, streamsize n)
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: s...
virtual CT_INT_TYPE overflow(CT_INT_TYPE c)
CT_CHAR_TYPE * m_WriteBuf
CT_POS_TYPE x_ErrPos
position of the _write_ error (if x_Err)
virtual CNcbiStreambuf * setbuf(CT_CHAR_TYPE *buf, streamsize buf_size)
Per the standard, setbuf(0, 0) makes I/O unbuffered.
@ fOwnReader
Own the underlying reader.
@ fOwnWriter
Own the underlying writer.
@ fUntie
Do not flush before reading.
int TFlags
Bitwise OR of EFlags.
CT_POS_TYPE x_GPos
get position [for istream::tellg()]
ERW_Result x_Pushback(void)
virtual streamsize showmanyc(void)
CRWStreambuf(IReaderWriter *rw=0, streamsize buf_size=0, CT_CHAR_TYPE *buf=0, TFlags flags=0)
bool x_Err
whether there was a _write_ error
CT_POS_TYPE x_GetGPos(void)
streamsize x_Read(CT_CHAR_TYPE *s, streamsize n)
CT_POS_TYPE x_GetPPos(void)
AutoPtr< IReader > m_Reader
AutoPtr< IWriter > m_Writer
virtual streamsize xsputn(const CT_CHAR_TYPE *buf, streamsize n)
virtual CT_INT_TYPE underflow(void)
CT_POS_TYPE x_PPos
put position [for ostream::tellp()]
A very basic data-read/write interface.
A very basic data-read interface.
A very basic data-write interface.
Abstract reader-writer interface classes.
std::ofstream out("events_result.xml")
main entry point for tests
element_type * get(void) const
Get pointer.
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void Critical(CExceptionArgs_Base &args)
#define NCBI_CATCH_ALL_X(err_subcode, message)
#define THROW1_TRACE(exception_class, exception_arg)
Throw trace.
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
ERW_Result
Result codes for I/O operations.
const char * g_RW_ResultToString(ERW_Result result)
virtual ERW_Result Flush(void)=0
Flush pending data (if any) down to the output device.
virtual ERW_Result PendingCount(size_t *count)=0
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
virtual ERW_Result Pushback(const void *buf, size_t count, void *del_ptr=0)
This method gets called by RStream buffer destructor to return buffered yet still unread (from the st...
virtual ERW_Result Write(const void *buf, size_t count, size_t *bytes_written=0)=0
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
virtual ERW_Result Read(void *buf, size_t count, size_t *bytes_read=0)=0
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
IO_PREFIX::streambuf CNcbiStreambuf
Portable alias for streambuf.
@ eRW_NotImplemented
Action / information is not available.
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Error
Unrecoverable error, no retry possible.
@ eRW_Success
Everything is okay, I/O completed.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in corelib (xncbi.lib).
NCBI C++ auxiliary debug macros.
Defines NCBI C++ exception handling.
std::istream & in(std::istream &in_, double &x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
Reader-writer based streams.
#define RWSTREAMBUF_HANDLE_EXCEPTIONS(call, subcode, message, action)
static bool x_CheckRW(const void *rw)
static const streamsize kDefaultBufSize
static EOwnership x_IfToOwnWriter(const IReader *r, const IWriter *w, CRWStreambuf::TFlags f)
static EOwnership x_IfToOwnReader(const IReader *r, const IWriter *w, CRWStreambuf::TFlags f)