- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Configs/TI_DSP_BIOS/stl/stl_tempbuf.h

    00001 /*
    00002  *
    00003  * Copyright (c) 1994
    00004  * Hewlett-Packard Company
    00005  *
    00006  * Permission to use, copy, modify, distribute and sell this software
    00007  * and its documentation for any purpose is hereby granted without fee,
    00008  * provided that the above copyright notice appear in all copies and
    00009  * that both that copyright notice and this permission notice appear
    00010  * in supporting documentation.  Hewlett-Packard Company makes no
    00011  * representations about the suitability of this software for any
    00012  * purpose.  It is provided "as is" without express or implied warranty.
    00013  *
    00014  *
    00015  * Copyright (c) 1996,1997
    00016  * Silicon Graphics Computer Systems, Inc.
    00017  *
    00018  * Permission to use, copy, modify, distribute and sell this software
    00019  * and its documentation for any purpose is hereby granted without fee,
    00020  * provided that the above copyright notice appear in all copies and
    00021  * that both that copyright notice and this permission notice appear
    00022  * in supporting documentation.  Silicon Graphics makes no
    00023  * representations about the suitability of this software for any
    00024  * purpose.  It is provided "as is" without express or implied warranty.
    00025  */
    00026
    00027 /* NOTE: This is an internal header file, included by other STL headers.
    00028  *   You should not attempt to use it directly.
    00029  */
    00030
    00031 #ifndef __SGI_STL_INTERNAL_TEMPBUF_H
    00032 #define __SGI_STL_INTERNAL_TEMPBUF_H
    00033
    00034
    00035 __STL_BEGIN_NAMESPACE
    00036
    00037 template <class _Tp>
    00038 pair<_Tp*, ptrdiff_t>
    00039 __get_temporary_buffer(ptrdiff_t __len, _Tp*)
    00040 {
    00041   if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
    00042     __len = INT_MAX / sizeof(_Tp);
    00043
    00044   while (__len > 0) {
    00045     _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
    00046     if (__tmp != 0)
    00047       return pair<_Tp*, ptrdiff_t>(__tmp, __len);
    00048     __len /= 2;
    00049   }
    00050
    00051   return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
    00052 }
    00053
    00054 #ifdef __STL_EXPLICIT_FUNCTION_TMPL_ARGS
    00055
    00056 template <class _Tp>
    00057 inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) {
    00058   return __get_temporary_buffer(__len, (_Tp*) 0);
    00059 }
    00060
    00061 #endif /* __STL_EXPLICIT_FUNCTION_TMPL_ARGS */
    00062
    00063 // This overload is not required by the standard; it is an extension.
    00064 // It is supported for backward compatibility with the HP STL, and
    00065 // because not all compilers support the language feature (explicit
    00066 // function template arguments) that is required for the standard
    00067 // version of get_temporary_buffer.
    00068 template <class _Tp>
    00069 inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len, _Tp*) {
    00070   return __get_temporary_buffer(__len, (_Tp*) 0);
    00071 }
    00072
    00073 template <class _Tp>
    00074 void return_temporary_buffer(_Tp* __p) {
    00075   free(__p);
    00076 }
    00077
    00078 template <class _ForwardIterator, class _Tp>
    00079 class _Temporary_buffer {
    00080 private:
    00081   ptrdiff_t  _M_original_len;
    00082   ptrdiff_t  _M_len;
    00083   _Tp*       _M_buffer;
    00084
    00085   void _M_allocate_buffer() {
    00086     _M_original_len = _M_len;
    00087     _M_buffer = 0;
    00088
    00089     if (_M_len > (ptrdiff_t)(INT_MAX / sizeof(_Tp)))
    00090       _M_len = INT_MAX / sizeof(_Tp);
    00091
    00092     while (_M_len > 0) {
    00093       _M_buffer = (_Tp*) malloc(_M_len * sizeof(_Tp));
    00094       if (_M_buffer)
    00095         break;
    00096       _M_len /= 2;
    00097     }
    00098   }
    00099
    00100   void _M_initialize_buffer(const _Tp&, __true_type) {}
    00101   void _M_initialize_buffer(const _Tp& val, __false_type) {
    00102     uninitialized_fill_n(_M_buffer, _M_len, val);
    00103   }
    00104
    00105 public:
    00106   ptrdiff_t size() const { return _M_len; }
    00107   ptrdiff_t requested_size() const { return _M_original_len; }
    00108   _Tp* begin() { return _M_buffer; }
    00109   _Tp* end() { return _M_buffer + _M_len; }
    00110
    00111   _Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) {
    00112     typedef typename __type_traits<_Tp>::has_trivial_default_constructor
    00113             _Trivial;
    00114     __STL_TRY {
    00115       _M_len = 0;
    00116       distance(__first, __last, _M_len);
    00117       _M_allocate_buffer();
    00118       if (_M_len > 0)
    00119         _M_initialize_buffer(*__first, _Trivial());
    00120     }
    00121     __STL_UNWIND(free(_M_buffer); _M_buffer = 0; _M_len = 0);
    00122   }
    00123
    00124   ~_Temporary_buffer() {
    00125     destroy(_M_buffer, _M_buffer + _M_len);
    00126     free(_M_buffer);
    00127   }
    00128
    00129 private:
    00130   // Disable copy constructor and assignment operator.
    00131   _Temporary_buffer(const _Temporary_buffer&) {}
    00132   void operator=(const _Temporary_buffer&) {}
    00133 };
    00134
    00135 // Class temporary_buffer is not part of the standard.  It is an extension.
    00136
    00137 template <class _ForwardIterator,
    00138           class _Tp
    00139 #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
    00140                     = typename iterator_traits<_ForwardIterator>::value_type
    00141 #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
    00142          >
    00143 struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
    00144 {
    00145   temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
    00146     : _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) {}
    00147   ~temporary_buffer() {}
    00148 };
    00149
    00150 __STL_END_NAMESPACE
    00151
    00152 #endif /* __SGI_STL_INTERNAL_TEMPBUF_H */
    00153
    00154 // Local Variables:
    00155 // mode:C++
    00156 // End: