4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_DBG_DEQUE_H
31 #define _STLP_INTERNAL_DBG_DEQUE_H
33 #include <stl/debug/_iterator.h>
35 # if !defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM) && !defined (_STLP_NO_DEFAULT_NON_TYPE_PARAM)
37 # define _DBG_deque deque
40 # define _DEQUE_WRAPPER _DBG_deque<_Tp,_Alloc>
42 # define _STLP_DEQUE_SUPER __WORKAROUND_DBG_RENAME(deque) <_Tp,_Alloc>
46 # ifdef _STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS
47 template <class _Tp, class _Alloc>
48 inline _Tp* value_type(const _DBG_iter_base< _STLP_DEQUE_SUPER >&) {
51 template <class _Tp, class _Alloc>
52 inline random_access_iterator_tag iterator_category(const _DBG_iter_base< _STLP_DEQUE_SUPER >&) {
53 return random_access_iterator_tag();
57 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
58 class _DBG_deque : public _STLP_DEQUE_SUPER {
60 typedef _DBG_deque<_Tp,_Alloc> _Self;
61 typedef _STLP_DEQUE_SUPER _Base;
63 public: // Basic types
65 __IMPORT_CONTAINER_TYPEDEFS(_Base)
68 typedef _DBG_iter< _STLP_DEQUE_SUPER, _Nonconst_traits<value_type> > iterator;
69 typedef _DBG_iter< _STLP_DEQUE_SUPER, _Const_traits<value_type> > const_iterator;
71 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
74 __owned_list _M_iter_list;
75 void _Invalidate_iterator(const iterator& __it) {
76 __invalidate_iterator(&_M_iter_list,__it);
78 void _Invalidate_all() {
79 _M_iter_list._Invalidate_all();
82 public: // Basic accessors
83 iterator begin() { return iterator(&_M_iter_list, this->_M_start); }
84 iterator end() { return iterator(&_M_iter_list, this->_M_finish); }
85 const_iterator begin() const {
86 return const_iterator(&_M_iter_list, this->_M_start);
88 const_iterator end() const {
89 return const_iterator(&_M_iter_list, this->_M_finish);
92 reverse_iterator rbegin() { return reverse_iterator(end()); }
93 reverse_iterator rend() { return reverse_iterator(begin()); }
94 const_reverse_iterator rbegin() const
95 { return const_reverse_iterator(end()); }
96 const_reverse_iterator rend() const
97 { return const_reverse_iterator(begin()); }
99 reference operator[](size_type __n)
100 { return begin()[difference_type(__n)]; }
101 const_reference operator[](size_type __n) const
102 { return begin()[difference_type(__n)]; }
104 reference front() { return *begin(); }
106 iterator __tmp = end();
110 const_reference front() const { return *begin(); }
111 const_reference back() const {
112 const_iterator __tmp = end();
117 public: // Constructor, destructor.
119 const _Base* _Get_base() const { return (const _Base*)this; }
121 explicit _DBG_deque(const allocator_type& __a = allocator_type()) :
122 _STLP_DEQUE_SUPER(__a), _M_iter_list(_Get_base()) {}
123 _DBG_deque(const _Self& __x) : _STLP_DEQUE_SUPER(__x), _M_iter_list(_Get_base()) {}
124 _DBG_deque(size_type __n, const value_type& __value,
125 const allocator_type& __a = allocator_type()) :
126 _STLP_DEQUE_SUPER(__n, __value, __a), _M_iter_list(_Get_base()) {}
127 explicit _DBG_deque(size_type __n) : _STLP_DEQUE_SUPER(__n), _M_iter_list(_Get_base()) {}
129 #ifdef _STLP_MEMBER_TEMPLATES
130 template <class _InputIterator>
131 _DBG_deque(_InputIterator __first, _InputIterator __last,
132 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) :
133 _STLP_DEQUE_SUPER(__first, __last, __a) , _M_iter_list(_Get_base()) {}
134 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
135 template <class _InputIterator>
136 _DBG_deque(_InputIterator __first, _InputIterator __last):
137 _STLP_DEQUE_SUPER(__first, __last, allocator_type()) , _M_iter_list(_Get_base()) {}
139 #else /* _STLP_MEMBER_TEMPLATES */
140 _DBG_deque(const value_type* __first, const value_type* __last,
141 const allocator_type& __a = allocator_type())
142 : _STLP_DEQUE_SUPER(__first, __last, __a), _M_iter_list(_Get_base()) {}
144 _DBG_deque(const_iterator __first, const_iterator __last,
145 const allocator_type& __a = allocator_type())
146 : _STLP_DEQUE_SUPER(__first._M_iterator, __last._M_iterator, __a),
147 _M_iter_list(_Get_base()) {}
148 #endif /* _STLP_MEMBER_TEMPLATES */
150 _Self& operator= (const _Self& __x) {
152 (_Base&)*this = (const _Base&)__x;
156 void swap(_Self& __x) {
157 _M_iter_list._Swap_owners(__x._M_iter_list);
162 void assign(size_type __n, const _Tp& __val) {
163 _Base::assign(__n, __val);
166 #ifdef _STLP_MEMBER_TEMPLATES
168 template <class _InputIterator>
169 void assign(_InputIterator __first, _InputIterator __last) {
170 _Base::assign(__first, __last);
172 #endif /* _STLP_MEMBER_TEMPLATES */
174 public: // push_* and pop_*
176 void push_back(const value_type& __t) {
178 _Base::push_back(__t);
186 void push_front(const value_type& __t) {
188 _Base::push_front(__t);
198 _Invalidate_iterator(end());
203 _Invalidate_iterator(begin());
209 iterator insert(iterator __position, const value_type& __x) {
210 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
211 // fbp : invalidation !
212 return iterator(&_M_iter_list, _Base::insert(__position._M_iterator, __x));
215 iterator insert(iterator __position) {
216 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
217 // fbp : invalidation !
218 return iterator(&_M_iter_list, _Base::insert(__position._M_iterator));
221 void insert(iterator __position, size_type __n, const value_type& __x) {
222 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
223 // fbp : invalidation !
224 _Base::insert(__position._M_iterator, __n, __x);
227 #ifdef _STLP_MEMBER_TEMPLATES
228 template <class _InputIterator>
229 void insert(iterator __position, _InputIterator __first, _InputIterator __last) {
230 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
231 // fbp : invalidation !
232 _Base::insert(__position._M_iterator, __first, __last);
234 #else /* _STLP_MEMBER_TEMPLATES */
235 void insert(iterator __position,
236 const value_type* __first, const value_type* __last) {
237 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
238 _Base::insert(__position._M_iterator, __first, __last);
240 void insert(iterator __position,
241 const_iterator __first, const_iterator __last) {
242 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __position))
243 _Base::insert(__position._M_iterator, __first._M_iterator, __last._M_iterator);
245 #endif /* _STLP_MEMBER_TEMPLATES */
248 iterator erase(iterator __pos) {
249 _STLP_DEBUG_CHECK(__check_if_owner(&_M_iter_list, __pos) && (__pos != end()))
250 return iterator (&_M_iter_list, _Base::erase(__pos._M_iterator));
253 iterator erase(iterator __first, iterator __last) {
254 _STLP_DEBUG_CHECK(__first >= begin() && __last <= end())
255 return iterator (&_M_iter_list, _Base::erase(__first._M_iterator, __last._M_iterator));
264 #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
265 #define _STLP_TEMPLATE_CONTAINER _DBG_deque<_Tp, _Alloc>
266 #define _STLP_TEMPLATE_CONTAINER_BASE _STLP_DEQUE_SUPER
267 #include <stl/debug/_relops_cont.h>
268 #undef _STLP_TEMPLATE_CONTAINER_BASE
269 #undef _STLP_TEMPLATE_CONTAINER
270 #undef _STLP_TEMPLATE_HEADER
275 # undef _STLP_DEQUE_SUPER
277 #endif /* _STLP_INTERNAL_DEQUE_H */