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;
288 _ASSERT(pbase() <= pptr() && pptr() <= epptr());
294 size_t n_towrite = (size_t)(pptr() - pbase());
304 5,
"CRWStreambuf::overflow(): IWriter::Write()",
306 _ASSERT(n_written <= n_towrite);
312 memmove(pbase(), pbase() + n_written, n_towrite - n_written);
314 pbump(-
int(n_written));
321 n_towrite -= n_written;
337 6,
"CRWStreambuf::overflow(): IWriter::Write(1)",
356 7,
"CRWStreambuf::overflow(): IWriter::Flush()",
376 _ASSERT(pbase() <= pptr() && pptr() <= epptr());
382 size_t n = (size_t) m;
383 size_t n_written = 0;
391 if (
n && pbase() +
n < epptr()) {
393 x_written = (size_t)(epptr() - pptr());
397 memcpy(pptr(),
buf, x_written);
398 pbump(
int(x_written));
399 n_written += x_written;
402 return (streamsize) n_written;
407 size_t x_towrite = (size_t)(pptr() - pbase());
412 8,
"CRWStreambuf::xsputn(): IWriter::Write()",
414 _ASSERT(x_written <= x_towrite);
421 memmove(pbase(), pbase() + x_written, x_towrite - x_written);
423 pbump(-
int(x_written));
431 9,
"CRWStreambuf::xsputn(): IWriter::Write()",
434 if (!x_written &&
n) {
441 n_written += x_written;
444 return (streamsize) n_written;
451 x_written = (size_t)(epptr() - pptr());
455 memcpy(pptr(),
buf, x_written);
456 n_written += x_written;
457 pbump(
int(x_written));
463 return (streamsize) n_written;
481 #ifdef NCBI_COMPILER_MIPSPRO
482 if (m_MIPSPRO_ReadsomeGptrSetLevel && m_MIPSPRO_ReadsomeGptr != gptr())
493 10,
"CRWStreambuf::underflow(): IReader::Read()",
531 size_t n = (size_t) m;
536 n_read = (size_t)(egptr() - gptr());
540 memcpy(
buf, gptr(), n_read);
544 return (streamsize) n_read;
551 return (streamsize) n_read;
563 11,
"CRWStreambuf::xsgetn(): IReader::Read()",
573 size_t xx_read = x_read;
598 return (streamsize) n_read;
628 12,
"CRWStreambuf::showmanyc(): IReader::PendingCount()",
654 IOS_BASE::openmode which)
656 if (whence == IOS_BASE::cur && off == 0) {
667 && ((whence == IOS_BASE::cur && (off > 0)) ||
668 (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_)
double f(double x_, const double &y_)
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)