OSDN Git Service

2002-01-24 Phil Edwards <pme@gcc.gnu.org>
authorpme <pme@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 Jan 2002 04:14:40 +0000 (04:14 +0000)
committerpme <pme@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 Jan 2002 04:14:40 +0000 (04:14 +0000)
* include/bits/stl_tempbuf.h (_Temporary_buffer):  Add doxygen hook.
* include/bits/stl_algo.h:  Include stl_tempbuf.h.
* include/ext/memory:  Do not include stl_tempbuf.h.
(temporary_buffer):  Add doxygen hook.
(__get_temporary_buffer, get_temporary_buffer,
return_temporary_buffer):  Move back to std:: header...
* include/std/std_memory.h:  ...here.  Do not include stl_tempbuf.h.
* include/ext/rope:  Do not include stl_tempbuf.h.
* include/ext/stl_hashtable.h:  Likewise.
* include/std/std_algorithm.h:  Likewise.
* testsuite/20_util/temporary_buffer.cc:  New file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49199 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/include/bits/stl_tempbuf.h
libstdc++-v3/include/ext/memory
libstdc++-v3/include/ext/rope
libstdc++-v3/include/ext/stl_hashtable.h
libstdc++-v3/include/std/std_algorithm.h
libstdc++-v3/include/std/std_memory.h
libstdc++-v3/testsuite/20_util/temporary_buffer.cc [new file with mode: 0644]

index 5e849a4..62a66d0 100644 (file)
@@ -1,3 +1,17 @@
+2002-01-24  Phil Edwards  <pme@gcc.gnu.org>
+
+       * include/bits/stl_tempbuf.h (_Temporary_buffer):  Add doxygen hook.
+       * include/bits/stl_algo.h:  Include stl_tempbuf.h.
+       * include/ext/memory:  Do not include stl_tempbuf.h.
+       (temporary_buffer):  Add doxygen hook.
+       (__get_temporary_buffer, get_temporary_buffer,
+       return_temporary_buffer):  Move back to std:: header...
+       * include/std/std_memory.h:  ...here.  Do not include stl_tempbuf.h.
+       * include/ext/rope:  Do not include stl_tempbuf.h.
+       * include/ext/stl_hashtable.h:  Likewise.
+       * include/std/std_algorithm.h:  Likewise.
+       * testsuite/20_util/temporary_buffer.cc:  New file.
+
 2002-01-24  andrew@andypo.net
            (tweaks, test and commit by Loren J. Rittle  <ljrittle@acm.org>)
 
index e8e9845..a8059b7 100644 (file)
@@ -62,6 +62,7 @@
 #define __GLIBCPP_INTERNAL_ALGO_H
 
 #include <bits/stl_heap.h>
+#include <bits/stl_tempbuf.h>     // for _Temporary_buffer
 
 // See concept_check.h for the __glibcpp_*_requires macros.
 
index 05565e0..0bf4718 100644 (file)
@@ -1,6 +1,6 @@
 // Temporary buffer implementation -*- C++ -*-
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
 namespace std
 {
 
+/**
+ *  @maint
+ *  This class is used in two places:  stl_algo.h and ext/memory, where it
+ *  is wrapped as the temporary_buffer class.
+ *  @endmaint
+*/
 template <class _ForwardIterator, class _Tp>
 class _Temporary_buffer {
 private:
@@ -71,6 +77,7 @@ private:
   ptrdiff_t  _M_len;
   _Tp*       _M_buffer;
 
+  // this is basically get_temporary_buffer() all over again
   void _M_allocate_buffer() {
     _M_original_len = _M_len;
     _M_buffer = 0;
index 73fa427..3318611 100644 (file)
@@ -58,6 +58,7 @@
 
 #pragma GCC system_header
 #include <memory>
+#include <bits/stl_tempbuf.h>
 
 namespace __gnu_cxx
 {
@@ -124,45 +125,14 @@ namespace __gnu_cxx
                                    __iterator_category(__first));
     }
 
-  template <class _Tp>
-  pair<_Tp*, ptrdiff_t> 
-  __get_temporary_buffer(ptrdiff_t __len, _Tp*)
-  {
-    if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
-      __len = INT_MAX / sizeof(_Tp);
-
-    while (__len > 0) {
-      _Tp* __tmp = (_Tp*) std::malloc((std::size_t)__len * sizeof(_Tp));
-      if (__tmp != 0)
-       return pair<_Tp*, ptrdiff_t>(__tmp, __len);
-      __len /= 2;
-    }
-
-    return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
-  }
-
-  /**
-   *  This is a mostly-useless wrapper around malloc().
-   */
-  template <class _Tp>
-  inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) {
-    return __get_temporary_buffer(__len, (_Tp*) 0);
-  }
 
   /**
-   *  The companion to get_temporary_buffer().
-   */
-  template <class _Tp>
-  void return_temporary_buffer(_Tp* __p) {
-    std::free(__p);
-  }
-
-  // Class temporary_buffer is not part of the standard.  It is an extension.
-
+   *  Must come back and figure out these notes.
+   *  @ingroup SGIextensions
+  */
   template <class _ForwardIterator, 
            class _Tp 
-           = typename std::iterator_traits<_ForwardIterator>::value_type
-  >
+             = typename std::iterator_traits<_ForwardIterator>::value_type >
   struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
   {
     temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
index 78bb7dc..c52db59 100644 (file)
@@ -1,6 +1,6 @@
 // SGI's rope class -*- C++ -*-
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
@@ -49,7 +49,6 @@
 #define __SGI_STL_ROPE
 
 #include <bits/stl_algobase.h>
-#include <bits/stl_tempbuf.h>
 #include <bits/stl_algo.h>
 #include <bits/stl_function.h>
 #include <bits/stl_numeric.h>
index 2317638..2d5c110 100644 (file)
@@ -1,6 +1,6 @@
 // Hashtable implementation used by containers -*- C++ -*-
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
@@ -67,7 +67,6 @@
 #include <bits/stl_algobase.h>
 #include <bits/stl_alloc.h>
 #include <bits/stl_construct.h>
-#include <bits/stl_tempbuf.h>
 #include <bits/stl_algo.h>
 #include <bits/stl_uninitialized.h>
 #include <bits/stl_function.h>
index 746eb47..ff5d257 100644 (file)
@@ -1,6 +1,6 @@
 // <algorithm> -*- C++ -*-
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
@@ -66,7 +66,6 @@
 #include <bits/stl_algobase.h>
 #include <bits/stl_construct.h>
 #include <bits/stl_uninitialized.h>
-#include <bits/stl_tempbuf.h>
 #include <bits/stl_algo.h>
 
 #endif /* _CPP_ALGORITHM */
index c9a2e59..6ca31c2 100644 (file)
@@ -1,6 +1,6 @@
 // <memory> -*- C++ -*-
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
 #include <bits/stl_alloc.h>
 #include <bits/stl_construct.h>
 #include <bits/stl_iterator_base_types.h> //for iterator_traits
-#include <bits/stl_tempbuf.h>
 #include <bits/stl_uninitialized.h>
 #include <bits/stl_raw_storage_iter.h>
 
 namespace std
 {
 
- template<class _Tp1> struct auto_ptr_ref {
+  /**
+   *  @maint
+   *  This is a helper function.  The unused second parameter exists to
+   *  permit the real get_temporary_buffer to use template parameter deduction.
+   *  @endmaint
+  */
+  template <class _Tp>
+  pair<_Tp*, ptrdiff_t> 
+  __get_temporary_buffer(ptrdiff_t __len, _Tp*)
+  {
+    if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
+      __len = INT_MAX / sizeof(_Tp);
+
+    while (__len > 0) {
+      _Tp* __tmp = (_Tp*) std::malloc((std::size_t)__len * sizeof(_Tp));
+      if (__tmp != 0)
+       return pair<_Tp*, ptrdiff_t>(__tmp, __len);
+      __len /= 2;
+    }
+
+    return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
+  }
+
+  /**
+   *  @brief This is a mostly-useless wrapper around malloc().
+   *  @param  len  The number of objects of type Tp.
+   *  @return   See full description.
+   *
+   *  Reinventing the wheel, but this time with prettier spokes!
+   *
+   *  This function tries to obtain storage for @c len adjacent Tp objects.
+   *  The objects themselves are not constructed, of course.  A pair<> is
+   *  returned containing "the buffer s address and capacity (in the units of
+   *  sizeof(Tp)), or a pair of 0 values if no storage can be obtained."
+   *  Note that the capacity obtained may be less than that requested if the
+   *  memory is unavailable; you should compare len with the .second return
+   *  value.
+  */
+  template <class _Tp>
+  inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) {
+    return __get_temporary_buffer(__len, (_Tp*) 0);
+  }
+
+  /**
+   *  @brief The companion to get_temporary_buffer().
+   *  @param  p  A buffer previously allocated by get_temporary_buffer.
+   *  @return   None.
+   *
+   *  Frees the memory pointed to by p.
+   */
+  template <class _Tp>
+  void return_temporary_buffer(_Tp* __p) {
+    std::free(__p);
+  }
+
+
+template <class _Tp1>
+  struct auto_ptr_ref
+{
    _Tp1* _M_ptr;
    auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
 };
@@ -70,7 +127,9 @@ namespace std
 /**
  *  A simple smart pointer providing strict ownership semantics.  (More later.)
 */
-template <class _Tp> class auto_ptr {
+template <class _Tp>
+  class auto_ptr
+{
 private:
   _Tp* _M_ptr;
 
diff --git a/libstdc++-v3/testsuite/20_util/temporary_buffer.cc b/libstdc++-v3/testsuite/20_util/temporary_buffer.cc
new file mode 100644 (file)
index 0000000..602b2fe
--- /dev/null
@@ -0,0 +1,50 @@
+// 2002-01-24  Phil Edwards  <pme@gcc.gnu.org>
+
+// Copyright (C) 2002 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.
+
+// 20.4.3 temporary buffers
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct junk { char j[12]; };
+
+int main(void)
+{
+  bool test = true;
+
+  std::pair<junk*,ptrdiff_t>  results = std::get_temporary_buffer<junk>(5);
+
+  if (results.second != 0)
+  {
+      // make sure it works:  test the returned capacity, and then construct
+      // some junk in the buffer.
+      // XXX
+      VERIFY( results.first != 0 );
+  }
+  else
+  {
+      // if it says it didn't work, make sure it didn't work
+      VERIFY( results.first == 0 );
+  }
+
+  std::return_temporary_buffer(results.first);
+
+  return 0;
+}