1
// (C) Copyright John Maddock 2001.
2
// Use, modification and distribution are subject to the
3
// Boost Software License, Version 1.0. (See accompanying file
4
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
// See http://www.boost.org/libs/config for most recent version.
8
// MACRO: BOOST_NO_STD_WSTREAMBUF
9
// TITLE: std::basic_streambuf<wchar_t>
10
// DESCRIPTION: The standard library lacks std::basic_streambuf<wchar_t>.
16
namespace boost_no_std_wstreambuf{
18
template <class charT,
19
class traits = ::std::char_traits<charT> >
20
class parser_buf : public ::std::basic_streambuf<charT, traits>
22
typedef ::std::basic_streambuf<charT, traits> base_type;
23
typedef typename base_type::int_type int_type;
24
typedef typename base_type::char_type char_type;
25
typedef typename base_type::pos_type pos_type;
26
typedef ::std::streamsize streamsize;
27
typedef typename base_type::off_type off_type;
29
parser_buf() : base_type() { setbuf(0, 0); }
30
const charT* getnext() { return this->gptr(); }
32
std::basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n);
33
typename parser_buf<charT, traits>::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which);
34
typename parser_buf<charT, traits>::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which);
36
parser_buf& operator=(const parser_buf&)
38
parser_buf(const parser_buf&){};
41
template<class charT, class traits>
42
std::basic_streambuf<charT, traits>*
43
parser_buf<charT, traits>::setbuf(char_type* s, streamsize n)
45
this->setg(s, s, s + n);
49
template<class charT, class traits>
50
typename parser_buf<charT, traits>::pos_type
51
parser_buf<charT, traits>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
53
typedef typename parser_buf<charT, traits>::pos_type pos_type;
54
if(which & ::std::ios_base::out)
55
return pos_type(off_type(-1));
56
int size = this->egptr() - this->eback();
57
int pos = this->gptr() - this->eback();
58
charT* g = this->eback();
61
case ::std::ios_base::beg:
62
if((off < 0) || (off > size))
63
return pos_type(off_type(-1));
65
this->setg(g, g + off, g + size);
66
case ::std::ios_base::end:
67
if((off < 0) || (off > size))
68
return pos_type(off_type(-1));
70
this->setg(g, g + size - off, g + size);
71
case ::std::ios_base::cur:
73
int newpos = pos + off;
74
if((newpos < 0) || (newpos > size))
75
return pos_type(off_type(-1));
77
this->setg(g, g + newpos, g + size);
80
return static_cast<pos_type>(this->gptr() - this->eback());
83
template<class charT, class traits>
84
typename parser_buf<charT, traits>::pos_type
85
parser_buf<charT, traits>::seekpos(pos_type sp, ::std::ios_base::openmode which)
87
if(which & ::std::ios_base::out)
88
return pos_type(off_type(-1));
89
int size = this->egptr() - this->eback();
90
charT* g = this->eback();
91
if(off_type(sp) <= size)
93
this->setg(g, g + off_type(sp), g + size);
95
return pos_type(off_type(-1));
104
template class parser_buf<char>;
105
template class parser_buf<wchar_t>;