mirror of git://gcc.gnu.org/git/gcc.git
basic_ios.tcc: Small tweak.
2001-05-24 Benjamin Kosnik <bkoz@redhat.com> libstdc++/2832 * include/bits/basic_ios.tcc: Small tweak. * include/bits/std_fstream.h (ifstream): Add buffer member. Adjust ctors and dtors, and rdbuf settings. (ofstream): Same. (fstream): Same. * include/bits/std_sstream.h: Same, but for stringstream classes. * testsuite/27_io/ostringstream_members.cc: New. * testsuite/27_io/stringstream_members.cc: New. * testsuite/27_io/fstream_members.cc: New. * testsuite/27_io/ifstream_members.cc: Add test. * testsuite/27_io/istringstream_members.cc: Add test. * testsuite/27_io/ofstream_members.cc: Add test. From-SVN: r42547
This commit is contained in:
parent
476c334ecf
commit
d422980b3f
|
@ -1,3 +1,19 @@
|
||||||
|
2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
libstdc++/2832
|
||||||
|
* include/bits/basic_ios.tcc: Small tweak.
|
||||||
|
* include/bits/std_fstream.h (ifstream): Add buffer member. Adjust
|
||||||
|
ctors and dtors, and rdbuf settings.
|
||||||
|
(ofstream): Same.
|
||||||
|
(fstream): Same.
|
||||||
|
* include/bits/std_sstream.h: Same, but for stringstream classes.
|
||||||
|
* testsuite/27_io/ostringstream_members.cc: New.
|
||||||
|
* testsuite/27_io/stringstream_members.cc: New.
|
||||||
|
* testsuite/27_io/fstream_members.cc: New.
|
||||||
|
* testsuite/27_io/ifstream_members.cc: Add test.
|
||||||
|
* testsuite/27_io/istringstream_members.cc: Add test.
|
||||||
|
* testsuite/27_io/ofstream_members.cc: Add test.
|
||||||
|
|
||||||
2001-05-24 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
|
2001-05-24 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
|
||||||
|
|
||||||
* include/bits/c++config(__NO_MATH_INLINES): Move to...
|
* include/bits/c++config(__NO_MATH_INLINES): Move to...
|
||||||
|
|
|
@ -132,6 +132,6 @@ namespace std {
|
||||||
|
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
#endif /* _CPP_BITS_BASICIOS_TCC */
|
#endif // _CPP_BITS_BASICIOS_TCC
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -244,41 +244,45 @@ namespace std
|
||||||
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
|
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
|
||||||
typedef basic_istream<char_type, traits_type> __istream_type;
|
typedef basic_istream<char_type, traits_type> __istream_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
__filebuf_type _M_filebuf;
|
||||||
|
|
||||||
|
public:
|
||||||
// Constructors/Destructors:
|
// Constructors/Destructors:
|
||||||
basic_ifstream()
|
basic_ifstream()
|
||||||
: __istream_type(new __filebuf_type())
|
: __istream_type(NULL), _M_filebuf()
|
||||||
{ }
|
{ this->init(&_M_filebuf); }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
|
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
|
||||||
: __istream_type(new __filebuf_type())
|
: __istream_type(NULL), _M_filebuf()
|
||||||
{ this->open(__s, __mode); }
|
{
|
||||||
|
this->init(&_M_filebuf);
|
||||||
|
this->open(__s, __mode);
|
||||||
|
}
|
||||||
|
|
||||||
~basic_ifstream()
|
~basic_ifstream()
|
||||||
{
|
{ }
|
||||||
delete _M_streambuf;
|
|
||||||
_M_streambuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Members:
|
// Members:
|
||||||
__filebuf_type*
|
__filebuf_type*
|
||||||
rdbuf() const
|
rdbuf() const
|
||||||
{ return static_cast<__filebuf_type*>(_M_streambuf); }
|
{ return const_cast<__filebuf_type*>(&_M_filebuf); }
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_open(void) { return rdbuf()->is_open(); }
|
is_open(void) { return _M_filebuf.is_open(); }
|
||||||
|
|
||||||
void
|
void
|
||||||
open(const char* __s, ios_base::openmode __mode = ios_base::in)
|
open(const char* __s, ios_base::openmode __mode = ios_base::in)
|
||||||
{
|
{
|
||||||
if (rdbuf()->open(__s, __mode | ios_base::in) == NULL)
|
if (_M_filebuf.open(__s, __mode | ios_base::in) == NULL)
|
||||||
this->setstate(ios_base::failbit);
|
this->setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
close(void)
|
close(void)
|
||||||
{
|
{
|
||||||
if (!rdbuf()->close())
|
if (!_M_filebuf.close())
|
||||||
this->setstate(ios_base::failbit);
|
this->setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -300,43 +304,47 @@ namespace std
|
||||||
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
|
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
|
||||||
typedef basic_ostream<char_type, traits_type> __ostream_type;
|
typedef basic_ostream<char_type, traits_type> __ostream_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
__filebuf_type _M_filebuf;
|
||||||
|
|
||||||
|
public:
|
||||||
// Constructors:
|
// Constructors:
|
||||||
basic_ofstream()
|
basic_ofstream()
|
||||||
: __ostream_type(new __filebuf_type())
|
: __ostream_type(NULL), _M_filebuf()
|
||||||
{ }
|
{ this->init(&_M_filebuf); }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
basic_ofstream(const char* __s,
|
basic_ofstream(const char* __s,
|
||||||
ios_base::openmode __mode = ios_base::out|ios_base::trunc)
|
ios_base::openmode __mode = ios_base::out|ios_base::trunc)
|
||||||
: __ostream_type(new __filebuf_type())
|
: __ostream_type(NULL), _M_filebuf()
|
||||||
{ this->open(__s, __mode); }
|
{
|
||||||
|
this->init(&_M_filebuf);
|
||||||
|
this->open(__s, __mode);
|
||||||
|
}
|
||||||
|
|
||||||
~basic_ofstream()
|
~basic_ofstream()
|
||||||
{
|
{ }
|
||||||
delete _M_streambuf;
|
|
||||||
_M_streambuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Members:
|
// Members:
|
||||||
__filebuf_type*
|
__filebuf_type*
|
||||||
rdbuf(void) const
|
rdbuf(void) const
|
||||||
{ return static_cast<__filebuf_type*>(_M_streambuf); }
|
{ return const_cast<__filebuf_type*>(&_M_filebuf); }
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_open(void) { return rdbuf()->is_open(); }
|
is_open(void) { return _M_filebuf.is_open(); }
|
||||||
|
|
||||||
void
|
void
|
||||||
open(const char* __s,
|
open(const char* __s,
|
||||||
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
|
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
|
||||||
{
|
{
|
||||||
if (!rdbuf()->open(__s, __mode | ios_base::out))
|
if (!_M_filebuf.open(__s, __mode | ios_base::out))
|
||||||
this->setstate(ios_base::failbit);
|
this->setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
close(void)
|
close(void)
|
||||||
{
|
{
|
||||||
if (!rdbuf()->close())
|
if (!_M_filebuf.close())
|
||||||
setstate(ios_base::failbit);
|
setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -359,44 +367,48 @@ namespace std
|
||||||
typedef basic_ios<char_type, traits_type> __ios_type;
|
typedef basic_ios<char_type, traits_type> __ios_type;
|
||||||
typedef basic_iostream<char_type, traits_type> __iostream_type;
|
typedef basic_iostream<char_type, traits_type> __iostream_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
__filebuf_type _M_filebuf;
|
||||||
|
|
||||||
|
public:
|
||||||
// Constructors/destructor:
|
// Constructors/destructor:
|
||||||
basic_fstream()
|
basic_fstream()
|
||||||
: __iostream_type(new __filebuf_type())
|
: __iostream_type(NULL), _M_filebuf()
|
||||||
{ }
|
{ this->init(&_M_filebuf); }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
basic_fstream(const char* __s,
|
basic_fstream(const char* __s,
|
||||||
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
||||||
: __iostream_type(new __filebuf_type())
|
: __iostream_type(NULL), _M_filebuf()
|
||||||
{ this->open(__s, __mode); }
|
{
|
||||||
|
this->init(&_M_filebuf);
|
||||||
|
this->open(__s, __mode);
|
||||||
|
}
|
||||||
|
|
||||||
~basic_fstream()
|
~basic_fstream()
|
||||||
{
|
{ }
|
||||||
delete _M_streambuf;
|
|
||||||
_M_streambuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Members:
|
// Members:
|
||||||
__filebuf_type*
|
__filebuf_type*
|
||||||
rdbuf(void) const
|
rdbuf(void) const
|
||||||
{ return static_cast<__filebuf_type*>(_M_streambuf); }
|
{ return const_cast<__filebuf_type*>(&_M_filebuf); }
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_open(void) { return rdbuf()->is_open(); }
|
is_open(void) { return _M_filebuf.is_open(); }
|
||||||
|
|
||||||
void
|
void
|
||||||
open(const char* __s,
|
open(const char* __s,
|
||||||
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
ios_base::openmode __mode = ios_base::in | ios_base::out)
|
||||||
{
|
{
|
||||||
if (!rdbuf()->open(__s, __mode))
|
if (!_M_filebuf.open(__s, __mode))
|
||||||
setstate (ios_base::failbit);
|
setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
close(void)
|
close(void)
|
||||||
{
|
{
|
||||||
if (!rdbuf()->close())
|
if (!_M_filebuf.close())
|
||||||
setstate (ios_base::failbit);
|
setstate(ios_base::failbit);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
|
@ -203,37 +203,37 @@ namespace std
|
||||||
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
|
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
|
||||||
typedef basic_istream<char_type, traits_type> __istream_type;
|
typedef basic_istream<char_type, traits_type> __istream_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
__stringbuf_type _M_stringbuf;
|
||||||
|
|
||||||
|
public:
|
||||||
// Constructors:
|
// Constructors:
|
||||||
explicit
|
explicit
|
||||||
basic_istringstream(ios_base::openmode __mode = ios_base::in)
|
basic_istringstream(ios_base::openmode __mode = ios_base::in)
|
||||||
: __istream_type(new __stringbuf_type(__mode | ios_base::in))
|
: __istream_type(NULL), _M_stringbuf(__mode | ios_base::in)
|
||||||
{ }
|
{ this->init(&_M_stringbuf); }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
basic_istringstream(const __string_type& __str,
|
basic_istringstream(const __string_type& __str,
|
||||||
ios_base::openmode __mode = ios_base::in)
|
ios_base::openmode __mode = ios_base::in)
|
||||||
: __istream_type(new __stringbuf_type(__str, __mode | ios_base::in))
|
: __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in)
|
||||||
{ }
|
{ this->init(&_M_stringbuf); }
|
||||||
|
|
||||||
~basic_istringstream()
|
~basic_istringstream()
|
||||||
{
|
{ }
|
||||||
delete _M_streambuf;
|
|
||||||
_M_streambuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Members:
|
// Members:
|
||||||
__stringbuf_type*
|
__stringbuf_type*
|
||||||
rdbuf() const
|
rdbuf() const
|
||||||
{ return static_cast<__stringbuf_type*>(_M_streambuf); }
|
{ return const_cast<__stringbuf_type*>(&_M_stringbuf); }
|
||||||
|
|
||||||
__string_type
|
__string_type
|
||||||
str() const
|
str() const
|
||||||
{ return this->rdbuf()->str(); }
|
{ return _M_stringbuf.str(); }
|
||||||
|
|
||||||
void
|
void
|
||||||
str(const __string_type& __s)
|
str(const __string_type& __s)
|
||||||
{ rdbuf()->str(__s); }
|
{ _M_stringbuf.str(__s); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,37 +254,37 @@ namespace std
|
||||||
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
|
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
|
||||||
typedef basic_ostream<char_type, traits_type> __ostream_type;
|
typedef basic_ostream<char_type, traits_type> __ostream_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
__stringbuf_type _M_stringbuf;
|
||||||
|
|
||||||
|
public:
|
||||||
// Constructors/destructor:
|
// Constructors/destructor:
|
||||||
explicit
|
explicit
|
||||||
basic_ostringstream(ios_base::openmode __mode = ios_base::out)
|
basic_ostringstream(ios_base::openmode __mode = ios_base::out)
|
||||||
: __ostream_type(new __stringbuf_type(__mode | ios_base::out))
|
: __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out)
|
||||||
{ }
|
{ this->init(&_M_stringbuf); }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
basic_ostringstream(const __string_type __str,
|
basic_ostringstream(const __string_type __str,
|
||||||
ios_base::openmode __mode = ios_base::out)
|
ios_base::openmode __mode = ios_base::out)
|
||||||
: __ostream_type(new __stringbuf_type(__str, __mode | ios_base::out))
|
: __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out)
|
||||||
{ }
|
{ this->init(&_M_stringbuf); }
|
||||||
|
|
||||||
~basic_ostringstream()
|
~basic_ostringstream()
|
||||||
{
|
{ }
|
||||||
delete _M_streambuf;
|
|
||||||
_M_streambuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Members:
|
// Members:
|
||||||
__stringbuf_type*
|
__stringbuf_type*
|
||||||
rdbuf() const
|
rdbuf() const
|
||||||
{ return static_cast<__stringbuf_type*>(_M_streambuf); }
|
{ return const_cast<__stringbuf_type*>(&_M_stringbuf); }
|
||||||
|
|
||||||
__string_type
|
__string_type
|
||||||
str() const
|
str() const
|
||||||
{ return this->rdbuf()->str(); }
|
{ return _M_stringbuf.str(); }
|
||||||
|
|
||||||
void
|
void
|
||||||
str(const __string_type& __s)
|
str(const __string_type& __s)
|
||||||
{ rdbuf()->str(__s); }
|
{ _M_stringbuf.str(__s); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -305,40 +305,38 @@ namespace std
|
||||||
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
|
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
|
||||||
typedef basic_iostream<char_type, traits_type> __iostream_type;
|
typedef basic_iostream<char_type, traits_type> __iostream_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
__stringbuf_type _M_stringbuf;
|
||||||
|
|
||||||
|
public:
|
||||||
// Constructors/destructors
|
// Constructors/destructors
|
||||||
explicit
|
explicit
|
||||||
basic_stringstream(ios_base::openmode __mode =
|
basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
|
||||||
ios_base::out | ios_base::in)
|
: __iostream_type(NULL), _M_stringbuf(__m)
|
||||||
: __iostream_type(new __stringbuf_type(__mode))
|
{ this->init(&_M_stringbuf); }
|
||||||
{ }
|
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
basic_stringstream(const __string_type& __str,
|
basic_stringstream(const __string_type& __str,
|
||||||
ios_base::openmode __mode =
|
ios_base::openmode __m = ios_base::out | ios_base::in)
|
||||||
ios_base::out | ios_base::in)
|
: __iostream_type(NULL), _M_stringbuf(__str, __m)
|
||||||
: __iostream_type(new __stringbuf_type(__str, __mode))
|
{ this->init(&_M_stringbuf); }
|
||||||
{ }
|
|
||||||
|
|
||||||
~basic_stringstream()
|
~basic_stringstream()
|
||||||
{
|
{ }
|
||||||
delete _M_streambuf;
|
|
||||||
_M_streambuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Members:
|
// Members:
|
||||||
__stringbuf_type*
|
__stringbuf_type*
|
||||||
rdbuf() const
|
rdbuf() const
|
||||||
{ return static_cast<__stringbuf_type*>(_M_streambuf); }
|
{ return const_cast<__stringbuf_type*>(&_M_stringbuf); }
|
||||||
|
|
||||||
__string_type
|
__string_type
|
||||||
str() const
|
str() const
|
||||||
{ return rdbuf()->str(); }
|
{ return _M_stringbuf.str(); }
|
||||||
|
|
||||||
void
|
void
|
||||||
str(const __string_type& __s)
|
str(const __string_type& __s)
|
||||||
{ rdbuf()->str(__s); }
|
{ _M_stringbuf.str(__s); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
|
|
||||||
|
@ -350,5 +348,5 @@ namespace std
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _CPP_SSTREAM */
|
#endif // _CPP_SSTREAM
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2001 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.
|
||||||
|
|
||||||
|
// 27.8.1.13 member functions (fstream_members)
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
redirect_buffer(std::ios& stream, std::streambuf* new_buf)
|
||||||
|
{ stream.rdbuf(new_buf); }
|
||||||
|
|
||||||
|
std::streambuf*
|
||||||
|
active_buffer(std::ios& stream)
|
||||||
|
{ return stream.rdbuf(); }
|
||||||
|
|
||||||
|
// libstdc++/2832
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
const char* strlit01 = "fuck war";
|
||||||
|
const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01(strlit01);
|
||||||
|
std::string str02;
|
||||||
|
std::filebuf fbuf;
|
||||||
|
std::streambuf* pbasebuf0 = &fbuf;
|
||||||
|
|
||||||
|
std::fstream sstrm1;
|
||||||
|
// derived rdbuf() always returns original streambuf, even though
|
||||||
|
// it's no longer associated with the stream.
|
||||||
|
std::filebuf* const buf1 = sstrm1.rdbuf();
|
||||||
|
// base rdbuf() returns the currently associated streambuf
|
||||||
|
std::streambuf* pbasebuf1 = active_buffer(sstrm1);
|
||||||
|
redirect_buffer(sstrm1, &fbuf);
|
||||||
|
std::filebuf* const buf2 = sstrm1.rdbuf();
|
||||||
|
std::streambuf* pbasebuf2 = active_buffer(sstrm1);
|
||||||
|
VERIFY( buf1 == buf2 );
|
||||||
|
VERIFY( pbasebuf1 != pbasebuf2 );
|
||||||
|
VERIFY( pbasebuf2 == pbasebuf0 );
|
||||||
|
|
||||||
|
// How confusing and non-intuitive is this?
|
||||||
|
// These semantics are a joke, a serious defect, and incredibly lame.
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test02();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2000 Free Software Foundation, Inc.
|
// Copyright (C) 2000, 2001 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
|
||||||
|
@ -73,10 +73,51 @@ bool test01()
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
redirect_buffer(std::ios& stream, std::streambuf* new_buf)
|
||||||
|
{ stream.rdbuf(new_buf); }
|
||||||
|
|
||||||
|
std::streambuf*
|
||||||
|
active_buffer(std::ios& stream)
|
||||||
|
{ return stream.rdbuf(); }
|
||||||
|
|
||||||
|
// libstdc++/2832
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
const char* strlit01 = "fuck war";
|
||||||
|
const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01(strlit01);
|
||||||
|
std::string str02;
|
||||||
|
std::filebuf fbuf;
|
||||||
|
std::streambuf* pbasebuf0 = &fbuf;
|
||||||
|
|
||||||
|
std::ifstream sstrm1;
|
||||||
|
// derived rdbuf() always returns original streambuf, even though
|
||||||
|
// it's no longer associated with the stream.
|
||||||
|
std::filebuf* const buf1 = sstrm1.rdbuf();
|
||||||
|
// base rdbuf() returns the currently associated streambuf
|
||||||
|
std::streambuf* pbasebuf1 = active_buffer(sstrm1);
|
||||||
|
redirect_buffer(sstrm1, &fbuf);
|
||||||
|
std::filebuf* const buf2 = sstrm1.rdbuf();
|
||||||
|
std::streambuf* pbasebuf2 = active_buffer(sstrm1);
|
||||||
|
VERIFY( buf1 == buf2 );
|
||||||
|
VERIFY( pbasebuf1 != pbasebuf2 );
|
||||||
|
VERIFY( pbasebuf2 == pbasebuf0 );
|
||||||
|
|
||||||
|
// How confusing and non-intuitive is this?
|
||||||
|
// These semantics are a joke, a serious defect, and incredibly lame.
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test00();
|
test00();
|
||||||
test01();
|
test01();
|
||||||
|
|
||||||
|
test02();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// 2000-01-10 bkoz
|
// 2000-01-10 bkoz
|
||||||
|
|
||||||
// Copyright (C) 2000 Free Software Foundation, Inc.
|
// Copyright (C) 2000, 2001 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
|
||||||
|
@ -18,19 +18,16 @@
|
||||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
// USA.
|
// USA.
|
||||||
|
|
||||||
// 27.7.2 template class basic_istringstream
|
|
||||||
// 27.7.2.2 member functions (istringstream_members)
|
// 27.7.2.2 member functions (istringstream_members)
|
||||||
|
|
||||||
// stringbuf* rdbuf() const
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <debug_assert.h>
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
|
||||||
void test01()
|
void test01()
|
||||||
{
|
{
|
||||||
bool test = true;
|
bool test = true;
|
||||||
std::istringstream is01;
|
std::istringstream is01;
|
||||||
|
const std::string str00;
|
||||||
const std::string str01 = "123";
|
const std::string str01 = "123";
|
||||||
std::string str02;
|
std::string str02;
|
||||||
const int i01 = 123;
|
const int i01 = 123;
|
||||||
|
@ -40,8 +37,14 @@ void test01()
|
||||||
statefail = std::ios_base::failbit;
|
statefail = std::ios_base::failbit;
|
||||||
stateeof = std::ios_base::eofbit;
|
stateeof = std::ios_base::eofbit;
|
||||||
|
|
||||||
|
// string str() const
|
||||||
|
str02 = is01.str();
|
||||||
|
VERIFY( str00 == str02 );
|
||||||
|
|
||||||
// void str(const basic_string&)
|
// void str(const basic_string&)
|
||||||
is01.str(str01);
|
is01.str(str01);
|
||||||
|
str02 = is01.str();
|
||||||
|
VERIFY( str01 == str02 );
|
||||||
state1 = is01.rdstate();
|
state1 = is01.rdstate();
|
||||||
is01 >> a;
|
is01 >> a;
|
||||||
state2 = is01.rdstate();
|
state2 = is01.rdstate();
|
||||||
|
@ -66,17 +69,63 @@ void test01()
|
||||||
VERIFY( state1 != state2 );
|
VERIFY( state1 != state2 );
|
||||||
VERIFY( state2 == stateeof );
|
VERIFY( state2 == stateeof );
|
||||||
|
|
||||||
// string str() const
|
|
||||||
str02 = is01.str();
|
|
||||||
VERIFY( str01 == str02 );
|
|
||||||
|
|
||||||
#ifdef DEBUG_ASSERT
|
#ifdef DEBUG_ASSERT
|
||||||
assert(test);
|
assert(test);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
redirect_buffer(std::ios& stream, std::streambuf* new_buf)
|
||||||
|
{ stream.rdbuf(new_buf); }
|
||||||
|
|
||||||
|
std::streambuf*
|
||||||
|
active_buffer(std::ios& stream)
|
||||||
|
{ return stream.rdbuf(); }
|
||||||
|
|
||||||
|
// libstdc++/2832
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
const char* strlit01 = "fuck war";
|
||||||
|
const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01(strlit01);
|
||||||
|
std::string str02;
|
||||||
|
std::stringbuf sbuf(str01);
|
||||||
|
std::streambuf* pbasebuf0 = &sbuf;
|
||||||
|
|
||||||
|
std::istringstream sstrm1;
|
||||||
|
VERIFY( sstrm1.str() == str00 );
|
||||||
|
// derived rdbuf() always returns original streambuf, even though
|
||||||
|
// it's no longer associated with the stream.
|
||||||
|
std::stringbuf* const buf1 = sstrm1.rdbuf();
|
||||||
|
// base rdbuf() returns the currently associated streambuf
|
||||||
|
std::streambuf* pbasebuf1 = active_buffer(sstrm1);
|
||||||
|
redirect_buffer(sstrm1, &sbuf);
|
||||||
|
std::stringbuf* const buf2 = sstrm1.rdbuf();
|
||||||
|
std::streambuf* pbasebuf2 = active_buffer(sstrm1);
|
||||||
|
VERIFY( buf1 == buf2 );
|
||||||
|
VERIFY( pbasebuf1 != pbasebuf2 );
|
||||||
|
VERIFY( pbasebuf2 == pbasebuf0 );
|
||||||
|
|
||||||
|
// derived rdbuf() returns the original buf, so str() doesn't change.
|
||||||
|
VERIFY( sstrm1.str() != str01 );
|
||||||
|
VERIFY( sstrm1.str() == str00 );
|
||||||
|
// however, casting the active streambuf to a stringbuf shows what's up:
|
||||||
|
std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
|
||||||
|
str02 = psbuf->str();
|
||||||
|
VERIFY( str02 == str01 );
|
||||||
|
|
||||||
|
// How confusing and non-intuitive is this?
|
||||||
|
// These semantics are a joke, a serious defect, and incredibly lame.
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
|
test02();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2000 Free Software Foundation, Inc.
|
// Copyright (C) 2000, 2001 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
|
||||||
|
@ -74,9 +74,51 @@ bool test01()
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
redirect_buffer(std::ios& stream, std::streambuf* new_buf)
|
||||||
|
{ stream.rdbuf(new_buf); }
|
||||||
|
|
||||||
|
std::streambuf*
|
||||||
|
active_buffer(std::ios& stream)
|
||||||
|
{ return stream.rdbuf(); }
|
||||||
|
|
||||||
|
// libstdc++/2832
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
const char* strlit01 = "fuck war";
|
||||||
|
const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01(strlit01);
|
||||||
|
std::string str02;
|
||||||
|
std::filebuf fbuf;
|
||||||
|
std::streambuf* pbasebuf0 = &fbuf;
|
||||||
|
|
||||||
|
std::ofstream sstrm1;
|
||||||
|
// derived rdbuf() always returns original streambuf, even though
|
||||||
|
// it's no longer associated with the stream.
|
||||||
|
std::filebuf* const buf1 = sstrm1.rdbuf();
|
||||||
|
// base rdbuf() returns the currently associated streambuf
|
||||||
|
std::streambuf* pbasebuf1 = active_buffer(sstrm1);
|
||||||
|
redirect_buffer(sstrm1, &fbuf);
|
||||||
|
std::filebuf* const buf2 = sstrm1.rdbuf();
|
||||||
|
std::streambuf* pbasebuf2 = active_buffer(sstrm1);
|
||||||
|
VERIFY( buf1 == buf2 );
|
||||||
|
VERIFY( pbasebuf1 != pbasebuf2 );
|
||||||
|
VERIFY( pbasebuf2 == pbasebuf0 );
|
||||||
|
|
||||||
|
// How confusing and non-intuitive is this?
|
||||||
|
// These semantics are a joke, a serious defect, and incredibly lame.
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test00();
|
test00();
|
||||||
test01();
|
test01();
|
||||||
|
|
||||||
|
test02();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
// 2001-05-23 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2001 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.
|
||||||
|
|
||||||
|
// 27.7.3.2 member functions (ostringstream_members)
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
std::ostringstream os01;
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01 = "123";
|
||||||
|
std::string str02;
|
||||||
|
const int i01 = 123;
|
||||||
|
int a,b;
|
||||||
|
|
||||||
|
std::ios_base::iostate state1, state2, statefail, stateeof;
|
||||||
|
statefail = std::ios_base::failbit;
|
||||||
|
stateeof = std::ios_base::eofbit;
|
||||||
|
|
||||||
|
// string str() const
|
||||||
|
str02 = os01.str();
|
||||||
|
VERIFY( str00 == str02 );
|
||||||
|
|
||||||
|
// void str(const basic_string&)
|
||||||
|
os01.str(str01);
|
||||||
|
str02 = os01.str();
|
||||||
|
VERIFY( str01 == str02 );
|
||||||
|
|
||||||
|
#ifdef DEBUG_ASSERT
|
||||||
|
assert(test);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
redirect_buffer(std::ios& stream, std::streambuf* new_buf)
|
||||||
|
{ stream.rdbuf(new_buf); }
|
||||||
|
|
||||||
|
std::streambuf*
|
||||||
|
active_buffer(std::ios& stream)
|
||||||
|
{ return stream.rdbuf(); }
|
||||||
|
|
||||||
|
// libstdc++/2832
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
const char* strlit01 = "fuck war";
|
||||||
|
const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01(strlit01);
|
||||||
|
std::string str02;
|
||||||
|
std::stringbuf sbuf(str01);
|
||||||
|
std::streambuf* pbasebuf0 = &sbuf;
|
||||||
|
|
||||||
|
std::ostringstream sstrm1;
|
||||||
|
VERIFY( sstrm1.str() == str00 );
|
||||||
|
// derived rdbuf() always returns original streambuf, even though
|
||||||
|
// it's no longer associated with the stream.
|
||||||
|
std::stringbuf* const buf1 = sstrm1.rdbuf();
|
||||||
|
// base rdbuf() returns the currently associated streambuf
|
||||||
|
std::streambuf* pbasebuf1 = active_buffer(sstrm1);
|
||||||
|
redirect_buffer(sstrm1, &sbuf);
|
||||||
|
std::stringbuf* const buf2 = sstrm1.rdbuf();
|
||||||
|
std::streambuf* pbasebuf2 = active_buffer(sstrm1);
|
||||||
|
VERIFY( buf1 == buf2 );
|
||||||
|
VERIFY( pbasebuf1 != pbasebuf2 );
|
||||||
|
VERIFY( pbasebuf2 == pbasebuf0 );
|
||||||
|
|
||||||
|
// derived rdbuf() returns the original buf, so str() doesn't change.
|
||||||
|
VERIFY( sstrm1.str() != str01 );
|
||||||
|
VERIFY( sstrm1.str() == str00 );
|
||||||
|
// however, casting the active streambuf to a stringbuf shows what's up:
|
||||||
|
std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
|
||||||
|
str02 = psbuf->str();
|
||||||
|
VERIFY( str02 == str01 );
|
||||||
|
|
||||||
|
// How confusing and non-intuitive is this?
|
||||||
|
// These semantics are a joke, a serious defect, and incredibly lame.
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
test02();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2001 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.
|
||||||
|
|
||||||
|
// 27.7.6 member functions (stringstream_members)
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
std::stringstream is01;
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01 = "123";
|
||||||
|
std::string str02;
|
||||||
|
const int i01 = 123;
|
||||||
|
int a,b;
|
||||||
|
|
||||||
|
std::ios_base::iostate state1, state2, statefail, stateeof;
|
||||||
|
statefail = std::ios_base::failbit;
|
||||||
|
stateeof = std::ios_base::eofbit;
|
||||||
|
|
||||||
|
// string str() const
|
||||||
|
str02 = is01.str();
|
||||||
|
VERIFY( str00 == str02 );
|
||||||
|
|
||||||
|
// void str(const basic_string&)
|
||||||
|
is01.str(str01);
|
||||||
|
str02 = is01.str();
|
||||||
|
VERIFY( str01 == str02 );
|
||||||
|
state1 = is01.rdstate();
|
||||||
|
is01 >> a;
|
||||||
|
state2 = is01.rdstate();
|
||||||
|
VERIFY( a = i01 );
|
||||||
|
// 22.2.2.1.2 num_get virtual functions
|
||||||
|
// p 13
|
||||||
|
// in any case, if stage 2 processing was terminated by the test for
|
||||||
|
// in == end then err != ios_base::eofbit is performed.
|
||||||
|
VERIFY( state1 != state2 );
|
||||||
|
VERIFY( state2 == stateeof );
|
||||||
|
|
||||||
|
is01.str(str01);
|
||||||
|
is01 >> b;
|
||||||
|
VERIFY( b != a );
|
||||||
|
// as is01.good() is false, istream::sentry blocks extraction.
|
||||||
|
|
||||||
|
is01.clear();
|
||||||
|
state1 = is01.rdstate();
|
||||||
|
is01 >> b;
|
||||||
|
state2 = is01.rdstate();
|
||||||
|
VERIFY( b == a );
|
||||||
|
VERIFY( state1 != state2 );
|
||||||
|
VERIFY( state2 == stateeof );
|
||||||
|
|
||||||
|
#ifdef DEBUG_ASSERT
|
||||||
|
assert(test);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
redirect_buffer(std::ios& stream, std::streambuf* new_buf)
|
||||||
|
{ stream.rdbuf(new_buf); }
|
||||||
|
|
||||||
|
std::streambuf*
|
||||||
|
active_buffer(std::ios& stream)
|
||||||
|
{ return stream.rdbuf(); }
|
||||||
|
|
||||||
|
// libstdc++/2832
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
bool test = true;
|
||||||
|
const char* strlit01 = "fuck war";
|
||||||
|
const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
|
||||||
|
const std::string str00;
|
||||||
|
const std::string str01(strlit01);
|
||||||
|
std::string str02;
|
||||||
|
std::stringbuf sbuf(str01);
|
||||||
|
std::streambuf* pbasebuf0 = &sbuf;
|
||||||
|
|
||||||
|
std::stringstream sstrm1;
|
||||||
|
VERIFY( sstrm1.str() == str00 );
|
||||||
|
// derived rdbuf() always returns original streambuf, even though
|
||||||
|
// it's no longer associated with the stream.
|
||||||
|
std::stringbuf* const buf1 = sstrm1.rdbuf();
|
||||||
|
// base rdbuf() returns the currently associated streambuf
|
||||||
|
std::streambuf* pbasebuf1 = active_buffer(sstrm1);
|
||||||
|
redirect_buffer(sstrm1, &sbuf);
|
||||||
|
std::stringbuf* const buf2 = sstrm1.rdbuf();
|
||||||
|
std::streambuf* pbasebuf2 = active_buffer(sstrm1);
|
||||||
|
VERIFY( buf1 == buf2 );
|
||||||
|
VERIFY( pbasebuf1 != pbasebuf2 );
|
||||||
|
VERIFY( pbasebuf2 == pbasebuf0 );
|
||||||
|
|
||||||
|
// derived rdbuf() returns the original buf, so str() doesn't change.
|
||||||
|
VERIFY( sstrm1.str() != str01 );
|
||||||
|
VERIFY( sstrm1.str() == str00 );
|
||||||
|
// however, casting the active streambuf to a stringbuf shows what's up:
|
||||||
|
std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
|
||||||
|
str02 = psbuf->str();
|
||||||
|
VERIFY( str02 == str01 );
|
||||||
|
|
||||||
|
// How confusing and non-intuitive is this?
|
||||||
|
// These semantics are a joke, a serious defect, and incredibly lame.
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
test02();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue