1 /*
2  * Copyright (c) 1997-1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  */
17 
18 #ifndef _STLP_DBG_STRING_H
19 #define _STLP_DBG_STRING_H
20 
21 #ifndef _STLP_DBG_ITERATOR_H
22 #  include <stl/debug/_iterator.h>
23 #endif
24 
25 _STLP_BEGIN_NAMESPACE
26 
27 #define _STLP_NON_DBG_STRING_NAME _STLP_NON_DBG_NAME(str)
28 #define _STLP_NON_DBG_STRING _STLP_PRIV _STLP_NON_DBG_STRING_NAME <_CharT, _Traits, _Alloc>
29 
30 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
31 template <class _CharT,class _Traits, class _Alloc>
32 inline _CharT*
value_type(const _STLP_PRIV _DBG_iter_base<_STLP_NON_DBG_STRING> &)33 value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_STRING >&)
34 { return (_CharT*)0; }
35 template <class _CharT, class _Traits, class _Alloc>
36 inline random_access_iterator_tag
iterator_category(const _STLP_PRIV _DBG_iter_base<_STLP_NON_DBG_STRING> &)37 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_STRING >&)
38 { return random_access_iterator_tag(); }
39 #endif
40 
41 template <class _CharT, class _Traits, class _Alloc>
42 class basic_string :
43 #if !defined (__DMC__)
44                      private
45 #else
46                      public
47 #endif
48                              _STLP_PRIV __construct_checker<_STLP_NON_DBG_STRING >
49 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (basic_string)
50                    , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
51 #endif
52 {
53 protected:
54   typedef _STLP_NON_DBG_STRING _Base;
55   typedef basic_string<_CharT, _Traits, _Alloc> _Self;
56   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_STRING > _ConstructCheck;
57   typedef typename _IsPOD<_CharT>::_Type _Char_Is_POD;
58 
59 public:
60   __IMPORT_CONTAINER_TYPEDEFS(_Base)
61   typedef typename _Base::traits_type traits_type;
62   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Nonconst_traits<value_type> > > iterator;
63   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Const_traits<value_type> > > const_iterator;
64   _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
65 
66 public:                         // Constructor, destructor, assignment.
67   typedef typename _Base::_Reserve_t _Reserve_t;
68 
69 private:
70   _Base _M_non_dbg_impl;
71   _STLP_PRIV __owned_list _M_iter_list;
72 
_Invalidate_all()73   void _Invalidate_all()
74   { _M_iter_list._Invalidate_all(); }
_Compare_Capacity(size_type __old_capacity)75   void _Compare_Capacity (size_type __old_capacity) {
76     if (this->capacity() > __old_capacity) {
77       _Invalidate_all();
78     }
79   }
_Invalidate_iterator(const iterator & __it)80   void _Invalidate_iterator(const iterator& __it)
81   { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
_Invalidate_iterators(const iterator & __f,const iterator & __l)82   void _Invalidate_iterators(const iterator& __f, const iterator& __l)
83   { _STLP_PRIV __invalidate_range(&_M_iter_list, __f, __l); }
84 
85 public:
86 #include <stl/_string_npos.h>
87 
get_allocator()88   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
89 
90   explicit basic_string(const allocator_type& __a = allocator_type())
_M_non_dbg_impl(__a)91     : _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
92 
93   basic_string(_Reserve_t __r, size_t __n,
94                const allocator_type& __a = allocator_type())
_M_non_dbg_impl(__r,__n,__a)95     : _M_non_dbg_impl(__r, __n, __a), _M_iter_list(&_M_non_dbg_impl) {}
96 
basic_string(const _Self & __s)97   basic_string(const _Self& __s)
98     : _ConstructCheck(__s),
99       _M_non_dbg_impl(__s._M_non_dbg_impl), _M_iter_list(&_M_non_dbg_impl) {}
100 
101   basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
102                const allocator_type& __a = allocator_type())
103     : _M_non_dbg_impl(__s._M_non_dbg_impl, __pos, __n, __a),
104       _M_iter_list(&_M_non_dbg_impl) {}
105 
106   basic_string(const _CharT* __s, size_type __n,
107                const allocator_type& __a = allocator_type())
_ConstructCheck(__s)108     : _ConstructCheck(__s), _M_non_dbg_impl(__s, __n, __a),
109       _M_iter_list(&_M_non_dbg_impl) {}
110 
111   basic_string(const _CharT* __s,
112                const allocator_type& __a = allocator_type())
_ConstructCheck(__s)113     : _ConstructCheck(__s),
114       _M_non_dbg_impl(__s, __a), _M_iter_list(&_M_non_dbg_impl) {}
115 
116   basic_string(size_type __n, _CharT __c,
117                const allocator_type& __a = allocator_type())
_M_non_dbg_impl(__n,__c,__a)118     : _M_non_dbg_impl(__n, __c, __a), _M_iter_list(&_M_non_dbg_impl) {}
119 
120 #if !defined (_STLP_NO_MOVE_SEMANTIC)
basic_string(__move_source<_Self> src)121   basic_string(__move_source<_Self> src)
122     : _M_non_dbg_impl(__move_source<_Base >(src.get()._M_non_dbg_impl)),
123       _M_iter_list(&_M_non_dbg_impl) {
124 #  if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
125     src.get()._M_iter_list._Invalidate_all();
126 #  else
127     src.get()._M_iter_list._Set_owner(_M_iter_list);
128 #  endif
129   }
130 #endif
131 
132 #if !defined (_STLP_MEMBER_TEMPLATES)
133   basic_string(const _CharT* __f, const _CharT* __l,
134                const allocator_type& __a = allocator_type())
_ConstructCheck(__f,__l)135     : _ConstructCheck(__f, __l),
136       _M_non_dbg_impl(__f, __l, __a), _M_iter_list(&_M_non_dbg_impl) {
137   }
138   basic_string(const_iterator __f, const_iterator __l,
139                const allocator_type & __a = allocator_type())
_ConstructCheck(__f,__l)140     : _ConstructCheck(__f, __l),
141       _M_non_dbg_impl(__f._M_iterator, __l._M_iterator, __a), _M_iter_list(&_M_non_dbg_impl) {
142   }
143 #else
144   template <class _InputIterator>
basic_string(_InputIterator __f,_InputIterator __l,const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)145   basic_string(_InputIterator __f, _InputIterator __l,
146                const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
147     : _ConstructCheck(__f, __l),
148       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l), __a),
149       _M_iter_list(&_M_non_dbg_impl) {}
150 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
151   template <class _InputIterator>
basic_string(_InputIterator __f,_InputIterator __l)152   basic_string(_InputIterator __f, _InputIterator __l)
153     : _ConstructCheck(__f, __l),
154       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l)),
155       _M_iter_list(&_M_non_dbg_impl) {}
156 #  endif
157 #endif
158 
159 private:
160   // constructor from non-debug version for substr
basic_string(const _Base & __x)161   basic_string (const _Base& __x)
162     : _M_non_dbg_impl(__x), _M_iter_list(&_M_non_dbg_impl) {}
163 
164 public:
165   _Self& operator=(const _Self& __s) {
166     if (this != &__s) {
167       assign(__s);
168     }
169     return *this;
170   }
171 
172   _Self& operator=(const _CharT* __s) {
173     _STLP_FIX_LITERAL_BUG(__s)
174     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
175     return assign(__s);
176   }
177 
178   _Self& operator=(_CharT __c) {
179     return assign(1, __c);
180   }
181 
182   // Iterators.
begin()183   iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
begin()184   const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
end()185   iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
end()186   const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
187 
rbegin()188   reverse_iterator rbegin()             { return reverse_iterator(end()); }
rbegin()189   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
rend()190   reverse_iterator rend()               { return reverse_iterator(begin()); }
rend()191   const_reverse_iterator rend() const   { return const_reverse_iterator(begin()); }
192 
193   // Size, capacity, etc.
size()194   size_type size() const { return _M_non_dbg_impl.size(); }
length()195   size_type length() const { return _M_non_dbg_impl.length(); }
max_size()196   size_t max_size() const { return _M_non_dbg_impl.max_size(); }
197 
resize(size_type __n,_CharT __c)198   void resize(size_type __n, _CharT __c) {
199     if (__n > capacity())
200       _Invalidate_all();
201     else if (__n < size())
202       _Invalidate_iterators(begin() + __n, end());
203     _M_non_dbg_impl.resize(__n, __c);
204   }
resize(size_type __n)205   void resize(size_type __n) { resize(__n, _STLP_DEFAULT_CONSTRUCTED(_CharT)); }
capacity()206   size_type capacity() const { return _M_non_dbg_impl.capacity(); }
207 
208   void reserve(size_type __s = 0) {
209     if (__s > capacity()) _Invalidate_all();
210     _M_non_dbg_impl.reserve(__s);
211   }
212 
clear()213   void clear() {
214     _Invalidate_all();
215     _M_non_dbg_impl.clear();
216   }
217 
empty()218   bool empty() const { return _M_non_dbg_impl.empty(); }
219 
220   const_reference operator[](size_type __n) const {
221     _STLP_VERBOSE_ASSERT(__n <= this->size(), _StlMsg_OUT_OF_BOUNDS);
222     return _M_non_dbg_impl[__n];
223   }
224 
225   reference operator[](size_type __n) {
226     _STLP_VERBOSE_ASSERT(__n < this->size(), _StlMsg_OUT_OF_BOUNDS)
227     return _M_non_dbg_impl[__n];
228   }
229 
at(size_type __n)230   const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
at(size_type __n)231   reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
232 
233   // Append, operator+=, push_back.
234   _Self& operator+=(const _Self& __s) { return append(__s); }
235   _Self& operator+=(const _CharT* __s) {
236     _STLP_FIX_LITERAL_BUG(__s)
237     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
238     return append(__s);
239   }
240   _Self& operator+=(_CharT __c) { return append(1, __c); }
241 
242 #if defined (_STLP_MEMBER_TEMPLATES)
243   template <class _InputIter>
append(_InputIter __first,_InputIter __last)244   _Self& append(_InputIter __first, _InputIter __last) {
245     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
246     size_type __old_capacity = capacity();
247     _M_non_dbg_impl.append(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
248     _Compare_Capacity(__old_capacity);
249     return *this;
250   }
251 #endif
252 
253 #if !defined (_STLP_MEMBER_TEMPLATES) || \
254     !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
append(const _CharT * __f,const _CharT * __l)255   _Self& append(const _CharT* __f, const _CharT* __l) {
256     _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
257     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
258     size_type __old_capacity = capacity();
259     _M_non_dbg_impl.append(__f, __l);
260     _Compare_Capacity(__old_capacity);
261     return *this;
262   }
263 
append(const_iterator __f,const_iterator __l)264   _Self& append(const_iterator __f, const_iterator __l) {
265     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
266     size_type __old_capacity = capacity();
267     _M_non_dbg_impl.append(__f._M_iterator, __l._M_iterator);
268     _Compare_Capacity(__old_capacity);
269     return *this;
270   }
271 #endif
272 
append(const _Self & __s)273   _Self& append(const _Self& __s) {
274     size_type __old_capacity = capacity();
275     _M_non_dbg_impl.append(__s._M_non_dbg_impl);
276     _Compare_Capacity(__old_capacity);
277     return *this;
278   }
279 
append(const _Self & __s,size_type __pos,size_type __n)280   _Self& append(const _Self& __s, size_type __pos, size_type __n) {
281     size_type __old_capacity = capacity();
282     _M_non_dbg_impl.append(__s._M_non_dbg_impl, __pos, __n);
283     _Compare_Capacity(__old_capacity);
284     return *this;
285   }
286 
append(const _CharT * __s,size_type __n)287   _Self& append(const _CharT* __s, size_type __n) {
288     _STLP_FIX_LITERAL_BUG(__s)
289     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
290     size_type __old_capacity = capacity();
291     _M_non_dbg_impl.append(__s, __n);
292     _Compare_Capacity(__old_capacity);
293     return *this;
294   }
295 
append(const _CharT * __s)296   _Self& append(const _CharT* __s) {
297     _STLP_FIX_LITERAL_BUG(__s)
298     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
299     size_type __old_capacity = capacity();
300     _M_non_dbg_impl.append(__s);
301     _Compare_Capacity(__old_capacity);
302     return *this;
303   }
304 
append(size_type __n,_CharT __c)305   _Self& append(size_type __n, _CharT __c) {
306     size_type __old_capacity = this->capacity();
307     _M_non_dbg_impl.append(__n, __c);
308     _Compare_Capacity(__old_capacity);
309     return *this;
310   }
311 
push_back(_CharT __c)312   void push_back(_CharT __c) {
313     size_type __old_capacity = this->capacity();
314     _M_non_dbg_impl.push_back(__c);
315     _Compare_Capacity(__old_capacity);
316   }
317 
pop_back()318   void pop_back() {
319     _Invalidate_iterator(this->end());
320     _M_non_dbg_impl.pop_back();
321   }
322 
323   // Assign
assign(const _Self & __s)324   _Self& assign(const _Self& __s) {
325     _Invalidate_all();
326     _M_non_dbg_impl.assign(__s._M_non_dbg_impl);
327     return *this;
328   }
329 
assign(const _Self & __s,size_type __pos,size_type __n)330   _Self& assign(const _Self& __s, size_type __pos, size_type __n) {
331     if (__pos < __s.size()) {
332       _Invalidate_all();
333     }
334     _M_non_dbg_impl.assign(__s._M_non_dbg_impl, __pos, __n);
335     return *this;
336   }
337 
assign(const _CharT * __s,size_type __n)338   _Self& assign(const _CharT* __s, size_type __n) {
339     _STLP_FIX_LITERAL_BUG(__s)
340     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
341     _Invalidate_all();
342     _M_non_dbg_impl.assign(__s, __s + __n);
343     return *this;
344   }
345 
assign(const _CharT * __s)346   _Self& assign(const _CharT* __s) {
347     _STLP_FIX_LITERAL_BUG(__s)
348     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
349     _Invalidate_all();
350     _M_non_dbg_impl.assign(__s);
351     return *this;
352   }
353 
assign(size_type __n,_CharT __c)354   _Self& assign(size_type __n, _CharT __c) {
355     _Invalidate_all();
356     _M_non_dbg_impl.assign(__n, __c);
357     return *this;
358   }
359 
360 #if defined(_STLP_MEMBER_TEMPLATES)
361   template <class _InputIter>
assign(_InputIter __first,_InputIter __last)362   inline _Self& assign(_InputIter __first, _InputIter __last) {
363     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
364     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
365     _Invalidate_all();
366     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
367     return *this;
368   }
369 #endif
370 
371 #if !defined (_STLP_MEMBER_TEMPLATES) || \
372     !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
assign(const _CharT * __f,const _CharT * __l)373   _Self& assign(const _CharT* __f, const _CharT* __l) {
374     _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
375     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
376     _Invalidate_all();
377     _M_non_dbg_impl.assign(__f, __l);
378     return *this;
379   }
assign(const_iterator __f,const_iterator __l)380   _Self& assign(const_iterator __f, const_iterator __l) {
381     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
382     _Invalidate_all();
383     _M_non_dbg_impl.assign(__f._M_iterator, __l._M_iterator);
384     return *this;
385   }
386 #endif
387 
388   // Insert
insert(size_type __pos,const _Self & __s)389   _Self& insert(size_type __pos, const _Self& __s) {
390     size_type __old_capacity = capacity();
391     _M_non_dbg_impl.insert(__pos, __s._M_non_dbg_impl);
392     _Compare_Capacity(__old_capacity);
393     return *this;
394   }
395 
insert(size_type __pos,const _Self & __s,size_type __beg,size_type __n)396   _Self& insert(size_type __pos, const _Self& __s,
397                 size_type __beg, size_type __n) {
398     size_type __old_capacity = capacity();
399     _M_non_dbg_impl.insert(__pos, __s._M_non_dbg_impl, __beg, __n);
400     _Compare_Capacity(__old_capacity);
401     return *this;
402   }
403 
insert(size_type __pos,const _CharT * __s,size_type __n)404   _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
405     _STLP_FIX_LITERAL_BUG(__s)
406     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
407     size_type __old_capacity = capacity();
408     _M_non_dbg_impl.insert(__pos, __s, __n);
409     _Compare_Capacity(__old_capacity);
410     return *this;
411   }
412 
insert(size_type __pos,const _CharT * __s)413   _Self& insert(size_type __pos, const _CharT* __s) {
414     _STLP_FIX_LITERAL_BUG(__s)
415     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
416     return insert(__pos, __s, _Traits::length(__s));
417   }
418 
insert(size_type __pos,size_type __n,_CharT __c)419   _Self& insert(size_type __pos, size_type __n, _CharT __c) {
420     size_type __old_capacity = capacity();
421     _M_non_dbg_impl.insert(__pos, __n, __c);
422     _Compare_Capacity(__old_capacity);
423     return *this;
424   }
425 
insert(iterator __p,_CharT __c)426   iterator insert(iterator __p, _CharT __c) {
427     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__p))
428     size_type __old_capacity = capacity();
429     typename _Base::iterator __ret = _M_non_dbg_impl.insert(__p._M_iterator, __c);
430     _Compare_Capacity(__old_capacity);
431     return iterator(&_M_iter_list, __ret);
432   }
433 
insert(iterator __p,size_t __n,_CharT __c)434   void insert(iterator __p, size_t __n, _CharT __c) {
435     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__p))
436     size_type __old_capacity = capacity();
437     _M_non_dbg_impl.insert(__p._M_iterator, __n, __c);
438     _Compare_Capacity(__old_capacity);
439   }
440 
441 #if defined (_STLP_MEMBER_TEMPLATES)
442   template <class _InputIter>
insert(iterator __p,_InputIter __first,_InputIter __last)443   void insert(iterator __p, _InputIter __first, _InputIter __last) {
444     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__p))
445     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first,__last))
446 
447     size_type __old_capacity = this->capacity();
448     _M_non_dbg_impl.insert(__p._M_iterator,
449                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
450     _Compare_Capacity(__old_capacity);
451   }
452 #endif
453 
454 #if !defined (_STLP_MEMBER_TEMPLATES)
insert(iterator __p,const _CharT * __f,const _CharT * __l)455   void insert(iterator __p, const _CharT* __f, const _CharT* __l) {
456     _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
457     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__p))
458     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f,__l))
459     size_type __old_capacity = capacity();
460     _M_non_dbg_impl.insert(__p._M_iterator, __f, __l);
461     _Compare_Capacity(__old_capacity);
462   }
463 #endif
464 
465 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
466   // Those overloads are necessary to check self referencing correctly in non debug
467   // basic_string implementation
insert(iterator __p,const_iterator __f,const_iterator __l)468   void insert(iterator __p, const_iterator __f, const_iterator __l) {
469     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__p))
470     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f,__l))
471 #  if (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
472     _STLP_STD_DEBUG_CHECK(__check_if_not_owner(&_M_iter_list, __f))
473 #  endif
474     size_type __old_capacity = capacity();
475     _M_non_dbg_impl.insert(__p._M_iterator, __f._M_iterator, __l._M_iterator);
476     _Compare_Capacity(__old_capacity);
477   }
insert(iterator __p,iterator __f,iterator __l)478   void insert(iterator __p, iterator __f, iterator __l) {
479     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__p))
480     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f,__l))
481 #  if (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
482     _STLP_STD_DEBUG_CHECK(__check_if_not_owner(&_M_iter_list, __f))
483 #  endif
484     size_type __old_capacity = capacity();
485     _M_non_dbg_impl.insert(__p._M_iterator, __f._M_iterator, __l._M_iterator);
486     _Compare_Capacity(__old_capacity);
487   }
488 #endif
489 
490   // Erase.
491   _Self& erase(size_type __pos = 0, size_type __n = npos) {
492     if (__pos < size()) {
493       _Invalidate_iterators(begin() + __pos, end());
494     }
495     _M_non_dbg_impl.erase(__pos, __n);
496     return *this;
497   }
erase(iterator __pos)498   iterator erase(iterator __pos) {
499     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
500     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
501     _Invalidate_iterators(__pos, end());
502     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
503   }
erase(iterator __f,iterator __l)504   iterator erase(iterator __f, iterator __l) {
505     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l, begin(), end()))
506     _Invalidate_iterators(__f, end());
507     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__f._M_iterator, __l._M_iterator));
508   }
509 
510   // Substring.
511   _Self substr(size_type __pos = 0, size_type __n = npos) const
512   { return _M_non_dbg_impl.substr(__pos, __n); }
513 
514   // Replace.  (Conceptually equivalent to erase followed by insert.)
replace(size_type __pos,size_type __n,const _Self & __s)515   _Self& replace(size_type __pos, size_type __n, const _Self& __s) {
516     size_type __old_capacity = capacity();
517     _M_non_dbg_impl.replace(__pos, __n, __s._M_non_dbg_impl);
518     _Compare_Capacity(__old_capacity);
519     return *this;
520   }
521 
replace(size_type __pos1,size_type __n1,const _Self & __s,size_type __pos2,size_type __n2)522   _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,
523                  size_type __pos2, size_type __n2) {
524     size_type __old_capacity = capacity();
525     _M_non_dbg_impl.replace(__pos1, __n1, __s._M_non_dbg_impl, __pos2, __n2);
526     _Compare_Capacity(__old_capacity);
527     return *this;
528   }
529 
replace(size_type __pos,size_type __n1,const _CharT * __s,size_type __n2)530   _Self& replace(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) {
531     _STLP_FIX_LITERAL_BUG(__s)
532     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
533     size_type __old_capacity = capacity();
534     _M_non_dbg_impl.replace(__pos, __n1, __s, __n2);
535     _Compare_Capacity(__old_capacity);
536     return *this;
537   }
538 
replace(size_type __pos,size_type __n1,const _CharT * __s)539   _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {
540     _STLP_FIX_LITERAL_BUG(__s)
541     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
542     size_type __old_capacity = capacity();
543     _M_non_dbg_impl.replace(__pos, __n1, __s);
544     _Compare_Capacity(__old_capacity);
545     return *this;
546   }
547 
replace(size_type __pos,size_type __n1,size_type __n2,_CharT __c)548   _Self& replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) {
549     size_type __old_capacity = capacity();
550     _M_non_dbg_impl.replace(__pos, __n1, __n2, __c);
551     _Compare_Capacity(__old_capacity);
552     return *this;
553   }
554 
replace(iterator __f,iterator __l,const _Self & __s)555   _Self& replace(iterator __f, iterator __l, const _Self& __s) {
556     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l, begin(), end()))
557     size_type __old_capacity = capacity();
558     _M_non_dbg_impl.replace(__f._M_iterator, __l._M_iterator, __s._M_non_dbg_impl);
559     _Compare_Capacity(__old_capacity);
560     return *this;
561   }
562 
replace(iterator __f,iterator __l,const _CharT * __s,size_type __n)563   _Self& replace(iterator __f, iterator __l, const _CharT* __s, size_type __n) {
564     _STLP_FIX_LITERAL_BUG(__s)
565     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l, begin(), end()))
566     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
567     size_type __old_capacity = capacity();
568     _M_non_dbg_impl.replace(__f._M_iterator, __l._M_iterator, __s, __n);
569     _Compare_Capacity(__old_capacity);
570     return *this;
571   }
572 
replace(iterator __f,iterator __l,const _CharT * __s)573   _Self& replace(iterator __f, iterator __l, const _CharT* __s) {
574     _STLP_FIX_LITERAL_BUG(__s)
575     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l, begin(), end()))
576     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
577     size_type __old_capacity = capacity();
578     _M_non_dbg_impl.replace(__f._M_iterator, __l._M_iterator, __s);
579     _Compare_Capacity(__old_capacity);
580     return *this;
581   }
582 
replace(iterator __f,iterator __l,size_type __n,_CharT __c)583   _Self& replace(iterator __f, iterator __l, size_type __n, _CharT __c) {
584     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l, begin(), end()))
585     size_type __old_capacity = capacity();
586     _M_non_dbg_impl.replace(__f._M_iterator, __l._M_iterator, __n, __c);
587     _Compare_Capacity(__old_capacity);
588     return *this;
589   }
590 
591 #if defined (_STLP_MEMBER_TEMPLATES)
592   template <class _InputIter>
replace(iterator __first,iterator __last,_InputIter __f,_InputIter __l)593   _Self& replace(iterator __first, iterator __last,
594                  _InputIter __f, _InputIter __l) {
595     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
596     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
597 
598     size_type __old_capacity = capacity();
599     _M_non_dbg_impl.replace(__first._M_iterator, __last._M_iterator,
600                             _STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l));
601     _Compare_Capacity(__old_capacity);
602     return *this;
603   }
604 #endif
605 
606 #if !defined (_STLP_MEMBER_TEMPLATES)
replace(iterator __first,iterator __last,const _CharT * __f,const _CharT * __l)607   _Self& replace(iterator __first, iterator __last,
608                  const _CharT* __f, const _CharT* __l) {
609     _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
610     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
611     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
612     size_type __old_capacity = capacity();
613     _M_non_dbg_impl.replace(__first._M_iterator, __last._M_iterator, __f, __l);
614     _Compare_Capacity(__old_capacity);
615     return *this;
616   }
617 #endif
618 
619 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
replace(iterator __first,iterator __last,const_iterator __f,const_iterator __l)620   _Self& replace(iterator __first, iterator __last,
621                  const_iterator __f, const_iterator __l) {
622     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
623     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
624     size_type __old_capacity = capacity();
625     _M_non_dbg_impl.replace(__first._M_iterator, __last._M_iterator,
626                             __f._M_iterator, __l._M_iterator);
627     _Compare_Capacity(__old_capacity);
628     return *this;
629   }
replace(iterator __first,iterator __last,iterator __f,iterator __l)630   _Self& replace(iterator __first, iterator __last,
631                  iterator __f, iterator __l) {
632     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
633     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
634     size_type __old_capacity = capacity();
635     _M_non_dbg_impl.replace(__first._M_iterator, __last._M_iterator,
636                             __f._M_iterator, __l._M_iterator);
637     _Compare_Capacity(__old_capacity);
638     return *this;
639   }
640 #endif
641 
642   // Other modifier member functions.
swap(_Self & __s)643   void swap(_Self& __s) {
644     _M_iter_list._Swap_owners(__s._M_iter_list);
645     _M_non_dbg_impl.swap(__s._M_non_dbg_impl);
646   }
647 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
_M_swap_workaround(_Self & __x)648   void _M_swap_workaround(_Self& __x) { swap(__x); }
649 #endif
650 
compare(const _Self & __s)651   int compare(const _Self& __s) const
652   { return _M_non_dbg_impl.compare(__s._M_non_dbg_impl); }
compare(size_type __pos,size_type __n,const _Self & __s)653   int compare(size_type __pos, size_type __n, const _Self& __s) const
654   { return _M_non_dbg_impl.compare(__pos, __n, __s._M_non_dbg_impl); }
compare(size_type __pos1,size_type __n1,const _Self & __s,size_type __pos2,size_type __n2)655   int compare(size_type __pos1, size_type __n1, const _Self& __s,
656               size_type __pos2, size_type __n2) const
657   { return _M_non_dbg_impl.compare(__pos1, __n1, __s._M_non_dbg_impl, __pos2, __n2); }
compare(const _CharT * __s)658   int compare(const _CharT* __s) const {
659     _STLP_FIX_LITERAL_BUG(__s)
660     return _M_non_dbg_impl.compare(__s);
661   }
compare(size_type __pos,size_type __n,const _CharT * __s)662   int compare(size_type __pos, size_type __n, const _CharT* __s) const {
663     _STLP_FIX_LITERAL_BUG(__s)
664     return _M_non_dbg_impl.compare(__pos, __n, __s);
665   }
compare(size_type __pos1,size_type __n1,const _CharT * __s,size_type __n2)666   int compare(size_type __pos1, size_type __n1, const _CharT* __s,
667               size_type __n2) const {
668     _STLP_FIX_LITERAL_BUG(__s)
669     return _M_non_dbg_impl.compare(__pos1, __n1, __s, __n2);
670   }
671 
672   // Helper functions for compare.
_M_compare(const _CharT * __f1,const _CharT * __l1,const _CharT * __f2,const _CharT * __l2)673   static int _STLP_CALL _M_compare(const _CharT* __f1, const _CharT* __l1,
674                                    const _CharT* __f2, const _CharT* __l2)
675   { return _Base::_M_compare(__f1, __l1, __f2, __l2); }
_M_compare(const_iterator __f1,const_iterator __l1,const _CharT * __f2,const _CharT * __l2)676   static int _STLP_CALL _M_compare(const_iterator __f1, const_iterator __l1,
677                                    const _CharT* __f2, const _CharT* __l2)
678   { return _Base::_M_compare(__f1._M_iterator, __l1._M_iterator, __f2, __l2); }
_M_compare(const _CharT * __f1,const _CharT * __l1,const_iterator __f2,const_iterator __l2)679   static int _STLP_CALL _M_compare(const _CharT* __f1, const _CharT* __l1,
680                                    const_iterator __f2, const_iterator __l2)
681   { return _Base::_M_compare(__f1, __l1, __f2._M_iterator, __l2._M_iterator); }
_M_compare(const_iterator __f1,const_iterator __l1,const_iterator __f2,const_iterator __l2)682   static int _STLP_CALL _M_compare(const_iterator __f1, const_iterator __l1,
683                                    const_iterator __f2, const_iterator __l2)
684   { return _Base::_M_compare(__f1._M_iterator, __l1._M_iterator, __f2._M_iterator, __l2._M_iterator); }
685 
c_str()686   const _CharT* c_str() const { return _M_non_dbg_impl.c_str(); }
data()687   const _CharT* data()  const { return _M_non_dbg_impl.data(); }
688 
689   size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
690   { return _M_non_dbg_impl.copy(__s, __n, __pos); }
691 
692   // find.
693   size_type find(const _Self& __s, size_type __pos = 0) const
694   { return _M_non_dbg_impl.find(__s._M_non_dbg_impl, __pos); }
695   size_type find(const _CharT* __s, size_type __pos = 0) const {
696     _STLP_FIX_LITERAL_BUG(__s)
697     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
698     return _M_non_dbg_impl.find(__s, __pos);
699   }
find(const _CharT * __s,size_type __pos,size_type __n)700   size_type find(const _CharT* __s, size_type __pos, size_type __n) const {
701     _STLP_FIX_LITERAL_BUG(__s)
702     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
703     return _M_non_dbg_impl.find(__s, __pos, __n);
704   }
705   // WIE: Versant schema compiler 5.2.2 ICE workaround
find(_CharT __c)706   size_type find(_CharT __c) const { return find(__c, 0); }
find(_CharT __c,size_type __pos)707   size_type find(_CharT __c, size_type __pos /* = 0 */) const
708   { return _M_non_dbg_impl.find(__c, __pos); }
709 
710   // rfind.
711   size_type rfind(const _Self& __s, size_type __pos = npos) const
712   { return _M_non_dbg_impl.rfind(__s._M_non_dbg_impl, __pos); }
713   size_type rfind(const _CharT* __s, size_type __pos = npos) const {
714     _STLP_FIX_LITERAL_BUG(__s)
715     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
716     return _M_non_dbg_impl.rfind(__s, __pos);
717   }
rfind(const _CharT * __s,size_type __pos,size_type __n)718   size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const {
719     _STLP_FIX_LITERAL_BUG(__s)
720     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
721     return _M_non_dbg_impl.rfind(__s, __pos, __n);
722   }
723   size_type rfind(_CharT __c, size_type __pos = npos) const
724   { return _M_non_dbg_impl.rfind(__c, __pos); }
725 
726   // find_first_of
727   size_type find_first_of(const _Self& __s, size_type __pos = 0) const
728   { return _M_non_dbg_impl.find_first_of(__s._M_non_dbg_impl, __pos); }
729   size_type find_first_of(const _CharT* __s, size_type __pos = 0) const {
730     _STLP_FIX_LITERAL_BUG(__s)
731     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
732     return _M_non_dbg_impl.find_first_of(__s, __pos);
733   }
find_first_of(const _CharT * __s,size_type __pos,size_type __n)734   size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const {
735     _STLP_FIX_LITERAL_BUG(__s)
736     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
737     return _M_non_dbg_impl.find_first_of(__s, __pos, __n);
738   }
739   size_type find_first_of(_CharT __c, size_type __pos = 0) const
740   { return _M_non_dbg_impl.find_first_of(__c, __pos); }
741 
742   // find_last_of
743   size_type find_last_of(const _Self& __s, size_type __pos = npos) const
744   { return _M_non_dbg_impl.find_last_of(__s._M_non_dbg_impl, __pos); }
745   size_type find_last_of(const _CharT* __s, size_type __pos = npos) const {
746     _STLP_FIX_LITERAL_BUG(__s)
747     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
748     return _M_non_dbg_impl.find_last_of(__s, __pos);
749   }
find_last_of(const _CharT * __s,size_type __pos,size_type __n)750   size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const {
751     _STLP_FIX_LITERAL_BUG(__s)
752     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
753     return _M_non_dbg_impl.find_last_of(__s, __pos, __n);
754   }
755   size_type find_last_of(_CharT __c, size_type __pos = npos) const
756   { return _M_non_dbg_impl.rfind(__c, __pos); }
757 
758   // find_first_not_of
759   size_type find_first_not_of(const _Self& __s, size_type __pos = 0) const
760   { return _M_non_dbg_impl.find_first_not_of(__s._M_non_dbg_impl, __pos); }
761   size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const {
762     _STLP_FIX_LITERAL_BUG(__s)
763     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
764     return _M_non_dbg_impl.find_first_not_of(__s, __pos);
765   }
find_first_not_of(const _CharT * __s,size_type __pos,size_type __n)766   size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const {
767     _STLP_FIX_LITERAL_BUG(__s)
768     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
769     return _M_non_dbg_impl.find_first_not_of(__s, __pos, __n);
770   }
771   size_type find_first_not_of(_CharT __c, size_type __pos = 0) const
772   { return _M_non_dbg_impl.find_first_not_of(__c, __pos); }
773 
774   // find_last_not_of
775   size_type find_last_not_of(const _Self& __s, size_type __pos = npos) const
776   { return _M_non_dbg_impl.find_last_not_of(__s._M_non_dbg_impl, __pos); }
777   size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const {
778     _STLP_FIX_LITERAL_BUG(__s)
779     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
780     return _M_non_dbg_impl.find_last_not_of(__s, __pos);
781   }
find_last_not_of(const _CharT * __s,size_type __pos,size_type __n)782   size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const {
783     _STLP_FIX_LITERAL_BUG(__s)
784     _STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
785     return _M_non_dbg_impl.find_last_not_of(__s, __pos, __n);
786   }
787   size_type find_last_not_of(_CharT __c, size_type __pos = npos) const
788   { return _M_non_dbg_impl.find_last_not_of(__c, __pos); }
789 
790 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
791 #  include <stl/debug/_string_sum_methods.h>
792 #endif
793 };
794 
795 // This is a hook to instantiate STLport exports in a designated DLL
796 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
797 _STLP_MOVE_TO_PRIV_NAMESPACE
798 _STLP_EXPORT_TEMPLATE_CLASS __construct_checker<_STLP_NON_DBG_STRING_NAME <char, char_traits<char>, allocator<char> > >;
799 _STLP_MOVE_TO_STD_NAMESPACE
800 _STLP_EXPORT_TEMPLATE_CLASS basic_string<char, char_traits<char>, allocator<char> >;
801 #  if defined (_STLP_HAS_WCHAR_T)
802 _STLP_MOVE_TO_PRIV_NAMESPACE
803 _STLP_EXPORT_TEMPLATE_CLASS __construct_checker<_STLP_NON_DBG_STRING_NAME <wchar_t, char_traits<wchar_t>, allocator<wchar_t> > >;
804 _STLP_MOVE_TO_STD_NAMESPACE
805 _STLP_EXPORT_TEMPLATE_CLASS basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
806 #  endif
807 #endif
808 
809 #undef _STLP_NON_DBG_STRING
810 #undef _STLP_NON_DBG_STRING_NAME
811 
812 #if defined (__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 96)
813 template <class _CharT, class _Traits, class _Alloc>
814 const size_t basic_string<_CharT, _Traits, _Alloc>::npos = ~(size_t) 0;
815 #endif
816 
817 #if defined (basic_string)
818 _STLP_MOVE_TO_STD_NAMESPACE
819 #undef basic_string
820 #endif
821 
822 _STLP_END_NAMESPACE
823 
824 #endif /* _STLP_DBG_STRING */
825 
826 // Local Variables:
827 // mode:C++
828 // End:
829