_string.h 31 KB

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