OSDN Git Service

2006-06-06 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / std_sstream.h
index fc4c42a..f30c23b 100644 (file)
@@ -1,6 +1,6 @@
 // String based streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -16,7 +16,7 @@
 
 // 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,
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 // USA.
 
 // As a special exception, you may use this file as part of a free software
@@ -33,8 +33,7 @@
 //
 
 /** @file sstream
- *  This is a Standard C++ Library header.  You should @c #include this header
- *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
+ *  This is a Standard C++ Library header.
  */
 
 #ifndef _GLIBCXX_SSTREAM
@@ -45,8 +44,8 @@
 #include <istream>
 #include <ostream>
 
-namespace std
-{
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
   // [27.7.1] template class basic_stringbuf
   /**
    *  @brief  The actual work of input and output (for std::string).
@@ -73,16 +72,9 @@ namespace std
       typedef typename traits_type::pos_type           pos_type;
       typedef typename traits_type::off_type           off_type;
 
-      //@{
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
       typedef basic_streambuf<char_type, traits_type>          __streambuf_type;
       typedef basic_string<char_type, _Traits, _Alloc>         __string_type;
       typedef typename __string_type::size_type                __size_type;
-      //@}
 
     protected:
       /**
@@ -93,11 +85,6 @@ namespace std
       ios_base::openmode       _M_mode;
 
       // Data Members:
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
       __string_type            _M_string;
 
     public:
@@ -140,16 +127,18 @@ namespace std
       __string_type
       str() const
       {
+       __string_type __ret;
        if (this->pptr())
          {
            // The current egptr() may not be the actual string end.
            if (this->pptr() > this->egptr())
-             return __string_type(this->pbase(), this->pptr());
+             __ret = __string_type(this->pbase(), this->pptr());
            else
-             return __string_type(this->pbase(), this->egptr());
+             __ret = __string_type(this->pbase(), this->egptr());
          }
        else
-         return _M_string;
+         __ret = _M_string;
+       return __ret;
       }
 
       /**
@@ -164,36 +153,39 @@ namespace std
       {
        // Cannot use _M_string = __s, since v3 strings are COW.
        _M_string.assign(__s.data(), __s.size());
-       _M_stringbuf_init(this->_M_mode);
+       _M_stringbuf_init(_M_mode);
       }
 
     protected:
       // Common initialization code goes here.
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
       void
       _M_stringbuf_init(ios_base::openmode __mode)
       {
-       this->_M_mode = __mode;
-
+       _M_mode = __mode;
        __size_type __len = 0;
-       if (this->_M_mode & (ios_base::ate | ios_base::app))
+       if (_M_mode & (ios_base::ate | ios_base::app))
          __len = _M_string.size();
        _M_sync(const_cast<char_type*>(_M_string.data()), 0, __len);
       }
 
-      // [documentation is inherited]
+      virtual streamsize
+      showmanyc()
+      { 
+       streamsize __ret = -1;
+       if (_M_mode & ios_base::in)
+         {
+           _M_update_egptr();
+           __ret = this->egptr() - this->gptr();
+         }
+       return __ret;
+      }
+
       virtual int_type
       underflow();
 
-      // [documentation is inherited]
       virtual int_type
       pbackfail(int_type __c = traits_type::eof());
 
-      // [documentation is inherited]
       virtual int_type
       overflow(int_type __c = traits_type::eof());
 
@@ -219,69 +211,34 @@ namespace std
            // things will quickly blow up.
            
            // Step 1: Destroy the current internal array.
-           _M_string.assign(__s, __n);
+           _M_string.clear();
            
            // Step 2: Use the external array.
-           _M_sync(__s, 0, 0);
+           _M_sync(__s, __n, 0);
          }
        return this;
       }
 
-      // [documentation is inherited]
       virtual pos_type
       seekoff(off_type __off, ios_base::seekdir __way,
              ios_base::openmode __mode = ios_base::in | ios_base::out);
 
-      // [documentation is inherited]
       virtual pos_type
       seekpos(pos_type __sp,
              ios_base::openmode __mode = ios_base::in | ios_base::out);
 
       // Internal function for correctly updating the internal buffer
-      // for a particular _M_string, due to initialization or
-      // re-sizing of an existing _M_string.
-      // Assumes: contents of _M_string and internal buffer match exactly.
-      // __i == _M_in_cur - _M_in_beg
-      // __o == _M_out_cur - _M_out_beg
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
+      // for a particular _M_string, due to initialization or re-sizing
+      // of an existing _M_string.
       void
-      _M_sync(char_type* __base, __size_type __i, __size_type __o)
-      {
-       const bool __testin = this->_M_mode & ios_base::in;
-       const bool __testout = this->_M_mode & ios_base::out;
-       char_type* __end = __base + _M_string.size();
-
-       if (__testin)
-         this->setg(__base, __base + __i, __end);
-       if (__testout)
-         {
-           // If __base comes from setbuf we cannot trust capacity()
-           // to match the size of the buffer area: in general, after
-           // Step 1 above, _M_string.capacity() >= __n.
-           if (__base == _M_string.data())
-             this->setp(__base, __base + _M_string.capacity());
-           else
-             this->setp(__base, __end);
-           this->pbump(__o);
-           // egptr() always tracks the string end. When !__testin,
-           // for the correct functioning of the streambuf inlines
-           // the other get area pointers are identical.
-           if (!__testin)
-             this->setg(__end, __end, __end);
-         }
-      }
+      _M_sync(char_type* __base, __size_type __i, __size_type __o);
 
       // Internal function for correctly updating egptr() to the actual
       // string end.
       void
       _M_update_egptr()
       {
-       const bool __testin = this->_M_mode & ios_base::in;
-
+       const bool __testin = _M_mode & ios_base::in;
        if (this->pptr() && this->pptr() > this->egptr())
          if (__testin)
            this->setg(this->eback(), this->gptr(), this->pptr());
@@ -320,11 +277,6 @@ namespace std
       typedef basic_istream<char_type, traits_type>    __istream_type;
 
     private:
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
       __stringbuf_type _M_stringbuf;
 
     public:
@@ -438,11 +390,6 @@ namespace std
       typedef basic_ostream<char_type, traits_type>    __ostream_type;
 
     private:
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
       __stringbuf_type _M_stringbuf;
 
     public:
@@ -556,11 +503,6 @@ namespace std
       typedef basic_iostream<char_type, traits_type>   __iostream_type;
 
     private:
-      /**
-       *  @if maint
-       *  @doctodo
-       *  @endif
-      */
       __stringbuf_type _M_stringbuf;
 
     public:
@@ -639,7 +581,8 @@ namespace std
       str(const __string_type& __s)
       { _M_stringbuf.str(__s); }
     };
-} // namespace std
+
+_GLIBCXX_END_NAMESPACE
 
 #ifndef _GLIBCXX_EXPORT_TEMPLATE
 # include <bits/sstream.tcc>