46 #pragma GCC system_header
55 #include <bits/gthr.h>
57 #include <tr1/functional>
60 # define __GC_CONST const
67 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
69 _GLIBCXX_BEGIN_NAMESPACE_VERSION
73 enum { _S_max_rope_depth = 45 };
74 enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
78 template<
typename _ForwardIterator,
typename _Allocator>
80 _Destroy_const(_ForwardIterator __first,
81 _ForwardIterator __last, _Allocator __alloc)
83 for (; __first != __last; ++__first)
84 __alloc.destroy(&*__first);
87 template<
typename _ForwardIterator,
typename _Tp>
89 _Destroy_const(_ForwardIterator __first,
98 template <
class _CharT>
105 template <
class _CharT>
107 _S_is_basic_char_type(_CharT*)
110 template <
class _CharT>
112 _S_is_one_byte_char_type(_CharT*)
116 _S_is_basic_char_type(
char*)
120 _S_is_one_byte_char_type(
char*)
124 _S_is_basic_char_type(
wchar_t*)
129 template <
class _CharT>
131 _S_cond_store_eos(_CharT&) { }
134 _S_cond_store_eos(
char& __c)
138 _S_cond_store_eos(
wchar_t& __c)
145 template <
class _CharT>
149 virtual ~char_producer() { }
152 operator()(std::size_t __start_pos, std::size_t __len,
153 _CharT* __buffer) = 0;
174 template<
class _Sequence, std::
size_t _Buf_sz = 100>
175 class sequence_buffer
176 :
public std::iterator<std::output_iterator_tag, void, void, void, void>
179 typedef typename _Sequence::value_type value_type;
181 _Sequence* _M_prefix;
182 value_type _M_buffer[_Buf_sz];
183 std::size_t _M_buf_count;
189 _M_prefix->append(_M_buffer, _M_buffer + _M_buf_count);
197 : _M_prefix(0), _M_buf_count(0) { }
199 sequence_buffer(
const sequence_buffer& __x)
201 _M_prefix = __x._M_prefix;
202 _M_buf_count = __x._M_buf_count;
203 std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
207 sequence_buffer(sequence_buffer& __x)
210 _M_prefix = __x._M_prefix;
214 sequence_buffer(_Sequence& __s)
215 : _M_prefix(&__s), _M_buf_count(0) { }
219 operator=(sequence_buffer& __x)
222 _M_prefix = __x._M_prefix;
228 operator=(
const sequence_buffer& __x)
230 _M_prefix = __x._M_prefix;
231 _M_buf_count = __x._M_buf_count;
232 std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
236 #if __cplusplus >= 201103L
237 sequence_buffer(sequence_buffer&& __x) : sequence_buffer(__x) { }
238 sequence_buffer& operator=(sequence_buffer&& __x) {
return *
this = __x; }
242 push_back(value_type __x)
244 if (_M_buf_count < _Buf_sz)
246 _M_buffer[_M_buf_count] = __x;
258 append(value_type* __s, std::size_t __len)
260 if (__len + _M_buf_count <= _Buf_sz)
262 std::size_t __i = _M_buf_count;
263 for (std::size_t __j = 0; __j < __len; __i++, __j++)
264 _M_buffer[__i] = __s[__j];
265 _M_buf_count += __len;
267 else if (0 == _M_buf_count)
268 _M_prefix->append(__s, __s + __len);
277 write(value_type* __s, std::size_t __len)
291 operator=(
const value_type& __rhs)
311 template<
class _CharT>
312 class _Rope_char_consumer
320 virtual ~_Rope_char_consumer() { }
323 operator()(
const _CharT* __buffer, std::size_t __len) = 0;
329 template<
class _CharT,
class _Alloc = std::allocator<_CharT> >
332 template<
class _CharT,
class _Alloc>
333 struct _Rope_RopeConcatenation;
335 template<
class _CharT,
class _Alloc>
336 struct _Rope_RopeLeaf;
338 template<
class _CharT,
class _Alloc>
339 struct _Rope_RopeFunction;
341 template<
class _CharT,
class _Alloc>
342 struct _Rope_RopeSubstring;
344 template<
class _CharT,
class _Alloc>
345 class _Rope_iterator;
347 template<
class _CharT,
class _Alloc>
348 class _Rope_const_iterator;
350 template<
class _CharT,
class _Alloc>
351 class _Rope_char_ref_proxy;
353 template<
class _CharT,
class _Alloc>
354 class _Rope_char_ptr_proxy;
356 template<
class _CharT,
class _Alloc>
358 operator==(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
359 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y);
361 template<
class _CharT,
class _Alloc>
362 _Rope_const_iterator<_CharT, _Alloc>
363 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
366 template<
class _CharT,
class _Alloc>
367 _Rope_const_iterator<_CharT, _Alloc>
368 operator+(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
371 template<
class _CharT,
class _Alloc>
372 _Rope_const_iterator<_CharT, _Alloc>
374 const _Rope_const_iterator<_CharT, _Alloc>& __x);
376 template<
class _CharT,
class _Alloc>
378 operator==(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
379 const _Rope_const_iterator<_CharT, _Alloc>& __y);
381 template<
class _CharT,
class _Alloc>
383 operator<(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
384 const _Rope_const_iterator<_CharT, _Alloc>& __y);
386 template<
class _CharT,
class _Alloc>
388 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
389 const _Rope_const_iterator<_CharT, _Alloc>& __y);
391 template<
class _CharT,
class _Alloc>
392 _Rope_iterator<_CharT, _Alloc>
393 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x, std::ptrdiff_t __n);
395 template<
class _CharT,
class _Alloc>
396 _Rope_iterator<_CharT, _Alloc>
397 operator+(
const _Rope_iterator<_CharT, _Alloc>& __x, std::ptrdiff_t __n);
399 template<
class _CharT,
class _Alloc>
400 _Rope_iterator<_CharT, _Alloc>
401 operator+(std::ptrdiff_t __n,
const _Rope_iterator<_CharT, _Alloc>& __x);
403 template<
class _CharT,
class _Alloc>
405 operator==(
const _Rope_iterator<_CharT, _Alloc>& __x,
406 const _Rope_iterator<_CharT, _Alloc>& __y);
408 template<
class _CharT,
class _Alloc>
410 operator<(
const _Rope_iterator<_CharT, _Alloc>& __x,
411 const _Rope_iterator<_CharT, _Alloc>& __y);
413 template<
class _CharT,
class _Alloc>
415 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
416 const _Rope_iterator<_CharT, _Alloc>& __y);
418 template<
class _CharT,
class _Alloc>
420 operator+(
const rope<_CharT, _Alloc>& __left,
421 const rope<_CharT, _Alloc>& __right);
423 template<
class _CharT,
class _Alloc>
425 operator+(
const rope<_CharT, _Alloc>& __left,
const _CharT* __right);
427 template<
class _CharT,
class _Alloc>
429 operator+(
const rope<_CharT, _Alloc>& __left, _CharT __right);
436 template<
class _CharT,
class _Alloc>
437 struct _Rope_Concat_fn
439 rope<_CharT, _Alloc> >
442 operator()(
const rope<_CharT, _Alloc>& __x,
443 const rope<_CharT, _Alloc>& __y)
444 {
return __x + __y; }
447 template <
class _CharT,
class _Alloc>
448 inline rope<_CharT, _Alloc>
449 identity_element(_Rope_Concat_fn<_CharT, _Alloc>)
450 {
return rope<_CharT, _Alloc>(); }
456 struct _Refcount_Base
459 typedef std::size_t _RC_t;
465 #ifdef __GTHREAD_MUTEX_INIT
466 __gthread_mutex_t _M_ref_count_lock = __GTHREAD_MUTEX_INIT;
468 __gthread_mutex_t _M_ref_count_lock;
471 _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
473 #ifndef __GTHREAD_MUTEX_INIT
474 #ifdef __GTHREAD_MUTEX_INIT_FUNCTION
475 __GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock);
477 #error __GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org.
482 #ifndef __GTHREAD_MUTEX_INIT
484 { __gthread_mutex_destroy(&_M_ref_count_lock); }
490 __gthread_mutex_lock(&_M_ref_count_lock);
492 __gthread_mutex_unlock(&_M_ref_count_lock);
498 __gthread_mutex_lock(&_M_ref_count_lock);
499 _RC_t __tmp = --_M_ref_count;
500 __gthread_mutex_unlock(&_M_ref_count_lock);
530 #define __ROPE_DEFINE_ALLOCS(__a) \
531 __ROPE_DEFINE_ALLOC(_CharT,_Data) \
532 typedef _Rope_RopeConcatenation<_CharT,__a> __C; \
533 __ROPE_DEFINE_ALLOC(__C,_C) \
534 typedef _Rope_RopeLeaf<_CharT,__a> __L; \
535 __ROPE_DEFINE_ALLOC(__L,_L) \
536 typedef _Rope_RopeFunction<_CharT,__a> __F; \
537 __ROPE_DEFINE_ALLOC(__F,_F) \
538 typedef _Rope_RopeSubstring<_CharT,__a> __S; \
539 __ROPE_DEFINE_ALLOC(__S,_S)
548 #define __STATIC_IF_SGI_ALLOC
550 template <
class _CharT,
class _Alloc>
551 struct _Rope_rep_base
554 typedef std::size_t size_type;
555 typedef _Alloc allocator_type;
558 get_allocator()
const
559 {
return *
static_cast<const _Alloc*
>(
this); }
563 {
return *
static_cast<_Alloc*
>(
this); }
565 const allocator_type&
566 _M_get_allocator()
const
567 {
return *
static_cast<const _Alloc*
>(
this); }
569 _Rope_rep_base(size_type __size,
const allocator_type&)
570 : _M_size(__size) { }
574 # define __ROPE_DEFINE_ALLOC(_Tp, __name) \
576 __alloc_traits<_Alloc>::template rebind<_Tp>::other __name##Alloc; \
577 static _Tp* __name##_allocate(size_type __n) \
578 { return __name##Alloc().allocate(__n); } \
579 static void __name##_deallocate(_Tp *__p, size_type __n) \
580 { __name##Alloc().deallocate(__p, __n); }
581 __ROPE_DEFINE_ALLOCS(_Alloc)
582 # undef __ROPE_DEFINE_ALLOC
585 template<
class _CharT,
class _Alloc>
587 :
public _Rope_rep_base<_CharT, _Alloc>
593 __detail::_Tag _M_tag:8;
594 bool _M_is_balanced:8;
595 unsigned char _M_depth;
596 __GC_CONST _CharT* _M_c_string;
597 #ifdef __GTHREAD_MUTEX_INIT
598 __gthread_mutex_t _M_c_string_lock = __GTHREAD_MUTEX_INIT;
600 __gthread_mutex_t _M_c_string_lock;
608 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
610 typedef std::size_t size_type;
612 using _Rope_rep_base<_CharT, _Alloc>::get_allocator;
613 using _Rope_rep_base<_CharT, _Alloc>::_M_get_allocator;
615 _Rope_RopeRep(__detail::_Tag __t,
int __d,
bool __b, size_type __size,
616 const allocator_type& __a)
617 : _Rope_rep_base<_CharT, _Alloc>(__size, __a),
621 _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0)
622 #ifdef __GTHREAD_MUTEX_INIT
625 { __GTHREAD_MUTEX_INIT_FUNCTION (&_M_c_string_lock); }
627 { __gthread_mutex_destroy (&_M_c_string_lock); }
634 _S_free_string(__GC_CONST _CharT*, size_type __len,
635 allocator_type& __a);
636 #define __STL_FREE_STRING(__s, __l, __a) _S_free_string(__s, __l, __a);
644 void _M_free_c_string();
659 _S_unref(_Rope_RopeRep* __t)
662 __t->_M_unref_nonnil();
666 _S_ref(_Rope_RopeRep* __t)
673 _S_free_if_unref(_Rope_RopeRep* __t)
675 if (0 != __t && 0 == __t->_M_ref_count)
679 void _M_unref_nonnil() { }
680 void _M_ref_nonnil() { }
681 static void _S_unref(_Rope_RopeRep*) { }
682 static void _S_ref(_Rope_RopeRep*) { }
683 static void _S_free_if_unref(_Rope_RopeRep*) { }
687 operator=(
const _Rope_RopeRep&);
689 _Rope_RopeRep(
const _Rope_RopeRep&);
692 template<
class _CharT,
class _Alloc>
693 struct _Rope_RopeLeaf
694 :
public _Rope_RopeRep<_CharT, _Alloc>
696 typedef std::size_t size_type;
702 enum { _S_alloc_granularity = 8 };
705 _S_rounded_up_size(size_type __n)
707 size_type __size_with_eos;
709 if (_S_is_basic_char_type((_CharT*)0))
710 __size_with_eos = __n + 1;
712 __size_with_eos = __n;
714 return __size_with_eos;
717 return ((__size_with_eos + size_type(_S_alloc_granularity) - 1)
718 &~ (size_type(_S_alloc_granularity) - 1));
721 __GC_CONST _CharT* _M_data;
726 typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
729 _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_type __size,
730 const allocator_type& __a)
731 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_leaf, 0, true,
732 __size, __a), _M_data(__d)
734 if (_S_is_basic_char_type((_CharT *)0))
737 this->_M_c_string = __d;
744 ~_Rope_RopeLeaf() throw()
746 if (_M_data != this->_M_c_string)
747 this->_M_free_c_string();
749 this->__STL_FREE_STRING(_M_data, this->_M_size, this->_M_get_allocator());
754 operator=(
const _Rope_RopeLeaf&);
756 _Rope_RopeLeaf(
const _Rope_RopeLeaf&);
759 template<
class _CharT,
class _Alloc>
760 struct _Rope_RopeConcatenation
761 :
public _Rope_RopeRep<_CharT, _Alloc>
764 _Rope_RopeRep<_CharT, _Alloc>* _M_left;
765 _Rope_RopeRep<_CharT, _Alloc>* _M_right;
767 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
770 _Rope_RopeConcatenation(_Rope_RopeRep<_CharT, _Alloc>* __l,
771 _Rope_RopeRep<_CharT, _Alloc>* __r,
772 const allocator_type& __a)
773 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_concat,
774 std::max(__l->_M_depth,
777 __l->_M_size + __r->_M_size, __a),
778 _M_left(__l), _M_right(__r)
781 ~_Rope_RopeConcatenation() throw()
783 this->_M_free_c_string();
784 _M_left->_M_unref_nonnil();
785 _M_right->_M_unref_nonnil();
789 _Rope_RopeConcatenation&
790 operator=(
const _Rope_RopeConcatenation&);
792 _Rope_RopeConcatenation(
const _Rope_RopeConcatenation&);
795 template<
class _CharT,
class _Alloc>
796 struct _Rope_RopeFunction
797 :
public _Rope_RopeRep<_CharT, _Alloc>
800 char_producer<_CharT>* _M_fn;
802 bool _M_delete_when_done;
813 _S_fn_finalization_proc(
void * __tree,
void *)
814 {
delete ((_Rope_RopeFunction *)__tree) -> _M_fn; }
816 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
819 _Rope_RopeFunction(char_producer<_CharT>* __f, std::size_t __size,
820 bool __d,
const allocator_type& __a)
821 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_function, 0, true, __size, __a)
824 , _M_delete_when_done(__d)
830 GC_REGISTER_FINALIZER(
this, _Rope_RopeFunction::
831 _S_fn_finalization_proc, 0, 0, 0);
836 ~_Rope_RopeFunction() throw()
838 this->_M_free_c_string();
839 if (_M_delete_when_done)
845 operator=(
const _Rope_RopeFunction&);
847 _Rope_RopeFunction(
const _Rope_RopeFunction&);
856 template<
class _CharT,
class _Alloc>
857 struct _Rope_RopeSubstring
858 :
public _Rope_RopeFunction<_CharT, _Alloc>,
859 public char_producer<_CharT>
861 typedef std::size_t size_type;
864 _Rope_RopeRep<_CharT,_Alloc>* _M_base;
868 operator()(size_type __start_pos, size_type __req_len,
871 switch(_M_base->_M_tag)
873 case __detail::_S_function:
874 case __detail::_S_substringfn:
876 char_producer<_CharT>* __fn =
877 ((_Rope_RopeFunction<_CharT,_Alloc>*)_M_base)->_M_fn;
878 (*__fn)(__start_pos + _M_start, __req_len, __buffer);
881 case __detail::_S_leaf:
883 __GC_CONST _CharT* __s =
884 ((_Rope_RopeLeaf<_CharT,_Alloc>*)_M_base)->_M_data;
894 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
897 _Rope_RopeSubstring(_Rope_RopeRep<_CharT, _Alloc>* __b, size_type __s,
898 size_type __l,
const allocator_type& __a)
899 : _Rope_RopeFunction<_CharT, _Alloc>(this, __l, false, __a),
900 char_producer<_CharT>(), _M_base(__b), _M_start(__s)
903 _M_base->_M_ref_nonnil();
905 this->_M_tag = __detail::_S_substringfn;
907 virtual ~_Rope_RopeSubstring() throw()
910 _M_base->_M_unref_nonnil();
926 template<
class _CharT,
class _Alloc>
927 struct _Rope_self_destruct_ptr
929 _Rope_RopeRep<_CharT, _Alloc>* _M_ptr;
931 ~_Rope_self_destruct_ptr()
932 { _Rope_RopeRep<_CharT, _Alloc>::_S_unref(_M_ptr); }
934 _Rope_self_destruct_ptr() : _M_ptr(0) { }
936 _Rope_self_destruct_ptr() { }
938 _Rope_self_destruct_ptr(_Rope_RopeRep<_CharT, _Alloc>* __p)
941 _Rope_RopeRep<_CharT, _Alloc>&
945 _Rope_RopeRep<_CharT, _Alloc>*
949 operator _Rope_RopeRep<_CharT, _Alloc>*()
952 _Rope_self_destruct_ptr&
953 operator=(_Rope_RopeRep<_CharT, _Alloc>* __x)
954 { _M_ptr = __x;
return *
this; }
963 template<
class _CharT,
class _Alloc>
964 class _Rope_char_ref_proxy
966 friend class rope<_CharT, _Alloc>;
967 friend class _Rope_iterator<_CharT, _Alloc>;
968 friend class _Rope_char_ptr_proxy<_CharT, _Alloc>;
970 typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr;
972 typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr;
974 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
975 typedef rope<_CharT, _Alloc> _My_rope;
978 bool _M_current_valid;
981 _Rope_char_ref_proxy(_My_rope* __r, std::size_t __p)
982 : _M_pos(__p), _M_current(), _M_current_valid(false), _M_root(__r) { }
984 _Rope_char_ref_proxy(
const _Rope_char_ref_proxy& __x)
985 : _M_pos(__x._M_pos), _M_current(__x._M_current),
986 _M_current_valid(false), _M_root(__x._M_root) { }
992 _Rope_char_ref_proxy(_My_rope* __r, std::size_t __p, _CharT __c)
993 : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) { }
995 inline operator _CharT ()
const;
997 _Rope_char_ref_proxy&
998 operator=(_CharT __c);
1000 _Rope_char_ptr_proxy<_CharT, _Alloc>
operator&()
const;
1002 _Rope_char_ref_proxy&
1003 operator=(
const _Rope_char_ref_proxy& __c)
1004 {
return operator=((_CharT)__c); }
1007 template<
class _CharT,
class __Alloc>
1009 swap(_Rope_char_ref_proxy <_CharT, __Alloc > __a,
1010 _Rope_char_ref_proxy <_CharT, __Alloc > __b)
1017 template<
class _CharT,
class _Alloc>
1018 class _Rope_char_ptr_proxy
1021 friend class _Rope_char_ref_proxy<_CharT, _Alloc>;
1023 rope<_CharT,_Alloc>* _M_root;
1025 _Rope_char_ptr_proxy(
const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
1026 : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
1028 _Rope_char_ptr_proxy(
const _Rope_char_ptr_proxy& __x)
1029 : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
1031 _Rope_char_ptr_proxy() { }
1033 _Rope_char_ptr_proxy(_CharT* __x)
1034 : _M_root(0), _M_pos(0) { }
1036 _Rope_char_ptr_proxy&
1037 operator=(
const _Rope_char_ptr_proxy& __x)
1039 _M_pos = __x._M_pos;
1040 _M_root = __x._M_root;
1044 template<
class _CharT2,
class _Alloc2>
1046 operator==(
const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __x,
1047 const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __y);
1049 _Rope_char_ref_proxy<_CharT, _Alloc>
operator*()
const
1050 {
return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root, _M_pos); }
1062 template<
class _CharT,
class _Alloc>
1063 class _Rope_iterator_base
1064 :
public std::iterator<std::random_access_iterator_tag, _CharT>
1066 friend class rope<_CharT, _Alloc>;
1068 typedef _Alloc _allocator_type;
1069 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1072 enum { _S_path_cache_len = 4 };
1073 enum { _S_iterator_buf_len = 15 };
1074 std::size_t _M_current_pos;
1076 std::size_t _M_leaf_pos;
1077 __GC_CONST _CharT* _M_buf_start;
1080 __GC_CONST _CharT* _M_buf_ptr;
1083 __GC_CONST _CharT* _M_buf_end;
1089 const _RopeRep* _M_path_end[_S_path_cache_len];
1093 unsigned char _M_path_directions;
1098 _CharT _M_tmp_buf[_S_iterator_buf_len];
1106 static void _S_setbuf(_Rope_iterator_base& __x);
1109 static void _S_setcache(_Rope_iterator_base& __x);
1112 static void _S_setcache_for_incr(_Rope_iterator_base& __x);
1115 _Rope_iterator_base() { }
1117 _Rope_iterator_base(_RopeRep* __root, std::size_t __pos)
1118 : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) { }
1120 void _M_incr(std::size_t __n);
1121 void _M_decr(std::size_t __n);
1125 {
return _M_current_pos; }
1127 _Rope_iterator_base(
const _Rope_iterator_base& __x)
1129 if (0 != __x._M_buf_ptr && __x._M_buf_start != __x._M_tmp_buf)
1133 _M_current_pos = __x._M_current_pos;
1134 _M_root = __x._M_root;
1140 template<
class _CharT,
class _Alloc>
1141 class _Rope_iterator;
1143 template<
class _CharT,
class _Alloc>
1144 class _Rope_const_iterator
1145 :
public _Rope_iterator_base<_CharT, _Alloc>
1147 friend class rope<_CharT, _Alloc>;
1149 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1151 _Rope_const_iterator(
const _RopeRep* __root, std::size_t __pos)
1152 : _Rope_iterator_base<_CharT, _Alloc>(const_cast<_RopeRep*>(__root),
1157 typedef _CharT reference;
1160 typedef const _CharT* pointer;
1163 _Rope_const_iterator() { }
1165 _Rope_const_iterator(
const _Rope_const_iterator& __x)
1166 : _Rope_iterator_base<_CharT,_Alloc>(__x) { }
1168 _Rope_const_iterator(
const _Rope_iterator<_CharT,_Alloc>& __x);
1170 _Rope_const_iterator(
const rope<_CharT, _Alloc>& __r, std::size_t __pos)
1171 : _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr, __pos) { }
1173 _Rope_const_iterator&
1174 operator=(
const _Rope_const_iterator& __x)
1176 if (0 != __x._M_buf_ptr && __x._M_buf_start != __x._M_tmp_buf)
1177 *(
static_cast<_Rope_iterator_base<_CharT, _Alloc>*
>(
this)) = __x;
1180 this->_M_current_pos = __x._M_current_pos;
1181 this->_M_root = __x._M_root;
1182 this->_M_buf_ptr = 0;
1190 if (0 == this->_M_buf_ptr)
1191 this->_S_setcache(*
this);
1192 return *this->_M_buf_ptr;
1200 return *
const_cast<_Rope_const_iterator&
>(*this);
1203 _Rope_const_iterator&
1206 __GC_CONST _CharT* __next;
1207 if (0 != this->_M_buf_ptr
1208 && (__next = this->_M_buf_ptr + 1) < this->_M_buf_end)
1210 this->_M_buf_ptr = __next;
1211 ++this->_M_current_pos;
1218 _Rope_const_iterator&
1219 operator+=(std::ptrdiff_t __n)
1224 this->_M_decr(-__n);
1228 _Rope_const_iterator&
1235 _Rope_const_iterator&
1236 operator-=(std::ptrdiff_t __n)
1241 this->_M_incr(-__n);
1245 _Rope_const_iterator
1248 std::size_t __old_pos = this->_M_current_pos;
1250 return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
1256 _Rope_const_iterator
1259 std::size_t __old_pos = this->_M_current_pos;
1261 return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
1264 template<
class _CharT2,
class _Alloc2>
1265 friend _Rope_const_iterator<_CharT2, _Alloc2>
1266 operator-(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1267 std::ptrdiff_t __n);
1269 template<
class _CharT2,
class _Alloc2>
1270 friend _Rope_const_iterator<_CharT2, _Alloc2>
1271 operator+(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1272 std::ptrdiff_t __n);
1274 template<
class _CharT2,
class _Alloc2>
1275 friend _Rope_const_iterator<_CharT2, _Alloc2>
1277 const _Rope_const_iterator<_CharT2, _Alloc2>& __x);
1280 operator[](std::size_t __n)
1281 {
return rope<_CharT, _Alloc>::_S_fetch(this->_M_root,
1282 this->_M_current_pos + __n); }
1284 template<
class _CharT2,
class _Alloc2>
1286 operator==(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1287 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1289 template<
class _CharT2,
class _Alloc2>
1291 operator<(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1292 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1294 template<
class _CharT2,
class _Alloc2>
1295 friend std::ptrdiff_t
1296 operator-(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1297 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1300 template<
class _CharT,
class _Alloc>
1301 class _Rope_iterator
1302 :
public _Rope_iterator_base<_CharT, _Alloc>
1304 friend class rope<_CharT, _Alloc>;
1306 typedef typename _Rope_iterator_base<_CharT, _Alloc>::_RopeRep _RopeRep;
1307 rope<_CharT, _Alloc>* _M_root_rope;
1315 _Rope_iterator(rope<_CharT, _Alloc>* __r, std::size_t __pos)
1316 : _Rope_iterator_base<_CharT, _Alloc>(__r->_M_tree_ptr, __pos),
1318 { _RopeRep::_S_ref(this->_M_root);
1319 if (!(__r -> empty()))
1320 this->_S_setcache(*
this);
1325 typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
1326 typedef _Rope_char_ref_proxy<_CharT, _Alloc>* pointer;
1328 rope<_CharT, _Alloc>&
1330 {
return *_M_root_rope; }
1337 _Rope_iterator(
const _Rope_iterator& __x)
1338 : _Rope_iterator_base<_CharT, _Alloc>(__x)
1340 _M_root_rope = __x._M_root_rope;
1341 _RopeRep::_S_ref(this->_M_root);
1344 _Rope_iterator(rope<_CharT, _Alloc>& __r, std::size_t __pos);
1347 { _RopeRep::_S_unref(this->_M_root); }
1350 operator=(
const _Rope_iterator& __x)
1352 _RopeRep* __old = this->_M_root;
1354 _RopeRep::_S_ref(__x._M_root);
1355 if (0 != __x._M_buf_ptr && __x._M_buf_start != __x._M_tmp_buf)
1357 _M_root_rope = __x._M_root_rope;
1358 *(
static_cast<_Rope_iterator_base<_CharT, _Alloc>*
>(
this)) = __x;
1362 this->_M_current_pos = __x._M_current_pos;
1363 this->_M_root = __x._M_root;
1364 _M_root_rope = __x._M_root_rope;
1365 this->_M_buf_ptr = 0;
1367 _RopeRep::_S_unref(__old);
1375 if (0 == this->_M_buf_ptr)
1376 return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1377 this->_M_current_pos);
1379 return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1380 this->_M_current_pos,
1388 return *
const_cast<_Rope_iterator&
>(*this);
1399 operator+=(std::ptrdiff_t __n)
1404 this->_M_decr(-__n);
1416 operator-=(std::ptrdiff_t __n)
1421 this->_M_incr(-__n);
1428 std::size_t __old_pos = this->_M_current_pos;
1430 return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1436 std::size_t __old_pos = this->_M_current_pos;
1438 return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1442 operator[](std::ptrdiff_t __n)
1443 {
return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1444 this->_M_current_pos
1447 template<
class _CharT2,
class _Alloc2>
1449 operator==(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1450 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1452 template<
class _CharT2,
class _Alloc2>
1454 operator<(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1455 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1457 template<
class _CharT2,
class _Alloc2>
1458 friend std::ptrdiff_t
1459 operator-(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1460 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1462 template<
class _CharT2,
class _Alloc2>
1463 friend _Rope_iterator<_CharT2, _Alloc2>
1464 operator-(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1465 std::ptrdiff_t __n);
1467 template<
class _CharT2,
class _Alloc2>
1468 friend _Rope_iterator<_CharT2, _Alloc2>
1469 operator+(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1470 std::ptrdiff_t __n);
1472 template<
class _CharT2,
class _Alloc2>
1473 friend _Rope_iterator<_CharT2, _Alloc2>
1475 const _Rope_iterator<_CharT2, _Alloc2>& __x);
1479 template <
class _CharT,
class _Alloc>
1483 typedef _Alloc allocator_type;
1486 get_allocator()
const
1487 {
return *
static_cast<const _Alloc*
>(
this); }
1491 {
return *
static_cast<_Alloc*
>(
this); }
1493 const allocator_type&
1494 _M_get_allocator()
const
1495 {
return *
static_cast<const _Alloc*
>(
this); }
1497 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1500 _Rope_base(_RopeRep* __t,
const allocator_type&)
1501 : _M_tree_ptr(__t) { }
1503 _Rope_base(
const allocator_type&) { }
1506 _RopeRep *_M_tree_ptr;
1508 #define __ROPE_DEFINE_ALLOC(_Tp, __name) \
1510 __alloc_traits<_Alloc>::template rebind<_Tp>::other __name##Alloc; \
1511 static _Tp* __name##_allocate(std::size_t __n) \
1512 { return __name##Alloc().allocate(__n); } \
1513 static void __name##_deallocate(_Tp *__p, std::size_t __n) \
1514 { __name##Alloc().deallocate(__p, __n); }
1515 __ROPE_DEFINE_ALLOCS(_Alloc)
1516 #undef __ROPE_DEFINE_ALLOC
1520 operator=(
const _Rope_base&);
1522 _Rope_base(
const _Rope_base&);
1530 template <
class _CharT,
class _Alloc>
1531 class rope :
public _Rope_base<_CharT, _Alloc>
1534 typedef _CharT value_type;
1535 typedef std::ptrdiff_t difference_type;
1536 typedef std::size_t size_type;
1537 typedef _CharT const_reference;
1538 typedef const _CharT* const_pointer;
1539 typedef _Rope_iterator<_CharT, _Alloc> iterator;
1540 typedef _Rope_const_iterator<_CharT, _Alloc> const_iterator;
1541 typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
1542 typedef _Rope_char_ptr_proxy<_CharT, _Alloc> pointer;
1544 friend class _Rope_iterator<_CharT, _Alloc>;
1545 friend class _Rope_const_iterator<_CharT, _Alloc>;
1546 friend struct _Rope_RopeRep<_CharT, _Alloc>;
1547 friend class _Rope_iterator_base<_CharT, _Alloc>;
1548 friend class _Rope_char_ptr_proxy<_CharT, _Alloc>;
1549 friend class _Rope_char_ref_proxy<_CharT, _Alloc>;
1550 friend struct _Rope_RopeSubstring<_CharT, _Alloc>;
1553 typedef _Rope_base<_CharT, _Alloc> _Base;
1554 typedef typename _Base::allocator_type allocator_type;
1555 using _Base::_M_tree_ptr;
1556 using _Base::get_allocator;
1557 using _Base::_M_get_allocator;
1558 typedef __GC_CONST _CharT* _Cstrptr;
1560 static _CharT _S_empty_c_str[1];
1564 {
return __c == _S_eos((_CharT*)0); }
1566 enum { _S_copy_max = 23 };
1570 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1571 typedef _Rope_RopeConcatenation<_CharT, _Alloc> _RopeConcatenation;
1572 typedef _Rope_RopeLeaf<_CharT, _Alloc> _RopeLeaf;
1573 typedef _Rope_RopeFunction<_CharT, _Alloc> _RopeFunction;
1574 typedef _Rope_RopeSubstring<_CharT, _Alloc> _RopeSubstring;
1577 static _CharT _S_fetch(_RopeRep* __r, size_type __pos);
1586 static _CharT* _S_fetch_ptr(_RopeRep* __r, size_type __pos);
1591 _Rope_char_consumer<_CharT>& __c,
1592 const _RopeRep* __r,
1593 size_type __begin, size_type __end);
1598 _S_unref(_RopeRep* __t)
1599 { _RopeRep::_S_unref(__t); }
1602 _S_ref(_RopeRep* __t)
1603 { _RopeRep::_S_ref(__t); }
1606 static void _S_unref(_RopeRep*) { }
1607 static void _S_ref(_RopeRep*) { }
1611 typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr;
1613 typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr;
1617 static _RopeRep* _S_substring(_RopeRep*
__base,
1618 size_type __start, size_type __endp1);
1620 static _RopeRep* _S_concat_char_iter(_RopeRep* __r,
1621 const _CharT* __iter,
1623 allocator_type& __a);
1627 static _RopeRep* _S_destr_concat_char_iter(_RopeRep* __r,
1628 const _CharT* __iter,
1630 allocator_type& __a)
1636 {
return _S_concat_char_iter(__r, __iter, __slen, __a); }
1641 static _RopeRep* _S_concat(_RopeRep* __left, _RopeRep* __right);
1647 apply_to_pieces(size_type __begin, size_type __end,
1648 _Rope_char_consumer<_CharT>& __c)
const
1649 { _S_apply_to_pieces(__c, this->_M_tree_ptr, __begin, __end); }
1654 _S_rounded_up_size(size_type __n)
1655 {
return _RopeLeaf::_S_rounded_up_size(__n); }
1658 _S_allocated_capacity(size_type __n)
1660 if (_S_is_basic_char_type((_CharT*)0))
1661 return _S_rounded_up_size(__n) - 1;
1663 return _S_rounded_up_size(__n);
1670 _S_new_RopeLeaf(__GC_CONST _CharT *__s,
1671 size_type __size, allocator_type& __a)
1673 _RopeLeaf* __space =
typename _Base::_LAlloc(__a).allocate(1);
1674 return new(__space) _RopeLeaf(__s, __size, __a);
1677 static _RopeConcatenation*
1678 _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right,
1679 allocator_type& __a)
1681 _RopeConcatenation* __space =
typename _Base::_CAlloc(__a).allocate(1);
1682 return new(__space) _RopeConcatenation(__left, __right, __a);
1685 static _RopeFunction*
1686 _S_new_RopeFunction(char_producer<_CharT>* __f,
1687 size_type __size,
bool __d, allocator_type& __a)
1689 _RopeFunction* __space =
typename _Base::_FAlloc(__a).allocate(1);
1690 return new(__space) _RopeFunction(__f, __size, __d, __a);
1693 static _RopeSubstring*
1694 _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_type __s,
1695 size_type __l, allocator_type& __a)
1697 _RopeSubstring* __space =
typename _Base::_SAlloc(__a).allocate(1);
1698 return new(__space) _RopeSubstring(__b, __s, __l, __a);
1702 _S_RopeLeaf_from_unowned_char_ptr(
const _CharT *__s,
1703 size_type __size, allocator_type& __a)
1704 #define __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __size, __a) \
1705 _S_RopeLeaf_from_unowned_char_ptr(__s, __size, __a)
1709 _CharT* __buf = __a.allocate(_S_rounded_up_size(__size));
1711 __uninitialized_copy_n_a(__s, __size, __buf, __a);
1712 _S_cond_store_eos(__buf[__size]);
1714 {
return _S_new_RopeLeaf(__buf, __size, __a); }
1717 _RopeRep::__STL_FREE_STRING(__buf, __size, __a);
1718 __throw_exception_again;
1729 _S_tree_concat(_RopeRep* __left, _RopeRep* __right);
1733 _S_leaf_concat_char_iter(_RopeLeaf* __r,
1734 const _CharT* __iter, size_type __slen);
1740 _S_destr_leaf_concat_char_iter(_RopeLeaf* __r,
1741 const _CharT* __iter, size_type __slen);
1747 static size_type _S_char_ptr_len(
const _CharT* __s);
1750 rope(_RopeRep* __t,
const allocator_type& __a = allocator_type())
1751 : _Base(__t, __a) { }
1757 static _CharT* _S_flatten(_RopeRep* __r, _CharT* __buffer);
1761 static _CharT* _S_flatten(_RopeRep* __r,
1762 size_type __start, size_type __len,
1765 static const unsigned long
1766 _S_min_len[__detail::_S_max_rope_depth + 1];
1769 _S_is_balanced(_RopeRep* __r)
1770 {
return (__r->_M_size >= _S_min_len[__r->_M_depth]); }
1773 _S_is_almost_balanced(_RopeRep* __r)
1774 {
return (__r->_M_depth == 0
1775 || __r->_M_size >= _S_min_len[__r->_M_depth - 1]); }
1778 _S_is_roughly_balanced(_RopeRep* __r)
1779 {
return (__r->_M_depth <= 1
1780 || __r->_M_size >= _S_min_len[__r->_M_depth - 2]); }
1784 _S_concat_and_set_balanced(_RopeRep* __left, _RopeRep* __right)
1786 _RopeRep* __result = _S_concat(__left, __right);
1787 if (_S_is_balanced(__result))
1788 __result->_M_is_balanced =
true;
1797 static _RopeRep* _S_balance(_RopeRep* __r);
1801 static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest);
1804 static void _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest);
1807 static void _S_dump(_RopeRep* __r,
int __indent = 0);
1810 static int _S_compare(
const _RopeRep* __x,
const _RopeRep* __y);
1813 _GLIBCXX_NODISCARD
bool
1815 {
return 0 == this->_M_tree_ptr; }
1821 compare(
const rope& __y)
const
1822 {
return _S_compare(this->_M_tree_ptr, __y._M_tree_ptr); }
1824 rope(
const _CharT* __s,
const allocator_type& __a = allocator_type())
1828 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s),
1829 _M_get_allocator());
1832 rope(
const _CharT* __s, size_type __len,
1833 const allocator_type& __a = allocator_type())
1837 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, _M_get_allocator());
1843 rope(
const _CharT* __s,
const _CharT* __e,
1844 const allocator_type& __a = allocator_type())
1848 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, _M_get_allocator());
1851 rope(
const const_iterator& __s,
const const_iterator& __e,
1852 const allocator_type& __a = allocator_type())
1853 : _Base(_S_substring(__s._M_root, __s._M_current_pos,
1854 __e._M_current_pos), __a)
1857 rope(
const iterator& __s,
const iterator& __e,
1858 const allocator_type& __a = allocator_type())
1859 : _Base(_S_substring(__s._M_root, __s._M_current_pos,
1860 __e._M_current_pos), __a)
1863 rope(_CharT __c,
const allocator_type& __a = allocator_type())
1866 _CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1));
1872 this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1,
1873 _M_get_allocator());
1877 _RopeRep::__STL_FREE_STRING(__buf, 1, _M_get_allocator());
1878 __throw_exception_again;
1882 rope(size_type __n, _CharT __c,
1883 const allocator_type& __a = allocator_type());
1885 rope(
const allocator_type& __a = allocator_type())
1889 rope(char_producer<_CharT> *__fn, size_type __len,
bool __delete_fn,
1890 const allocator_type& __a = allocator_type())
1893 this->_M_tree_ptr = (0 == __len)
1895 : _S_new_RopeFunction(__fn, __len, __delete_fn, _M_get_allocator());
1898 rope(
const rope& __x,
const allocator_type& __a = allocator_type())
1899 : _Base(__x._M_tree_ptr, __a)
1900 { _S_ref(this->_M_tree_ptr); }
1903 { _S_unref(this->_M_tree_ptr); }
1906 operator=(
const rope& __x)
1908 _RopeRep* __old = this->_M_tree_ptr;
1909 this->_M_tree_ptr = __x._M_tree_ptr;
1910 _S_ref(this->_M_tree_ptr);
1918 _S_unref(this->_M_tree_ptr);
1919 this->_M_tree_ptr = 0;
1923 push_back(_CharT __x)
1925 allocator_type __a = _M_get_allocator();
1926 _RopeRep* __old = this->_M_tree_ptr;
1928 = _S_destr_concat_char_iter(this->_M_tree_ptr, &__x, 1, __a);
1935 _RopeRep* __old = this->_M_tree_ptr;
1936 this->_M_tree_ptr = _S_substring(this->_M_tree_ptr,
1937 0, this->_M_tree_ptr->_M_size - 1);
1943 {
return _S_fetch(this->_M_tree_ptr, this->_M_tree_ptr->_M_size - 1); }
1946 push_front(_CharT __x)
1948 _RopeRep* __old = this->_M_tree_ptr;
1950 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, _M_get_allocator());
1953 this->_M_tree_ptr = _S_concat(__left, this->_M_tree_ptr);
1960 __throw_exception_again;
1967 _RopeRep* __old = this->_M_tree_ptr;
1969 = _S_substring(this->_M_tree_ptr, 1, this->_M_tree_ptr->_M_size);
1975 {
return _S_fetch(this->_M_tree_ptr, 0); }
1980 _RopeRep* __old = this->_M_tree_ptr;
1981 this->_M_tree_ptr = _S_balance(this->_M_tree_ptr);
1986 copy(_CharT* __buffer)
const
1988 _Destroy_const(__buffer, __buffer + size(), _M_get_allocator());
1989 _S_flatten(this->_M_tree_ptr, __buffer);
1998 copy(size_type __pos, size_type __n, _CharT* __buffer)
const
2000 size_type __size = size();
2001 size_type __len = (__pos + __n > __size? __size - __pos : __n);
2003 _Destroy_const(__buffer, __buffer + __len, _M_get_allocator());
2004 _S_flatten(this->_M_tree_ptr, __pos, __len, __buffer);
2012 { _S_dump(this->_M_tree_ptr); }
2016 const _CharT* c_str()
const;
2020 const _CharT* replace_with_c_str();
2028 if (0 == this->_M_tree_ptr)
2030 if (__detail::_S_leaf == this->_M_tree_ptr->_M_tag &&
2031 ((_RopeLeaf*)this->_M_tree_ptr)->_M_data ==
2032 this->_M_tree_ptr->_M_c_string)
2038 this->_M_tree_ptr->_M_free_c_string();
2040 this->_M_tree_ptr->_M_c_string = 0;
2044 operator[] (size_type __pos)
const
2045 {
return _S_fetch(this->_M_tree_ptr, __pos); }
2048 at(size_type __pos)
const
2051 return (*
this)[__pos];
2056 {
return(const_iterator(this->_M_tree_ptr, 0)); }
2061 {
return(const_iterator(this->_M_tree_ptr, 0)); }
2065 {
return(const_iterator(this->_M_tree_ptr, size())); }
2069 {
return(const_iterator(this->_M_tree_ptr, size())); }
2073 {
return(0 == this->_M_tree_ptr? 0 : this->_M_tree_ptr->_M_size); }
2082 return _S_min_len[int(__detail::_S_max_rope_depth) - 1] - 1;
2095 const_rbegin()
const
2106 template<
class _CharT2,
class _Alloc2>
2111 template<
class _CharT2,
class _Alloc2>
2115 template<
class _CharT2,
class _Alloc2>
2126 append(
const _CharT* __iter, size_type __n)
2128 allocator_type __a = _M_get_allocator();
2129 _RopeRep* __result =
2130 _S_destr_concat_char_iter(this->_M_tree_ptr, __iter, __n, __a);
2131 _S_unref(this->_M_tree_ptr);
2132 this->_M_tree_ptr = __result;
2137 append(
const _CharT* __c_string)
2139 size_type __len = _S_char_ptr_len(__c_string);
2140 append(__c_string, __len);
2145 append(
const _CharT* __s,
const _CharT* __e)
2147 allocator_type __a = _M_get_allocator();
2148 _RopeRep* __result =
2149 _S_destr_concat_char_iter(this->_M_tree_ptr, __s, __e - __s, __a);
2150 _S_unref(this->_M_tree_ptr);
2151 this->_M_tree_ptr = __result;
2156 append(const_iterator __s, const_iterator __e)
2158 _Self_destruct_ptr __appendee(_S_substring(__s._M_root,
2160 __e._M_current_pos));
2161 _RopeRep* __result = _S_concat(this->_M_tree_ptr,
2162 (_RopeRep*)__appendee);
2163 _S_unref(this->_M_tree_ptr);
2164 this->_M_tree_ptr = __result;
2171 allocator_type __a = _M_get_allocator();
2172 _RopeRep* __result =
2173 _S_destr_concat_char_iter(this->_M_tree_ptr, &__c, 1, __a);
2174 _S_unref(this->_M_tree_ptr);
2175 this->_M_tree_ptr = __result;
2181 {
return append(_CharT()); }
2184 append(
const rope& __y)
2186 _RopeRep* __result = _S_concat(this->_M_tree_ptr, __y._M_tree_ptr);
2187 _S_unref(this->_M_tree_ptr);
2188 this->_M_tree_ptr = __result;
2193 append(size_type __n, _CharT __c)
2196 return append(__last);
2202 _RopeRep* __tmp = this->_M_tree_ptr;
2203 this->_M_tree_ptr = __b._M_tree_ptr;
2204 __b._M_tree_ptr = __tmp;
2210 replace(_RopeRep* __old, size_type __pos1,
2211 size_type __pos2, _RopeRep* __r)
2218 _Self_destruct_ptr __left(_S_substring(__old, 0, __pos1));
2219 _Self_destruct_ptr __right(_S_substring(__old, __pos2, __old->_M_size));
2223 __result = _S_concat(__left, __right);
2226 _Self_destruct_ptr __left_result(_S_concat(__left, __r));
2227 __result = _S_concat(__left_result, __right);
2234 insert(size_type __p,
const rope& __r)
2236 _RopeRep* __result =
2237 replace(this->_M_tree_ptr, __p, __p, __r._M_tree_ptr);
2238 _S_unref(this->_M_tree_ptr);
2239 this->_M_tree_ptr = __result;
2243 insert(size_type __p, size_type __n, _CharT __c)
2250 insert(size_type __p,
const _CharT* __i, size_type __n)
2252 _Self_destruct_ptr __left(_S_substring(this->_M_tree_ptr, 0, __p));
2253 _Self_destruct_ptr __right(_S_substring(this->_M_tree_ptr,
2255 _Self_destruct_ptr __left_result(_S_concat_char_iter(__left, __i, __n,
2256 _M_get_allocator()));
2260 _RopeRep* __result = _S_concat(__left_result, __right);
2261 _S_unref(this->_M_tree_ptr);
2262 this->_M_tree_ptr = __result;
2266 insert(size_type __p,
const _CharT* __c_string)
2267 { insert(__p, __c_string, _S_char_ptr_len(__c_string)); }
2270 insert(size_type __p, _CharT __c)
2271 { insert(__p, &__c, 1); }
2274 insert(size_type __p)
2276 _CharT __c = _CharT();
2277 insert(__p, &__c, 1);
2281 insert(size_type __p,
const _CharT* __i,
const _CharT* __j)
2288 insert(size_type __p,
const const_iterator& __i,
2289 const const_iterator& __j)
2296 insert(size_type __p,
const iterator& __i,
2297 const iterator& __j)
2306 replace(size_type __p, size_type __n,
const rope& __r)
2308 _RopeRep* __result =
2309 replace(this->_M_tree_ptr, __p, __p + __n, __r._M_tree_ptr);
2310 _S_unref(this->_M_tree_ptr);
2311 this->_M_tree_ptr = __result;
2315 replace(size_type __p, size_type __n,
2316 const _CharT* __i, size_type __i_len)
2318 rope __r(__i, __i_len);
2319 replace(__p, __n, __r);
2323 replace(size_type __p, size_type __n, _CharT __c)
2326 replace(__p, __n, __r);
2330 replace(size_type __p, size_type __n,
const _CharT* __c_string)
2332 rope __r(__c_string);
2333 replace(__p, __n, __r);
2337 replace(size_type __p, size_type __n,
2338 const _CharT* __i,
const _CharT* __j)
2341 replace(__p, __n, __r);
2345 replace(size_type __p, size_type __n,
2346 const const_iterator& __i,
const const_iterator& __j)
2349 replace(__p, __n, __r);
2353 replace(size_type __p, size_type __n,
2354 const iterator& __i,
const iterator& __j)
2357 replace(__p, __n, __r);
2362 replace(size_type __p, _CharT __c)
2364 iterator __i(
this, __p);
2369 replace(size_type __p,
const rope& __r)
2370 { replace(__p, 1, __r); }
2373 replace(size_type __p,
const _CharT* __i, size_type __i_len)
2374 { replace(__p, 1, __i, __i_len); }
2377 replace(size_type __p,
const _CharT* __c_string)
2378 { replace(__p, 1, __c_string); }
2381 replace(size_type __p,
const _CharT* __i,
const _CharT* __j)
2382 { replace(__p, 1, __i, __j); }
2385 replace(size_type __p,
const const_iterator& __i,
2386 const const_iterator& __j)
2387 { replace(__p, 1, __i, __j); }
2390 replace(size_type __p,
const iterator& __i,
2391 const iterator& __j)
2392 { replace(__p, 1, __i, __j); }
2396 erase(size_type __p, size_type __n)
2398 _RopeRep* __result = replace(this->_M_tree_ptr, __p,
2400 _S_unref(this->_M_tree_ptr);
2401 this->_M_tree_ptr = __result;
2406 insert(
const iterator& __p,
const rope& __r)
2408 insert(__p.index(), __r);
2413 insert(
const iterator& __p, size_type __n, _CharT __c)
2415 insert(__p.index(), __n, __c);
2419 iterator insert(
const iterator& __p, _CharT __c)
2421 insert(__p.index(), __c);
2426 insert(
const iterator& __p )
2428 insert(__p.index());
2433 insert(
const iterator& __p,
const _CharT* c_string)
2435 insert(__p.index(), c_string);
2440 insert(
const iterator& __p,
const _CharT* __i, size_type __n)
2442 insert(__p.index(), __i, __n);
2447 insert(
const iterator& __p,
const _CharT* __i,
2450 insert(__p.index(), __i, __j);
2455 insert(
const iterator& __p,
2456 const const_iterator& __i,
const const_iterator& __j)
2458 insert(__p.index(), __i, __j);
2463 insert(
const iterator& __p,
2464 const iterator& __i,
const iterator& __j)
2466 insert(__p.index(), __i, __j);
2472 replace(
const iterator& __p,
const iterator& __q,
const rope& __r)
2473 { replace(__p.index(), __q.index() - __p.index(), __r); }
2476 replace(
const iterator& __p,
const iterator& __q, _CharT __c)
2477 { replace(__p.index(), __q.index() - __p.index(), __c); }
2480 replace(
const iterator& __p,
const iterator& __q,
2481 const _CharT* __c_string)
2482 { replace(__p.index(), __q.index() - __p.index(), __c_string); }
2485 replace(
const iterator& __p,
const iterator& __q,
2486 const _CharT* __i, size_type __n)
2487 { replace(__p.index(), __q.index() - __p.index(), __i, __n); }
2490 replace(
const iterator& __p,
const iterator& __q,
2491 const _CharT* __i,
const _CharT* __j)
2492 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2495 replace(
const iterator& __p,
const iterator& __q,
2496 const const_iterator& __i,
const const_iterator& __j)
2497 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2500 replace(
const iterator& __p,
const iterator& __q,
2501 const iterator& __i,
const iterator& __j)
2502 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2506 replace(
const iterator& __p,
const rope& __r)
2507 { replace(__p.index(), __r); }
2510 replace(
const iterator& __p, _CharT __c)
2511 { replace(__p.index(), __c); }
2514 replace(
const iterator& __p,
const _CharT* __c_string)
2515 { replace(__p.index(), __c_string); }
2518 replace(
const iterator& __p,
const _CharT* __i, size_type __n)
2519 { replace(__p.index(), __i, __n); }
2522 replace(
const iterator& __p,
const _CharT* __i,
const _CharT* __j)
2523 { replace(__p.index(), __i, __j); }
2526 replace(
const iterator& __p, const_iterator __i, const_iterator __j)
2527 { replace(__p.index(), __i, __j); }
2530 replace(
const iterator& __p, iterator __i, iterator __j)
2531 { replace(__p.index(), __i, __j); }
2535 erase(
const iterator& __p,
const iterator& __q)
2537 size_type __p_index = __p.index();
2538 erase(__p_index, __q.index() - __p_index);
2539 return iterator(
this, __p_index);
2543 erase(
const iterator& __p)
2545 size_type __p_index = __p.index();
2546 erase(__p_index, 1);
2547 return iterator(
this, __p_index);
2551 substr(size_type __start, size_type __len = 1)
const
2559 substr(iterator __start, iterator __end)
const
2567 substr(iterator __start)
const
2569 size_type __pos = __start.index();
2575 substr(const_iterator __start, const_iterator __end)
const
2585 substr(const_iterator __start)
2587 size_type __pos = __start.index();
2592 static const size_type npos;
2594 size_type find(_CharT __c, size_type __pos = 0)
const;
2597 find(
const _CharT* __s, size_type __pos = 0)
const
2599 size_type __result_pos;
2600 const_iterator __result =
2601 std::search(const_begin() + __pos, const_end(),
2602 __s, __s + _S_char_ptr_len(__s));
2603 __result_pos = __result.index();
2604 #ifndef __STL_OLD_ROPE_SEMANTICS
2605 if (__result_pos == size())
2606 __result_pos = npos;
2608 return __result_pos;
2613 {
return(iterator(
this, 0)); }
2617 {
return(iterator(
this, size())); }
2630 mutable_reference_at(size_type __pos)
2631 {
return reference(
this, __pos); }
2635 operator[] (size_type __pos)
2636 {
return _char_ref_proxy(
this, __pos); }
2642 return (*
this)[__pos];
2645 void resize(size_type __n, _CharT __c) { }
2646 void resize(size_type __n) { }
2647 void reserve(size_type __res_arg = 0) { }
2651 {
return max_size(); }
2657 copy(_CharT* __buffer, size_type __n,
2658 size_type __pos = 0)
const
2659 {
return copy(__pos, __n, __buffer); }
2663 {
return mutable_end(); }
2667 {
return mutable_begin(); }
2671 {
return mutable_rend(); }
2675 {
return mutable_rbegin(); }
2680 {
return const_end(); }
2684 {
return const_begin(); }
2688 {
return const_rend(); }
2692 {
return const_rbegin(); }
2697 template <
class _CharT,
class _Alloc>
2698 const typename rope<_CharT, _Alloc>::size_type
2701 template <
class _CharT,
class _Alloc>
2702 inline bool operator==(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2703 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2704 {
return (__x._M_current_pos == __y._M_current_pos
2705 && __x._M_root == __y._M_root); }
2707 template <
class _CharT,
class _Alloc>
2708 inline bool operator<(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2709 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2710 {
return (__x._M_current_pos < __y._M_current_pos); }
2712 template <
class _CharT,
class _Alloc>
2713 inline bool operator!=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2714 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2715 {
return !(__x == __y); }
2717 template <
class _CharT,
class _Alloc>
2718 inline bool operator>(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2719 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2720 {
return __y < __x; }
2722 template <
class _CharT,
class _Alloc>
2724 operator<=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2725 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2726 {
return !(__y < __x); }
2728 template <
class _CharT,
class _Alloc>
2730 operator>=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2731 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2732 {
return !(__x < __y); }
2734 template <
class _CharT,
class _Alloc>
2735 inline std::ptrdiff_t
2736 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2737 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2739 return (std::ptrdiff_t)__x._M_current_pos
2740 - (std::ptrdiff_t)__y._M_current_pos;
2743 template <
class _CharT,
class _Alloc>
2744 inline _Rope_const_iterator<_CharT, _Alloc>
2745 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2747 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2748 __x._M_current_pos - __n); }
2750 template <
class _CharT,
class _Alloc>
2751 inline _Rope_const_iterator<_CharT, _Alloc>
2752 operator+(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2754 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2755 __x._M_current_pos + __n); }
2757 template <
class _CharT,
class _Alloc>
2758 inline _Rope_const_iterator<_CharT, _Alloc>
2760 const _Rope_const_iterator<_CharT, _Alloc>& __x)
2761 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2762 __x._M_current_pos + __n); }
2764 template <
class _CharT,
class _Alloc>
2766 operator==(
const _Rope_iterator<_CharT, _Alloc>& __x,
2767 const _Rope_iterator<_CharT, _Alloc>& __y)
2768 {
return (__x._M_current_pos == __y._M_current_pos
2769 && __x._M_root_rope == __y._M_root_rope); }
2771 template <
class _CharT,
class _Alloc>
2773 operator<(
const _Rope_iterator<_CharT, _Alloc>& __x,
2774 const _Rope_iterator<_CharT, _Alloc>& __y)
2775 {
return (__x._M_current_pos < __y._M_current_pos); }
2777 template <
class _CharT,
class _Alloc>
2779 operator!=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2780 const _Rope_iterator<_CharT, _Alloc>& __y)
2781 {
return !(__x == __y); }
2783 template <
class _CharT,
class _Alloc>
2785 operator>(
const _Rope_iterator<_CharT, _Alloc>& __x,
2786 const _Rope_iterator<_CharT, _Alloc>& __y)
2787 {
return __y < __x; }
2789 template <
class _CharT,
class _Alloc>
2791 operator<=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2792 const _Rope_iterator<_CharT, _Alloc>& __y)
2793 {
return !(__y < __x); }
2795 template <
class _CharT,
class _Alloc>
2797 operator>=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2798 const _Rope_iterator<_CharT, _Alloc>& __y)
2799 {
return !(__x < __y); }
2801 template <
class _CharT,
class _Alloc>
2802 inline std::ptrdiff_t
2803 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
2804 const _Rope_iterator<_CharT, _Alloc>& __y)
2805 {
return ((std::ptrdiff_t)__x._M_current_pos
2806 - (std::ptrdiff_t)__y._M_current_pos); }
2808 template <
class _CharT,
class _Alloc>
2809 inline _Rope_iterator<_CharT, _Alloc>
2810 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
2812 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2813 __x._M_current_pos - __n); }
2815 template <
class _CharT,
class _Alloc>
2816 inline _Rope_iterator<_CharT, _Alloc>
2817 operator+(
const _Rope_iterator<_CharT, _Alloc>& __x, std::ptrdiff_t __n)
2818 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2819 __x._M_current_pos + __n); }
2821 template <
class _CharT,
class _Alloc>
2822 inline _Rope_iterator<_CharT, _Alloc>
2823 operator+(std::ptrdiff_t __n,
const _Rope_iterator<_CharT, _Alloc>& __x)
2824 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2825 __x._M_current_pos + __n); }
2827 template <
class _CharT,
class _Alloc>
2828 inline rope<_CharT, _Alloc>
2829 operator+(
const rope<_CharT, _Alloc>& __left,
2830 const rope<_CharT, _Alloc>& __right)
2834 typedef rope<_CharT, _Alloc> rope_type;
2835 return rope_type(rope_type::_S_concat(__left._M_tree_ptr,
2836 __right._M_tree_ptr));
2839 template <
class _CharT,
class _Alloc>
2840 inline rope<_CharT, _Alloc>&
2841 operator+=(rope<_CharT, _Alloc>& __left,
2842 const rope<_CharT, _Alloc>& __right)
2844 __left.append(__right);
2848 template <
class _CharT,
class _Alloc>
2849 inline rope<_CharT, _Alloc>
2850 operator+(
const rope<_CharT, _Alloc>& __left,
2851 const _CharT* __right)
2853 typedef rope<_CharT, _Alloc> rope_type;
2854 std::size_t __rlen = rope_type::_S_char_ptr_len(__right);
2855 _Alloc __a = __left.get_allocator();
2856 return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
2857 __right, __rlen, __a));
2860 template <
class _CharT,
class _Alloc>
2861 inline rope<_CharT, _Alloc>&
2862 operator+=(rope<_CharT, _Alloc>& __left,
2863 const _CharT* __right)
2865 __left.append(__right);
2869 template <
class _CharT,
class _Alloc>
2870 inline rope<_CharT, _Alloc>
2871 operator+(
const rope<_CharT, _Alloc>& __left, _CharT __right)
2873 typedef rope<_CharT, _Alloc> rope_type;
2874 _Alloc __a = __left.get_allocator();
2875 return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
2879 template <
class _CharT,
class _Alloc>
2880 inline rope<_CharT, _Alloc>&
2881 operator+=(rope<_CharT, _Alloc>& __left, _CharT __right)
2883 __left.append(__right);
2887 template <
class _CharT,
class _Alloc>
2889 operator<(
const rope<_CharT, _Alloc>& __left,
2890 const rope<_CharT, _Alloc>& __right)
2891 {
return __left.compare(__right) < 0; }
2893 template <
class _CharT,
class _Alloc>
2895 operator==(
const rope<_CharT, _Alloc>& __left,
2896 const rope<_CharT, _Alloc>& __right)
2897 {
return __left.compare(__right) == 0; }
2899 template <
class _CharT,
class _Alloc>
2901 operator==(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
2902 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y)
2903 {
return (__x._M_pos == __y._M_pos && __x._M_root == __y._M_root); }
2905 template <
class _CharT,
class _Alloc>
2907 operator!=(
const rope<_CharT, _Alloc>& __x,
2908 const rope<_CharT, _Alloc>& __y)
2909 {
return !(__x == __y); }
2911 template <
class _CharT,
class _Alloc>
2913 operator>(
const rope<_CharT, _Alloc>& __x,
2914 const rope<_CharT, _Alloc>& __y)
2915 {
return __y < __x; }
2917 template <
class _CharT,
class _Alloc>
2919 operator<=(
const rope<_CharT, _Alloc>& __x,
2920 const rope<_CharT, _Alloc>& __y)
2921 {
return !(__y < __x); }
2923 template <
class _CharT,
class _Alloc>
2925 operator>=(
const rope<_CharT, _Alloc>& __x,
2926 const rope<_CharT, _Alloc>& __y)
2927 {
return !(__x < __y); }
2929 template <
class _CharT,
class _Alloc>
2931 operator!=(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
2932 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y)
2933 {
return !(__x == __y); }
2935 template<
class _CharT,
class _Traits,
class _Alloc>
2938 const rope<_CharT, _Alloc>& __r);
2940 typedef rope<char> crope;
2941 typedef rope<wchar_t> wrope;
2943 inline crope::reference
2944 __mutable_reference_at(crope& __c, std::size_t __i)
2945 {
return __c.mutable_reference_at(__i); }
2947 inline wrope::reference
2948 __mutable_reference_at(wrope& __c, std::size_t __i)
2949 {
return __c.mutable_reference_at(__i); }
2951 template <
class _CharT,
class _Alloc>
2953 swap(rope<_CharT, _Alloc>& __x, rope<_CharT, _Alloc>& __y)
2956 _GLIBCXX_END_NAMESPACE_VERSION
2960 namespace std _GLIBCXX_VISIBILITY(default)
2962 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2972 size_t __size = __str.size();
2975 return 13 * __str[0] + 5 * __str[__size - 1] + __size;
2986 size_t __size = __str.size();
2989 return 13 * __str[0] + 5 * __str[__size - 1] + __size;
2994 _GLIBCXX_END_NAMESPACE_VERSION
std::pair< _InputIter, _ForwardIter > uninitialized_copy_n(_InputIter __first, _Size __count, _ForwardIter __result)
Copies the range [first,last) into result.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
basic_ostream< _CharT, _Traits > & flush(basic_ostream< _CharT, _Traits > &__os)
Flushes the output stream.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last, _Allocator &__alloc)
GNU extensions for public use.
constexpr _Iterator __base(_Iterator __it)
Template class basic_ostream.
The standard allocator, as per C++03 [20.4.1].
Uniform interface to C++98 and C++11 allocators.