47 #pragma GCC system_header
56 #include <bits/gthr.h>
57 #include <tr1/functional>
60 # define __GC_CONST const
62 # define __GC_CONST // constant except for deallocation
67 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
71 enum { _S_max_rope_depth = 45 };
72 enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
80 _GLIBCXX_BEGIN_NAMESPACE_VERSION
83 template<
typename _ForwardIterator,
typename _Allocator>
85 _Destroy_const(_ForwardIterator __first,
86 _ForwardIterator __last, _Allocator __alloc)
88 for (; __first != __last; ++__first)
89 __alloc.destroy(&*__first);
92 template<
typename _ForwardIterator,
typename _Tp>
94 _Destroy_const(_ForwardIterator __first,
95 _ForwardIterator __last, allocator<_Tp>)
103 template <
class _CharT>
110 template <
class _CharT>
112 _S_is_basic_char_type(_CharT*)
115 template <
class _CharT>
117 _S_is_one_byte_char_type(_CharT*)
121 _S_is_basic_char_type(
char*)
125 _S_is_one_byte_char_type(
char*)
129 _S_is_basic_char_type(
wchar_t*)
134 template <
class _CharT>
136 _S_cond_store_eos(_CharT&) { }
139 _S_cond_store_eos(
char& __c)
143 _S_cond_store_eos(
wchar_t& __c)
150 template <
class _CharT>
154 virtual ~char_producer() { };
157 operator()(
size_t __start_pos,
size_t __len,
158 _CharT* __buffer) = 0;
179 template<
class _Sequence,
size_t _Buf_sz = 100>
180 class sequence_buffer
181 :
public std::iterator<std::output_iterator_tag, void, void, void, void>
184 typedef typename _Sequence::value_type value_type;
186 _Sequence* _M_prefix;
187 value_type _M_buffer[_Buf_sz];
194 _M_prefix->append(_M_buffer, _M_buffer + _M_buf_count);
202 : _M_prefix(0), _M_buf_count(0) { }
204 sequence_buffer(
const sequence_buffer& __x)
206 _M_prefix = __x._M_prefix;
207 _M_buf_count = __x._M_buf_count;
208 std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
211 sequence_buffer(sequence_buffer& __x)
214 _M_prefix = __x._M_prefix;
218 sequence_buffer(_Sequence& __s)
219 : _M_prefix(&__s), _M_buf_count(0) { }
222 operator=(sequence_buffer& __x)
225 _M_prefix = __x._M_prefix;
231 operator=(
const sequence_buffer& __x)
233 _M_prefix = __x._M_prefix;
234 _M_buf_count = __x._M_buf_count;
235 std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
240 push_back(value_type __x)
242 if (_M_buf_count < _Buf_sz)
244 _M_buffer[_M_buf_count] = __x;
256 append(value_type* __s,
size_t __len)
258 if (__len + _M_buf_count <= _Buf_sz)
260 size_t __i = _M_buf_count;
261 for (
size_t __j = 0; __j < __len; __i++, __j++)
262 _M_buffer[__i] = __s[__j];
263 _M_buf_count += __len;
265 else if (0 == _M_buf_count)
266 _M_prefix->append(__s, __s + __len);
275 write(value_type* __s,
size_t __len)
289 operator=(
const value_type& __rhs)
309 template<
class _CharT>
310 class _Rope_char_consumer
318 virtual ~_Rope_char_consumer() { };
321 operator()(
const _CharT* __buffer,
size_t __len) = 0;
327 template<
class _CharT,
class _Alloc = allocator<_CharT> >
330 template<
class _CharT,
class _Alloc>
331 struct _Rope_RopeConcatenation;
333 template<
class _CharT,
class _Alloc>
334 struct _Rope_RopeLeaf;
336 template<
class _CharT,
class _Alloc>
337 struct _Rope_RopeFunction;
339 template<
class _CharT,
class _Alloc>
340 struct _Rope_RopeSubstring;
342 template<
class _CharT,
class _Alloc>
343 class _Rope_iterator;
345 template<
class _CharT,
class _Alloc>
346 class _Rope_const_iterator;
348 template<
class _CharT,
class _Alloc>
349 class _Rope_char_ref_proxy;
351 template<
class _CharT,
class _Alloc>
352 class _Rope_char_ptr_proxy;
354 template<
class _CharT,
class _Alloc>
356 operator==(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
357 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y);
359 template<
class _CharT,
class _Alloc>
360 _Rope_const_iterator<_CharT, _Alloc>
361 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
364 template<
class _CharT,
class _Alloc>
365 _Rope_const_iterator<_CharT, _Alloc>
366 operator+(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
369 template<
class _CharT,
class _Alloc>
370 _Rope_const_iterator<_CharT, _Alloc>
371 operator+(ptrdiff_t __n,
372 const _Rope_const_iterator<_CharT, _Alloc>& __x);
374 template<
class _CharT,
class _Alloc>
376 operator==(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
377 const _Rope_const_iterator<_CharT, _Alloc>& __y);
379 template<
class _CharT,
class _Alloc>
381 operator<(const _Rope_const_iterator<_CharT, _Alloc>& __x,
382 const _Rope_const_iterator<_CharT, _Alloc>& __y);
384 template<
class _CharT,
class _Alloc>
386 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
387 const _Rope_const_iterator<_CharT, _Alloc>& __y);
389 template<
class _CharT,
class _Alloc>
390 _Rope_iterator<_CharT, _Alloc>
391 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n);
393 template<
class _CharT,
class _Alloc>
394 _Rope_iterator<_CharT, _Alloc>
395 operator+(
const _Rope_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n);
397 template<
class _CharT,
class _Alloc>
398 _Rope_iterator<_CharT, _Alloc>
399 operator+(ptrdiff_t __n,
const _Rope_iterator<_CharT, _Alloc>& __x);
401 template<
class _CharT,
class _Alloc>
403 operator==(
const _Rope_iterator<_CharT, _Alloc>& __x,
404 const _Rope_iterator<_CharT, _Alloc>& __y);
406 template<
class _CharT,
class _Alloc>
408 operator<(const _Rope_iterator<_CharT, _Alloc>& __x,
409 const _Rope_iterator<_CharT, _Alloc>& __y);
411 template<
class _CharT,
class _Alloc>
413 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
414 const _Rope_iterator<_CharT, _Alloc>& __y);
416 template<
class _CharT,
class _Alloc>
421 template<
class _CharT,
class _Alloc>
425 template<
class _CharT,
class _Alloc>
434 template<
class _CharT,
class _Alloc>
435 struct _Rope_Concat_fn
437 rope<_CharT, _Alloc> >
442 {
return __x + __y; }
445 template <
class _CharT,
class _Alloc>
446 inline rope<_CharT, _Alloc>
447 identity_element(_Rope_Concat_fn<_CharT, _Alloc>)
448 {
return rope<_CharT, _Alloc>(); }
454 struct _Refcount_Base
457 typedef size_t _RC_t;
460 volatile _RC_t _M_ref_count;
463 #ifdef __GTHREAD_MUTEX_INIT
464 __gthread_mutex_t _M_ref_count_lock = __GTHREAD_MUTEX_INIT;
466 __gthread_mutex_t _M_ref_count_lock;
469 _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
471 #ifndef __GTHREAD_MUTEX_INIT
472 #ifdef __GTHREAD_MUTEX_INIT_FUNCTION
473 __GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock);
475 #error __GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to [email protected].
480 #ifndef __GTHREAD_MUTEX_INIT
482 { __gthread_mutex_destroy(&_M_ref_count_lock); }
488 __gthread_mutex_lock(&_M_ref_count_lock);
490 __gthread_mutex_unlock(&_M_ref_count_lock);
496 __gthread_mutex_lock(&_M_ref_count_lock);
497 volatile _RC_t __tmp = --_M_ref_count;
498 __gthread_mutex_unlock(&_M_ref_count_lock);
528 #define __ROPE_DEFINE_ALLOCS(__a) \
529 __ROPE_DEFINE_ALLOC(_CharT,_Data) \
530 typedef _Rope_RopeConcatenation<_CharT,__a> __C; \
531 __ROPE_DEFINE_ALLOC(__C,_C) \
532 typedef _Rope_RopeLeaf<_CharT,__a> __L; \
533 __ROPE_DEFINE_ALLOC(__L,_L) \
534 typedef _Rope_RopeFunction<_CharT,__a> __F; \
535 __ROPE_DEFINE_ALLOC(__F,_F) \
536 typedef _Rope_RopeSubstring<_CharT,__a> __S; \
537 __ROPE_DEFINE_ALLOC(__S,_S)
546 #define __STATIC_IF_SGI_ALLOC
548 template <
class _CharT,
class _Alloc>
549 struct _Rope_rep_base
552 typedef _Alloc allocator_type;
555 get_allocator()
const
556 {
return *
static_cast<const _Alloc*
>(
this); }
560 {
return *
static_cast<_Alloc*
>(
this); }
562 const allocator_type&
563 _M_get_allocator()
const
564 {
return *
static_cast<const _Alloc*
>(
this); }
566 _Rope_rep_base(
size_t __size,
const allocator_type&)
567 : _M_size(__size) { }
571 # define __ROPE_DEFINE_ALLOC(_Tp, __name) \
573 _Alloc::template rebind<_Tp>::other __name##Alloc; \
574 static _Tp* __name##_allocate(size_t __n) \
575 { return __name##Alloc().allocate(__n); } \
576 static void __name##_deallocate(_Tp *__p, size_t __n) \
577 { __name##Alloc().deallocate(__p, __n); }
578 __ROPE_DEFINE_ALLOCS(_Alloc)
579 # undef __ROPE_DEFINE_ALLOC
582 template<
class _CharT,
class _Alloc>
584 :
public _Rope_rep_base<_CharT, _Alloc>
590 __detail::_Tag _M_tag:8;
591 bool _M_is_balanced:8;
592 unsigned char _M_depth;
593 __GC_CONST _CharT* _M_c_string;
594 #ifdef __GTHREAD_MUTEX_INIT
595 __gthread_mutex_t _M_c_string_lock = __GTHREAD_MUTEX_INIT;
597 __gthread_mutex_t _M_c_string_lock;
605 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
608 using _Rope_rep_base<_CharT, _Alloc>::get_allocator;
609 using _Rope_rep_base<_CharT, _Alloc>::_M_get_allocator;
611 _Rope_RopeRep(__detail::_Tag __t,
int __d,
bool __b,
size_t __size,
612 const allocator_type& __a)
613 : _Rope_rep_base<_CharT, _Alloc>(__size, __a),
617 _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0)
618 #ifdef __GTHREAD_MUTEX_INIT
621 { __GTHREAD_MUTEX_INIT_FUNCTION (&_M_c_string_lock); }
623 { __gthread_mutex_destroy (&_M_c_string_lock); }
630 _S_free_string(__GC_CONST _CharT*,
size_t __len,
631 allocator_type& __a);
632 #define __STL_FREE_STRING(__s, __l, __a) _S_free_string(__s, __l, __a);
640 void _M_free_c_string();
655 _S_unref(_Rope_RopeRep* __t)
658 __t->_M_unref_nonnil();
662 _S_ref(_Rope_RopeRep* __t)
669 _S_free_if_unref(_Rope_RopeRep* __t)
671 if (0 != __t && 0 == __t->_M_ref_count)
675 void _M_unref_nonnil() { }
676 void _M_ref_nonnil() { }
677 static void _S_unref(_Rope_RopeRep*) { }
678 static void _S_ref(_Rope_RopeRep*) { }
679 static void _S_free_if_unref(_Rope_RopeRep*) { }
683 operator=(
const _Rope_RopeRep&);
685 _Rope_RopeRep(
const _Rope_RopeRep&);
688 template<
class _CharT,
class _Alloc>
689 struct _Rope_RopeLeaf
690 :
public _Rope_RopeRep<_CharT, _Alloc>
697 enum { _S_alloc_granularity = 8 };
700 _S_rounded_up_size(
size_t __n)
702 size_t __size_with_eos;
704 if (_S_is_basic_char_type((_CharT*)0))
705 __size_with_eos = __n + 1;
707 __size_with_eos = __n;
709 return __size_with_eos;
712 return ((__size_with_eos +
size_t(_S_alloc_granularity) - 1)
713 &~ (
size_t(_S_alloc_granularity) - 1));
716 __GC_CONST _CharT* _M_data;
721 typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
724 _Rope_RopeLeaf(__GC_CONST _CharT* __d,
size_t __size,
725 const allocator_type& __a)
726 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_leaf, 0, true,
727 __size, __a), _M_data(__d)
729 if (_S_is_basic_char_type((_CharT *)0))
732 this->_M_c_string = __d;
739 ~_Rope_RopeLeaf() throw()
741 if (_M_data != this->_M_c_string)
742 this->_M_free_c_string();
744 this->__STL_FREE_STRING(_M_data, this->_M_size, this->_M_get_allocator());
749 operator=(
const _Rope_RopeLeaf&);
751 _Rope_RopeLeaf(
const _Rope_RopeLeaf&);
754 template<
class _CharT,
class _Alloc>
755 struct _Rope_RopeConcatenation
756 :
public _Rope_RopeRep<_CharT, _Alloc>
759 _Rope_RopeRep<_CharT, _Alloc>* _M_left;
760 _Rope_RopeRep<_CharT, _Alloc>* _M_right;
762 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
765 _Rope_RopeConcatenation(_Rope_RopeRep<_CharT, _Alloc>* __l,
766 _Rope_RopeRep<_CharT, _Alloc>* __r,
767 const allocator_type& __a)
768 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_concat,
769 std::
max(__l->_M_depth,
772 __l->_M_size + __r->_M_size, __a),
773 _M_left(__l), _M_right(__r)
776 ~_Rope_RopeConcatenation() throw()
778 this->_M_free_c_string();
779 _M_left->_M_unref_nonnil();
780 _M_right->_M_unref_nonnil();
784 _Rope_RopeConcatenation&
785 operator=(
const _Rope_RopeConcatenation&);
787 _Rope_RopeConcatenation(
const _Rope_RopeConcatenation&);
790 template<
class _CharT,
class _Alloc>
791 struct _Rope_RopeFunction
792 :
public _Rope_RopeRep<_CharT, _Alloc>
795 char_producer<_CharT>* _M_fn;
797 bool _M_delete_when_done;
808 _S_fn_finalization_proc(
void * __tree,
void *)
809 {
delete ((_Rope_RopeFunction *)__tree) -> _M_fn; }
811 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
814 _Rope_RopeFunction(char_producer<_CharT>* __f,
size_t __size,
815 bool __d,
const allocator_type& __a)
816 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_function, 0, true, __size, __a)
819 , _M_delete_when_done(__d)
825 GC_REGISTER_FINALIZER(
this, _Rope_RopeFunction::
826 _S_fn_finalization_proc, 0, 0, 0);
831 ~_Rope_RopeFunction() throw()
833 this->_M_free_c_string();
834 if (_M_delete_when_done)
840 operator=(
const _Rope_RopeFunction&);
842 _Rope_RopeFunction(
const _Rope_RopeFunction&);
851 template<
class _CharT,
class _Alloc>
852 struct _Rope_RopeSubstring
853 :
public _Rope_RopeFunction<_CharT, _Alloc>,
854 public char_producer<_CharT>
858 _Rope_RopeRep<_CharT,_Alloc>* _M_base;
862 operator()(
size_t __start_pos,
size_t __req_len,
865 switch(_M_base->_M_tag)
867 case __detail::_S_function:
868 case __detail::_S_substringfn:
870 char_producer<_CharT>* __fn =
871 ((_Rope_RopeFunction<_CharT,_Alloc>*)_M_base)->_M_fn;
872 (*__fn)(__start_pos + _M_start, __req_len, __buffer);
875 case __detail::_S_leaf:
877 __GC_CONST _CharT* __s =
878 ((_Rope_RopeLeaf<_CharT,_Alloc>*)_M_base)->_M_data;
888 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
891 _Rope_RopeSubstring(_Rope_RopeRep<_CharT, _Alloc>* __b,
size_t __s,
892 size_t __l,
const allocator_type& __a)
893 : _Rope_RopeFunction<_CharT, _Alloc>(this, __l, false, __a),
894 char_producer<_CharT>(), _M_base(__b), _M_start(__s)
897 _M_base->_M_ref_nonnil();
899 this->_M_tag = __detail::_S_substringfn;
901 virtual ~_Rope_RopeSubstring() throw()
904 _M_base->_M_unref_nonnil();
920 template<
class _CharT,
class _Alloc>
921 struct _Rope_self_destruct_ptr
923 _Rope_RopeRep<_CharT, _Alloc>* _M_ptr;
925 ~_Rope_self_destruct_ptr()
926 { _Rope_RopeRep<_CharT, _Alloc>::_S_unref(_M_ptr); }
928 _Rope_self_destruct_ptr() : _M_ptr(0) { };
930 _Rope_self_destruct_ptr() { };
932 _Rope_self_destruct_ptr(_Rope_RopeRep<_CharT, _Alloc>* __p)
935 _Rope_RopeRep<_CharT, _Alloc>&
939 _Rope_RopeRep<_CharT, _Alloc>*
943 operator _Rope_RopeRep<_CharT, _Alloc>*()
946 _Rope_self_destruct_ptr&
947 operator=(_Rope_RopeRep<_CharT, _Alloc>* __x)
948 { _M_ptr = __x;
return *
this; }
957 template<
class _CharT,
class _Alloc>
958 class _Rope_char_ref_proxy
960 friend class rope<_CharT, _Alloc>;
961 friend class _Rope_iterator<_CharT, _Alloc>;
962 friend class _Rope_char_ptr_proxy<_CharT, _Alloc>;
964 typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr;
966 typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr;
968 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
969 typedef rope<_CharT, _Alloc> _My_rope;
972 bool _M_current_valid;
975 _Rope_char_ref_proxy(_My_rope* __r,
size_t __p)
976 : _M_pos(__p), _M_current(), _M_current_valid(false), _M_root(__r) { }
978 _Rope_char_ref_proxy(
const _Rope_char_ref_proxy& __x)
979 : _M_pos(__x._M_pos), _M_current(__x._M_current),
980 _M_current_valid(false), _M_root(__x._M_root) { }
986 _Rope_char_ref_proxy(_My_rope* __r,
size_t __p, _CharT __c)
987 : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) { }
989 inline operator _CharT ()
const;
991 _Rope_char_ref_proxy&
992 operator=(_CharT __c);
994 _Rope_char_ptr_proxy<_CharT, _Alloc>
operator&()
const;
996 _Rope_char_ref_proxy&
997 operator=(
const _Rope_char_ref_proxy& __c)
998 {
return operator=((_CharT)__c); }
1001 template<
class _CharT,
class __Alloc>
1003 swap(_Rope_char_ref_proxy <_CharT, __Alloc > __a,
1004 _Rope_char_ref_proxy <_CharT, __Alloc > __b)
1011 template<
class _CharT,
class _Alloc>
1012 class _Rope_char_ptr_proxy
1015 friend class _Rope_char_ref_proxy<_CharT, _Alloc>;
1017 rope<_CharT,_Alloc>* _M_root;
1019 _Rope_char_ptr_proxy(
const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
1020 : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
1022 _Rope_char_ptr_proxy(
const _Rope_char_ptr_proxy& __x)
1023 : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
1025 _Rope_char_ptr_proxy() { }
1027 _Rope_char_ptr_proxy(_CharT* __x)
1028 : _M_root(0), _M_pos(0) { }
1030 _Rope_char_ptr_proxy&
1031 operator=(
const _Rope_char_ptr_proxy& __x)
1033 _M_pos = __x._M_pos;
1034 _M_root = __x._M_root;
1038 template<
class _CharT2,
class _Alloc2>
1040 operator==(
const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __x,
1041 const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __y);
1043 _Rope_char_ref_proxy<_CharT, _Alloc> operator*()
const
1044 {
return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root, _M_pos); }
1056 template<
class _CharT,
class _Alloc>
1057 class _Rope_iterator_base
1058 :
public std::iterator<std::random_access_iterator_tag, _CharT>
1060 friend class rope<_CharT, _Alloc>;
1062 typedef _Alloc _allocator_type;
1063 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1066 enum { _S_path_cache_len = 4 };
1067 enum { _S_iterator_buf_len = 15 };
1068 size_t _M_current_pos;
1071 __GC_CONST _CharT* _M_buf_start;
1074 __GC_CONST _CharT* _M_buf_ptr;
1077 __GC_CONST _CharT* _M_buf_end;
1083 const _RopeRep* _M_path_end[_S_path_cache_len];
1087 unsigned char _M_path_directions;
1092 _CharT _M_tmp_buf[_S_iterator_buf_len];
1100 static void _S_setbuf(_Rope_iterator_base& __x);
1103 static void _S_setcache(_Rope_iterator_base& __x);
1106 static void _S_setcache_for_incr(_Rope_iterator_base& __x);
1109 _Rope_iterator_base() { }
1111 _Rope_iterator_base(_RopeRep* __root,
size_t __pos)
1112 : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) { }
1114 void _M_incr(
size_t __n);
1115 void _M_decr(
size_t __n);
1119 {
return _M_current_pos; }
1121 _Rope_iterator_base(
const _Rope_iterator_base& __x)
1123 if (0 != __x._M_buf_ptr)
1127 _M_current_pos = __x._M_current_pos;
1128 _M_root = __x._M_root;
1134 template<
class _CharT,
class _Alloc>
1135 class _Rope_iterator;
1137 template<
class _CharT,
class _Alloc>
1138 class _Rope_const_iterator
1139 :
public _Rope_iterator_base<_CharT, _Alloc>
1141 friend class rope<_CharT, _Alloc>;
1143 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1145 _Rope_const_iterator(
const _RopeRep* __root,
size_t __pos)
1146 : _Rope_iterator_base<_CharT, _Alloc>(const_cast<_RopeRep*>(__root),
1151 typedef _CharT reference;
1154 typedef const _CharT* pointer;
1157 _Rope_const_iterator() { };
1159 _Rope_const_iterator(
const _Rope_const_iterator& __x)
1160 : _Rope_iterator_base<_CharT,_Alloc>(__x) { }
1162 _Rope_const_iterator(
const _Rope_iterator<_CharT,_Alloc>& __x);
1164 _Rope_const_iterator(
const rope<_CharT, _Alloc>& __r,
size_t __pos)
1165 : _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr, __pos) { }
1167 _Rope_const_iterator&
1168 operator=(
const _Rope_const_iterator& __x)
1170 if (0 != __x._M_buf_ptr)
1171 *(
static_cast<_Rope_iterator_base<_CharT, _Alloc>*
>(
this)) = __x;
1174 this->_M_current_pos = __x._M_current_pos;
1175 this->_M_root = __x._M_root;
1176 this->_M_buf_ptr = 0;
1184 if (0 == this->_M_buf_ptr)
1185 this->_S_setcache(*
this);
1186 return *this->_M_buf_ptr;
1194 return *
const_cast<_Rope_const_iterator&
>(*this);
1197 _Rope_const_iterator&
1200 __GC_CONST _CharT* __next;
1201 if (0 != this->_M_buf_ptr
1202 && (__next = this->_M_buf_ptr + 1) < this->_M_buf_end)
1204 this->_M_buf_ptr = __next;
1205 ++this->_M_current_pos;
1212 _Rope_const_iterator&
1213 operator+=(ptrdiff_t __n)
1218 this->_M_decr(-__n);
1222 _Rope_const_iterator&
1229 _Rope_const_iterator&
1230 operator-=(ptrdiff_t __n)
1235 this->_M_incr(-__n);
1239 _Rope_const_iterator
1242 size_t __old_pos = this->_M_current_pos;
1244 return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
1250 _Rope_const_iterator
1253 size_t __old_pos = this->_M_current_pos;
1255 return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
1258 template<
class _CharT2,
class _Alloc2>
1259 friend _Rope_const_iterator<_CharT2, _Alloc2>
1260 operator-(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1263 template<
class _CharT2,
class _Alloc2>
1264 friend _Rope_const_iterator<_CharT2, _Alloc2>
1265 operator+(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1268 template<
class _CharT2,
class _Alloc2>
1269 friend _Rope_const_iterator<_CharT2, _Alloc2>
1270 operator+(ptrdiff_t __n,
1271 const _Rope_const_iterator<_CharT2, _Alloc2>& __x);
1275 {
return rope<_CharT, _Alloc>::_S_fetch(this->_M_root,
1276 this->_M_current_pos + __n); }
1278 template<
class _CharT2,
class _Alloc2>
1280 operator==(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1281 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1283 template<
class _CharT2,
class _Alloc2>
1285 operator<(const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1286 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1288 template<
class _CharT2,
class _Alloc2>
1290 operator-(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1291 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1294 template<
class _CharT,
class _Alloc>
1295 class _Rope_iterator
1296 :
public _Rope_iterator_base<_CharT, _Alloc>
1298 friend class rope<_CharT, _Alloc>;
1300 typedef typename _Rope_iterator_base<_CharT, _Alloc>::_RopeRep _RopeRep;
1301 rope<_CharT, _Alloc>* _M_root_rope;
1309 _Rope_iterator(rope<_CharT, _Alloc>* __r,
size_t __pos)
1310 : _Rope_iterator_base<_CharT, _Alloc>(__r->_M_tree_ptr, __pos),
1312 { _RopeRep::_S_ref(this->_M_root);
1313 if (!(__r -> empty()))
1314 this->_S_setcache(*
this);
1319 typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
1320 typedef _Rope_char_ref_proxy<_CharT, _Alloc>* pointer;
1322 rope<_CharT, _Alloc>&
1324 {
return *_M_root_rope; }
1331 _Rope_iterator(
const _Rope_iterator& __x)
1332 : _Rope_iterator_base<_CharT, _Alloc>(__x)
1334 _M_root_rope = __x._M_root_rope;
1335 _RopeRep::_S_ref(this->_M_root);
1338 _Rope_iterator(rope<_CharT, _Alloc>& __r,
size_t __pos);
1341 { _RopeRep::_S_unref(this->_M_root); }
1344 operator=(
const _Rope_iterator& __x)
1346 _RopeRep* __old = this->_M_root;
1348 _RopeRep::_S_ref(__x._M_root);
1349 if (0 != __x._M_buf_ptr)
1351 _M_root_rope = __x._M_root_rope;
1352 *(
static_cast<_Rope_iterator_base<_CharT, _Alloc>*
>(
this)) = __x;
1356 this->_M_current_pos = __x._M_current_pos;
1357 this->_M_root = __x._M_root;
1358 _M_root_rope = __x._M_root_rope;
1359 this->_M_buf_ptr = 0;
1361 _RopeRep::_S_unref(__old);
1369 if (0 == this->_M_buf_ptr)
1370 return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1371 this->_M_current_pos);
1373 return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1374 this->_M_current_pos,
1382 return *
const_cast<_Rope_iterator&
>(*this);
1393 operator+=(ptrdiff_t __n)
1398 this->_M_decr(-__n);
1410 operator-=(ptrdiff_t __n)
1415 this->_M_incr(-__n);
1422 size_t __old_pos = this->_M_current_pos;
1424 return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1430 size_t __old_pos = this->_M_current_pos;
1432 return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1437 {
return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1438 this->_M_current_pos
1441 template<
class _CharT2,
class _Alloc2>
1443 operator==(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1444 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1446 template<
class _CharT2,
class _Alloc2>
1448 operator<(const _Rope_iterator<_CharT2, _Alloc2>& __x,
1449 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1451 template<
class _CharT2,
class _Alloc2>
1453 operator-(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1454 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1456 template<
class _CharT2,
class _Alloc2>
1457 friend _Rope_iterator<_CharT2, _Alloc2>
1458 operator-(
const _Rope_iterator<_CharT2, _Alloc2>& __x, ptrdiff_t __n);
1460 template<
class _CharT2,
class _Alloc2>
1461 friend _Rope_iterator<_CharT2, _Alloc2>
1462 operator+(
const _Rope_iterator<_CharT2, _Alloc2>& __x, ptrdiff_t __n);
1464 template<
class _CharT2,
class _Alloc2>
1465 friend _Rope_iterator<_CharT2, _Alloc2>
1466 operator+(ptrdiff_t __n,
const _Rope_iterator<_CharT2, _Alloc2>& __x);
1470 template <
class _CharT,
class _Alloc>
1474 typedef _Alloc allocator_type;
1477 get_allocator()
const
1478 {
return *
static_cast<const _Alloc*
>(
this); }
1482 {
return *
static_cast<_Alloc*
>(
this); }
1484 const allocator_type&
1485 _M_get_allocator()
const
1486 {
return *
static_cast<const _Alloc*
>(
this); }
1488 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1491 _Rope_base(_RopeRep* __t,
const allocator_type&)
1492 : _M_tree_ptr(__t) { }
1494 _Rope_base(
const allocator_type&) { }
1497 _RopeRep *_M_tree_ptr;
1499 #define __ROPE_DEFINE_ALLOC(_Tp, __name) \
1501 _Alloc::template rebind<_Tp>::other __name##Alloc; \
1502 static _Tp* __name##_allocate(size_t __n) \
1503 { return __name##Alloc().allocate(__n); } \
1504 static void __name##_deallocate(_Tp *__p, size_t __n) \
1505 { __name##Alloc().deallocate(__p, __n); }
1506 __ROPE_DEFINE_ALLOCS(_Alloc)
1507 #undef __ROPE_DEFINE_ALLOC
1511 operator=(
const _Rope_base&);
1513 _Rope_base(
const _Rope_base&);
1521 template <
class _CharT,
class _Alloc>
1522 class rope :
public _Rope_base<_CharT, _Alloc>
1525 typedef _CharT value_type;
1526 typedef ptrdiff_t difference_type;
1527 typedef size_t size_type;
1528 typedef _CharT const_reference;
1529 typedef const _CharT* const_pointer;
1530 typedef _Rope_iterator<_CharT, _Alloc> iterator;
1531 typedef _Rope_const_iterator<_CharT, _Alloc> const_iterator;
1532 typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
1533 typedef _Rope_char_ptr_proxy<_CharT, _Alloc> pointer;
1535 friend class _Rope_iterator<_CharT, _Alloc>;
1536 friend class _Rope_const_iterator<_CharT, _Alloc>;
1537 friend struct _Rope_RopeRep<_CharT, _Alloc>;
1538 friend class _Rope_iterator_base<_CharT, _Alloc>;
1539 friend class _Rope_char_ptr_proxy<_CharT, _Alloc>;
1540 friend class _Rope_char_ref_proxy<_CharT, _Alloc>;
1541 friend struct _Rope_RopeSubstring<_CharT, _Alloc>;
1544 typedef _Rope_base<_CharT, _Alloc> _Base;
1545 typedef typename _Base::allocator_type allocator_type;
1546 using _Base::_M_tree_ptr;
1547 using _Base::get_allocator;
1548 using _Base::_M_get_allocator;
1549 typedef __GC_CONST _CharT* _Cstrptr;
1551 static _CharT _S_empty_c_str[1];
1555 {
return __c == _S_eos((_CharT*)0); }
1557 enum { _S_copy_max = 23 };
1561 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1562 typedef _Rope_RopeConcatenation<_CharT, _Alloc> _RopeConcatenation;
1563 typedef _Rope_RopeLeaf<_CharT, _Alloc> _RopeLeaf;
1564 typedef _Rope_RopeFunction<_CharT, _Alloc> _RopeFunction;
1565 typedef _Rope_RopeSubstring<_CharT, _Alloc> _RopeSubstring;
1568 static _CharT _S_fetch(_RopeRep* __r, size_type __pos);
1577 static _CharT* _S_fetch_ptr(_RopeRep* __r, size_type __pos);
1582 _Rope_char_consumer<_CharT>& __c,
1583 const _RopeRep* __r,
1584 size_t __begin,
size_t __end);
1589 _S_unref(_RopeRep* __t)
1590 { _RopeRep::_S_unref(__t); }
1593 _S_ref(_RopeRep* __t)
1594 { _RopeRep::_S_ref(__t); }
1597 static void _S_unref(_RopeRep*) { }
1598 static void _S_ref(_RopeRep*) { }
1602 typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr;
1604 typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr;
1608 static _RopeRep* _S_substring(_RopeRep*
__base,
1609 size_t __start,
size_t __endp1);
1611 static _RopeRep* _S_concat_char_iter(_RopeRep* __r,
1612 const _CharT* __iter,
size_t __slen);
1616 static _RopeRep* _S_destr_concat_char_iter(_RopeRep* __r,
1617 const _CharT* __iter,
1624 {
return _S_concat_char_iter(__r, __iter, __slen); }
1629 static _RopeRep* _S_concat(_RopeRep* __left, _RopeRep* __right);
1635 apply_to_pieces(
size_t __begin,
size_t __end,
1636 _Rope_char_consumer<_CharT>& __c)
const
1637 { _S_apply_to_pieces(__c, this->_M_tree_ptr, __begin, __end); }
1642 _S_rounded_up_size(
size_t __n)
1643 {
return _RopeLeaf::_S_rounded_up_size(__n); }
1646 _S_allocated_capacity(
size_t __n)
1648 if (_S_is_basic_char_type((_CharT*)0))
1649 return _S_rounded_up_size(__n) - 1;
1651 return _S_rounded_up_size(__n);
1658 _S_new_RopeLeaf(__GC_CONST _CharT *__s,
1659 size_t __size, allocator_type& __a)
1661 _RopeLeaf* __space =
typename _Base::_LAlloc(__a).allocate(1);
1662 return new(__space) _RopeLeaf(__s, __size, __a);
1665 static _RopeConcatenation*
1666 _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right,
1667 allocator_type& __a)
1669 _RopeConcatenation* __space =
typename _Base::_CAlloc(__a).allocate(1);
1670 return new(__space) _RopeConcatenation(__left, __right, __a);
1673 static _RopeFunction*
1674 _S_new_RopeFunction(char_producer<_CharT>* __f,
1675 size_t __size,
bool __d, allocator_type& __a)
1677 _RopeFunction* __space =
typename _Base::_FAlloc(__a).allocate(1);
1678 return new(__space) _RopeFunction(__f, __size, __d, __a);
1681 static _RopeSubstring*
1682 _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b,
size_t __s,
1683 size_t __l, allocator_type& __a)
1685 _RopeSubstring* __space =
typename _Base::_SAlloc(__a).allocate(1);
1686 return new(__space) _RopeSubstring(__b, __s, __l, __a);
1690 _S_RopeLeaf_from_unowned_char_ptr(
const _CharT *__s,
1691 size_t __size, allocator_type& __a)
1692 #define __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __size, __a) \
1693 _S_RopeLeaf_from_unowned_char_ptr(__s, __size, __a)
1697 _CharT* __buf = __a.allocate(_S_rounded_up_size(__size));
1699 __uninitialized_copy_n_a(__s, __size, __buf, __a);
1700 _S_cond_store_eos(__buf[__size]);
1702 {
return _S_new_RopeLeaf(__buf, __size, __a); }
1705 _RopeRep::__STL_FREE_STRING(__buf, __size, __a);
1706 __throw_exception_again;
1717 _S_tree_concat(_RopeRep* __left, _RopeRep* __right);
1721 _S_leaf_concat_char_iter(_RopeLeaf* __r,
1722 const _CharT* __iter,
size_t __slen);
1728 _S_destr_leaf_concat_char_iter(_RopeLeaf* __r,
1729 const _CharT* __iter,
size_t __slen);
1735 static size_t _S_char_ptr_len(
const _CharT* __s);
1738 rope(_RopeRep* __t,
const allocator_type& __a = allocator_type())
1739 : _Base(__t, __a) { }
1745 static _CharT* _S_flatten(_RopeRep* __r, _CharT* __buffer);
1749 static _CharT* _S_flatten(_RopeRep* __r,
1750 size_t __start,
size_t __len,
1753 static const unsigned long
1754 _S_min_len[__detail::_S_max_rope_depth + 1];
1757 _S_is_balanced(_RopeRep* __r)
1758 {
return (__r->_M_size >= _S_min_len[__r->_M_depth]); }
1761 _S_is_almost_balanced(_RopeRep* __r)
1762 {
return (__r->_M_depth == 0
1763 || __r->_M_size >= _S_min_len[__r->_M_depth - 1]); }
1766 _S_is_roughly_balanced(_RopeRep* __r)
1767 {
return (__r->_M_depth <= 1
1768 || __r->_M_size >= _S_min_len[__r->_M_depth - 2]); }
1772 _S_concat_and_set_balanced(_RopeRep* __left, _RopeRep* __right)
1774 _RopeRep* __result = _S_concat(__left, __right);
1775 if (_S_is_balanced(__result))
1776 __result->_M_is_balanced =
true;
1785 static _RopeRep* _S_balance(_RopeRep* __r);
1789 static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest);
1792 static void _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest);
1795 static void _S_dump(_RopeRep* __r,
int __indent = 0);
1798 static int _S_compare(
const _RopeRep* __x,
const _RopeRep* __y);
1803 {
return 0 == this->_M_tree_ptr; }
1809 compare(
const rope& __y)
const
1810 {
return _S_compare(this->_M_tree_ptr, __y._M_tree_ptr); }
1812 rope(
const _CharT* __s,
const allocator_type& __a = allocator_type())
1816 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s),
1817 _M_get_allocator());
1820 rope(
const _CharT* __s,
size_t __len,
1821 const allocator_type& __a = allocator_type())
1825 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, _M_get_allocator());
1831 rope(
const _CharT* __s,
const _CharT* __e,
1832 const allocator_type& __a = allocator_type())
1836 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, _M_get_allocator());
1839 rope(
const const_iterator& __s,
const const_iterator& __e,
1840 const allocator_type& __a = allocator_type())
1841 : _Base(_S_substring(__s._M_root, __s._M_current_pos,
1842 __e._M_current_pos), __a)
1845 rope(
const iterator& __s,
const iterator& __e,
1846 const allocator_type& __a = allocator_type())
1847 : _Base(_S_substring(__s._M_root, __s._M_current_pos,
1848 __e._M_current_pos), __a)
1851 rope(_CharT __c,
const allocator_type& __a = allocator_type())
1854 _CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1));
1856 _M_get_allocator().construct(__buf, __c);
1859 this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1,
1860 _M_get_allocator());
1864 _RopeRep::__STL_FREE_STRING(__buf, 1, _M_get_allocator());
1865 __throw_exception_again;
1869 rope(
size_t __n, _CharT __c,
1870 const allocator_type& __a = allocator_type());
1872 rope(
const allocator_type& __a = allocator_type())
1876 rope(char_producer<_CharT> *__fn,
size_t __len,
bool __delete_fn,
1877 const allocator_type& __a = allocator_type())
1880 this->_M_tree_ptr = (0 == __len) ?
1881 0 : _S_new_RopeFunction(__fn, __len, __delete_fn, __a);
1884 rope(
const rope& __x,
const allocator_type& __a = allocator_type())
1885 : _Base(__x._M_tree_ptr, __a)
1886 { _S_ref(this->_M_tree_ptr); }
1889 { _S_unref(this->_M_tree_ptr); }
1892 operator=(
const rope& __x)
1894 _RopeRep* __old = this->_M_tree_ptr;
1895 this->_M_tree_ptr = __x._M_tree_ptr;
1896 _S_ref(this->_M_tree_ptr);
1904 _S_unref(this->_M_tree_ptr);
1905 this->_M_tree_ptr = 0;
1909 push_back(_CharT __x)
1911 _RopeRep* __old = this->_M_tree_ptr;
1913 = _S_destr_concat_char_iter(this->_M_tree_ptr, &__x, 1);
1920 _RopeRep* __old = this->_M_tree_ptr;
1921 this->_M_tree_ptr = _S_substring(this->_M_tree_ptr,
1922 0, this->_M_tree_ptr->_M_size - 1);
1928 {
return _S_fetch(this->_M_tree_ptr, this->_M_tree_ptr->_M_size - 1); }
1931 push_front(_CharT __x)
1933 _RopeRep* __old = this->_M_tree_ptr;
1935 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, _M_get_allocator());
1938 this->_M_tree_ptr = _S_concat(__left, this->_M_tree_ptr);
1945 __throw_exception_again;
1952 _RopeRep* __old = this->_M_tree_ptr;
1954 = _S_substring(this->_M_tree_ptr, 1, this->_M_tree_ptr->_M_size);
1960 {
return _S_fetch(this->_M_tree_ptr, 0); }
1965 _RopeRep* __old = this->_M_tree_ptr;
1966 this->_M_tree_ptr = _S_balance(this->_M_tree_ptr);
1971 copy(_CharT* __buffer)
const
1973 _Destroy_const(__buffer, __buffer +
size(), _M_get_allocator());
1974 _S_flatten(this->_M_tree_ptr, __buffer);
1983 copy(size_type __pos, size_type __n, _CharT* __buffer)
const
1985 size_t __size =
size();
1986 size_t __len = (__pos + __n > __size? __size - __pos : __n);
1988 _Destroy_const(__buffer, __buffer + __len, _M_get_allocator());
1989 _S_flatten(this->_M_tree_ptr, __pos, __len, __buffer);
1997 { _S_dump(this->_M_tree_ptr); }
2001 const _CharT* c_str()
const;
2005 const _CharT* replace_with_c_str();
2013 if (0 == this->_M_tree_ptr)
2015 if (__detail::_S_leaf == this->_M_tree_ptr->_M_tag &&
2016 ((_RopeLeaf*)this->_M_tree_ptr)->_M_data ==
2017 this->_M_tree_ptr->_M_c_string)
2023 this->_M_tree_ptr->_M_free_c_string();
2025 this->_M_tree_ptr->_M_c_string = 0;
2030 {
return _S_fetch(this->_M_tree_ptr, __pos); }
2033 at(size_type __pos)
const
2036 return (*
this)[__pos];
2041 {
return(const_iterator(this->_M_tree_ptr, 0)); }
2046 {
return(const_iterator(this->_M_tree_ptr, 0)); }
2050 {
return(const_iterator(this->_M_tree_ptr,
size())); }
2054 {
return(const_iterator(this->_M_tree_ptr,
size())); }
2058 {
return(0 == this->_M_tree_ptr? 0 : this->_M_tree_ptr->_M_size); }
2067 return _S_min_len[int(__detail::_S_max_rope_depth) - 1] - 1;
2075 const_reverse_iterator
2077 {
return const_reverse_iterator(
end()); }
2079 const_reverse_iterator
2080 const_rbegin()
const
2081 {
return const_reverse_iterator(
end()); }
2083 const_reverse_iterator
2085 {
return const_reverse_iterator(
begin()); }
2087 const_reverse_iterator
2089 {
return const_reverse_iterator(
begin()); }
2091 template<
class _CharT2,
class _Alloc2>
2092 friend rope<_CharT2, _Alloc2>
2093 operator+(
const rope<_CharT2, _Alloc2>& __left,
2094 const rope<_CharT2, _Alloc2>& __right);
2096 template<
class _CharT2,
class _Alloc2>
2097 friend rope<_CharT2, _Alloc2>
2098 operator+(
const rope<_CharT2, _Alloc2>& __left,
const _CharT2* __right);
2100 template<
class _CharT2,
class _Alloc2>
2101 friend rope<_CharT2, _Alloc2>
2102 operator+(
const rope<_CharT2, _Alloc2>& __left, _CharT2 __right);
2111 append(
const _CharT* __iter,
size_t __n)
2113 _RopeRep* __result =
2114 _S_destr_concat_char_iter(this->_M_tree_ptr, __iter, __n);
2115 _S_unref(this->_M_tree_ptr);
2116 this->_M_tree_ptr = __result;
2121 append(
const _CharT* __c_string)
2123 size_t __len = _S_char_ptr_len(__c_string);
2124 append(__c_string, __len);
2129 append(
const _CharT* __s,
const _CharT* __e)
2131 _RopeRep* __result =
2132 _S_destr_concat_char_iter(this->_M_tree_ptr, __s, __e - __s);
2133 _S_unref(this->_M_tree_ptr);
2134 this->_M_tree_ptr = __result;
2139 append(const_iterator __s, const_iterator __e)
2141 _Self_destruct_ptr __appendee(_S_substring(__s._M_root,
2143 __e._M_current_pos));
2144 _RopeRep* __result = _S_concat(this->_M_tree_ptr,
2145 (_RopeRep*)__appendee);
2146 _S_unref(this->_M_tree_ptr);
2147 this->_M_tree_ptr = __result;
2154 _RopeRep* __result =
2155 _S_destr_concat_char_iter(this->_M_tree_ptr, &__c, 1);
2156 _S_unref(this->_M_tree_ptr);
2157 this->_M_tree_ptr = __result;
2163 {
return append(_CharT()); }
2166 append(
const rope& __y)
2168 _RopeRep* __result = _S_concat(this->_M_tree_ptr, __y._M_tree_ptr);
2169 _S_unref(this->_M_tree_ptr);
2170 this->_M_tree_ptr = __result;
2175 append(
size_t __n, _CharT __c)
2177 rope<_CharT,_Alloc> __last(__n, __c);
2178 return append(__last);
2184 _RopeRep* __tmp = this->_M_tree_ptr;
2185 this->_M_tree_ptr = __b._M_tree_ptr;
2186 __b._M_tree_ptr = __tmp;
2192 replace(_RopeRep* __old,
size_t __pos1,
2193 size_t __pos2, _RopeRep* __r)
2200 _Self_destruct_ptr __left(_S_substring(__old, 0, __pos1));
2201 _Self_destruct_ptr __right(_S_substring(__old, __pos2, __old->_M_size));
2205 __result = _S_concat(__left, __right);
2208 _Self_destruct_ptr __left_result(_S_concat(__left, __r));
2209 __result = _S_concat(__left_result, __right);
2216 insert(
size_t __p,
const rope& __r)
2218 _RopeRep* __result =
2219 replace(this->_M_tree_ptr, __p, __p, __r._M_tree_ptr);
2220 _S_unref(this->_M_tree_ptr);
2221 this->_M_tree_ptr = __result;
2225 insert(
size_t __p,
size_t __n, _CharT __c)
2227 rope<_CharT,_Alloc> __r(__n,__c);
2232 insert(
size_t __p,
const _CharT* __i,
size_t __n)
2234 _Self_destruct_ptr __left(_S_substring(this->_M_tree_ptr, 0, __p));
2235 _Self_destruct_ptr __right(_S_substring(this->_M_tree_ptr,
2237 _Self_destruct_ptr __left_result(_S_concat_char_iter(__left, __i, __n));
2241 _RopeRep* __result = _S_concat(__left_result, __right);
2242 _S_unref(this->_M_tree_ptr);
2243 this->_M_tree_ptr = __result;
2247 insert(
size_t __p,
const _CharT* __c_string)
2248 { insert(__p, __c_string, _S_char_ptr_len(__c_string)); }
2251 insert(
size_t __p, _CharT __c)
2252 { insert(__p, &__c, 1); }
2257 _CharT __c = _CharT();
2258 insert(__p, &__c, 1);
2262 insert(
size_t __p,
const _CharT* __i,
const _CharT* __j)
2269 insert(
size_t __p,
const const_iterator& __i,
2270 const const_iterator& __j)
2277 insert(
size_t __p,
const iterator& __i,
2278 const iterator& __j)
2287 replace(
size_t __p,
size_t __n,
const rope& __r)
2289 _RopeRep* __result =
2290 replace(this->_M_tree_ptr, __p, __p + __n, __r._M_tree_ptr);
2291 _S_unref(this->_M_tree_ptr);
2292 this->_M_tree_ptr = __result;
2296 replace(
size_t __p,
size_t __n,
2297 const _CharT* __i,
size_t __i_len)
2299 rope __r(__i, __i_len);
2300 replace(__p, __n, __r);
2304 replace(
size_t __p,
size_t __n, _CharT __c)
2307 replace(__p, __n, __r);
2311 replace(
size_t __p,
size_t __n,
const _CharT* __c_string)
2313 rope __r(__c_string);
2314 replace(__p, __n, __r);
2318 replace(
size_t __p,
size_t __n,
2319 const _CharT* __i,
const _CharT* __j)
2322 replace(__p, __n, __r);
2326 replace(
size_t __p,
size_t __n,
2327 const const_iterator& __i,
const const_iterator& __j)
2330 replace(__p, __n, __r);
2334 replace(
size_t __p,
size_t __n,
2335 const iterator& __i,
const iterator& __j)
2338 replace(__p, __n, __r);
2343 replace(
size_t __p, _CharT __c)
2345 iterator __i(
this, __p);
2350 replace(
size_t __p,
const rope& __r)
2351 { replace(__p, 1, __r); }
2354 replace(
size_t __p,
const _CharT* __i,
size_t __i_len)
2355 { replace(__p, 1, __i, __i_len); }
2358 replace(
size_t __p,
const _CharT* __c_string)
2359 { replace(__p, 1, __c_string); }
2362 replace(
size_t __p,
const _CharT* __i,
const _CharT* __j)
2363 { replace(__p, 1, __i, __j); }
2366 replace(
size_t __p,
const const_iterator& __i,
2367 const const_iterator& __j)
2368 { replace(__p, 1, __i, __j); }
2371 replace(
size_t __p,
const iterator& __i,
2372 const iterator& __j)
2373 { replace(__p, 1, __i, __j); }
2377 erase(
size_t __p,
size_t __n)
2379 _RopeRep* __result = replace(this->_M_tree_ptr, __p,
2381 _S_unref(this->_M_tree_ptr);
2382 this->_M_tree_ptr = __result;
2388 { erase(__p, __p + 1); }
2392 insert(
const iterator& __p,
const rope& __r)
2394 insert(__p.index(), __r);
2399 insert(
const iterator& __p,
size_t __n, _CharT __c)
2401 insert(__p.index(), __n, __c);
2405 iterator insert(
const iterator& __p, _CharT __c)
2407 insert(__p.index(), __c);
2412 insert(
const iterator& __p )
2414 insert(__p.index());
2419 insert(
const iterator& __p,
const _CharT* c_string)
2421 insert(__p.index(), c_string);
2426 insert(
const iterator& __p,
const _CharT* __i,
size_t __n)
2428 insert(__p.index(), __i, __n);
2433 insert(
const iterator& __p,
const _CharT* __i,
2436 insert(__p.index(), __i, __j);
2441 insert(
const iterator& __p,
2442 const const_iterator& __i,
const const_iterator& __j)
2444 insert(__p.index(), __i, __j);
2449 insert(
const iterator& __p,
2450 const iterator& __i,
const iterator& __j)
2452 insert(__p.index(), __i, __j);
2458 replace(
const iterator& __p,
const iterator& __q,
const rope& __r)
2459 { replace(__p.index(), __q.index() - __p.index(), __r); }
2462 replace(
const iterator& __p,
const iterator& __q, _CharT __c)
2463 { replace(__p.index(), __q.index() - __p.index(), __c); }
2466 replace(
const iterator& __p,
const iterator& __q,
2467 const _CharT* __c_string)
2468 { replace(__p.index(), __q.index() - __p.index(), __c_string); }
2471 replace(
const iterator& __p,
const iterator& __q,
2472 const _CharT* __i,
size_t __n)
2473 { replace(__p.index(), __q.index() - __p.index(), __i, __n); }
2476 replace(
const iterator& __p,
const iterator& __q,
2477 const _CharT* __i,
const _CharT* __j)
2478 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2481 replace(
const iterator& __p,
const iterator& __q,
2482 const const_iterator& __i,
const const_iterator& __j)
2483 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2486 replace(
const iterator& __p,
const iterator& __q,
2487 const iterator& __i,
const iterator& __j)
2488 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2492 replace(
const iterator& __p,
const rope& __r)
2493 { replace(__p.index(), __r); }
2496 replace(
const iterator& __p, _CharT __c)
2497 { replace(__p.index(), __c); }
2500 replace(
const iterator& __p,
const _CharT* __c_string)
2501 { replace(__p.index(), __c_string); }
2504 replace(
const iterator& __p,
const _CharT* __i,
size_t __n)
2505 { replace(__p.index(), __i, __n); }
2508 replace(
const iterator& __p,
const _CharT* __i,
const _CharT* __j)
2509 { replace(__p.index(), __i, __j); }
2512 replace(
const iterator& __p, const_iterator __i, const_iterator __j)
2513 { replace(__p.index(), __i, __j); }
2516 replace(
const iterator& __p, iterator __i, iterator __j)
2517 { replace(__p.index(), __i, __j); }
2521 erase(
const iterator& __p,
const iterator& __q)
2523 size_t __p_index = __p.index();
2524 erase(__p_index, __q.index() - __p_index);
2525 return iterator(
this, __p_index);
2529 erase(
const iterator& __p)
2531 size_t __p_index = __p.index();
2532 erase(__p_index, 1);
2533 return iterator(
this, __p_index);
2537 substr(
size_t __start,
size_t __len = 1)
const
2539 return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr,
2545 substr(iterator __start, iterator __end)
const
2547 return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr,
2553 substr(iterator __start)
const
2555 size_t __pos = __start.index();
2556 return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr,
2561 substr(const_iterator __start, const_iterator __end)
const
2565 return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr,
2570 rope<_CharT, _Alloc>
2571 substr(const_iterator __start)
2573 size_t __pos = __start.index();
2574 return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr,
2578 static const size_type npos;
2580 size_type find(_CharT __c, size_type __pos = 0)
const;
2583 find(
const _CharT* __s, size_type __pos = 0)
const
2585 size_type __result_pos;
2586 const_iterator __result =
2588 __s, __s + _S_char_ptr_len(__s));
2589 __result_pos = __result.index();
2590 #ifndef __STL_OLD_ROPE_SEMANTICS
2591 if (__result_pos ==
size())
2592 __result_pos = npos;
2594 return __result_pos;
2599 {
return(iterator(
this, 0)); }
2603 {
return(iterator(
this,
size())); }
2609 {
return reverse_iterator(mutable_end()); }
2613 {
return reverse_iterator(mutable_begin()); }
2616 mutable_reference_at(size_type __pos)
2617 {
return reference(
this, __pos); }
2622 {
return _char_ref_proxy(
this, __pos); }
2628 return (*
this)[__pos];
2631 void resize(size_type __n, _CharT __c) { }
2632 void resize(size_type __n) { }
2633 void reserve(size_type __res_arg = 0) { }
2637 {
return max_size(); }
2643 copy(_CharT* __buffer, size_type __n,
2644 size_type __pos = 0)
const
2645 {
return copy(__pos, __n, __buffer); }
2649 {
return mutable_end(); }
2653 {
return mutable_begin(); }
2657 {
return mutable_rend(); }
2661 {
return mutable_rbegin(); }
2666 {
return const_end(); }
2670 {
return const_begin(); }
2672 const_reverse_iterator
2674 {
return const_rend(); }
2676 const_reverse_iterator
2678 {
return const_rbegin(); }
2683 template <
class _CharT,
class _Alloc>
2684 const typename rope<_CharT, _Alloc>::size_type
2685 rope<_CharT, _Alloc>::npos = (size_type)(-1);
2687 template <
class _CharT,
class _Alloc>
2688 inline bool operator==(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2689 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2690 {
return (__x._M_current_pos == __y._M_current_pos
2691 && __x._M_root == __y._M_root); }
2693 template <
class _CharT,
class _Alloc>
2694 inline bool operator<(const _Rope_const_iterator<_CharT, _Alloc>& __x,
2695 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2696 {
return (__x._M_current_pos < __y._M_current_pos); }
2698 template <
class _CharT,
class _Alloc>
2699 inline bool operator!=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2700 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2701 {
return !(__x == __y); }
2703 template <
class _CharT,
class _Alloc>
2704 inline bool operator>(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2705 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2706 {
return __y < __x; }
2708 template <
class _CharT,
class _Alloc>
2710 operator<=(const _Rope_const_iterator<_CharT, _Alloc>& __x,
2711 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2712 {
return !(__y < __x); }
2714 template <
class _CharT,
class _Alloc>
2716 operator>=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2717 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2718 {
return !(__x < __y); }
2720 template <
class _CharT,
class _Alloc>
2722 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2723 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2724 {
return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; }
2726 template <
class _CharT,
class _Alloc>
2727 inline _Rope_const_iterator<_CharT, _Alloc>
2728 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n)
2729 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2730 __x._M_current_pos - __n); }
2732 template <
class _CharT,
class _Alloc>
2733 inline _Rope_const_iterator<_CharT, _Alloc>
2734 operator+(
const _Rope_const_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n)
2735 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2736 __x._M_current_pos + __n); }
2738 template <
class _CharT,
class _Alloc>
2739 inline _Rope_const_iterator<_CharT, _Alloc>
2740 operator+(ptrdiff_t __n,
const _Rope_const_iterator<_CharT, _Alloc>& __x)
2741 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2742 __x._M_current_pos + __n); }
2744 template <
class _CharT,
class _Alloc>
2746 operator==(
const _Rope_iterator<_CharT, _Alloc>& __x,
2747 const _Rope_iterator<_CharT, _Alloc>& __y)
2748 {
return (__x._M_current_pos == __y._M_current_pos
2749 && __x._M_root_rope == __y._M_root_rope); }
2751 template <
class _CharT,
class _Alloc>
2753 operator<(const _Rope_iterator<_CharT, _Alloc>& __x,
2754 const _Rope_iterator<_CharT, _Alloc>& __y)
2755 {
return (__x._M_current_pos < __y._M_current_pos); }
2757 template <
class _CharT,
class _Alloc>
2759 operator!=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2760 const _Rope_iterator<_CharT, _Alloc>& __y)
2761 {
return !(__x == __y); }
2763 template <
class _CharT,
class _Alloc>
2765 operator>(
const _Rope_iterator<_CharT, _Alloc>& __x,
2766 const _Rope_iterator<_CharT, _Alloc>& __y)
2767 {
return __y < __x; }
2769 template <
class _CharT,
class _Alloc>
2771 operator<=(const _Rope_iterator<_CharT, _Alloc>& __x,
2772 const _Rope_iterator<_CharT, _Alloc>& __y)
2773 {
return !(__y < __x); }
2775 template <
class _CharT,
class _Alloc>
2777 operator>=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2778 const _Rope_iterator<_CharT, _Alloc>& __y)
2779 {
return !(__x < __y); }
2781 template <
class _CharT,
class _Alloc>
2783 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
2784 const _Rope_iterator<_CharT, _Alloc>& __y)
2785 {
return ((ptrdiff_t)__x._M_current_pos
2786 - (ptrdiff_t)__y._M_current_pos); }
2788 template <
class _CharT,
class _Alloc>
2789 inline _Rope_iterator<_CharT, _Alloc>
2790 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
2792 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2793 __x._M_current_pos - __n); }
2795 template <
class _CharT,
class _Alloc>
2796 inline _Rope_iterator<_CharT, _Alloc>
2797 operator+(
const _Rope_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n)
2798 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2799 __x._M_current_pos + __n); }
2801 template <
class _CharT,
class _Alloc>
2802 inline _Rope_iterator<_CharT, _Alloc>
2803 operator+(ptrdiff_t __n,
const _Rope_iterator<_CharT, _Alloc>& __x)
2804 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2805 __x._M_current_pos + __n); }
2807 template <
class _CharT,
class _Alloc>
2808 inline rope<_CharT, _Alloc>
2809 operator+(
const rope<_CharT, _Alloc>& __left,
2810 const rope<_CharT, _Alloc>& __right)
2814 typedef rope<_CharT, _Alloc> rope_type;
2815 return rope_type(rope_type::_S_concat(__left._M_tree_ptr,
2816 __right._M_tree_ptr));
2819 template <
class _CharT,
class _Alloc>
2820 inline rope<_CharT, _Alloc>&
2821 operator+=(rope<_CharT, _Alloc>& __left,
2822 const rope<_CharT, _Alloc>& __right)
2824 __left.append(__right);
2828 template <
class _CharT,
class _Alloc>
2829 inline rope<_CharT, _Alloc>
2830 operator+(
const rope<_CharT, _Alloc>& __left,
2831 const _CharT* __right)
2833 typedef rope<_CharT, _Alloc> rope_type;
2834 size_t __rlen = rope_type::_S_char_ptr_len(__right);
2835 return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
2839 template <
class _CharT,
class _Alloc>
2840 inline rope<_CharT, _Alloc>&
2841 operator+=(rope<_CharT, _Alloc>& __left,
2842 const _CharT* __right)
2844 __left.append(__right);
2848 template <
class _CharT,
class _Alloc>
2849 inline rope<_CharT, _Alloc>
2850 operator+(
const rope<_CharT, _Alloc>& __left, _CharT __right)
2852 typedef rope<_CharT, _Alloc> rope_type;
2853 return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
2857 template <
class _CharT,
class _Alloc>
2858 inline rope<_CharT, _Alloc>&
2859 operator+=(rope<_CharT, _Alloc>& __left, _CharT __right)
2861 __left.append(__right);
2865 template <
class _CharT,
class _Alloc>
2867 operator<(const rope<_CharT, _Alloc>& __left,
2868 const rope<_CharT, _Alloc>& __right)
2869 {
return __left.compare(__right) < 0; }
2871 template <
class _CharT,
class _Alloc>
2873 operator==(
const rope<_CharT, _Alloc>& __left,
2874 const rope<_CharT, _Alloc>& __right)
2875 {
return __left.compare(__right) == 0; }
2877 template <
class _CharT,
class _Alloc>
2879 operator==(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
2880 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y)
2881 {
return (__x._M_pos == __y._M_pos && __x._M_root == __y._M_root); }
2883 template <
class _CharT,
class _Alloc>
2885 operator!=(
const rope<_CharT, _Alloc>& __x,
2886 const rope<_CharT, _Alloc>& __y)
2887 {
return !(__x == __y); }
2889 template <
class _CharT,
class _Alloc>
2891 operator>(
const rope<_CharT, _Alloc>& __x,
2892 const rope<_CharT, _Alloc>& __y)
2893 {
return __y < __x; }
2895 template <
class _CharT,
class _Alloc>
2897 operator<=(const rope<_CharT, _Alloc>& __x,
2898 const rope<_CharT, _Alloc>& __y)
2899 {
return !(__y < __x); }
2901 template <
class _CharT,
class _Alloc>
2903 operator>=(
const rope<_CharT, _Alloc>& __x,
2904 const rope<_CharT, _Alloc>& __y)
2905 {
return !(__x < __y); }
2907 template <
class _CharT,
class _Alloc>
2909 operator!=(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
2910 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y)
2911 {
return !(__x == __y); }
2913 template<
class _CharT,
class _Traits,
class _Alloc>
2915 operator<<(std::basic_ostream<_CharT, _Traits>& __o,
2916 const rope<_CharT, _Alloc>& __r);
2918 typedef rope<char> crope;
2919 typedef rope<wchar_t> wrope;
2921 inline crope::reference
2922 __mutable_reference_at(crope& __c,
size_t __i)
2923 {
return __c.mutable_reference_at(__i); }
2925 inline wrope::reference
2926 __mutable_reference_at(wrope& __c,
size_t __i)
2927 {
return __c.mutable_reference_at(__i); }
2929 template <
class _CharT,
class _Alloc>
2931 swap(rope<_CharT, _Alloc>& __x, rope<_CharT, _Alloc>& __y)
2934 _GLIBCXX_END_NAMESPACE_VERSION
2938 namespace std _GLIBCXX_VISIBILITY(default)
2942 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2945 struct hash<__gnu_cxx::crope>
2950 size_t __size = __str.size();
2953 return 13 * __str[0] + 5 * __str[__size - 1] + __size;
2959 struct hash<__gnu_cxx::wrope>
2964 size_t __size = __str.size();
2967 return 13 * __str[0] + 5 * __str[__size - 1] + __size;
2971 _GLIBCXX_END_NAMESPACE_VERSION
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
The standard allocator, as per [20.4].
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __predicate)
Search a sequence for a matching sub-sequence using a predicate.
void _Destroy(_Tp *__pointer)
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
pair< _InputIter, _ForwardIter > uninitialized_copy_n(_InputIter __first, _Size __count, _ForwardIter __result)
Copies the range [first,last) into result.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initilizer_list.
reference operator[](size_t __position)
Array-indexing support.
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
basic_ostream< _CharT, _Traits > & flush(basic_ostream< _CharT, _Traits > &__os)
Flushes the output stream.
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) _GLIBCXX_NOEXCEPT
Global bitwise operations on bitsets.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initilizer_list.
constexpr size_t size() const _GLIBCXX_NOEXCEPT
Returns the total number of bits.