stl_tempbuf.h (_Temporary_buffer): Add doxygen hook.

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.

From-SVN: r49199
This commit is contained in:
Phil Edwards 2002-01-25 04:14:40 +00:00
parent 9fa5237cb7
commit 6b20f9b59a
9 changed files with 144 additions and 46 deletions

View 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>)

View 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.

View 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
@ -64,6 +64,12 @@
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;

View 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)

View 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>

View 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>

View 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 */

View 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
@ -55,14 +55,71 @@
#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;

View File

@ -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;
}