79 | | class parser_buf : public ::std::basic_streambuf<charT, traits> |
80 | | { |
81 | | typedef ::std::basic_streambuf<charT, traits> base_type; |
82 | | typedef typename base_type::int_type int_type; |
83 | | typedef typename base_type::char_type char_type; |
84 | | typedef typename base_type::pos_type pos_type; |
85 | | typedef ::std::streamsize streamsize; |
86 | | typedef typename base_type::off_type off_type; |
87 | | public: |
88 | | parser_buf() : base_type() { setbuf(0, 0); } |
89 | | const charT* getnext() { return this->gptr(); } |
90 | | protected: |
91 | | std::basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n); |
92 | | typename parser_buf<charT, traits>::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which); |
93 | | typename parser_buf<charT, traits>::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which); |
94 | | private: |
95 | | parser_buf& operator=(const parser_buf&); |
96 | | parser_buf(const parser_buf&); |
97 | | }; |
| 80 | class parser_buf |
| 81 | : public boost::detail::basic_pointerbuf<charT, std::basic_streambuf<charT, traits> > |
| 82 | {}; |
99 | | template<class charT, class traits> |
100 | | std::basic_streambuf<charT, traits>* |
101 | | parser_buf<charT, traits>::setbuf(char_type* s, streamsize n) |
102 | | { |
103 | | this->setg(s, s, s + n); |
104 | | return this; |
105 | | } |
106 | | |
107 | | template<class charT, class traits> |
108 | | typename parser_buf<charT, traits>::pos_type |
109 | | parser_buf<charT, traits>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which) |
110 | | { |
111 | | typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type; |
112 | | |
113 | | if(which & ::std::ios_base::out) |
114 | | return pos_type(off_type(-1)); |
115 | | std::ptrdiff_t size = this->egptr() - this->eback(); |
116 | | std::ptrdiff_t pos = this->gptr() - this->eback(); |
117 | | charT* g = this->eback(); |
118 | | switch(static_cast<cast_type>(way)) |
119 | | { |
120 | | case ::std::ios_base::beg: |
121 | | if((off < 0) || (off > size)) |
122 | | return pos_type(off_type(-1)); |
123 | | else |
124 | | this->setg(g, g + off, g + size); |
125 | | break; |
126 | | case ::std::ios_base::end: |
127 | | if((off < 0) || (off > size)) |
128 | | return pos_type(off_type(-1)); |
129 | | else |
130 | | this->setg(g, g + size - off, g + size); |
131 | | break; |
132 | | case ::std::ios_base::cur: |
133 | | { |
134 | | std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off); |
135 | | if((newpos < 0) || (newpos > size)) |
136 | | return pos_type(off_type(-1)); |
137 | | else |
138 | | this->setg(g, g + newpos, g + size); |
139 | | break; |
140 | | } |
141 | | default: ; |
142 | | } |
143 | | #ifdef BOOST_MSVC |
144 | | #pragma warning(push) |
145 | | #pragma warning(disable:4244) |
146 | | #endif |
147 | | return static_cast<pos_type>(this->gptr() - this->eback()); |
148 | | #ifdef BOOST_MSVC |
149 | | #pragma warning(pop) |
150 | | #endif |
151 | | } |
152 | | |
153 | | template<class charT, class traits> |
154 | | typename parser_buf<charT, traits>::pos_type |
155 | | parser_buf<charT, traits>::seekpos(pos_type sp, ::std::ios_base::openmode which) |
156 | | { |
157 | | if(which & ::std::ios_base::out) |
158 | | return pos_type(off_type(-1)); |
159 | | off_type size = static_cast<off_type>(this->egptr() - this->eback()); |
160 | | charT* g = this->eback(); |
161 | | if(off_type(sp) <= size) |
162 | | { |
163 | | this->setg(g, g + off_type(sp), g + size); |
164 | | } |
165 | | return pos_type(off_type(-1)); |
166 | | } |
167 | | |