1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_tempbuf.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,167 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 1994
1.7 + * Hewlett-Packard Company
1.8 + *
1.9 + * Copyright (c) 1996,1997
1.10 + * Silicon Graphics Computer Systems, Inc.
1.11 + *
1.12 + * Copyright (c) 1997
1.13 + * Moscow Center for SPARC Technology
1.14 + *
1.15 + * Copyright (c) 1999
1.16 + * Boris Fomitchev
1.17 + *
1.18 + * This material is provided "as is", with absolutely no warranty expressed
1.19 + * or implied. Any use is at your own risk.
1.20 + *
1.21 + * Permission to use or copy this software for any purpose is hereby granted
1.22 + * without fee, provided the above notices are retained on all copies.
1.23 + * Permission to modify the code and to distribute modified code is granted,
1.24 + * provided the above notices are retained, and a notice that the code was
1.25 + * modified is included with the above copyright notice.
1.26 + *
1.27 + */
1.28 +
1.29 +/* NOTE: This is an internal header file, included by other STL headers.
1.30 + * You should not attempt to use it directly.
1.31 + */
1.32 +
1.33 +#ifndef _STLP_INTERNAL_TEMPBUF_H
1.34 +#define _STLP_INTERNAL_TEMPBUF_H
1.35 +
1.36 +#ifndef _STLP_CLIMITS
1.37 +# include <climits>
1.38 +#endif
1.39 +
1.40 +#ifndef _STLP_INTERNAL_CSTDLIB
1.41 +# include <stl/_cstdlib.h>
1.42 +#endif
1.43 +
1.44 +#ifndef _STLP_INTERNAL_UNINITIALIZED_H
1.45 +# include <stl/_uninitialized.h>
1.46 +#endif
1.47 +
1.48 +_STLP_BEGIN_NAMESPACE
1.49 +
1.50 +template <class _Tp>
1.51 +pair<_Tp*, ptrdiff_t> _STLP_CALL
1.52 +__get_temporary_buffer(ptrdiff_t __len, _Tp*);
1.53 +
1.54 +#ifndef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
1.55 +
1.56 +template <class _Tp>
1.57 +inline pair<_Tp*, ptrdiff_t> _STLP_CALL get_temporary_buffer(ptrdiff_t __len) {
1.58 + return __get_temporary_buffer(__len, (_Tp*) 0);
1.59 +}
1.60 +
1.61 +# if ! defined(_STLP_NO_EXTENSIONS)
1.62 +// This overload is not required by the standard; it is an extension.
1.63 +// It is supported for backward compatibility with the HP STL, and
1.64 +// because not all compilers support the language feature (explicit
1.65 +// function template arguments) that is required for the standard
1.66 +// version of get_temporary_buffer.
1.67 +template <class _Tp>
1.68 +inline pair<_Tp*, ptrdiff_t> _STLP_CALL
1.69 +get_temporary_buffer(ptrdiff_t __len, _Tp*) {
1.70 + return __get_temporary_buffer(__len, (_Tp*) 0);
1.71 +}
1.72 +# endif
1.73 +#endif
1.74 +
1.75 +template <class _Tp>
1.76 +inline void _STLP_CALL return_temporary_buffer(_Tp* __p) {
1.77 +// SunPro brain damage
1.78 + free((char*)__p);
1.79 +}
1.80 +
1.81 +template <class _ForwardIterator, class _Tp>
1.82 +class _Temporary_buffer {
1.83 +private:
1.84 + ptrdiff_t _M_original_len;
1.85 + ptrdiff_t _M_len;
1.86 + _Tp* _M_buffer;
1.87 +
1.88 + void _M_allocate_buffer() {
1.89 + _M_original_len = _M_len;
1.90 + _M_buffer = 0;
1.91 +
1.92 + if (_M_len > (ptrdiff_t)(INT_MAX / sizeof(_Tp)))
1.93 + _M_len = INT_MAX / sizeof(_Tp);
1.94 +
1.95 + while (_M_len > 0) {
1.96 + _M_buffer = (_Tp*) malloc(_M_len * sizeof(_Tp));
1.97 + if (_M_buffer)
1.98 + break;
1.99 + _M_len /= 2;
1.100 + }
1.101 + }
1.102 +
1.103 + void _M_initialize_buffer(const _Tp&, const __true_type&) {}
1.104 + void _M_initialize_buffer(const _Tp& val, const __false_type&) {
1.105 + uninitialized_fill_n(_M_buffer, _M_len, val);
1.106 + }
1.107 +
1.108 +public:
1.109 + ptrdiff_t size() const { return _M_len; }
1.110 + ptrdiff_t requested_size() const { return _M_original_len; }
1.111 + _Tp* begin() { return _M_buffer; }
1.112 + _Tp* end() { return _M_buffer + _M_len; }
1.113 +
1.114 + _Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) {
1.115 + // Workaround for a __type_traits bug in the pre-7.3 compiler.
1.116 +# if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION < 730
1.117 + typedef typename __type_traits<_Tp>::is_POD_type _Trivial;
1.118 +# else
1.119 + typedef typename __type_traits<_Tp>::has_trivial_default_constructor _Trivial;
1.120 +# endif
1.121 + _STLP_TRY {
1.122 + _M_len = distance(__first, __last);
1.123 + _M_allocate_buffer();
1.124 + if (_M_len > 0)
1.125 + _M_initialize_buffer(*__first, _Trivial());
1.126 + }
1.127 + _STLP_UNWIND(free(_M_buffer); _M_buffer = 0; _M_len = 0)
1.128 + }
1.129 +
1.130 + ~_Temporary_buffer() {
1.131 + _STLP_STD::_Destroy_Range(_M_buffer, _M_buffer + _M_len);
1.132 + free(_M_buffer);
1.133 + }
1.134 +
1.135 +private:
1.136 + // Disable copy constructor and assignment operator.
1.137 + _Temporary_buffer(const _Temporary_buffer<_ForwardIterator, _Tp>&) {}
1.138 + void operator=(const _Temporary_buffer<_ForwardIterator, _Tp>&) {}
1.139 +};
1.140 +
1.141 +# ifndef _STLP_NO_EXTENSIONS
1.142 +
1.143 +// Class temporary_buffer is not part of the standard. It is an extension.
1.144 +
1.145 +template <class _ForwardIterator,
1.146 + class _Tp
1.147 +#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
1.148 + = typename iterator_traits<_ForwardIterator>::value_type
1.149 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
1.150 + >
1.151 +struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
1.152 +{
1.153 + temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
1.154 + : _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) {}
1.155 + ~temporary_buffer() {}
1.156 +};
1.157 +
1.158 +# endif /* _STLP_NO_EXTENSIONS */
1.159 +
1.160 +_STLP_END_NAMESPACE
1.161 +
1.162 +# ifndef _STLP_LINK_TIME_INSTANTIATION
1.163 +# include <stl/_tempbuf.c>
1.164 +# endif
1.165 +
1.166 +#endif /* _STLP_INTERNAL_TEMPBUF_H */
1.167 +
1.168 +// Local Variables:
1.169 +// mode:C++
1.170 +// End: