This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::string overloads for xfstream


All,

This is a new patch and ChangeLog.

The actual changes to std/fstream are the same as in the last patch.
The test cases all are now simple compile only tests and there is now only one filebuf test.


Ed

Attachment: CL_fstream_string
Description: Binary data

Index: include/std/fstream
===================================================================
--- include/std/fstream	(revision 145023)
+++ include/std/fstream	(working copy)
@@ -45,8 +45,11 @@
 #include <istream>
 #include <ostream>
 #include <bits/codecvt.h>
-#include <cstdio>             // For BUFSIZ     
+#include <cstdio>             // For BUFSIZ
 #include <bits/basic_file.h>  // For __basic_file, __c_lock
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#include <string>             // For std::string overloads.
+#endif
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -121,12 +124,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       bool			_M_buf_allocated;
 
       /**
-       *  _M_reading == false && _M_writing == false for 'uncommitted' mode;  
+       *  _M_reading == false && _M_writing == false for 'uncommitted' mode;
        *  _M_reading == true for 'read' mode;
        *  _M_writing == true for 'write' mode;
        *
        *  NB: _M_reading == true && _M_writing == true is unused.
-      */ 
+      */
       bool                      _M_reading;
       bool                      _M_writing;
 
@@ -136,10 +139,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *
        *  @note pbacks of over one character are not currently supported.
       */
-      char_type			_M_pback; 
+      char_type			_M_pback;
       char_type*		_M_pback_cur_save;
       char_type*		_M_pback_end_save;
-      bool			_M_pback_init; 
+      bool			_M_pback_init;
       //@}
 
       // Cached codecvt facet.
@@ -149,19 +152,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Buffer for external characters. Used for input when
        *  codecvt::always_noconv() == false. When valid, this corresponds
        *  to eback().
-      */ 
+      */
       char*			_M_ext_buf;
 
       /**
        *  Size of buffer held by _M_ext_buf.
-      */ 
+      */
       streamsize		_M_ext_buf_size;
 
       /**
        *  Pointers into the buffer held by _M_ext_buf that delimit a
        *  subsequence of bytes that have been read but not yet converted.
        *  When valid, _M_ext_next corresponds to egptr().
-      */ 
+      */
       const char*		_M_ext_next;
       char*			_M_ext_end;
 
@@ -186,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Deactivates pback buffer contents, and restores normal buffer.
        *  Assumptions:
        *  The pback buffer has only moved forward.
-      */ 
+      */
       void
       _M_destroy_pback() throw()
       {
@@ -266,6 +269,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       __filebuf_type*
       open(const char* __s, ios_base::openmode __mode);
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *  @return  @c this on success, NULL on failure
+       */
+      __filebuf_type*
+      open(const std::string& __s, ios_base::openmode __mode)
+      { return open(__s.c_str(), __mode); }
+#endif
+
       /**
        *  @brief  Closes the currently associated file.
        *  @return  @c this on success, NULL on failure
@@ -367,7 +382,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *   __off == egptr() - eback() upon underflow/uflow ('read' mode);
        *   __off == 0 upon overflow ('write' mode);
        *   __off == -1 upon open, setbuf, seekoff/pos ('uncommitted' mode).
-       * 
+       *
        *  NB: epptr() - pbase() == _M_buf_size - 1, since _M_buf_size
        *  reflects the actual allocated memory and the last cell is reserved
        *  for the overflow char of a full put area.
@@ -448,6 +463,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an input file stream.
+       *  @param  s  std::string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       *
+       *  @c ios_base::in is automatically included in @a mode.
+      */
+      explicit
+      basic_ifstream(const std::string& __s,
+		     ios_base::openmode __mode = ios_base::in)
+      : __istream_type(), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -504,6 +537,27 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode|in).  If that function
+       *  fails, @c failbit is set in the stream's error state.
+      */
+      void
+      open(const std::string& __s, ios_base::openmode __mode = ios_base::in)
+      {
+	if (!_M_filebuf.open(__s, __mode | ios_base::in))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
@@ -579,6 +633,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an output file stream.
+       *  @param  s  std::string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       *
+       *  @c ios_base::out|ios_base::trunc is automatically included in
+       *  @a mode.
+      */
+      explicit
+      basic_ofstream(const std::string& __s,
+		     ios_base::openmode __mode = ios_base::out|ios_base::trunc)
+      : __ostream_type(), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -636,6 +709,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode|out|trunc).  If that
+       *  function fails, @c failbit is set in the stream's error state.
+      */
+      void
+      open(const std::string& __s,
+	   ios_base::openmode __mode = ios_base::out | ios_base::trunc)
+      {
+	if (!_M_filebuf.open(__s, __mode | ios_base::out))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
@@ -710,6 +805,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an input/output file stream.
+       *  @param  s  Null terminated string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       */
+      explicit
+      basic_fstream(const std::string& __s,
+		    ios_base::openmode __mode = ios_base::in | ios_base::out)
+      : __iostream_type(NULL), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -767,6 +878,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode).  If that
+       *  function fails, @c failbit is set in the stream's error state.
+       */
+      void
+      open(const std::string& __s,
+	   ios_base::openmode __mode = ios_base::in | ios_base::out)
+      {
+	if (!_M_filebuf.open(__s, __mode))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
Index: testsuite/27_io/basic_ofstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_ofstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ofstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.13 ofstream member functions
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::ofstream ofs;
+
+  const std::string name = "ofstream_name.txt";
+  ofs.open(name);
+
+  ofs.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ofstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_ofstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ofstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,42 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.11 ofstream constructors
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  const std::string name = "ofstream_name.txt";
+  std::ofstream ofs(name);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_fstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_fstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_fstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.17 fstream member functions
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::fstream fs;
+  
+  const std::string name = "fstream_name.txt";
+  fs.open(name);
+
+  fs.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_fstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_fstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_fstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,43 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.15 fstream constructors
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  
+  const std::string name = "fstream_name.txt";
+  std::fstream fs(name);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ifstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_ifstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ifstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.9 ifstream member functions
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::ifstream ifs;
+
+  const std::string name = "ifstream_name.txt";
+  ifs.open(name);
+
+  ifs.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ifstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_ifstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ifstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,42 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.7 ifstream constructors
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  const std::string name = "ifstream_name.txt";
+  std::ifstream ifs(name);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_filebuf/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/1.cc	(revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 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)
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.3 filebuf member functions
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// Test member functions.
+void test_01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::filebuf fb;
+
+  const std::string name = "filebuf_name.txt";
+  fb.open(name, std::ios_base::in | std::ios_base::ate);
+}
+
+int
+main()
+{
+  test_01();
+  return 0;
+}
+
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]