OSDN Git Service

2009-11-06 Jonathan Wakely <jwakely.gcc@gmail.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / ostream
index 2a84f80..d6241ba 100644 (file)
@@ -1,13 +1,13 @@
 // Output streams -*- C++ -*-
 
 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007
+// 2006, 2007, 2008, 2009
 // 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)
+// 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,
 // 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
 
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
 
 /** @file ostream
  *  This is a Standard C++ Library header.
 #pragma GCC system_header
 
 #include <ios>
-#include <locale>
+#include <bits/ostream_insert.h>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   // [27.6.2.1] Template class basic_ostream
   /**
    *  @brief  Controlling output.
+   *  @ingroup io
    *
    *  This is the base class for all output streams.  It provides text
    *  formatting of all builtin types, and communicates with any class
@@ -74,31 +70,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                                                        __num_put_type;
       typedef ctype<_CharT>                            __ctype_type;
 
-      template<typename _CharT2, typename _Traits2>
-        friend basic_ostream<_CharT2, _Traits2>&
-        operator<<(basic_ostream<_CharT2, _Traits2>&, _CharT2);
-      template<typename _Traits2>
-        friend basic_ostream<char, _Traits2>&
-        operator<<(basic_ostream<char, _Traits2>&, char);
-      template<typename _CharT2, typename _Traits2>
-        friend basic_ostream<_CharT2, _Traits2>&
-        operator<<(basic_ostream<_CharT2, _Traits2>&, const _CharT2*);
-      template<typename _Traits2>
-        friend basic_ostream<char, _Traits2>&
-        operator<<(basic_ostream<char, _Traits2>&, const char*);
-      template<typename _CharT2, typename _Traits2>
-        friend basic_ostream<_CharT2, _Traits2>&
-        operator<<(basic_ostream<_CharT2, _Traits2>&, const char*);
-
-      template<typename _CharT2, typename _Traits2, typename _Alloc>
-        friend basic_ostream<_CharT2, _Traits2>&
-        operator<<(basic_ostream<_CharT2, _Traits2>&,
-                  const basic_string<_CharT2, _Traits2, _Alloc>&);
-
       // [27.6.2.2] constructor/destructor
       /**
        *  @brief  Base constructor.
@@ -129,7 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       /**
        *  @brief  Interface for manipulators.
        *
-       *  Manuipulators such as @c std::endl and @c std::hex use these
+       *  Manipulators such as @c std::endl and @c std::hex use these
        *  functions in constructs like "std::cout << std::endl".  For more
        *  information, see the iomanip header.
       */
@@ -320,20 +291,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
          this->setstate(ios_base::badbit);
       }
 
-      void
-      _M_write(char_type __c, streamsize __n)
-      {
-       for (; __n > 0; --__n)
-         {
-           const int_type __put = this->rdbuf()->sputc(__c);
-           if (traits_type::eq_int_type(__put, traits_type::eof()))
-             {
-               this->setstate(ios_base::badbit);
-               break;
-             }
-         }
-      }
-
       /**
        *  @brief  Character string insertion.
        *  @param  s  The array to insert.
@@ -401,15 +358,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       seekp(off_type, ios_base::seekdir);
       
     protected:
-      explicit 
-      basic_ostream() { }
+      basic_ostream()
+      { this->init(0); }
 
       template<typename _ValueT>
         __ostream_type&
         _M_insert(_ValueT __v);
-
-      __ostream_type&
-      _M_insert(const char_type* __s, streamsize __n);
     };
 
   /**
@@ -417,15 +371,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
    *
    *  Objects of this class are created before all of the standard
    *  inserters are run.  It is responsible for "exception-safe prefix and
-   *  suffix operations."  Additional actions may be added by the
-   *  implementation, and we list them in
-   *  http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/howto.html#5
-   *  under [27.6] notes.
+   *  suffix operations." 
   */
   template <typename _CharT, typename _Traits>
     class basic_ostream<_CharT, _Traits>::sentry
     {
-      // Data Members:
+      // Data Members.
       bool                             _M_ok;
       basic_ostream<_CharT, _Traits>&  _M_os;
       
@@ -454,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       ~sentry()
       {
        // XXX MT
-       if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
+       if (bool(_M_os.flags() & ios_base::unitbuf) && !uncaught_exception())
          {
            // Can't call flush directly or else will get into recursive lock.
            if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
@@ -469,6 +420,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  For ease of use, sentries may be converted to booleans.  The
        *  return value is that of the sentry state (true == okay).
       */
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      explicit
+#endif
       operator bool() const
       { return _M_ok; }
     };
@@ -493,7 +447,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   template<typename _CharT, typename _Traits>
     inline basic_ostream<_CharT, _Traits>&
     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
-    { return __out._M_insert(&__c, 1); }
+    { return __ostream_insert(__out, &__c, 1); }
 
   template<typename _CharT, typename _Traits>
     inline basic_ostream<_CharT, _Traits>&
@@ -504,7 +458,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   template <class _Traits> 
     inline basic_ostream<char, _Traits>&
     operator<<(basic_ostream<char, _Traits>& __out, char __c)
-    { return __out._M_insert(&__c, 1); }
+    { return __ostream_insert(__out, &__c, 1); }
 
   // Signed and unsigned
   template<class _Traits>
@@ -539,7 +493,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       if (!__s)
        __out.setstate(ios_base::badbit);
       else
-       __out._M_insert(__s, static_cast<streamsize>(_Traits::length(__s)));
+       __ostream_insert(__out, __s,
+                        static_cast<streamsize>(_Traits::length(__s)));
       return __out;
     }
 
@@ -547,7 +502,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     basic_ostream<_CharT, _Traits> &
     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
 
-  // Partial specializationss
+  // Partial specializations
   template<class _Traits>
     inline basic_ostream<char, _Traits>&
     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
@@ -555,7 +510,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       if (!__s)
        __out.setstate(ios_base::badbit);
       else
-       __out._M_insert(__s, static_cast<streamsize>(_Traits::length(__s)));
+       __ostream_insert(__out, __s,
+                        static_cast<streamsize>(_Traits::length(__s)));
       return __out;
     }
 
@@ -577,8 +533,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
    *
    *  This manipulator is often mistakenly used when a simple newline is
    *  desired, leading to poor buffering performance.  See
-   *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for more
-   *  on this subject.
+   *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html
+   *  for more on this subject.
   */
   template<typename _CharT, typename _Traits>
     inline basic_ostream<_CharT, _Traits>& 
@@ -606,6 +562,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     flush(basic_ostream<_CharT, _Traits>& __os)
     { return __os.flush(); }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  // [27.7.2.9] Rvalue stream insertion
+  /**
+   *  @brief  Generic inserter for rvalue stream
+   *  @param  os  An input stream.
+   *  @param  x  A reference to the object being inserted.
+   *  @return  os
+   *
+   *  This is just a forwarding function to allow insertion to
+   *  rvalue streams since they won't bind to the inserter functions
+   *  that take an lvalue reference.
+  */
+  template<typename _CharT, typename _Traits, typename _Tp>
+    inline basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
+    { return (__os << __x); }
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
 _GLIBCXX_END_NAMESPACE
 
 #ifndef _GLIBCXX_EXPORT_TEMPLATE