* from the sequence).
*/
template<typename _CharT, typename _Traits>
- class basic_streambuf
+ class basic_streambuf
{
public:
//@{
/// This is a non-standard type.
typedef basic_streambuf<char_type, traits_type> __streambuf_type;
//@}
-
+
friend class basic_ios<char_type, traits_type>;
friend class basic_istream<char_type, traits_type>;
friend class basic_ostream<char_type, traits_type>;
__copy_streambufs_eof<>(basic_streambuf*, basic_streambuf*, bool&);
template<bool _IsMove, typename _CharT2>
- friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
+ friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
_CharT2*>::__type
__copy_move_a2(istreambuf_iterator<_CharT2>,
istreambuf_iterator<_CharT2>, _CharT2*);
char_type* _M_out_end; ///< End of put area.
/// Current locale setting.
- locale _M_buf_locale;
+ locale _M_buf_locale;
public:
/// Destructor deallocates no buffer space.
- virtual
- ~basic_streambuf()
+ virtual
+ ~basic_streambuf()
{ }
// [27.5.2.2.1] locales
*
* Calls the derived imbue(__loc).
*/
- locale
+ locale
pubimbue(const locale& __loc)
{
locale __tmp(this->getloc());
* is returned. Otherwise the global locale in effect at the time
* of construction is returned.
*/
- locale
+ locale
getloc() const
- { return _M_buf_locale; }
+ { return _M_buf_locale; }
// [27.5.2.2.2] buffer management and positioning
//@{
* and returning the result unchanged.
*/
basic_streambuf*
- pubsetbuf(char_type* __s, streamsize __n)
+ pubsetbuf(char_type* __s, streamsize __n)
{ return this->setbuf(__s, __n); }
/**
*
* Calls virtual seekoff function.
*/
- pos_type
- pubseekoff(off_type __off, ios_base::seekdir __way,
+ pos_type
+ pubseekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __mode = ios_base::in | ios_base::out)
{ return this->seekoff(__off, __way, __mode); }
*
* Calls virtual seekpos function.
*/
- pos_type
+ pos_type
pubseekpos(pos_type __sp,
ios_base::openmode __mode = ios_base::in | ios_base::out)
{ return this->seekpos(__sp, __mode); }
/**
* @brief Calls virtual sync function.
*/
- int
+ int
pubsync() { return this->sync(); }
//@}
* available for reading before the buffer must be refilled.
* Otherwise returns the derived @c showmanyc().
*/
- streamsize
- in_avail()
- {
+ streamsize
+ in_avail()
+ {
const streamsize __ret = this->egptr() - this->gptr();
return __ret ? __ret : this->showmanyc();
}
* Calls @c sbumpc(), and if that function returns
* @c traits::eof(), so does this function. Otherwise, @c sgetc().
*/
- int_type
+ int_type
snextc()
{
int_type __ret = traits_type::eof();
- if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
+ if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
__ret), true))
__ret = this->sgetc();
return __ret;
* and increments the read pointer, otherwise calls and returns
* @c uflow().
*/
- int_type
+ int_type
sbumpc()
{
int_type __ret;
__ret = traits_type::to_int_type(*this->gptr());
this->gbump(1);
}
- else
+ else
__ret = this->uflow();
return __ret;
}
* @return The next character, or eof.
*
* If the input read position is available, returns that character,
- * otherwise calls and returns @c underflow(). Does not move the
+ * otherwise calls and returns @c underflow(). Does not move the
* read position after fetching the character.
*/
- int_type
+ int_type
sgetc()
{
int_type __ret;
if (__builtin_expect(this->gptr() < this->egptr(), true))
__ret = traits_type::to_int_type(*this->gptr());
- else
+ else
__ret = this->underflow();
return __ret;
}
* Returns xsgetn(__s,__n). The effect is to fill @a __s[0] through
* @a __s[__n-1] with characters from the input sequence, if possible.
*/
- streamsize
+ streamsize
sgetn(char_type* __s, streamsize __n)
{ return this->xsgetn(__s, __n); }
* the next character fetched from the input stream will be @a
* __c.
*/
- int_type
+ int_type
sputbackc(char_type __c)
{
int_type __ret;
const bool __testpos = this->eback() < this->gptr();
- if (__builtin_expect(!__testpos ||
+ if (__builtin_expect(!__testpos ||
!traits_type::eq(__c, this->gptr()[-1]), false))
__ret = this->pbackfail(traits_type::to_int_type(__c));
- else
+ else
{
this->gbump(-1);
__ret = traits_type::to_int_type(*this->gptr());
* calls and returns pbackfail(). The effect is to @a unget
* the last character @a gotten.
*/
- int_type
+ int_type
sungetc()
{
int_type __ret;
this->gbump(-1);
__ret = traits_type::to_int_type(*this->gptr());
}
- else
+ else
__ret = this->pbackfail();
return __ret;
}
* the position, and returns @c traits::to_int_type(__c). If a write
* position is not available, returns @c overflow(__c).
*/
- int_type
+ int_type
sputc(char_type __c)
{
int_type __ret;
* Returns xsputn(__s,__n). The effect is to write @a __s[0] through
* @a __s[__n-1] to the output sequence, if possible.
*/
- streamsize
+ streamsize
sputn(const char_type* __s, streamsize __n)
{ return this->xsputn(__s, __n); }
* - this is not an error
*/
basic_streambuf()
- : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
+ : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
_M_out_beg(0), _M_out_cur(0), _M_out_end(0),
- _M_buf_locale(locale())
+ _M_buf_locale(locale())
{ }
// [27.5.2.3.1] get area access
* - gptr() returns the next pointer for the input sequence
* - egptr() returns the end pointer for the input sequence
*/
- char_type*
+ char_type*
eback() const { return _M_in_beg; }
- char_type*
+ char_type*
gptr() const { return _M_in_cur; }
- char_type*
+ char_type*
egptr() const { return _M_in_end; }
//@}
*
* This just advances the read position without returning any data.
*/
- void
+ void
gbump(int __n) { _M_in_cur += __n; }
/**
* @post @a __gbeg == @c eback(), @a __gnext == @c gptr(), and
* @a __gend == @c egptr()
*/
- void
+ void
setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
{
_M_in_beg = __gbeg;
* - pptr() returns the next pointer for the output sequence
* - epptr() returns the end pointer for the output sequence
*/
- char_type*
+ char_type*
pbase() const { return _M_out_beg; }
- char_type*
+ char_type*
pptr() const { return _M_out_cur; }
- char_type*
+ char_type*
epptr() const { return _M_out_end; }
//@}
*
* This just advances the write position without returning any data.
*/
- void
+ void
pbump(int __n) { _M_out_cur += __n; }
/**
* @post @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and
* @a __pend == @c epptr()
*/
- void
+ void
setp(char_type* __pbeg, char_type* __pend)
- {
- _M_out_beg = _M_out_cur = __pbeg;
+ {
+ _M_out_beg = _M_out_cur = __pbeg;
_M_out_end = __pend;
}
*
* @note Base class version does nothing.
*/
- virtual void
- imbue(const locale& __loc)
+ virtual void
+ imbue(const locale& __loc)
{ }
// [27.5.2.4.2] buffer management and positioning
* @brief Manipulates the buffer.
*
* Each derived class provides its own appropriate behavior. See
- * the next-to-last paragraph of
+ * the next-to-last paragraph of
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html
* for more on this function.
*
* @note Base class version does nothing, returns @c this.
*/
- virtual basic_streambuf<char_type,_Traits>*
+ virtual basic_streambuf<char_type,_Traits>*
setbuf(char_type*, streamsize)
{ return this; }
-
+
/**
* @brief Alters the stream positions.
*
* @note Base class version does nothing, returns a @c pos_type
* that represents an invalid stream position.
*/
- virtual pos_type
+ virtual pos_type
seekoff(off_type, ios_base::seekdir,
ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
- { return pos_type(off_type(-1)); }
+ { return pos_type(off_type(-1)); }
/**
* @brief Alters the stream positions.
* @note Base class version does nothing, returns a @c pos_type
* that represents an invalid stream position.
*/
- virtual pos_type
- seekpos(pos_type,
+ virtual pos_type
+ seekpos(pos_type,
ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
- { return pos_type(off_type(-1)); }
+ { return pos_type(off_type(-1)); }
/**
* @brief Synchronizes the buffer arrays with the controlled sequences.
* including the definition of @a failure.
* @note Base class version does nothing, returns zero.
*/
- virtual int
+ virtual int
sync() { return 0; }
// [27.5.2.4.3] get area
* @note The standard adds that <em>the morphemes of @c showmanyc are
* @b es-how-many-see, not @b show-manic.</em>
*/
- virtual streamsize
+ virtual streamsize
showmanyc() { return 0; }
/**
* It is expected that derived classes provide a more efficient
* implementation by overriding this definition.
*/
- virtual streamsize
+ virtual streamsize
xsgetn(char_type* __s, streamsize __n);
/**
*
* @note Base class version does nothing, returns eof().
*/
- virtual int_type
+ virtual int_type
underflow()
{ return traits_type::eof(); }
* the new character, like @c underflow() does. However, this
* function also moves the read position forward by one.
*/
- virtual int_type
- uflow()
+ virtual int_type
+ uflow()
{
int_type __ret = traits_type::eof();
- const bool __testeof = traits_type::eq_int_type(this->underflow(),
+ const bool __testeof = traits_type::eq_int_type(this->underflow(),
__ret);
if (!__testeof)
{
__ret = traits_type::to_int_type(*this->gptr());
this->gbump(1);
}
- return __ret;
+ return __ret;
}
// [27.5.2.4.4] putback
*
* @note Base class version does nothing, returns eof().
*/
- virtual int_type
+ virtual int_type
pbackfail(int_type __c = traits_type::eof())
{ return traits_type::eof(); }
* It is expected that derived classes provide a more efficient
* implementation by overriding this definition.
*/
- virtual streamsize
+ virtual streamsize
xsputn(const char_type* __s, streamsize __n);
/**
*
* @note Base class version does nothing, returns eof().
*/
- virtual int_type
+ virtual int_type
overflow(int_type __c = traits_type::eof())
{ return traits_type::eof(); }
*
* See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
*/
- void
- stossc()
+ void
+ stossc()
{
- if (this->gptr() < this->egptr())
+ if (this->gptr() < this->egptr())
this->gbump(1);
- else
+ else
this->uflow();
}
#endif
// Also used by specializations for char and wchar_t in src.
- void
+ void
__safe_gbump(streamsize __n) { _M_in_cur += __n; }
void
__safe_pbump(streamsize __n) { _M_out_cur += __n; }
+#if __cplusplus < 201103L
private:
// _GLIBCXX_RESOLVE_LIB_DEFECTS
- // Side effect of DR 50.
+ // Side effect of DR 50.
basic_streambuf(const basic_streambuf& __sb)
- : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur),
- _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg),
- _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_cur),
- _M_buf_locale(__sb._M_buf_locale)
+ : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur),
+ _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg),
+ _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_end),
+ _M_buf_locale(__sb._M_buf_locale)
{ }
basic_streambuf&
- operator=(const basic_streambuf&) { return *this; };
+ operator=(const basic_streambuf&) { return *this; }
+#else
+ protected:
+ basic_streambuf(const basic_streambuf&) = default;
+
+ basic_streambuf&
+ operator=(const basic_streambuf&) = default;
+
+ void
+ swap(basic_streambuf& __sb)
+ {
+ std::swap(_M_in_beg, __sb._M_in_beg);
+ std::swap(_M_in_cur, __sb._M_in_cur);
+ std::swap(_M_in_end, __sb._M_in_end);
+ std::swap(_M_out_beg, __sb._M_out_beg);
+ std::swap(_M_out_cur, __sb._M_out_cur);
+ std::swap(_M_out_end, __sb._M_out_end);
+ std::swap(_M_buf_locale, __sb._M_buf_locale);
+ }
+#endif
};
// Explicit specialization declarations, defined in src/streambuf.cc.
--- /dev/null
+// Copyright (C) 2014 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-require-namedlocale "de_DE" }
+
+// 27.6.3 template class basic_streambuf
+
+#include <streambuf>
+#include <testsuite_hooks.h>
+
+struct streambuf : std::streambuf
+{
+ streambuf()
+ {
+ setp(pbuf, std::end(pbuf));
+ setg(gbuf, gbuf, gbuf);
+ }
+
+ streambuf(const std::locale& loc) : streambuf()
+ {
+ imbue(loc);
+ }
+
+ // implement tests as member functions to be able to call protected members
+ void test_copy() const;
+ void test_assign() const;
+ void test_swap() const;
+
+ char gbuf[32];
+ char pbuf[32];
+};
+
+void streambuf::test_copy() const
+{
+ bool test __attribute__((unused)) = true;
+
+ streambuf a(*this);
+
+ VERIFY( eback() == a.eback() );
+ VERIFY( gptr() == a.gptr() );
+ VERIFY( egptr() == a.egptr() );
+ VERIFY( pbase() == a.pbase() );
+ VERIFY( pptr() == a.pptr() );
+ VERIFY( epptr() == a.epptr() );
+ VERIFY( getloc() == a.getloc() );
+}
+
+void streambuf::test_assign() const
+{
+ bool test __attribute__((unused)) = true;
+
+ streambuf a;
+ a = *this;
+
+ VERIFY( eback() == a.eback() );
+ VERIFY( gptr() == a.gptr() );
+ VERIFY( egptr() == a.egptr() );
+ VERIFY( pbase() == a.pbase() );
+ VERIFY( pptr() == a.pptr() );
+ VERIFY( epptr() == a.epptr() );
+ VERIFY( getloc() == a.getloc() );
+}
+
+void streambuf::test_swap() const
+{
+ bool test __attribute__((unused)) = true;
+
+ streambuf a(*this);
+ streambuf b;
+ const streambuf c(b);
+
+ a.swap(b);
+
+ VERIFY( eback() == b.eback() );
+ VERIFY( gptr() == b.gptr() );
+ VERIFY( egptr() == b.egptr() );
+ VERIFY( pbase() == b.pbase() );
+ VERIFY( pptr() == b.pptr() );
+ VERIFY( epptr() == b.epptr() );
+ VERIFY( getloc() == b.getloc() );
+
+ VERIFY( c.eback() == a.eback() );
+ VERIFY( c.gptr() == a.gptr() );
+ VERIFY( c.egptr() == a.egptr() );
+ VERIFY( c.pbase() == a.pbase() );
+ VERIFY( c.pptr() == a.pptr() );
+ VERIFY( c.epptr() == a.epptr() );
+ VERIFY( c.getloc() == a.getloc() );
+}
+
+int main()
+{
+ std::locale loc("de_DE");
+ streambuf s(loc);
+ s.test_copy();
+ s.test_assign();
+ s.test_swap();
+}