Commit 497e42fd by Benjamin Kosnik

[multiple changes]


2002-06-08  Paolo Carlini  <pcarlini@unitus.it>

	* testsuite/backwards/strstream_members.cc: New.

2002-06-08  Benjamin Kosnik  <bkoz@redhat.com>

	* include/backwards/strstream: Format.
	* src/strstream.cc: Format.

2002-06-08  Andreas Schwab  <schwab@suse.de>

	* src/strstream.cc (strstreambuf::overflow): Set _M_buf,
	_M_buf_size and _M_buf_size_opt to the new buffer and size.

From-SVN: r54375
parent e3623158
2002-06-08 Paolo Carlini <pcarlini@unitus.it>
* testsuite/backwards/strstream_members.cc: New.
2002-06-08 Benjamin Kosnik <bkoz@redhat.com>
* include/backwards/strstream: Format.
* src/strstream.cc: Format.
2002-06-08 Andreas Schwab <schwab@suse.de>
* src/strstream.cc (strstreambuf::overflow): Set _M_buf,
_M_buf_size and _M_buf_size_opt to the new buffer and size.
2002-06-08 Benjamin Kosnik <bkoz@redhat.com> 2002-06-08 Benjamin Kosnik <bkoz@redhat.com>
* config/os/generic/bits/ctype_noninline.h: Tweak format. * config/os/generic/bits/ctype_noninline.h: Tweak format.
......
// Backward-compat support -*- C++ -*- // Backward-compat support -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation, Inc. // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -57,18 +57,17 @@ ...@@ -57,18 +57,17 @@
namespace std namespace std
{ {
// Class strstreambuf, a streambuf class that manages an array of char.
//---------------------------------------------------------------------- // Note that this class is not a template.
// Class strstreambuf, a streambuf class that manages an array of char. class strstreambuf : public basic_streambuf<char, char_traits<char> >
// Note that this class is not a template. {
public:
class strstreambuf : public basic_streambuf<char, char_traits<char> > // Types.
{
public: // Types.
typedef char_traits<char> _Traits; typedef char_traits<char> _Traits;
typedef basic_streambuf<char, _Traits> _Base; typedef basic_streambuf<char, _Traits> _Base;
public: // Constructor, destructor public:
// Constructor, destructor
explicit strstreambuf(streamsize __initial_capacity = 0); explicit strstreambuf(streamsize __initial_capacity = 0);
strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*)); strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
...@@ -82,12 +81,12 @@ public: // Constructor, destructor ...@@ -82,12 +81,12 @@ public: // Constructor, destructor
virtual ~strstreambuf(); virtual ~strstreambuf();
public: // strstreambuf operations. public:
void freeze(bool = true); void freeze(bool = true);
char* str(); char* str();
int pcount() const; int pcount() const;
protected: // Overridden virtual member functions. protected:
virtual int_type overflow(int_type __c = _Traits::eof()); virtual int_type overflow(int_type __c = _Traits::eof());
virtual int_type pbackfail(int_type __c = _Traits::eof()); virtual int_type pbackfail(int_type __c = _Traits::eof());
virtual int_type underflow(); virtual int_type underflow();
...@@ -98,7 +97,7 @@ protected: // Overridden virtual member functions. ...@@ -98,7 +97,7 @@ protected: // Overridden virtual member functions.
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
= ios_base::in | ios_base::out); = ios_base::in | ios_base::out);
private: // Helper functions. private:
// Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun. // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
char* _M_alloc(size_t); char* _M_alloc(size_t);
void _M_free(char*); void _M_free(char*);
...@@ -106,21 +105,20 @@ private: // Helper functions. ...@@ -106,21 +105,20 @@ private: // Helper functions.
// Helper function used in constructors. // Helper function used in constructors.
void _M_setup(char* __get, char* __put, streamsize __n); void _M_setup(char* __get, char* __put, streamsize __n);
private: // Data members. private:
// Data members.
void* (*_M_alloc_fun)(size_t); void* (*_M_alloc_fun)(size_t);
void (*_M_free_fun)(void*); void (*_M_free_fun)(void*);
bool _M_dynamic : 1; bool _M_dynamic : 1;
bool _M_frozen : 1; bool _M_frozen : 1;
bool _M_constant : 1; bool _M_constant : 1;
}; };
//----------------------------------------------------------------------
// Class istrstream, an istream that manages a strstreambuf.
class istrstream : public basic_istream<char> // Class istrstream, an istream that manages a strstreambuf.
{ class istrstream : public basic_istream<char>
public: {
public:
explicit istrstream(char*); explicit istrstream(char*);
explicit istrstream(const char*); explicit istrstream(const char*);
istrstream(char* , streamsize); istrstream(char* , streamsize);
...@@ -130,16 +128,14 @@ public: ...@@ -130,16 +128,14 @@ public:
strstreambuf* rdbuf() const; strstreambuf* rdbuf() const;
char* str(); char* str();
private: private:
strstreambuf _M_buf; strstreambuf _M_buf;
}; };
//----------------------------------------------------------------------
// Class ostrstream
class ostrstream : public basic_ostream<char> // Class ostrstream
{ class ostrstream : public basic_ostream<char>
public: {
public:
ostrstream(); ostrstream();
ostrstream(char*, int, ios_base::openmode = ios_base::out); ostrstream(char*, int, ios_base::openmode = ios_base::out);
virtual ~ostrstream(); virtual ~ostrstream();
...@@ -149,16 +145,14 @@ public: ...@@ -149,16 +145,14 @@ public:
char* str(); char* str();
int pcount() const; int pcount() const;
private: private:
strstreambuf _M_buf; strstreambuf _M_buf;
}; };
//---------------------------------------------------------------------- // Class strstream
// Class strstream class strstream : public basic_iostream<char>
{
class strstream : public basic_iostream<char> public:
{
public:
typedef char char_type; typedef char char_type;
typedef char_traits<char>::int_type int_type; typedef char_traits<char>::int_type int_type;
typedef char_traits<char>::pos_type pos_type; typedef char_traits<char>::pos_type pos_type;
...@@ -173,16 +167,8 @@ public: ...@@ -173,16 +167,8 @@ public:
int pcount() const; int pcount() const;
char* str(); char* str();
private: private:
strstreambuf _M_buf; strstreambuf _M_buf;
}; };
} // namespace std } // namespace std
#endif
#endif /* __SGI_STL_STRSTREAM */
// Local Variables:
// mode:C++
// End:
// strstream definitions -*- C++ -*- // strstream definitions -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation // Copyright (C) 2001, 2002 Free Software Foundation
// //
// This file is part of GNU CC. // This file is part of GNU CC.
// //
...@@ -56,14 +56,10 @@ ...@@ -56,14 +56,10 @@
namespace std namespace std
{ {
strstreambuf::strstreambuf(streamsize initial_capacity)
// strstreambuf constructor, destructor. : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(true),
_M_frozen(false), _M_constant(false)
strstreambuf::strstreambuf(streamsize initial_capacity) {
: _Base(),
_M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(true), _M_frozen(false), _M_constant(false)
{
_M_buf_size = _M_buf_size_opt = max(initial_capacity, streamsize(16)); _M_buf_size = _M_buf_size_opt = max(initial_capacity, streamsize(16));
_M_buf = _M_alloc(_M_buf_size); _M_buf = _M_alloc(_M_buf_size);
if (_M_buf) if (_M_buf)
...@@ -71,13 +67,12 @@ strstreambuf::strstreambuf(streamsize initial_capacity) ...@@ -71,13 +67,12 @@ strstreambuf::strstreambuf(streamsize initial_capacity)
setp(_M_buf, _M_buf + _M_buf_size); setp(_M_buf, _M_buf + _M_buf_size);
setg(_M_buf, _M_buf, _M_buf); setg(_M_buf, _M_buf, _M_buf);
} }
} }
strstreambuf::strstreambuf(void* (*alloc_f)(size_t), void (*free_f)(void*)) strstreambuf::strstreambuf(void* (*alloc_f)(size_t), void (*free_f)(void*))
: _Base(), : _Base(), _M_alloc_fun(alloc_f), _M_free_fun(free_f), _M_dynamic(true),
_M_alloc_fun(alloc_f), _M_free_fun(free_f), _M_frozen(false), _M_constant(false)
_M_dynamic(true), _M_frozen(false), _M_constant(false) {
{
_M_buf_size = _M_buf_size_opt = 16; _M_buf_size = _M_buf_size_opt = 16;
_M_buf = _M_alloc(_M_buf_size); _M_buf = _M_alloc(_M_buf_size);
if (_M_buf) if (_M_buf)
...@@ -85,59 +80,41 @@ strstreambuf::strstreambuf(void* (*alloc_f)(size_t), void (*free_f)(void*)) ...@@ -85,59 +80,41 @@ strstreambuf::strstreambuf(void* (*alloc_f)(size_t), void (*free_f)(void*))
setp(_M_buf, _M_buf + _M_buf_size); setp(_M_buf, _M_buf + _M_buf_size);
setg(_M_buf, _M_buf, _M_buf); setg(_M_buf, _M_buf, _M_buf);
} }
} }
strstreambuf::strstreambuf(char* get, streamsize n, char* put) strstreambuf::strstreambuf(char* get, streamsize n, char* put)
: _Base(), : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(false),
_M_alloc_fun(0), _M_free_fun(0), _M_frozen(false), _M_constant(false)
_M_dynamic(false), _M_frozen(false), _M_constant(false) { _M_setup(get, put, n); }
{
_M_setup(get, put, n);
}
strstreambuf::strstreambuf(signed char* get, streamsize n, signed char* put) strstreambuf::strstreambuf(signed char* get, streamsize n, signed char* put)
: _Base(), : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(false),
_M_alloc_fun(0), _M_free_fun(0), _M_frozen(false), _M_constant(false)
_M_dynamic(false), _M_frozen(false), _M_constant(false) { _M_setup(reinterpret_cast<char*>(get), reinterpret_cast<char*>(put), n); }
{
_M_setup(reinterpret_cast<char*>(get), reinterpret_cast<char*>(put), n);
}
strstreambuf::strstreambuf(unsigned char* get, streamsize n, strstreambuf::strstreambuf(unsigned char* get, streamsize n,
unsigned char* put) unsigned char* put)
: _Base(), : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(false),
_M_alloc_fun(0), _M_free_fun(0), _M_frozen(false), _M_constant(false)
_M_dynamic(false), _M_frozen(false), _M_constant(false) { _M_setup(reinterpret_cast<char*>(get), reinterpret_cast<char*>(put), n); }
{
_M_setup(reinterpret_cast<char*>(get), reinterpret_cast<char*>(put), n); strstreambuf::strstreambuf(const char* get, streamsize n)
} : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(false),
_M_frozen(false), _M_constant(true)
strstreambuf::strstreambuf(const char* get, streamsize n) { _M_setup(const_cast<char*>(get), 0, n); }
: _Base(),
_M_alloc_fun(0), _M_free_fun(0), strstreambuf::strstreambuf(const signed char* get, streamsize n)
_M_dynamic(false), _M_frozen(false), _M_constant(true) : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(false),
{ _M_frozen(false), _M_constant(true)
_M_setup(const_cast<char*>(get), 0, n); { _M_setup(reinterpret_cast<char*>(const_cast<signed char*>(get)), 0, n); }
}
strstreambuf::strstreambuf(const unsigned char* get, streamsize n)
strstreambuf::strstreambuf(const signed char* get, streamsize n) : _Base(), _M_alloc_fun(0), _M_free_fun(0), _M_dynamic(false),
: _Base(), _M_frozen(false), _M_constant(true)
_M_alloc_fun(0), _M_free_fun(0), { _M_setup(reinterpret_cast<char*>(const_cast<unsigned char*>(get)), 0, n); }
_M_dynamic(false), _M_frozen(false), _M_constant(true)
{ strstreambuf::~strstreambuf()
_M_setup(reinterpret_cast<char*>(const_cast<signed char*>(get)), 0, n); {
}
strstreambuf::strstreambuf(const unsigned char* get, streamsize n)
: _Base(),
_M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(true)
{
_M_setup(reinterpret_cast<char*>(const_cast<unsigned char*>(get)), 0, n);
}
strstreambuf::~strstreambuf()
{
if (_M_dynamic && !_M_frozen) if (_M_dynamic && !_M_frozen)
{ {
char* p = this->eback(); char* p = this->eback();
...@@ -147,88 +124,102 @@ strstreambuf::~strstreambuf() ...@@ -147,88 +124,102 @@ strstreambuf::~strstreambuf()
} }
if (_M_buf) if (_M_buf)
_M_free(_M_buf); _M_free(_M_buf);
} }
void strstreambuf::freeze(bool frozenflag) void
{ strstreambuf::freeze(bool frozenflag)
{
if (_M_dynamic) if (_M_dynamic)
_M_frozen = frozenflag; _M_frozen = frozenflag;
} }
char* strstreambuf::str() char*
{ strstreambuf::str()
{
freeze(true); freeze(true);
return eback(); return eback();
} }
int strstreambuf::pcount() const int
{ strstreambuf::pcount() const
return pptr() ? pptr() - pbase() : 0; { return pptr() ? pptr() - pbase() : 0; }
}
strstreambuf::int_type strstreambuf::overflow(int_type c) { strstreambuf::int_type
strstreambuf::overflow(int_type c)
{
if (c == traits_type::eof()) if (c == traits_type::eof())
return traits_type::not_eof(c); return traits_type::not_eof(c);
// Try to expand the buffer. // Try to expand the buffer.
if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant) { if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant)
{
ptrdiff_t old_size = epptr() - pbase(); ptrdiff_t old_size = epptr() - pbase();
ptrdiff_t new_size = max(2 * old_size, ptrdiff_t(1)); ptrdiff_t new_size = max(2 * old_size, ptrdiff_t(1));
char* buf = _M_alloc(new_size); char* buf = _M_alloc(new_size);
if (buf) { if (buf)
{
memcpy(buf, pbase(), old_size); memcpy(buf, pbase(), old_size);
char* old_buffer = pbase(); char* old_buffer = pbase();
bool reposition_get = false; bool reposition_get = false;
ptrdiff_t old_get_offset; ptrdiff_t old_get_offset;
if (gptr() != 0) { if (gptr() != 0)
{
reposition_get = true; reposition_get = true;
old_get_offset = gptr() - eback(); old_get_offset = gptr() - eback();
} }
_M_buf = buf;
_M_buf_size = _M_buf_size_opt = new_size;
setp(buf, buf + new_size); setp(buf, buf + new_size);
pbump(old_size); pbump(old_size);
if (reposition_get) if (reposition_get)
setg(buf, buf + old_get_offset, buf + max(old_get_offset, old_size)); setg(buf, buf + old_get_offset, buf +
max(old_get_offset, old_size));
_M_free(old_buffer); _M_free(old_buffer);
} }
} }
if (pptr() != epptr()) { if (pptr() != epptr())
{
*pptr() = c; *pptr() = c;
pbump(1); pbump(1);
return c; return c;
} }
else else
return traits_type::eof(); return traits_type::eof();
} }
strstreambuf::int_type strstreambuf::pbackfail(int_type c) strstreambuf::int_type
{ strstreambuf::pbackfail(int_type c)
if (gptr() != eback()) { {
if (c == _Traits::eof()) { if (gptr() != eback())
{
if (c == _Traits::eof())
{
gbump(-1); gbump(-1);
return _Traits::not_eof(c); return _Traits::not_eof(c);
} }
else if (c == static_cast<int_type>(gptr()[-1])) { // KLUDGE else if (c == static_cast<int_type>(gptr()[-1]))
{ // KLUDGE
gbump(-1); gbump(-1);
return c; return c;
} }
else if (!_M_constant) { else if (!_M_constant)
{
gbump(-1); gbump(-1);
*gptr() = c; *gptr() = c;
return c; return c;
} }
} }
return _Traits::eof(); return _Traits::eof();
} }
strstreambuf::int_type strstreambuf::underflow() strstreambuf::int_type
{ strstreambuf::underflow()
{
if (gptr() == egptr() && pptr() && pptr() > egptr()) if (gptr() == egptr() && pptr() && pptr() > egptr())
setg(eback(), gptr(), pptr()); setg(eback(), gptr(), pptr());
...@@ -236,23 +227,21 @@ strstreambuf::int_type strstreambuf::underflow() ...@@ -236,23 +227,21 @@ strstreambuf::int_type strstreambuf::underflow()
return (unsigned char) *gptr(); return (unsigned char) *gptr();
else else
return _Traits::eof(); return _Traits::eof();
} }
basic_streambuf<char, char_traits<char> >* basic_streambuf<char, char_traits<char> >*
strstreambuf::setbuf(char*, streamsize) strstreambuf::setbuf(char*, streamsize)
{ { return this; }
return this;
}
strstreambuf::pos_type strstreambuf::pos_type
strstreambuf::seekoff(off_type off, strstreambuf::seekoff(off_type off, ios_base::seekdir dir,
ios_base::seekdir dir, ios_base::openmode mode) ios_base::openmode mode)
{ {
bool do_get = false; bool do_get = false;
bool do_put = false; bool do_put = false;
if ((mode & (ios_base::in | ios_base::out)) == if ((mode & (ios_base::in | ios_base::out))
(ios_base::in | ios_base::out) && == (ios_base::in | ios_base::out) &&
(dir == ios_base::beg || dir == ios_base::end)) (dir == ios_base::beg || dir == ios_base::end))
do_get = do_put = true; do_get = do_put = true;
else if (mode & ios_base::in) else if (mode & ios_base::in)
...@@ -269,7 +258,8 @@ strstreambuf::seekoff(off_type off, ...@@ -269,7 +258,8 @@ strstreambuf::seekoff(off_type off,
char* seekhigh = epptr() ? epptr() : egptr(); char* seekhigh = epptr() ? epptr() : egptr();
off_type newoff; off_type newoff;
switch(dir) { switch (dir)
{
case ios_base::beg: case ios_base::beg:
newoff = 0; newoff = 0;
break; break;
...@@ -287,17 +277,21 @@ strstreambuf::seekoff(off_type off, ...@@ -287,17 +277,21 @@ strstreambuf::seekoff(off_type off,
if (off < 0 || off > seekhigh - seeklow) if (off < 0 || off > seekhigh - seeklow)
return pos_type(off_type(-1)); return pos_type(off_type(-1));
if (do_put) { if (do_put)
if (seeklow + off < pbase()) { {
if (seeklow + off < pbase())
{
setp(seeklow, epptr()); setp(seeklow, epptr());
pbump(off); pbump(off);
} }
else { else
{
setp(pbase(), epptr()); setp(pbase(), epptr());
pbump(off - (pbase() - seeklow)); pbump(off - (pbase() - seeklow));
} }
} }
if (do_get) { if (do_get)
{
if (off <= egptr() - seeklow) if (off <= egptr() - seeklow)
setg(seeklow, seeklow + off, egptr()); setg(seeklow, seeklow + off, egptr());
else if (off <= pptr() - seeklow) else if (off <= pptr() - seeklow)
...@@ -305,161 +299,126 @@ strstreambuf::seekoff(off_type off, ...@@ -305,161 +299,126 @@ strstreambuf::seekoff(off_type off,
else else
setg(seeklow, seeklow + off, epptr()); setg(seeklow, seeklow + off, epptr());
} }
return pos_type(newoff); return pos_type(newoff);
} }
strstreambuf::pos_type strstreambuf::pos_type
strstreambuf::seekpos(pos_type pos, ios_base::openmode mode) strstreambuf::seekpos(pos_type pos, ios_base::openmode mode)
{ { return seekoff(pos - pos_type(off_type(0)), ios_base::beg, mode); }
return seekoff(pos - pos_type(off_type(0)), ios_base::beg, mode);
}
char* strstreambuf::_M_alloc(size_t n) char*
{ strstreambuf::_M_alloc(size_t n)
{
if (_M_alloc_fun) if (_M_alloc_fun)
return static_cast<char*>(_M_alloc_fun(n)); return static_cast<char*>(_M_alloc_fun(n));
else else
return new char[n]; return new char[n];
} }
void strstreambuf::_M_free(char* p) void
{ strstreambuf::_M_free(char* p)
{
if (p) if (p)
if (_M_free_fun) if (_M_free_fun)
_M_free_fun(p); _M_free_fun(p);
else else
delete[] p; delete[] p;
} }
void strstreambuf::_M_setup(char* get, char* put, streamsize n) void
{ strstreambuf::_M_setup(char* get, char* put, streamsize n)
if (get) { {
if (get)
{
size_t N = n > 0 ? size_t(n) : n == 0 ? strlen(get) : size_t(INT_MAX); size_t N = n > 0 ? size_t(n) : n == 0 ? strlen(get) : size_t(INT_MAX);
if (put) { if (put)
{
setg(get, get, put); setg(get, get, put);
setp(put, put + N); setp(put, put + N);
} }
else { else
setg(get, get, get + N); setg(get, get, get + N);
} }
} }
}
//----------------------------------------------------------------------
// Class istrstream
istrstream::istrstream(char* s) istrstream::istrstream(char* s)
: basic_ios<char>(), basic_istream<char>(0), _M_buf(s, 0) : basic_ios<char>(), basic_istream<char>(0), _M_buf(s, 0)
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
istrstream::istrstream(const char* s) istrstream::istrstream(const char* s)
: basic_ios<char>(), basic_istream<char>(0), _M_buf(s, 0) : basic_ios<char>(), basic_istream<char>(0), _M_buf(s, 0)
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
istrstream::istrstream(char* s, streamsize n) istrstream::istrstream(char* s, streamsize n)
: basic_ios<char>(), basic_istream<char>(0), _M_buf(s, n) : basic_ios<char>(), basic_istream<char>(0), _M_buf(s, n)
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
istrstream::istrstream(const char* s, streamsize n) istrstream::istrstream(const char* s, streamsize n)
: basic_ios<char>(), basic_istream<char>(0), _M_buf(s, n) : basic_ios<char>(), basic_istream<char>(0), _M_buf(s, n)
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
istrstream::~istrstream() {} istrstream::~istrstream() { }
strstreambuf* istrstream::rdbuf() const { strstreambuf*
return const_cast<strstreambuf*>(&_M_buf); istrstream::rdbuf() const
} { return const_cast<strstreambuf*>(&_M_buf); }
char* istrstream::str() { return _M_buf.str(); } char*
istrstream::str()
{ return _M_buf.str(); }
//---------------------------------------------------------------------- ostrstream::ostrstream()
// Class ostrstream
ostrstream::ostrstream()
: basic_ios<char>(), basic_ostream<char>(0), _M_buf() : basic_ios<char>(), basic_ostream<char>(0), _M_buf()
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
ostrstream::ostrstream(char* s, int n, ios_base::openmode mode) ostrstream::ostrstream(char* s, int n, ios_base::openmode mode)
: basic_ios<char>(), basic_ostream<char>(0), : basic_ios<char>(), basic_ostream<char>(0),
_M_buf(s, n, mode & ios_base::app ? s + strlen(s) : s) _M_buf(s, n, mode & ios_base::app ? s + strlen(s) : s)
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
ostrstream::~ostrstream() {} ostrstream::~ostrstream() {}
strstreambuf* ostrstream::rdbuf() const
{
return const_cast<strstreambuf*>(&_M_buf);
}
void ostrstream::freeze(bool freezeflag) strstreambuf*
{ ostrstream::rdbuf() const
_M_buf.freeze(freezeflag); { return const_cast<strstreambuf*>(&_M_buf); }
}
char* ostrstream::str() void
{ ostrstream::freeze(bool freezeflag)
return _M_buf.str(); { _M_buf.freeze(freezeflag); }
}
int ostrstream::pcount() const char*
{ ostrstream::str()
return _M_buf.pcount(); { return _M_buf.str(); }
}
//---------------------------------------------------------------------- int
// Class strstream ostrstream::pcount() const
{ return _M_buf.pcount(); }
strstream::strstream() strstream::strstream()
: basic_ios<char>(), basic_iostream<char>(0), _M_buf() : basic_ios<char>(), basic_iostream<char>(0), _M_buf()
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
strstream::strstream(char* s, int n, ios_base::openmode mode) strstream::strstream(char* s, int n, ios_base::openmode mode)
: basic_ios<char>(), basic_iostream<char>(0), : basic_ios<char>(), basic_iostream<char>(0),
_M_buf(s, n, mode & ios_base::app ? s + strlen(s) : s) _M_buf(s, n, mode & ios_base::app ? s + strlen(s) : s)
{ { basic_ios<char>::init(&_M_buf); }
basic_ios<char>::init(&_M_buf);
}
strstream::~strstream() {} strstream::~strstream() { }
strstreambuf* strstream::rdbuf() const strstreambuf*
{ strstream::rdbuf() const
return const_cast<strstreambuf*>(&_M_buf); { return const_cast<strstreambuf*>(&_M_buf); }
}
void strstream::freeze(bool freezeflag) void
{ strstream::freeze(bool freezeflag)
_M_buf.freeze(freezeflag); { _M_buf.freeze(freezeflag); }
}
int strstream::pcount() const int
{ strstream::pcount() const
return _M_buf.pcount(); { return _M_buf.pcount(); }
}
char* strstream::str()
{
return _M_buf.str();
}
char*
strstream::str()
{ return _M_buf.str(); }
} // namespace std } // namespace std
// Local Variables:
// mode:C++
// End:
// Copyright (C) 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// backward strstream members
#include <strstream.h>
#include <testsuite_hooks.h>
// { dg-options "-Wno-deprecated" }
int test01()
{
strstream s;
for (unsigned i=0 ; i!= 1000 ; ++i)
s << i << std::endl;
s << std::ends;
return 0;
}
int main()
{
test01();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment