1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/debug/_vector.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,440 @@
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_DBG_VECTOR_H
1.34 +#define _STLP_INTERNAL_DBG_VECTOR_H
1.35 +
1.36 +#ifndef _STLP_DBG_ITERATOR_H
1.37 +# include <stl/debug/_iterator.h>
1.38 +#endif
1.39 +
1.40 +#define _STLP_NON_DBG_VECTOR _STLP_PRIV _STLP_NON_DBG_NAME(vector) <_Tp, _Alloc>
1.41 +
1.42 +_STLP_BEGIN_NAMESPACE
1.43 +
1.44 +#if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
1.45 +template <class _Tp, class _Alloc>
1.46 +inline _Tp*
1.47 +value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
1.48 +{ return (_Tp*)0; }
1.49 +template <class _Tp, class _Alloc>
1.50 +inline random_access_iterator_tag
1.51 +iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_VECTOR >&)
1.52 +{ return random_access_iterator_tag(); }
1.53 +#endif
1.54 +
1.55 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.56 +
1.57 +template <class _Tp, class _NcIt>
1.58 +struct _Vector_const_traits;
1.59 +
1.60 +template <class _Tp, class _NcIt>
1.61 +struct _Vector_nonconst_traits {
1.62 + typedef _Nonconst_traits<_Tp> _BaseT;
1.63 + typedef _Tp value_type;
1.64 + typedef _Tp& reference;
1.65 + typedef _Tp* pointer;
1.66 + typedef _Vector_const_traits<_Tp, _NcIt> _ConstTraits;
1.67 + typedef _Vector_nonconst_traits<_Tp, _NcIt> _NonConstTraits;
1.68 +};
1.69 +
1.70 +template <class _Tp, class _NcIt>
1.71 +struct _Vector_const_traits {
1.72 + typedef _Const_traits<_Tp> _BaseT;
1.73 + typedef _Tp value_type;
1.74 + typedef const _Tp& reference;
1.75 + typedef const _Tp* pointer;
1.76 + typedef _Vector_const_traits<_Tp, _NcIt> _ConstTraits;
1.77 + typedef _Vector_nonconst_traits<_Tp, _NcIt> _NonConstTraits;
1.78 +};
1.79 +
1.80 +_STLP_TEMPLATE_NULL
1.81 +struct _Vector_nonconst_traits<bool, _Bit_iterator> {
1.82 + typedef _Bit_iterator::value_type value_type;
1.83 + typedef _Bit_iterator::reference reference;
1.84 + typedef _Bit_iterator::pointer pointer;
1.85 + typedef _Vector_const_traits<bool, _Bit_iterator> _ConstTraits;
1.86 + typedef _Vector_nonconst_traits<bool, _Bit_iterator> _NonConstTraits;
1.87 +};
1.88 +
1.89 +_STLP_TEMPLATE_NULL
1.90 +struct _Vector_const_traits<bool, _Bit_iterator> {
1.91 + typedef _Bit_const_iterator::value_type value_type;
1.92 + typedef _Bit_const_iterator::reference reference;
1.93 + typedef _Bit_const_iterator::pointer pointer;
1.94 + typedef _Vector_const_traits<bool, _Bit_iterator> _ConstTraits;
1.95 + typedef _Vector_nonconst_traits<bool, _Bit_iterator> _NonConstTraits;
1.96 +};
1.97 +
1.98 +_STLP_MOVE_TO_STD_NAMESPACE
1.99 +
1.100 +template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
1.101 +class vector :
1.102 +#if !defined (__DMC__)
1.103 + private
1.104 +#endif
1.105 + _STLP_PRIV __construct_checker< _STLP_NON_DBG_VECTOR >
1.106 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
1.107 + , public __stlport_class<vector<_Tp, _Alloc> >
1.108 +#endif
1.109 +{
1.110 +private:
1.111 + typedef _STLP_NON_DBG_VECTOR _Base;
1.112 + typedef vector<_Tp, _Alloc> _Self;
1.113 + typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_VECTOR > _ConstructCheck;
1.114 + _Base _M_non_dbg_impl;
1.115 + _STLP_PRIV __owned_list _M_iter_list;
1.116 +
1.117 +public:
1.118 + __IMPORT_CONTAINER_TYPEDEFS(_Base)
1.119 +
1.120 + typedef _STLP_PRIV _DBG_iter<_Base,
1.121 + _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_nonconst_traits<value_type, typename _Base::iterator> > > iterator;
1.122 +
1.123 + typedef _STLP_PRIV _DBG_iter<_Base,
1.124 + _STLP_PRIV _DbgTraits<_STLP_PRIV _Vector_const_traits<value_type, typename _Base::iterator> > > const_iterator;
1.125 +
1.126 +private:
1.127 + void _Invalidate_all()
1.128 + { _M_iter_list._Invalidate_all(); }
1.129 + void _Invalidate_iterator(const iterator& __it)
1.130 + { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
1.131 + void _Invalidate_iterators(const iterator& __first, const iterator& __last)
1.132 + { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
1.133 +
1.134 + void _Check_Overflow(size_type __nb) {
1.135 + if (size() + __nb > capacity())
1.136 + _Invalidate_all();
1.137 + }
1.138 + void _Compare_Capacity (size_type __old_capacity) {
1.139 + if (capacity() > __old_capacity) {
1.140 + _Invalidate_all();
1.141 + }
1.142 + }
1.143 +
1.144 +public:
1.145 + _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
1.146 +
1.147 + allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
1.148 +
1.149 + iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
1.150 + const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
1.151 + iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
1.152 + const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
1.153 +
1.154 + reverse_iterator rbegin() { return reverse_iterator(end()); }
1.155 + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
1.156 + reverse_iterator rend() { return reverse_iterator(begin()); }
1.157 + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
1.158 +
1.159 + size_type size() const { return _M_non_dbg_impl.size(); }
1.160 + size_type max_size() const { return _M_non_dbg_impl.max_size(); }
1.161 + size_type capacity() const { return _M_non_dbg_impl.capacity(); }
1.162 + bool empty() const { return _M_non_dbg_impl.empty(); }
1.163 +
1.164 + reference operator[](size_type __n) {
1.165 + _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
1.166 + return _M_non_dbg_impl[__n];
1.167 + }
1.168 +
1.169 + const_reference operator[](size_type __n) const {
1.170 + _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
1.171 + return _M_non_dbg_impl[__n];
1.172 + }
1.173 +
1.174 + reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
1.175 + const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
1.176 +
1.177 + explicit vector(const allocator_type& __a = allocator_type())
1.178 + : _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
1.179 +
1.180 +#if !defined(_STLP_DONT_SUP_DFLT_PARAM)
1.181 + explicit vector(size_type __n, const _Tp& __x = _Tp(),
1.182 +#else
1.183 + vector(size_type __n, const _Tp& __x,
1.184 +#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
1.185 + const allocator_type& __a = allocator_type())
1.186 + : _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
1.187 +
1.188 +#if defined(_STLP_DONT_SUP_DFLT_PARAM)
1.189 + explicit vector(size_type __n)
1.190 + : _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
1.191 +#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
1.192 +
1.193 + vector(const _Self& __x)
1.194 + : _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl), _M_iter_list(&_M_non_dbg_impl) {}
1.195 +
1.196 + vector(__move_source<_Self> src)
1.197 + : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
1.198 + _M_iter_list(&_M_non_dbg_impl) {
1.199 +#if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
1.200 + src.get()._M_iter_list._Invalidate_all();
1.201 +#else
1.202 + src.get()._M_iter_list._Set_owner(_M_iter_list);
1.203 +#endif
1.204 + }
1.205 +
1.206 +#if defined (_STLP_MEMBER_TEMPLATES)
1.207 + template <class _InputIterator>
1.208 + vector(_InputIterator __first, _InputIterator __last,
1.209 + const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
1.210 + : _ConstructCheck(__first, __last),
1.211 + _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
1.212 + _M_iter_list(&_M_non_dbg_impl) {}
1.213 +
1.214 +# if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
1.215 + template <class _InputIterator>
1.216 + vector(_InputIterator __first, _InputIterator __last)
1.217 + : _ConstructCheck(__first, __last),
1.218 + _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
1.219 + _M_iter_list(&_M_non_dbg_impl) {}
1.220 +# endif
1.221 +#else
1.222 + vector(const _Tp* __first, const _Tp* __last,
1.223 + const allocator_type& __a = allocator_type())
1.224 + : _ConstructCheck(__first, __last), _M_non_dbg_impl(__first, __last, __a),
1.225 + _M_iter_list(&_M_non_dbg_impl) {}
1.226 +
1.227 + // mysterious VC++ bug ?
1.228 + vector(const_iterator __first, const_iterator __last ,
1.229 + const allocator_type& __a = allocator_type())
1.230 + : _ConstructCheck(__first, __last),
1.231 + _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
1.232 + _M_iter_list(&_M_non_dbg_impl) {}
1.233 +#endif /* _STLP_MEMBER_TEMPLATES */
1.234 +
1.235 + _Self& operator=(const _Self& __x) {
1.236 + if (this != &__x) {
1.237 + _Invalidate_all();
1.238 + _M_non_dbg_impl = __x._M_non_dbg_impl;
1.239 + }
1.240 + return *this;
1.241 + }
1.242 +
1.243 + void reserve(size_type __n) {
1.244 + if (capacity() < __n)
1.245 + _Invalidate_all();
1.246 + _M_non_dbg_impl.reserve(__n);
1.247 + }
1.248 +
1.249 + reference front() {
1.250 + _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
1.251 + return *begin();
1.252 + }
1.253 + const_reference front() const {
1.254 + _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
1.255 + return *begin();
1.256 + }
1.257 + reference back() {
1.258 + _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
1.259 + return *(--end());
1.260 + }
1.261 + const_reference back() const {
1.262 + _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
1.263 + return *(--end());
1.264 + }
1.265 +
1.266 + void swap(_Self& __x) {
1.267 + _M_iter_list._Swap_owners(__x._M_iter_list);
1.268 + _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
1.269 + }
1.270 +
1.271 +#if !defined(_STLP_DONT_SUP_DFLT_PARAM)
1.272 + iterator insert(iterator __pos, const _Tp& __x = _Tp()) {
1.273 +#else
1.274 + iterator insert(iterator __pos, const _Tp& __x) {
1.275 +#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
1.276 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
1.277 + _Check_Overflow(1);
1.278 + return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
1.279 + }
1.280 +
1.281 +#if defined(_STLP_DONT_SUP_DFLT_PARAM)
1.282 + iterator insert(iterator __pos)
1.283 + { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
1.284 +#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
1.285 +
1.286 +#if defined (_STLP_MEMBER_TEMPLATES)
1.287 + // Check whether it's an integral type. If so, it's not an iterator.
1.288 + template <class _InputIterator>
1.289 + void insert(iterator __pos,
1.290 + _InputIterator __first, _InputIterator __last) {
1.291 + typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
1.292 + typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
1.293 + typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
1.294 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
1.295 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
1.296 + //Sequence requirements 23.1.1 Table 67:
1.297 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
1.298 + size_type __old_capacity = capacity();
1.299 + _M_non_dbg_impl.insert(__pos._M_iterator,
1.300 + _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
1.301 + _Compare_Capacity(__old_capacity);
1.302 + }
1.303 +#else
1.304 + void insert (iterator __pos,
1.305 + const value_type *__first, const value_type *__last) {
1.306 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
1.307 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
1.308 + size_type __old_capacity = capacity();
1.309 + _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
1.310 + _Compare_Capacity(__old_capacity);
1.311 + }
1.312 +
1.313 + void insert(iterator __pos,
1.314 + const_iterator __first, const_iterator __last) {
1.315 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
1.316 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
1.317 + //Sequence requirements 23.1.1 Table 67:
1.318 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
1.319 + size_type __old_capacity = capacity();
1.320 + _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
1.321 + _Compare_Capacity(__old_capacity);
1.322 +}
1.323 +#endif
1.324 +
1.325 + void insert (iterator __pos, size_type __n, const _Tp& __x){
1.326 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
1.327 + _Check_Overflow(__n);
1.328 + _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
1.329 + }
1.330 +
1.331 + void pop_back() {
1.332 + _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
1.333 + _Invalidate_iterator(end());
1.334 + _M_non_dbg_impl.pop_back();
1.335 + }
1.336 + iterator erase(iterator __pos) {
1.337 + _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
1.338 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
1.339 + _Invalidate_iterators(__pos, end());
1.340 + return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
1.341 + }
1.342 + iterator erase(iterator __first, iterator __last) {
1.343 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
1.344 + _Invalidate_iterators(__first, end());
1.345 + return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
1.346 + }
1.347 +
1.348 +#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
1.349 + void resize(size_type __new_size, const _Tp& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp)) {
1.350 +#else
1.351 + void resize(size_type __new_size, const _Tp& __x) {
1.352 +#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
1.353 + if (__new_size > capacity()) {
1.354 + _Invalidate_all();
1.355 + }
1.356 + else if (__new_size < size()) {
1.357 + _Invalidate_iterators(begin() + __new_size, end());
1.358 + }
1.359 + _M_non_dbg_impl.resize(__new_size, __x);
1.360 + }
1.361 +
1.362 +#if defined (_STLP_DONT_SUP_DFLT_PARAM)
1.363 + void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
1.364 +#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
1.365 +
1.366 +#if defined (_STLP_MEMBER_TEMPLATES)
1.367 +private:
1.368 + template <class _Integer>
1.369 + void _M_assign_dispatch(_Integer __n, _Integer __val,
1.370 + const __true_type& /*_IsIntegral*/) {
1.371 + _M_check_assign(__n);
1.372 + _M_non_dbg_impl.assign(__n, __val);
1.373 + }
1.374 +
1.375 + template <class _InputIter>
1.376 + void _M_assign_dispatch(_InputIter __first, _InputIter __last,
1.377 + const __false_type& /*_IsIntegral*/) {
1.378 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
1.379 + size_type __len = distance(__first, __last);
1.380 + _M_check_assign(__len);
1.381 + _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
1.382 + }
1.383 +
1.384 +public:
1.385 + template <class _InputIterator>
1.386 + void assign(_InputIterator __first, _InputIterator __last) {
1.387 + typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
1.388 + _M_assign_dispatch(__first, __last, _Integral());
1.389 + }
1.390 +#else
1.391 +private:
1.392 + void _M_assign(const value_type *__first, const value_type *__last) {
1.393 + size_type __len = distance(__first, __last);
1.394 + _M_check_assign(__len);
1.395 + _M_non_dbg_impl.assign(__first, __last);
1.396 + }
1.397 +public:
1.398 + void assign(const value_type *__first, const value_type *__last) {
1.399 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first,__last))
1.400 + _M_assign(__first, __last);
1.401 + }
1.402 +
1.403 + void assign(const_iterator __first, const_iterator __last) {
1.404 + _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
1.405 + _M_assign(__first._M_iterator, __last._M_iterator);
1.406 + }
1.407 +#endif
1.408 +
1.409 +private:
1.410 + void _M_check_assign(size_type __n) {
1.411 + if (__n > capacity()) {
1.412 + _Invalidate_all();
1.413 + }
1.414 + else if (__n < size()) {
1.415 + _Invalidate_iterators(begin() + __n, end());
1.416 + }
1.417 + }
1.418 +
1.419 +public:
1.420 + void assign(size_type __n, const _Tp& __val) {
1.421 + _M_check_assign(__n);
1.422 + _M_non_dbg_impl.assign(__n, __val);
1.423 + }
1.424 +
1.425 + void clear() {
1.426 + _Invalidate_all();
1.427 + _M_non_dbg_impl.clear();
1.428 + }
1.429 + void push_back(const _Tp& __x) {
1.430 + _Check_Overflow(1);
1.431 + _M_non_dbg_impl.push_back(__x);
1.432 + }
1.433 +};
1.434 +
1.435 +_STLP_END_NAMESPACE
1.436 +
1.437 +#undef _STLP_NON_DBG_VECTOR
1.438 +
1.439 +#endif /* _STLP_DBG_VECTOR_H */
1.440 +
1.441 +// Local Variables:
1.442 +// mode:C++
1.443 +// End: