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