ReactOS 0.4.15-dev-7924-g5949c20
_tempbuf.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
5 *
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
8 *
9 * Copyright (c) 1997
10 * Moscow Center for SPARC Technology
11 *
12 * Copyright (c) 1999
13 * Boris Fomitchev
14 *
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
17 *
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
23 *
24 */
25
26/* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
28 */
29
30#ifndef _STLP_INTERNAL_TEMPBUF_H
31#define _STLP_INTERNAL_TEMPBUF_H
32
33#ifndef _STLP_CLIMITS
34# include <climits>
35#endif
36
37#ifndef _STLP_INTERNAL_CSTDLIB
38# include <stl/_cstdlib.h>
39#endif
40
41#ifndef _STLP_INTERNAL_UNINITIALIZED_H
42# include <stl/_uninitialized.h>
43#endif
44
46
47template <class _Tp>
50
51#ifndef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
52
53template <class _Tp>
55 return __get_temporary_buffer(__len, (_Tp*) 0);
56}
57
58# if ! defined(_STLP_NO_EXTENSIONS)
59// This overload is not required by the standard; it is an extension.
60// It is supported for backward compatibility with the HP STL, and
61// because not all compilers support the language feature (explicit
62// function template arguments) that is required for the standard
63// version of get_temporary_buffer.
64template <class _Tp>
67 return __get_temporary_buffer(__len, (_Tp*) 0);
68}
69# endif
70#endif
71
72template <class _Tp>
73inline void _STLP_CALL return_temporary_buffer(_Tp* __p) {
74// SunPro brain damage
75 free((char*)__p);
76}
77
78template <class _ForwardIterator, class _Tp>
80private:
84
87 _M_buffer = 0;
88
89 if (_M_len > (ptrdiff_t)(INT_MAX / sizeof(_Tp)))
90 _M_len = INT_MAX / sizeof(_Tp);
91
92 while (_M_len > 0) {
93 _M_buffer = (_Tp*) malloc(_M_len * sizeof(_Tp));
94 if (_M_buffer)
95 break;
96 _M_len /= 2;
97 }
98 }
99
100 void _M_initialize_buffer(const _Tp&, const __true_type&) {}
101 void _M_initialize_buffer(const _Tp& val, const __false_type&) {
103 }
104
105public:
106 ptrdiff_t size() const { return _M_len; }
108 _Tp* begin() { return _M_buffer; }
109 _Tp* end() { return _M_buffer + _M_len; }
110
111 _Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) {
112 // Workaround for a __type_traits bug in the pre-7.3 compiler.
113# if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION < 730
114 typedef typename __type_traits<_Tp>::is_POD_type _Trivial;
115# else
117# endif
118 _STLP_TRY {
119 _M_len = _STLP_STD::distance(__first, __last);
121 if (_M_len > 0)
122 _M_initialize_buffer(*__first, _Trivial());
123 }
125 }
126
128 _STLP_STD::_Destroy_Range(_M_buffer, _M_buffer + _M_len);
130 }
131
132private:
133 // Disable copy constructor and assignment operator.
136};
137
138# ifndef _STLP_NO_EXTENSIONS
139
140// Class temporary_buffer is not part of the standard. It is an extension.
141
142template <class _ForwardIterator,
143 class _Tp
144#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
146#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
147 >
148struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
149{
150 temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
151 : _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) {}
153};
154
155# endif /* _STLP_NO_EXTENSIONS */
156
158
159# ifndef _STLP_LINK_TIME_INSTANTIATION
160# include <stl/_tempbuf.c>
161# endif
162
163#endif /* _STLP_INTERNAL_TEMPBUF_H */
164
165// Local Variables:
166// mode:C++
167// End:
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
#define _STLP_CALL
Definition: _bc.h:131
pair< _Tp *, ptrdiff_t > _STLP_CALL get_temporary_buffer(ptrdiff_t __len)
Definition: _tempbuf.h:54
_STLP_BEGIN_NAMESPACE pair< _Tp *, ptrdiff_t > _STLP_CALL __get_temporary_buffer(ptrdiff_t __len, _Tp *)
Definition: _tempbuf.c:37
void _STLP_CALL return_temporary_buffer(_Tp *__p)
Definition: _tempbuf.h:73
_STLP_MOVE_TO_STD_NAMESPACE void uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp &__x)
void _M_initialize_buffer(const _Tp &val, const __false_type &)
Definition: _tempbuf.h:101
_Temporary_buffer(const _Temporary_buffer< _ForwardIterator, _Tp > &)
Definition: _tempbuf.h:134
void _M_allocate_buffer()
Definition: _tempbuf.h:85
_Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
Definition: _tempbuf.h:111
void _M_initialize_buffer(const _Tp &, const __true_type &)
Definition: _tempbuf.h:100
ptrdiff_t _M_len
Definition: _tempbuf.h:82
void operator=(const _Temporary_buffer< _ForwardIterator, _Tp > &)
Definition: _tempbuf.h:135
ptrdiff_t size() const
Definition: _tempbuf.h:106
ptrdiff_t requested_size() const
Definition: _tempbuf.h:107
ptrdiff_t _M_original_len
Definition: _tempbuf.h:81
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define _STLP_UNWIND(action)
Definition: features.h:824
#define _STLP_TRY
Definition: features.h:817
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
GLuint GLfloat * val
Definition: glext.h:7180
#define INT_MAX
Definition: limits.h:40
_Iterator::value_type value_type
Definition: _pair.h:47
temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
Definition: _tempbuf.h:150