29#ifndef RW_STREAMBUF_H_INCLUDED
30#define RW_STREAMBUF_H_INCLUDED
60static const char*
const streambuf_func_names[] = {
61 "setbuf",
"seekoff",
"seekpos",
"showmanyc",
"xsgetn",
"underflow",
62 "uflow",
"overflow",
"pbackfail",
"xsputn",
"sync"
65template <
class charT,
class Traits>
70 typedef std::basic_streambuf<char_type, traits_type>
Base;
77 MyStreambuf (
const char*, std::streamsize,
int,
int);
85 return this->eback ();
93 return this->egptr ();
97 return this->pbase ();
101 return this->pptr ();
105 return this->epptr ();
109 this->setg (beg,
cur,
end);
113 this->setp (beg,
end);
114 this->pbump (
cur - beg);
125 seekoff (
off_type, std::ios_base::seekdir, std::ios_base::openmode) {
131 seekpos (
pos_type, std::ios_base::openmode) {
136 virtual std::streamsize showmanyc () {
141 virtual std::streamsize xsgetn (
char_type*, std::streamsize) {
151 overflow (
int_type = traits_type::eof ());
154 pbackfail (
int_type = traits_type::eof ());
156 virtual std::streamsize
157 xsputn (
const char_type *
buf, std::streamsize bufsize) {
160 return Base::xsputn (
buf, bufsize);
163 virtual int sync () {
202template <
class charT,
class Traits>
207template <
class charT,
class Traits>
212template <
class charT,
class Traits>
214MyStreambuf (std::streamsize bufsize,
int fail_set,
int when)
215 :
Base (), buf_ (0), bufsize_ (bufsize),
216 throw_set_ (0), fail_set_ (0), threw_ (
None), failed_ (
None),
217 fail_when_ (when), allthrows_ (0), allcalls_ (0)
220 std::memset (ncalls_, 0,
sizeof ncalls_);
236 if (fail_set &
Throw) {
239 for (
unsigned i = 0;
i < 11; ++
i)
249template <
class charT,
class Traits>
251MyStreambuf (
const char *
buf, std::streamsize bufsize,
int fail_set,
int when)
252 :
Base (), buf_ (0), bufsize_ (bufsize),
253 throw_set_ (0), fail_set_ (0), threw_ (
None), failed_ (
None),
254 fail_when_ (when), allthrows_ (0), allcalls_ (0)
257 std::memset (ncalls_, 0,
sizeof ncalls_);
264 if (std::streamsize (-1) ==
bufsize_)
265 bufsize_ = std::streamsize (std::char_traits<char>::length (
buf)) + 1;
272 typedef unsigned char UChar;
286 if (fail_set &
Throw) {
289 for (
unsigned i = 0;
i < 11; ++
i)
299template <
class charT,
class Traits>
305 return traits_type::eof ();
307 if (this->egptr () - this->gptr () > 0) {
309 return traits_type::to_int_type (*this->gptr ());
312 if (this->egptr () < buf_ + bufsize_) {
316 std::streamsize
pending = buf_ + bufsize_ - this->egptr ();
321 this->setg (this->eback (), this->gptr (), this->egptr () +
pending);
322 return traits_type::to_int_type (*this->gptr ());
326 return traits_type::eof ();
330template <
class charT,
class Traits>
336 return traits_type::eof ();
338 if (this->epptr () - this->pptr () > 0) {
339 traits_type::assign (*this->pptr (), traits_type::to_char_type (
c));
341 return traits_type::not_eof (
c);
344 if (this->epptr () < buf_ + bufsize_) {
348 std::streamsize
pending = buf_ + bufsize_ - this->epptr ();
353 const std::streamsize pptr_off = this->pptr () - this->pbase ();
355 this->setp (this->pbase (), this->epptr () +
pending);
357 this->pbump (pptr_off);
359 traits_type::assign (*this->pptr (), traits_type::to_char_type (
c));
363 return traits_type::not_eof (
c);
367 return traits_type::eof ();
371template <
class charT,
class Traits>
377 return traits_type::eof ();
379 if (this->gptr () == buf_) {
381 return traits_type::eof ();
384 this->setg (this->gptr () - 1, this->gptr () - 1, this->gptr ());
386 const int_type
last = traits_type::to_int_type (*this->gptr ());
388 if (!traits_type::eq_int_type (
c, traits_type::eof ()))
389 traits_type::assign (*this->gptr (), traits_type::to_char_type (
c));
395template <
class charT,
class Traits>
401 return traits_type::eof ();
403 if (this->egptr () - this->gptr () > 0) {
405 return traits_type::to_int_type (*this->gptr ());
408 if (this->egptr () < buf_ + bufsize_) {
412 std::streamsize
pending = buf_ + bufsize_ - this->egptr ();
417 this->setg (this->eback (), this->gptr (), this->egptr () +
pending);
418 return traits_type::to_int_type (*this->gptr ());
422 return traits_type::eof ();
425template <
class charT,
class Traits>
432 for (
unsigned i = 0;
i <
sizeof (
which) * _RWSTD_CHAR_BIT; ++
i) {
444template <
class charT,
class Traits>
451 return ncalls_ [
inx];
457template <
class charT,
class Traits>
470 RW_ASSERT ((_RWSTD_SIZE_T)
inx <
sizeof ncalls_ /
sizeof *ncalls_);
475 self->ncalls_ [
inx] ++;
477 const int callno = self->ncalls_ [
inx];
479#ifndef _RWSTD_NO_EXCEPTIONS
484 if (callno == throw_when_ [
inx] && throw_set_ &
which) {
489 streambuf_func_names [
inx],
490 "%s",
"test exception");
495 if (callno == throw_when_ [
inx] && throw_set_ &
which) {
504 const bool success = !(fail_set_ &
which) || callno != fail_when_;
std::char_traits< S > Traits
#define _RWSTD_CONST_CAST(T, x)
UserChar make_char(char c, UserChar *)
_TEST_EXPORT void rw_throw(ExceptionId exid, const char *file, int line, const char *function, const char *fmt,...)
char_type * pubgptr() const
void pubsetg(charT *beg, charT *cur, charT *end)
char_type * pubepptr() const
static std::streamsize in_pending_
char_type * pubeback() const
char_type * pubpptr() const
char_type * pubegptr() const
char_type * pubpbase() const
void pubsetp(charT *beg, charT *cur, charT *end)
std::basic_streambuf< char_type, traits_type > Base
int memfun_inx(MemFun) const
static std::streamsize out_pending_