1
/* Copyright (C) 2004 Garrett A. Kajmowicz
3
This file is part of the uClibc++ Library.
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <basic_definitions>
22
#ifndef HEADER_STD_SSTREAM
23
#define HEADER_STD_SSTREAM 1
32
#pragma GCC visibility push(default)
36
template <class charT, class traits, class Allocator>
37
class _UCXXEXPORT basic_stringbuf : public basic_streambuf<charT,traits>
40
typedef charT char_type;
41
typedef typename traits::int_type int_type;
42
typedef typename traits::pos_type pos_type;
43
typedef typename traits::off_type off_type;
44
typedef typename Allocator::size_type size_type;
46
explicit _UCXXEXPORT basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out)
47
: data(), ielement(0), oelement(0)
49
basic_streambuf<charT,traits>::openedFor = which;
52
explicit _UCXXEXPORT basic_stringbuf(const basic_string<charT,traits,Allocator>& str,
53
ios_base::openmode which = ios_base::in | ios_base::out)
54
: data(str), ielement(0), oelement(0)
56
if(which & ios_base::ate){
57
oelement = data.length();
59
basic_streambuf<charT,traits>::openedFor = which;
62
virtual _UCXXEXPORT ~basic_stringbuf() { }
64
_UCXXEXPORT basic_string<charT,traits,Allocator> str() const{
68
_UCXXEXPORT void str(const basic_string<charT,traits,Allocator>& s){
71
if(basic_streambuf<charT,traits>::openedFor & ios_base::ate){
72
oelement = data.length();
79
virtual _UCXXEXPORT int sync(){
82
virtual _UCXXEXPORT int_type underflow(){
83
if(ielement >= data.length()){
86
return traits::to_int_type(data[ielement]);
89
virtual _UCXXEXPORT int_type uflow(){
90
int_type retval = underflow();
91
if(retval != traits::eof()){
97
virtual _UCXXEXPORT int_type pbackfail(int_type c = traits::eof()){
100
return traits::eof();
102
if(ielement > data.length()){
103
ielement = data.length();
104
return traits::eof();
107
if(traits::eq_int_type(c,traits::eof())==true){
109
return traits::not_eof(c);
111
if(traits::eq(traits::to_char_type(c),data[ielement-1]) == true){
115
if(basic_streambuf<charT,traits>::openedFor & ios_base::out){
120
return traits::eof();
123
virtual _UCXXEXPORT int showmanyc(){
124
return data.length() - ielement;
126
virtual _UCXXEXPORT streamsize xsgetn(char_type* c, streamsize n){
128
while(ielement < data.length() && i < n ){
129
c[i] = data[ielement];
136
virtual _UCXXEXPORT int_type overflow (int_type c = traits::eof()){
138
if(traits::eq_int_type(c,traits::eof())){
139
return traits::not_eof(c);
142
//Actually add character, if possible
143
if(basic_streambuf<charT,traits>::openedFor & ios_base::out){
144
if(oelement >= data.length()){
153
return traits::eof();
156
virtual _UCXXEXPORT basic_streambuf<charT,traits>* setbuf(charT*, streamsize){
157
//This function does nothing
161
virtual _UCXXEXPORT streamsize xsputn(const char_type* s, streamsize n){
162
data.replace(oelement, n, s, n);
167
virtual _UCXXEXPORT pos_type seekoff(off_type off, ios_base::seekdir way,
168
ios_base::openmode which = ios_base::in | ios_base::out)
170
//Test for invalid option
171
if( (which & ios_base::in) && (which & ios_base::out) && (way == ios_base::cur)){
175
//Calculate new location
176
size_type newpos = 0;
178
if(way == ios_base::beg){
180
}else if(way == ios_base::cur){
181
if(which & ios_base::out){
182
newpos = data.length() + off;
184
if(which & ios_base::in){
185
newpos = ielement + off;
189
newpos = data.length() + off;
192
//Test for error conditions
193
if(newpos > data.length()){
199
if(which & ios_base::in){
202
if(which & ios_base::out){
204
if(ielement > data.length()){
205
ielement = data.length();
212
virtual _UCXXEXPORT pos_type seekpos(pos_type sp,
213
ios_base::openmode which = ios_base::in | ios_base::out)
215
return seekoff(sp, ios_base::beg, which);
218
basic_string<charT,traits,Allocator> data;
224
template <class charT, class traits, class Allocator> class _UCXXEXPORT basic_istringstream
225
: public basic_istream<charT,traits>
228
typedef charT char_type;
229
typedef typename traits::int_type int_type;
230
typedef typename traits::pos_type pos_type;
231
typedef typename traits::off_type off_type;
234
explicit _UCXXEXPORT basic_istringstream(ios_base::openmode m = ios_base::in)
235
: basic_ios<charT, traits>(&sb), basic_istream<charT,traits>(&sb), sb(m)
238
explicit _UCXXEXPORT basic_istringstream( const basic_string<charT,traits,Allocator>& str,
239
ios_base::openmode which = ios_base::in)
240
: basic_ios<charT, traits>(&sb), basic_istream<charT,traits>(&sb), sb(str, which)
243
virtual _UCXXEXPORT ~basic_istringstream() { }
244
_UCXXEXPORT basic_stringbuf<charT,traits,Allocator>* rdbuf() const{
247
_UCXXEXPORT basic_string<charT,traits,Allocator> str() const{
250
_UCXXEXPORT void str(const basic_string<charT,traits,Allocator>& s){
252
basic_istream<charT,traits>::clear();
255
basic_stringbuf<charT,traits,Allocator> sb;
259
template <class charT, class traits, class Allocator> class _UCXXEXPORT basic_ostringstream
260
: public basic_ostream<charT,traits>
264
typedef charT char_type;
265
typedef typename traits::int_type int_type;
266
typedef typename traits::pos_type pos_type;
267
typedef typename traits::off_type off_type;
269
explicit _UCXXEXPORT basic_ostringstream(ios_base::openmode m = ios_base::out)
270
: basic_ios<charT, traits>(&sb), basic_ostream<charT,traits>(&sb), sb(m)
273
explicit _UCXXEXPORT basic_ostringstream(const basic_string<charT,traits,Allocator>& str,
274
ios_base::openmode which = ios_base::out)
275
: basic_ios<charT, traits>(&sb), basic_ostream<charT,traits>(&sb), sb(str, which)
278
virtual _UCXXEXPORT ~basic_ostringstream() { }
280
_UCXXEXPORT basic_stringbuf<charT,traits,Allocator>* rdbuf() const{
283
_UCXXEXPORT basic_string<charT,traits,Allocator> str() const{
286
_UCXXEXPORT void str(const basic_string<charT,traits,Allocator>& s){
288
basic_ostream<charT,traits>::clear();
291
basic_stringbuf<charT,traits,Allocator> sb;
295
template <class charT, class traits, class Allocator> class _UCXXEXPORT basic_stringstream
296
: public basic_iostream<charT,traits>
300
typedef charT char_type;
301
typedef typename traits::int_type int_type;
302
typedef typename traits::pos_type pos_type;
303
typedef typename traits::off_type off_type;
305
explicit _UCXXEXPORT basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in)
306
: basic_ios<charT, traits>(&sb), basic_iostream<charT,traits>(&sb), sb(which)
310
explicit _UCXXEXPORT basic_stringstream(const basic_string<charT,traits,Allocator>& str,
311
ios_base::openmode which = ios_base::out|ios_base::in)
312
: basic_ios<charT, traits>(&sb), basic_iostream<charT,traits>(&sb), sb(str, which)
315
virtual _UCXXEXPORT ~basic_stringstream(){ }
317
_UCXXEXPORT basic_stringbuf<charT,traits,Allocator>* rdbuf(){
320
_UCXXEXPORT basic_string<charT,traits,Allocator> str() const{
323
_UCXXEXPORT void str(const basic_string<charT,traits,Allocator>& s){
325
basic_iostream<charT,traits>::clear();
328
basic_stringbuf<charT, traits> sb;
331
#ifdef __UCLIBCXX_EXPAND_SSTREAM_CHAR__
332
#ifndef __UCLIBCXX_COMPILE_SSTREAM__
334
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
336
template <> _UCXXEXPORT basic_stringbuf<char, char_traits<char>, allocator<char> >::
337
basic_stringbuf(ios_base::openmode which);
338
template <> _UCXXEXPORT basic_stringbuf<char, char_traits<char>, allocator<char> >::~basic_stringbuf();
340
#endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
342
template <> _UCXXEXPORT basic_string<char, char_traits<char>, allocator<char> >
343
basic_stringbuf<char, char_traits<char>, allocator<char> >::str() const;
345
template <> _UCXXEXPORT basic_stringbuf<char, char_traits<char>, allocator<char> >::int_type
346
basic_stringbuf<char, char_traits<char>, allocator<char> >::
347
pbackfail(basic_stringbuf<char, char_traits<char>, allocator<char> >::int_type c);
349
template <> _UCXXEXPORT basic_stringbuf<char, char_traits<char>, allocator<char> >::pos_type
350
basic_stringbuf<char, char_traits<char>, allocator<char> >::
351
seekoff (basic_stringbuf<char, char_traits<char>, allocator<char> >::off_type off,
352
ios_base::seekdir way,
353
ios_base::openmode which
356
template <> _UCXXEXPORT basic_stringbuf<char, char_traits<char>, allocator<char> >::int_type
357
basic_stringbuf<char, char_traits<char>, allocator<char> >::
358
overflow (basic_stringbuf<char, char_traits<char>, allocator<char> >::int_type c);
360
template <> _UCXXEXPORT basic_stringbuf<char, char_traits<char>, allocator<char> >::int_type
361
basic_stringbuf<char, char_traits<char>, allocator<char> >::underflow ();
363
template <> _UCXXEXPORT streamsize basic_stringbuf<char, char_traits<char>, allocator<char> >::
364
xsputn(const char* s, streamsize n);
366
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
368
template <> _UCXXEXPORT basic_stringstream<char, char_traits<char>, allocator<char> >::
369
basic_stringstream(ios_base::openmode which);
370
template <> _UCXXEXPORT basic_stringstream<char, char_traits<char>, allocator<char> >::~basic_stringstream();
371
template <> _UCXXEXPORT basic_istringstream<char, char_traits<char>, allocator<char> >::~basic_istringstream();
372
template <> _UCXXEXPORT basic_ostringstream<char, char_traits<char>, allocator<char> >::~basic_ostringstream();
374
#endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
379
#pragma GCC visibility pop