epoc32/include/stdapis/stlportv5/stl/_rope.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100 (2010-03-31)
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@4
     2
 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
williamr@4
     3
 *
williamr@2
     4
 * Copyright (c) 1996,1997
williamr@2
     5
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     6
 *
williamr@2
     7
 * Copyright (c) 1997
williamr@2
     8
 * Moscow Center for SPARC Technology
williamr@2
     9
 *
williamr@4
    10
 * Copyright (c) 1999
williamr@2
    11
 * Boris Fomitchev
williamr@2
    12
 *
williamr@2
    13
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
    14
 * or implied. Any use is at your own risk.
williamr@2
    15
 *
williamr@4
    16
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
    17
 * without fee, provided the above notices are retained on all copies.
williamr@2
    18
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    19
 * provided the above notices are retained, and a notice that the code was
williamr@2
    20
 * modified is included with the above copyright notice.
williamr@2
    21
 *
williamr@2
    22
 */
williamr@2
    23
williamr@2
    24
/* NOTE: This is an internal header file, included by other STL headers.
williamr@2
    25
 *   You should not attempt to use it directly.
williamr@2
    26
 */
williamr@2
    27
williamr@2
    28
// rope<_CharT,_Alloc> is a sequence of _CharT.
williamr@2
    29
// Ropes appear to be mutable, but update operations
williamr@2
    30
// really copy enough of the data structure to leave the original
williamr@2
    31
// valid.  Thus ropes can be logically copied by just copying
williamr@2
    32
// a pointer value.
williamr@2
    33
williamr@2
    34
#ifndef _STLP_INTERNAL_ROPE_H
williamr@4
    35
#define _STLP_INTERNAL_ROPE_H
williamr@2
    36
williamr@4
    37
#ifndef _STLP_INTERNAL_ALGOBASE_H
williamr@2
    38
#  include <stl/_algobase.h>
williamr@4
    39
#endif
williamr@2
    40
williamr@4
    41
#ifndef _STLP_IOSFWD
williamr@2
    42
#  include <iosfwd>
williamr@4
    43
#endif
williamr@2
    44
williamr@4
    45
#ifndef _STLP_INTERNAL_ALLOC_H
williamr@2
    46
#  include <stl/_alloc.h>
williamr@4
    47
#endif
williamr@2
    48
williamr@4
    49
#ifndef _STLP_INTERNAL_ITERATOR_H
williamr@2
    50
#  include <stl/_iterator.h>
williamr@4
    51
#endif
williamr@2
    52
williamr@4
    53
#ifndef _STLP_INTERNAL_ALGO_H
williamr@2
    54
#  include <stl/_algo.h>
williamr@4
    55
#endif
williamr@2
    56
williamr@4
    57
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
williamr@4
    58
#  include <stl/_function_base.h>
williamr@4
    59
#endif
williamr@2
    60
williamr@4
    61
#ifndef _STLP_INTERNAL_NUMERIC_H
williamr@2
    62
#  include <stl/_numeric.h>
williamr@4
    63
#endif
williamr@2
    64
williamr@4
    65
#ifndef _STLP_INTERNAL_HASH_FUN_H
williamr@2
    66
#  include <stl/_hash_fun.h>
williamr@4
    67
#endif
williamr@2
    68
williamr@4
    69
#ifndef _STLP_CHAR_TRAITS_H
williamr@4
    70
#  include <stl/char_traits.h>
williamr@4
    71
#endif
williamr@2
    72
williamr@4
    73
#ifndef _STLP_INTERNAL_THREADS_H
williamr@4
    74
#  include <stl/_threads.h>
williamr@4
    75
#endif
williamr@4
    76
williamr@4
    77
#ifdef _STLP_SGI_THREADS
williamr@4
    78
#  include <mutex.h>
williamr@4
    79
#endif
williamr@4
    80
williamr@4
    81
#ifndef _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE
williamr@4
    82
#  define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) (_Alloc_traits<_Tp,__atype>::create_allocator(__a))
williamr@4
    83
#elif defined(__MRC__)||defined(__SC__)
williamr@4
    84
#  define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) __stl_alloc_create<_Tp,__atype>(__a,(_Tp*)0)
williamr@4
    85
#else
williamr@4
    86
#  define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
williamr@4
    87
#endif
williamr@2
    88
williamr@2
    89
_STLP_BEGIN_NAMESPACE
williamr@2
    90
williamr@2
    91
// First a lot of forward declarations.  The standard seems to require
williamr@2
    92
// much stricter "declaration before use" than many of the implementations
williamr@2
    93
// that preceded it.
williamr@2
    94
template<class _CharT, _STLP_DEFAULT_ALLOCATOR_SELECT(_CharT) > class rope;
williamr@2
    95
template<class _CharT, class _Alloc> struct _Rope_RopeConcatenation;
williamr@2
    96
template<class _CharT, class _Alloc> struct _Rope_RopeRep;
williamr@2
    97
template<class _CharT, class _Alloc> struct _Rope_RopeLeaf;
williamr@2
    98
template<class _CharT, class _Alloc> struct _Rope_RopeFunction;
williamr@2
    99
template<class _CharT, class _Alloc> struct _Rope_RopeSubstring;
williamr@2
   100
template<class _CharT, class _Alloc> class _Rope_iterator;
williamr@2
   101
template<class _CharT, class _Alloc> class _Rope_const_iterator;
williamr@2
   102
template<class _CharT, class _Alloc> class _Rope_char_ref_proxy;
williamr@2
   103
template<class _CharT, class _Alloc> class _Rope_char_ptr_proxy;
williamr@2
   104
williamr@4
   105
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   106
williamr@4
   107
// Some helpers, so we can use the power algorithm on ropes.
williamr@2
   108
// See below for why this isn't local to the implementation.
williamr@2
   109
williamr@2
   110
// This uses a nonstandard refcount convention.
williamr@2
   111
// The result has refcount 0.
williamr@2
   112
template<class _CharT, class _Alloc>
williamr@2
   113
struct _Rope_Concat_fn
williamr@2
   114
  : public binary_function<rope<_CharT,_Alloc>, rope<_CharT,_Alloc>,
williamr@4
   115
                           rope<_CharT,_Alloc> > {
williamr@2
   116
  rope<_CharT,_Alloc> operator() (const rope<_CharT,_Alloc>& __x,
williamr@2
   117
                                  const rope<_CharT,_Alloc>& __y) {
williamr@2
   118
    return __x + __y;
williamr@2
   119
  }
williamr@2
   120
};
williamr@2
   121
williamr@2
   122
template <class _CharT, class _Alloc>
williamr@2
   123
inline
williamr@2
   124
rope<_CharT,_Alloc>
williamr@2
   125
__identity_element(_Rope_Concat_fn<_CharT, _Alloc>)
williamr@4
   126
{ return rope<_CharT,_Alloc>(); }
williamr@4
   127
williamr@4
   128
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   129
williamr@4
   130
// Store an eos
williamr@4
   131
template <class _CharT>
williamr@4
   132
inline void _S_construct_null_aux(_CharT *__p, const __true_type&)
williamr@4
   133
{ *__p = 0; }
williamr@4
   134
williamr@4
   135
template <class _CharT>
williamr@4
   136
inline void _S_construct_null_aux(_CharT *__p, const __false_type&)
williamr@4
   137
{ _STLP_STD::_Construct(__p); }
williamr@4
   138
williamr@4
   139
template <class _CharT>
williamr@4
   140
inline void _S_construct_null(_CharT *__p) {
williamr@4
   141
  typedef typename _IsIntegral<_CharT>::_Ret _Char_Is_Integral;
williamr@4
   142
  _S_construct_null_aux(__p, _Char_Is_Integral());
williamr@2
   143
}
williamr@2
   144
williamr@2
   145
// char_producers are logically functions that generate a section of
williamr@4
   146
// a string.  These can be converted to ropes.  The resulting rope
williamr@2
   147
// invokes the char_producer on demand.  This allows, for example,
williamr@2
   148
// files to be viewed as ropes without reading the entire file.
williamr@2
   149
template <class _CharT>
williamr@2
   150
class char_producer {
williamr@2
   151
public:
williamr@4
   152
  virtual ~char_producer() {}
williamr@4
   153
  virtual void operator()(size_t __start_pos, size_t __len,
williamr@2
   154
                          _CharT* __buffer) = 0;
williamr@2
   155
  // Buffer should really be an arbitrary output iterator.
williamr@2
   156
  // That way we could flatten directly into an ostream, etc.
williamr@2
   157
  // This is thoroughly impossible, since iterator types don't
williamr@2
   158
  // have runtime descriptions.
williamr@2
   159
};
williamr@2
   160
williamr@2
   161
// Sequence buffers:
williamr@2
   162
//
williamr@2
   163
// Sequence must provide an append operation that appends an
williamr@2
   164
// array to the sequence.  Sequence buffers are useful only if
williamr@2
   165
// appending an entire array is cheaper than appending element by element.
williamr@2
   166
// This is true for many string representations.
williamr@2
   167
// This should  perhaps inherit from ostream<sequence::value_type>
williamr@2
   168
// and be implemented correspondingly, so that they can be used
williamr@2
   169
// for formatted.  For the sake of portability, we don't do this yet.
williamr@2
   170
//
williamr@2
   171
// For now, sequence buffers behave as output iterators.  But they also
williamr@2
   172
// behave a little like basic_ostringstream<sequence::value_type> and a
williamr@2
   173
// little like containers.
williamr@2
   174
williamr@2
   175
template<class _Sequence
williamr@2
   176
# if !(defined (_STLP_NON_TYPE_TMPL_PARAM_BUG) || \
williamr@2
   177
       defined ( _STLP_NO_DEFAULT_NON_TYPE_PARAM ))
williamr@4
   178
         , size_t _Buf_sz = 100
williamr@2
   179
#   if defined(__sgi) && !defined(__GNUC__)
williamr@4
   180
#   define __TYPEDEF_WORKAROUND
williamr@4
   181
         ,class _V = typename _Sequence::value_type
williamr@2
   182
#   endif /* __sgi */
williamr@2
   183
# endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
williamr@4
   184
         >
williamr@2
   185
// The 3rd parameter works around a common compiler bug.
williamr@2
   186
class sequence_buffer : public iterator <output_iterator_tag, void, void, void, void> {
williamr@2
   187
public:
williamr@4
   188
# ifndef __TYPEDEF_WORKAROUND
williamr@2
   189
  typedef typename _Sequence::value_type value_type;
williamr@2
   190
  typedef sequence_buffer<_Sequence
williamr@2
   191
# if !(defined (_STLP_NON_TYPE_TMPL_PARAM_BUG) || \
williamr@2
   192
       defined ( _STLP_NO_DEFAULT_NON_TYPE_PARAM ))
williamr@2
   193
  , _Buf_sz
williamr@2
   194
  > _Self;
williamr@2
   195
# else /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
williamr@2
   196
  > _Self;
williamr@4
   197
  enum { _Buf_sz = 100};
williamr@2
   198
# endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
williamr@2
   199
  // # endif
williamr@4
   200
# else /* __TYPEDEF_WORKAROUND */
williamr@2
   201
  typedef _V value_type;
williamr@2
   202
  typedef sequence_buffer<_Sequence, _Buf_sz, _V> _Self;
williamr@4
   203
# endif /* __TYPEDEF_WORKAROUND */
williamr@2
   204
protected:
williamr@2
   205
  _Sequence* _M_prefix;
williamr@2
   206
  value_type _M_buffer[_Buf_sz];
williamr@2
   207
  size_t     _M_buf_count;
williamr@2
   208
public:
williamr@2
   209
  void flush() {
williamr@2
   210
    _M_prefix->append(_M_buffer, _M_buffer + _M_buf_count);
williamr@2
   211
    _M_buf_count = 0;
williamr@2
   212
  }
williamr@2
   213
  ~sequence_buffer() { flush(); }
williamr@2
   214
  sequence_buffer() : _M_prefix(0), _M_buf_count(0) {}
williamr@2
   215
  sequence_buffer(const _Self& __x) {
williamr@2
   216
    _M_prefix = __x._M_prefix;
williamr@2
   217
    _M_buf_count = __x._M_buf_count;
williamr@2
   218
    copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
williamr@2
   219
  }
williamr@2
   220
  sequence_buffer(_Self& __x) {
williamr@2
   221
    __x.flush();
williamr@2
   222
    _M_prefix = __x._M_prefix;
williamr@2
   223
    _M_buf_count = 0;
williamr@2
   224
  }
williamr@2
   225
  sequence_buffer(_Sequence& __s) : _M_prefix(&__s), _M_buf_count(0) {}
williamr@2
   226
  _Self& operator= (_Self& __x) {
williamr@2
   227
    __x.flush();
williamr@2
   228
    _M_prefix = __x._M_prefix;
williamr@2
   229
    _M_buf_count = 0;
williamr@2
   230
    return *this;
williamr@2
   231
  }
williamr@2
   232
  _Self& operator= (const _Self& __x) {
williamr@2
   233
    _M_prefix = __x._M_prefix;
williamr@2
   234
    _M_buf_count = __x._M_buf_count;
williamr@2
   235
    copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
williamr@2
   236
    return *this;
williamr@2
   237
  }
williamr@4
   238
  void push_back(value_type __x) {
williamr@2
   239
    if (_M_buf_count < _Buf_sz) {
williamr@2
   240
      _M_buffer[_M_buf_count] = __x;
williamr@2
   241
      ++_M_buf_count;
williamr@2
   242
    } else {
williamr@2
   243
      flush();
williamr@2
   244
      _M_buffer[0] = __x;
williamr@2
   245
      _M_buf_count = 1;
williamr@2
   246
    }
williamr@2
   247
  }
williamr@4
   248
  void append(const value_type *__s, size_t __len) {
williamr@2
   249
    if (__len + _M_buf_count <= _Buf_sz) {
williamr@2
   250
      size_t __i = _M_buf_count;
williamr@2
   251
      size_t __j = 0;
williamr@2
   252
      for (; __j < __len; __i++, __j++) {
williamr@2
   253
        _M_buffer[__i] = __s[__j];
williamr@2
   254
      }
williamr@2
   255
      _M_buf_count += __len;
williamr@2
   256
    } else if (0 == _M_buf_count) {
williamr@2
   257
      _M_prefix->append(__s, __s + __len);
williamr@2
   258
    } else {
williamr@2
   259
      flush();
williamr@2
   260
      append(__s, __len);
williamr@2
   261
    }
williamr@2
   262
  }
williamr@4
   263
  _Self& write(const value_type *__s, size_t __len) {
williamr@2
   264
    append(__s, __len);
williamr@2
   265
    return *this;
williamr@2
   266
  }
williamr@4
   267
  _Self& put(value_type __x) {
williamr@2
   268
    push_back(__x);
williamr@2
   269
    return *this;
williamr@2
   270
  }
williamr@4
   271
  _Self& operator=(const value_type& __rhs) {
williamr@2
   272
    push_back(__rhs);
williamr@2
   273
    return *this;
williamr@2
   274
  }
williamr@2
   275
  _Self& operator*() { return *this; }
williamr@2
   276
  _Self& operator++() { return *this; }
williamr@2
   277
  _Self& operator++(int) { return *this; }
williamr@2
   278
};
williamr@2
   279
williamr@2
   280
// The following should be treated as private, at least for now.
williamr@2
   281
template<class _CharT>
williamr@2
   282
class _Rope_char_consumer {
williamr@4
   283
#if !defined (_STLP_MEMBER_TEMPLATES)
williamr@2
   284
public:
williamr@4
   285
  //Without member templates we have to use run-time parameterization.
williamr@2
   286
  // The symmetry with char_producer is accidental and temporary.
williamr@4
   287
  virtual ~_Rope_char_consumer() {}
williamr@2
   288
  virtual bool operator()(const _CharT* __buffer, size_t __len) = 0;
williamr@4
   289
#endif
williamr@2
   290
};
williamr@2
   291
williamr@2
   292
//
williamr@2
   293
// What follows should really be local to rope.  Unfortunately,
williamr@2
   294
// that doesn't work, since it makes it impossible to define generic
williamr@2
   295
// equality on rope iterators.  According to the draft standard, the
williamr@2
   296
// template parameters for such an equality operator cannot be inferred
williamr@2
   297
// from the occurence of a member class as a parameter.
williamr@2
   298
// (SGI compilers in fact allow this, but the __result wouldn't be
williamr@2
   299
// portable.)
williamr@2
   300
// Similarly, some of the static member functions are member functions
williamr@2
   301
// only to avoid polluting the global namespace, and to circumvent
williamr@2
   302
// restrictions on type inference for template functions.
williamr@2
   303
//
williamr@2
   304
williamr@2
   305
//
williamr@2
   306
// The internal data structure for representing a rope.  This is
williamr@2
   307
// private to the implementation.  A rope is really just a pointer
williamr@2
   308
// to one of these.
williamr@2
   309
//
williamr@2
   310
// A few basic functions for manipulating this data structure
williamr@2
   311
// are members of _RopeRep.  Most of the more complex algorithms
williamr@2
   312
// are implemented as rope members.
williamr@2
   313
//
williamr@2
   314
// Some of the static member functions of _RopeRep have identically
williamr@2
   315
// named functions in rope that simply invoke the _RopeRep versions.
williamr@2
   316
//
williamr@2
   317
williamr@2
   318
template<class _CharT, class _Alloc>
williamr@2
   319
struct _Rope_RopeRep
williamr@2
   320
  : public _Refcount_Base
williamr@2
   321
{
williamr@2
   322
  typedef _Rope_RopeRep<_CharT, _Alloc> _Self;
williamr@2
   323
public:
williamr@4
   324
  //
williamr@4
   325
  // GAB: 11/09/05
williamr@4
   326
  //
williamr@4
   327
  // "__ROPE_DEPTH_SIZE" is set to one more then the "__ROPE_MAX_DEPTH".
williamr@4
   328
  // This was originally just an addition of "__ROPE_MAX_DEPTH + 1"
williamr@4
   329
  // but this addition causes the sunpro compiler to complain about
williamr@4
   330
  // multiple declarations during the initialization of "_S_min_len".
williamr@4
   331
  // Changed to be a fixed value and the sunpro compiler appears to
williamr@4
   332
  // be happy???
williamr@4
   333
  //
williamr@2
   334
#  define __ROPE_MAX_DEPTH  45
williamr@4
   335
#  define __ROPE_DEPTH_SIZE 46 // __ROPE_MAX_DEPTH + 1
williamr@2
   336
  enum { _S_max_rope_depth = __ROPE_MAX_DEPTH };
williamr@2
   337
  enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
williamr@2
   338
  // Apparently needed by VC++
williamr@2
   339
  // The data fields of leaves are allocated with some
williamr@2
   340
  // extra space, to accomodate future growth and for basic
williamr@2
   341
  // character types, to hold a trailing eos character.
williamr@2
   342
  enum { _S_alloc_granularity = 8 };
williamr@2
   343
williamr@2
   344
  _Tag _M_tag:8;
williamr@2
   345
  bool _M_is_balanced:8;
williamr@2
   346
williamr@2
   347
  _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
williamr@4
   348
  typedef typename _Alloc_traits<_CharT,_Alloc>::allocator_type allocator_type;
williamr@4
   349
williamr@2
   350
  allocator_type get_allocator() const { return allocator_type(_M_size);  }
williamr@2
   351
williamr@2
   352
  unsigned char _M_depth;
williamr@4
   353
  _CharT* _STLP_VOLATILE _M_c_string;
williamr@4
   354
  _STLP_PRIV _STLP_alloc_proxy<size_t, _CharT, allocator_type> _M_size;
williamr@2
   355
williamr@2
   356
# ifdef _STLP_NO_ARROW_OPERATOR
williamr@2
   357
  _Rope_RopeRep() : _Refcount_Base(1), _M_size(allocator_type(), 0) {}
williamr@2
   358
# endif
williamr@2
   359
williamr@2
   360
  /* Flattened version of string, if needed.  */
williamr@2
   361
  /* typically 0.                             */
williamr@2
   362
  /* If it's not 0, then the memory is owned  */
williamr@2
   363
  /* by this node.                            */
williamr@2
   364
  /* In the case of a leaf, this may point to */
williamr@2
   365
  /* the same memory as the data field.       */
williamr@4
   366
  _Rope_RopeRep(_Tag __t, unsigned char __d, bool __b, size_t _p_size,
williamr@2
   367
                allocator_type __a) :
williamr@2
   368
    _Refcount_Base(1),
williamr@2
   369
    _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0), _M_size(__a, _p_size)
williamr@2
   370
  { }
williamr@2
   371
williamr@4
   372
  typedef typename _AreSameUnCVTypes<_CharT, char>::_Ret _IsChar;
williamr@4
   373
# ifdef _STLP_HAS_WCHAR_T
williamr@4
   374
  typedef typename _AreSameUnCVTypes<_CharT, wchar_t>::_Ret _IsWCharT;
williamr@4
   375
# else
williamr@4
   376
  typedef __false_type _IsWCharT;
williamr@4
   377
# endif
williamr@4
   378
williamr@4
   379
  typedef typename _Lor2<_IsChar, _IsWCharT>::_Ret _IsBasicCharType;
williamr@4
   380
williamr@4
   381
#if 0
williamr@4
   382
  /* Please tell why this code is necessary if you uncomment it.
williamr@4
   383
   * Problem with it is that rope implementation expect that _S_rounded_up_size(n)
williamr@4
   384
   * returns a size > n in order to store the terminating null charater. When
williamr@4
   385
   * instanciation type is not a char or wchar_t this is not guaranty resulting in
williamr@4
   386
   * memory overrun.
williamr@4
   387
   */
williamr@4
   388
  static size_t _S_rounded_up_size_aux(size_t __n, __true_type const& /*_IsBasicCharType*/) {
williamr@2
   389
    // Allow slop for in-place expansion.
williamr@4
   390
    return (__n + _S_alloc_granularity) & ~(_S_alloc_granularity - 1);
williamr@2
   391
  }
williamr@2
   392
williamr@4
   393
  static size_t _S_rounded_up_size_aux(size_t __n, __false_type const& /*_IsBasicCharType*/) {
williamr@4
   394
    // Allow slop for in-place expansion.
williamr@4
   395
    return (__n + _S_alloc_granularity - 1) & ~(_S_alloc_granularity - 1);
williamr@4
   396
  }
williamr@4
   397
#endif
williamr@4
   398
  // fbp : moved from RopeLeaf
williamr@4
   399
  static size_t _S_rounded_up_size(size_t __n)
williamr@4
   400
  //{ return _S_rounded_up_size_aux(__n, _IsBasicCharType()); }
williamr@4
   401
  { return (__n + _S_alloc_granularity) & ~(_S_alloc_granularity - 1); }
williamr@4
   402
williamr@4
   403
  static void _S_free_string( _CharT* __s, size_t __len,
williamr@2
   404
                             allocator_type __a) {
williamr@4
   405
    _STLP_STD::_Destroy_Range(__s, __s + __len);
williamr@2
   406
    //  This has to be a static member, so this gets a bit messy
williamr@4
   407
#   ifndef _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE
williamr@4
   408
    __a.deallocate(__s, _S_rounded_up_size(__len));    //*ty 03/24/2001 - restored not to use __stl_alloc_rebind() since it is not defined under _STLP_MEMBER_TEMPLATE_CLASSES
williamr@2
   409
#   else
williamr@2
   410
    __stl_alloc_rebind (__a, (_CharT*)0).deallocate(__s, _S_rounded_up_size(__len));
williamr@2
   411
#   endif
williamr@2
   412
  }
williamr@4
   413
williamr@2
   414
  // Deallocate data section of a leaf.
williamr@2
   415
  // This shouldn't be a member function.
williamr@2
   416
  // But its hard to do anything else at the
williamr@2
   417
  // moment, because it's templatized w.r.t.
williamr@2
   418
  // an allocator.
williamr@2
   419
  // Does nothing if __GC is defined.
williamr@2
   420
  void _M_free_c_string();
williamr@2
   421
  void _M_free_tree();
williamr@2
   422
  // Deallocate t. Assumes t is not 0.
williamr@4
   423
  void _M_unref_nonnil() {
williamr@4
   424
    if (_M_decr() == 0) _M_free_tree();
williamr@2
   425
  }
williamr@4
   426
  void _M_ref_nonnil() {
williamr@2
   427
    _M_incr();
williamr@2
   428
  }
williamr@4
   429
  static void _S_unref(_Self* __t) {
williamr@2
   430
    if (0 != __t) {
williamr@2
   431
      __t->_M_unref_nonnil();
williamr@2
   432
    }
williamr@2
   433
  }
williamr@4
   434
  static void _S_ref(_Self* __t) {
williamr@2
   435
    if (0 != __t) __t->_M_incr();
williamr@2
   436
  }
williamr@4
   437
  //static void _S_free_if_unref(_Self* __t) {
williamr@4
   438
  //  if (0 != __t && 0 == __t->_M_ref_count) __t->_M_free_tree();
williamr@4
   439
  //}
williamr@4
   440
};
williamr@2
   441
williamr@2
   442
template<class _CharT, class _Alloc>
williamr@2
   443
struct _Rope_RopeLeaf : public _Rope_RopeRep<_CharT,_Alloc> {
williamr@2
   444
public:
williamr@4
   445
  _CharT* _M_data; /* Not necessarily 0 terminated. */
williamr@2
   446
                                /* The allocated size is         */
williamr@2
   447
                                /* _S_rounded_up_size(size), except */
williamr@2
   448
                                /* in the GC case, in which it   */
williamr@2
   449
                                /* doesn't matter.               */
williamr@4
   450
private:
williamr@4
   451
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@4
   452
  typedef typename _RopeRep::_IsBasicCharType _IsBasicCharType;
williamr@4
   453
  void _M_init(__true_type const& /*_IsBasicCharType*/) {
williamr@4
   454
    this->_M_c_string = _M_data;
williamr@4
   455
  }
williamr@4
   456
  void _M_init(__false_type const& /*_IsBasicCharType*/) {}
williamr@4
   457
williamr@4
   458
public:
williamr@2
   459
  _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
williamr@4
   460
  typedef typename _RopeRep::allocator_type allocator_type;
williamr@4
   461
williamr@4
   462
  _Rope_RopeLeaf( _CharT* __d, size_t _p_size, allocator_type __a)
williamr@4
   463
    : _Rope_RopeRep<_CharT,_Alloc>(_RopeRep::_S_leaf, 0, true, _p_size, __a),
williamr@4
   464
      _M_data(__d) {
williamr@2
   465
    _STLP_ASSERT(_p_size > 0)
williamr@4
   466
    _M_init(_IsBasicCharType());
williamr@2
   467
  }
williamr@2
   468
williamr@2
   469
# ifdef _STLP_NO_ARROW_OPERATOR
williamr@2
   470
  _Rope_RopeLeaf() {}
williamr@2
   471
  _Rope_RopeLeaf(const _Rope_RopeLeaf<_CharT, _Alloc>& ) {}
williamr@2
   472
# endif
williamr@4
   473
williamr@2
   474
// The constructor assumes that d has been allocated with
williamr@2
   475
  // the proper allocator and the properly padded size.
williamr@2
   476
  // In contrast, the destructor deallocates the data:
williamr@2
   477
  ~_Rope_RopeLeaf() {
williamr@2
   478
    if (_M_data != this->_M_c_string) {
williamr@2
   479
      this->_M_free_c_string();
williamr@2
   480
    }
williamr@4
   481
    _RopeRep::_S_free_string(_M_data, this->_M_size._M_data, this->get_allocator());
williamr@2
   482
  }
williamr@2
   483
};
williamr@2
   484
williamr@2
   485
template<class _CharT, class _Alloc>
williamr@4
   486
struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT, _Alloc> {
williamr@4
   487
private:
williamr@4
   488
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@4
   489
williamr@2
   490
public:
williamr@4
   491
  _RopeRep* _M_left;
williamr@4
   492
  _RopeRep* _M_right;
williamr@2
   493
  _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
williamr@4
   494
  typedef typename _RopeRep::allocator_type allocator_type;
williamr@4
   495
  _Rope_RopeConcatenation(_RopeRep* __l, _RopeRep* __r, allocator_type __a)
williamr@4
   496
    : _Rope_RopeRep<_CharT,_Alloc>(_RopeRep::_S_concat,
williamr@4
   497
                                   (max)(__l->_M_depth, __r->_M_depth) + 1, false,
williamr@4
   498
                                   __l->_M_size._M_data + __r->_M_size._M_data, __a), _M_left(__l), _M_right(__r)
williamr@2
   499
  {}
williamr@2
   500
# ifdef _STLP_NO_ARROW_OPERATOR
williamr@2
   501
  _Rope_RopeConcatenation() {}
williamr@2
   502
  _Rope_RopeConcatenation(const _Rope_RopeConcatenation<_CharT, _Alloc>&) {}
williamr@2
   503
# endif
williamr@2
   504
williamr@2
   505
  ~_Rope_RopeConcatenation() {
williamr@2
   506
    this->_M_free_c_string();
williamr@2
   507
    _M_left->_M_unref_nonnil();
williamr@2
   508
    _M_right->_M_unref_nonnil();
williamr@2
   509
  }
williamr@2
   510
};
williamr@2
   511
williamr@4
   512
template <class _CharT, class _Alloc>
williamr@4
   513
struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT, _Alloc> {
williamr@4
   514
private:
williamr@4
   515
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@2
   516
public:
williamr@2
   517
  char_producer<_CharT>* _M_fn;
williamr@4
   518
  /*
williamr@4
   519
   * Char_producer is owned by the
williamr@4
   520
   * rope and should be explicitly
williamr@4
   521
   * deleted when the rope becomes
williamr@4
   522
   * inaccessible.
williamr@4
   523
   */
williamr@4
   524
  bool _M_delete_when_done;
williamr@2
   525
  _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
williamr@2
   526
  typedef typename _Rope_RopeRep<_CharT,_Alloc>::allocator_type allocator_type;
williamr@2
   527
# ifdef _STLP_NO_ARROW_OPERATOR
williamr@2
   528
  _Rope_RopeFunction() {}
williamr@2
   529
  _Rope_RopeFunction(const _Rope_RopeFunction<_CharT, _Alloc>& ) {}
williamr@2
   530
# endif
williamr@2
   531
williamr@2
   532
  _Rope_RopeFunction(char_producer<_CharT>* __f, size_t _p_size,
williamr@2
   533
                     bool __d, allocator_type __a)
williamr@4
   534
    : _Rope_RopeRep<_CharT,_Alloc>(_RopeRep::_S_function, 0, true, _p_size, __a), _M_fn(__f)
williamr@2
   535
    , _M_delete_when_done(__d)
williamr@4
   536
  { _STLP_ASSERT(_p_size > 0) }
williamr@4
   537
williamr@2
   538
  ~_Rope_RopeFunction() {
williamr@2
   539
    this->_M_free_c_string();
williamr@2
   540
    if (_M_delete_when_done) {
williamr@2
   541
      delete _M_fn;
williamr@2
   542
    }
williamr@2
   543
  }
williamr@2
   544
};
williamr@4
   545
williamr@4
   546
/*
williamr@4
   547
 * Substring results are usually represented using just
williamr@4
   548
 * concatenation nodes.  But in the case of very long flat ropes
williamr@4
   549
 * or ropes with a functional representation that isn't practical.
williamr@4
   550
 * In that case, we represent the __result as a special case of
williamr@4
   551
 * RopeFunction, whose char_producer points back to the rope itself.
williamr@4
   552
 * In all cases except repeated substring operations and
williamr@4
   553
 * deallocation, we treat the __result as a RopeFunction.
williamr@4
   554
 */
williamr@2
   555
template<class _CharT, class _Alloc>
williamr@4
   556
struct _Rope_RopeSubstring : public char_producer<_CharT>, public _Rope_RopeFunction<_CharT,_Alloc> {
williamr@2
   557
public:
williamr@2
   558
  // XXX this whole class should be rewritten.
williamr@4
   559
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@4
   560
  _RopeRep *_M_base;      // not 0
williamr@2
   561
  size_t _M_start;
williamr@4
   562
  /* virtual */ void operator()(size_t __start_pos, size_t __req_len,
williamr@4
   563
                                _CharT* __buffer) {
williamr@4
   564
    typedef _Rope_RopeFunction<_CharT,_Alloc> _RopeFunction;
williamr@4
   565
    typedef _Rope_RopeLeaf<_CharT,_Alloc> _RopeLeaf;
williamr@4
   566
    switch (_M_base->_M_tag) {
williamr@4
   567
    case _RopeRep::_S_function:
williamr@4
   568
    case _RopeRep::_S_substringfn:
williamr@2
   569
      {
williamr@2
   570
        char_producer<_CharT>* __fn =
williamr@4
   571
          __STATIC_CAST(_RopeFunction*, _M_base)->_M_fn;
williamr@2
   572
        _STLP_ASSERT(__start_pos + __req_len <= this->_M_size._M_data)
williamr@2
   573
        _STLP_ASSERT(_M_start + this->_M_size._M_data <= _M_base->_M_size._M_data)
williamr@2
   574
        (*__fn)(__start_pos + _M_start, __req_len, __buffer);
williamr@2
   575
      }
williamr@2
   576
      break;
williamr@4
   577
    case _RopeRep::_S_leaf:
williamr@2
   578
      {
williamr@4
   579
        _CharT* __s =
williamr@4
   580
          __STATIC_CAST(_RopeLeaf*, _M_base)->_M_data;
williamr@4
   581
        _STLP_PRIV __ucopy_n(__s + __start_pos + _M_start, __req_len, __buffer);
williamr@2
   582
      }
williamr@2
   583
      break;
williamr@2
   584
    default:
williamr@2
   585
      _STLP_ASSERT(false)
williamr@2
   586
        ;
williamr@2
   587
    }
williamr@2
   588
  }
williamr@2
   589
williamr@2
   590
  _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
williamr@4
   591
  typedef typename _RopeRep::allocator_type allocator_type;
williamr@2
   592
williamr@4
   593
  _Rope_RopeSubstring(_RopeRep* __b, size_t __s, size_t __l, allocator_type __a)
williamr@2
   594
    : _Rope_RopeFunction<_CharT,_Alloc>(this, __l, false, __a),
williamr@4
   595
      _M_base(__b), _M_start(__s) {
williamr@2
   596
    _STLP_ASSERT(__l > 0)
williamr@2
   597
    _STLP_ASSERT(__s + __l <= __b->_M_size._M_data)
williamr@2
   598
    _M_base->_M_ref_nonnil();
williamr@4
   599
    this->_M_tag = _RopeRep::_S_substringfn;
williamr@2
   600
  }
williamr@2
   601
  virtual ~_Rope_RopeSubstring()
williamr@4
   602
  { _M_base->_M_unref_nonnil(); }
williamr@2
   603
};
williamr@2
   604
williamr@4
   605
/*
williamr@4
   606
 * Self-destructing pointers to Rope_rep.
williamr@4
   607
 * These are not conventional smart pointers.  Their
williamr@4
   608
 * only purpose in life is to ensure that unref is called
williamr@4
   609
 * on the pointer either at normal exit or if an exception
williamr@4
   610
 * is raised.  It is the caller's responsibility to
williamr@4
   611
 * adjust reference counts when these pointers are initialized
williamr@4
   612
 * or assigned to.  (This convention significantly reduces
williamr@4
   613
 * the number of potentially expensive reference count
williamr@4
   614
 * updates.)
williamr@4
   615
 */
williamr@2
   616
template<class _CharT, class _Alloc>
williamr@2
   617
struct _Rope_self_destruct_ptr {
williamr@2
   618
  _Rope_RopeRep<_CharT,_Alloc>* _M_ptr;
williamr@4
   619
  ~_Rope_self_destruct_ptr()
williamr@2
   620
  { _Rope_RopeRep<_CharT,_Alloc>::_S_unref(_M_ptr); }
williamr@2
   621
#   ifdef _STLP_USE_EXCEPTIONS
williamr@4
   622
  _Rope_self_destruct_ptr() : _M_ptr(0) {}
williamr@2
   623
#   else
williamr@4
   624
  _Rope_self_destruct_ptr() {}
williamr@2
   625
#   endif
williamr@2
   626
  _Rope_self_destruct_ptr(_Rope_RopeRep<_CharT,_Alloc>* __p) : _M_ptr(__p) {}
williamr@2
   627
  _Rope_RopeRep<_CharT,_Alloc>& operator*() { return *_M_ptr; }
williamr@2
   628
  _Rope_RopeRep<_CharT,_Alloc>* operator->() { return _M_ptr; }
williamr@2
   629
  operator _Rope_RopeRep<_CharT,_Alloc>*() { return _M_ptr; }
williamr@4
   630
  _Rope_self_destruct_ptr<_CharT, _Alloc>&
williamr@2
   631
  operator= (_Rope_RopeRep<_CharT,_Alloc>* __x)
williamr@2
   632
  { _M_ptr = __x; return *this; }
williamr@2
   633
};
williamr@2
   634
williamr@4
   635
/*
williamr@4
   636
 * Dereferencing a nonconst iterator has to return something
williamr@4
   637
 * that behaves almost like a reference.  It's not possible to
williamr@4
   638
 * return an actual reference since assignment requires extra
williamr@4
   639
 * work.  And we would get into the same problems as with the
williamr@4
   640
 * CD2 version of basic_string.
williamr@4
   641
 */
williamr@2
   642
template<class _CharT, class _Alloc>
williamr@2
   643
class _Rope_char_ref_proxy {
williamr@2
   644
  typedef _Rope_char_ref_proxy<_CharT, _Alloc> _Self;
williamr@2
   645
  friend class rope<_CharT,_Alloc>;
williamr@2
   646
  friend class _Rope_iterator<_CharT,_Alloc>;
williamr@2
   647
  friend class _Rope_char_ptr_proxy<_CharT,_Alloc>;
williamr@2
   648
  typedef _Rope_self_destruct_ptr<_CharT,_Alloc> _Self_destruct_ptr;
williamr@2
   649
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@2
   650
  typedef rope<_CharT,_Alloc> _My_rope;
williamr@2
   651
  size_t _M_pos;
williamr@2
   652
  _CharT _M_current;
williamr@2
   653
  bool _M_current_valid;
williamr@2
   654
  _My_rope* _M_root;     // The whole rope.
williamr@2
   655
public:
williamr@2
   656
  _Rope_char_ref_proxy(_My_rope* __r, size_t __p) :
williamr@2
   657
    _M_pos(__p), _M_current_valid(false), _M_root(__r) {}
williamr@2
   658
  _Rope_char_ref_proxy(const _Self& __x) :
williamr@2
   659
    _M_pos(__x._M_pos), _M_current_valid(false), _M_root(__x._M_root) {}
williamr@2
   660
  // Don't preserve cache if the reference can outlive the
williamr@2
   661
  // expression.  We claim that's not possible without calling
williamr@2
   662
  // a copy constructor or generating reference to a proxy
williamr@2
   663
  // reference.  We declare the latter to have undefined semantics.
williamr@4
   664
  _Rope_char_ref_proxy(_My_rope* __r, size_t __p, _CharT __c)
williamr@4
   665
    : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
williamr@2
   666
  inline operator _CharT () const;
williamr@2
   667
  _Self& operator= (_CharT __c);
williamr@2
   668
  _Rope_char_ptr_proxy<_CharT, _Alloc> operator& () const;
williamr@2
   669
  _Self& operator= (const _Self& __c) {
williamr@4
   670
    return operator=((_CharT)__c);
williamr@2
   671
  }
williamr@2
   672
};
williamr@2
   673
williamr@2
   674
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
williamr@2
   675
template<class _CharT, class __Alloc>
williamr@2
   676
inline void swap(_Rope_char_ref_proxy <_CharT, __Alloc > __a,
williamr@2
   677
                 _Rope_char_ref_proxy <_CharT, __Alloc > __b) {
williamr@2
   678
  _CharT __tmp = __a;
williamr@2
   679
  __a = __b;
williamr@2
   680
  __b = __tmp;
williamr@2
   681
}
williamr@2
   682
#else
williamr@2
   683
// There is no really acceptable way to handle this.  The default
williamr@2
   684
// definition of swap doesn't work for proxy references.
williamr@2
   685
// It can't really be made to work, even with ugly hacks, since
williamr@2
   686
// the only unusual operation it uses is the copy constructor, which
williamr@2
   687
// is needed for other purposes.  We provide a macro for
williamr@2
   688
// full specializations, and instantiate the most common case.
williamr@2
   689
# define _ROPE_SWAP_SPECIALIZATION(_CharT, __Alloc) \
williamr@2
   690
    inline void swap(_Rope_char_ref_proxy <_CharT, __Alloc > __a, \
williamr@2
   691
                     _Rope_char_ref_proxy <_CharT, __Alloc > __b) { \
williamr@2
   692
        _CharT __tmp = __a; \
williamr@2
   693
        __a = __b; \
williamr@2
   694
        __b = __tmp; \
williamr@2
   695
    }
williamr@2
   696
williamr@2
   697
_ROPE_SWAP_SPECIALIZATION(char,_STLP_DEFAULT_ALLOCATOR(char) )
williamr@2
   698
williamr@4
   699
# ifndef _STLP_NO_WCHAR_T
williamr@4
   700
_ROPE_SWAP_SPECIALIZATION(wchar_t,_STLP_DEFAULT_ALLOCATOR(wchar_t) )
williamr@4
   701
# endif
williamr@4
   702
williamr@2
   703
#endif /* !_STLP_FUNCTION_TMPL_PARTIAL_ORDER */
williamr@2
   704
williamr@4
   705
template<class _CharT, class _Alloc>
williamr@2
   706
class _Rope_char_ptr_proxy {
williamr@2
   707
  // XXX this class should be rewritten.
williamr@2
   708
public:
williamr@2
   709
  typedef _Rope_char_ptr_proxy<_CharT, _Alloc> _Self;
williamr@2
   710
  friend class _Rope_char_ref_proxy<_CharT,_Alloc>;
williamr@2
   711
  size_t _M_pos;
williamr@2
   712
  rope<_CharT,_Alloc>* _M_root;     // The whole rope.
williamr@2
   713
williamr@4
   714
  _Rope_char_ptr_proxy(const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
williamr@2
   715
    : _M_pos(__x._M_pos), _M_root(__x._M_root) {}
williamr@2
   716
  _Rope_char_ptr_proxy(const _Self& __x)
williamr@2
   717
    : _M_pos(__x._M_pos), _M_root(__x._M_root) {}
williamr@2
   718
  _Rope_char_ptr_proxy() {}
williamr@2
   719
  _Rope_char_ptr_proxy(_CharT* __x) : _M_pos(0), _M_root(0) {
williamr@2
   720
    _STLP_ASSERT(0 == __x)
williamr@2
   721
  }
williamr@4
   722
  _Self& operator= (const _Self& __x) {
williamr@2
   723
    _M_pos = __x._M_pos;
williamr@2
   724
    _M_root = __x._M_root;
williamr@2
   725
    return *this;
williamr@2
   726
  }
williamr@2
   727
williamr@2
   728
  _Rope_char_ref_proxy<_CharT,_Alloc> operator*() const {
williamr@2
   729
    return _Rope_char_ref_proxy<_CharT,_Alloc>(_M_root, _M_pos);
williamr@2
   730
  }
williamr@2
   731
};
williamr@2
   732
williamr@2
   733
williamr@4
   734
/*
williamr@4
   735
 * Rope iterators:
williamr@4
   736
 * Unlike in the C version, we cache only part of the stack
williamr@4
   737
 * for rope iterators, since they must be efficiently copyable.
williamr@4
   738
 * When we run out of cache, we have to reconstruct the iterator
williamr@4
   739
 * value.
williamr@4
   740
 * Pointers from iterators are not included in reference counts.
williamr@4
   741
 * Iterators are assumed to be thread private.  Ropes can
williamr@4
   742
 * be shared.
williamr@4
   743
 */
williamr@2
   744
template<class _CharT, class _Alloc>
williamr@2
   745
class _Rope_iterator_base
williamr@2
   746
/*   : public random_access_iterator<_CharT, ptrdiff_t>  */
williamr@2
   747
{
williamr@2
   748
  friend class rope<_CharT,_Alloc>;
williamr@2
   749
  typedef _Rope_iterator_base<_CharT, _Alloc> _Self;
williamr@4
   750
  typedef _Rope_RopeConcatenation<_CharT,_Alloc> _RopeConcat;
williamr@2
   751
public:
williamr@2
   752
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@4
   753
williamr@4
   754
  enum { _S_path_cache_len = 4 }; // Must be <= 9 because of _M_path_direction.
williamr@2
   755
  enum { _S_iterator_buf_len = 15 };
williamr@2
   756
  size_t _M_current_pos;
williamr@4
   757
  // The whole rope.
williamr@4
   758
  _RopeRep* _M_root;
williamr@4
   759
  // Starting position for current leaf
williamr@4
   760
  size_t _M_leaf_pos;
williamr@4
   761
  // Buffer possibly containing current char.
williamr@4
   762
  _CharT* _M_buf_start;
williamr@4
   763
  // Pointer to current char in buffer, != 0 ==> buffer valid.
williamr@4
   764
  _CharT* _M_buf_ptr;
williamr@2
   765
  // One past __last valid char in buffer.
williamr@4
   766
  _CharT* _M_buf_end;
williamr@4
   767
williamr@2
   768
  // What follows is the path cache.  We go out of our
williamr@2
   769
  // way to make this compact.
williamr@2
   770
  // Path_end contains the bottom section of the path from
williamr@2
   771
  // the root to the current leaf.
williamr@4
   772
  struct {
williamr@4
   773
#  if defined (__BORLANDC__) && (__BORLANDC__ < 0x560)
williamr@4
   774
    _RopeRep const*_M_data[4];
williamr@4
   775
#  else
williamr@4
   776
    _RopeRep const*_M_data[_S_path_cache_len];
williamr@4
   777
#  endif
williamr@4
   778
  } _M_path_end;
williamr@4
   779
  // Last valid __pos in path_end;
williamr@4
   780
  // _M_path_end[0] ... _M_path_end[_M_leaf_index-1]
williamr@2
   781
  // point to concatenation nodes.
williamr@4
   782
  int _M_leaf_index;
williamr@4
   783
  // (_M_path_directions >> __i) & 1 is 1
williamr@4
   784
  // if we got from _M_path_end[leaf_index - __i - 1]
williamr@2
   785
  // to _M_path_end[leaf_index - __i] by going to the
williamr@2
   786
  // __right. Assumes path_cache_len <= 9.
williamr@4
   787
  unsigned char _M_path_directions;
williamr@2
   788
  // Short buffer for surrounding chars.
williamr@4
   789
  // This is useful primarily for
williamr@2
   790
  // RopeFunctions.  We put the buffer
williamr@2
   791
  // here to avoid locking in the
williamr@2
   792
  // multithreaded case.
williamr@2
   793
  // The cached path is generally assumed to be valid
williamr@2
   794
  // only if the buffer is valid.
williamr@4
   795
  struct {
williamr@4
   796
#  if defined (__BORLANDC__) && (__BORLANDC__ < 0x560)
williamr@4
   797
    _CharT _M_data[15];
williamr@4
   798
#  else
williamr@4
   799
    _CharT _M_data[_S_iterator_buf_len];
williamr@4
   800
#  endif
williamr@4
   801
  } _M_tmp_buf;
williamr@4
   802
williamr@4
   803
  // Set buffer contents given path cache.
williamr@2
   804
  static void _S_setbuf(_Rope_iterator_base<_CharT, _Alloc>& __x);
williamr@4
   805
  // Set buffer contents and path cache.
williamr@2
   806
  static void _S_setcache(_Rope_iterator_base<_CharT, _Alloc>& __x);
williamr@4
   807
  // As above, but assumes path cache is valid for previous posn.
williamr@2
   808
  static void _S_setcache_for_incr(_Rope_iterator_base<_CharT, _Alloc>& __x);
williamr@2
   809
  _Rope_iterator_base() {}
williamr@2
   810
  _Rope_iterator_base(_RopeRep* __root, size_t __pos)
williamr@2
   811
    : _M_current_pos(__pos),_M_root(__root),  _M_buf_ptr(0) {}
williamr@2
   812
  void _M_incr(size_t __n);
williamr@2
   813
  void _M_decr(size_t __n);
williamr@2
   814
public:
williamr@2
   815
  size_t index() const { return _M_current_pos; }
williamr@4
   816
private:
williamr@4
   817
  void _M_copy_buf(const _Self& __x) {
williamr@4
   818
    _M_tmp_buf = __x._M_tmp_buf;
williamr@4
   819
    if (__x._M_buf_start == __x._M_tmp_buf._M_data) {
williamr@4
   820
      _M_buf_start = _M_tmp_buf._M_data;
williamr@4
   821
      _M_buf_end = _M_buf_start + (__x._M_buf_end - __x._M_buf_start);
williamr@4
   822
      _M_buf_ptr = _M_buf_start + (__x._M_buf_ptr - __x._M_buf_start);
williamr@2
   823
    } else {
williamr@4
   824
      _M_buf_end = __x._M_buf_end;
williamr@2
   825
    }
williamr@2
   826
  }
williamr@4
   827
williamr@4
   828
public:
williamr@4
   829
  _Rope_iterator_base(const _Self& __x) : 
williamr@4
   830
      _M_current_pos(__x._M_current_pos),
williamr@4
   831
      _M_root(__x._M_root),
williamr@4
   832
      _M_leaf_pos( __x._M_leaf_pos ),
williamr@4
   833
      _M_buf_start(__x._M_buf_start),
williamr@4
   834
      _M_buf_ptr(__x._M_buf_ptr),
williamr@4
   835
      _M_path_end(__x._M_path_end),
williamr@4
   836
      _M_leaf_index(__x._M_leaf_index),
williamr@4
   837
      _M_path_directions(__x._M_path_directions)
williamr@4
   838
      {
williamr@4
   839
        if (0 != __x._M_buf_ptr) {
williamr@4
   840
          _M_copy_buf(__x);
williamr@4
   841
        }
williamr@4
   842
      }
williamr@4
   843
  _Self& operator = (const _Self& __x)
williamr@4
   844
      {
williamr@4
   845
        _M_current_pos = __x._M_current_pos;
williamr@4
   846
        _M_root = __x._M_root;
williamr@4
   847
        _M_buf_start = __x._M_buf_start;
williamr@4
   848
        _M_buf_ptr = __x._M_buf_ptr;
williamr@4
   849
        _M_path_end = __x._M_path_end;
williamr@4
   850
        _M_leaf_index = __x._M_leaf_index;
williamr@4
   851
        _M_path_directions = __x._M_path_directions;
williamr@4
   852
        _M_leaf_pos = __x._M_leaf_pos;
williamr@4
   853
        if (0 != __x._M_buf_ptr) {
williamr@4
   854
          _M_copy_buf(__x);
williamr@4
   855
        }
williamr@4
   856
        return *this;
williamr@4
   857
      }
williamr@2
   858
};
williamr@2
   859
williamr@2
   860
template<class _CharT, class _Alloc> class _Rope_iterator;
williamr@2
   861
williamr@2
   862
template<class _CharT, class _Alloc>
williamr@2
   863
class _Rope_const_iterator : public _Rope_iterator_base<_CharT,_Alloc> {
williamr@2
   864
  friend class rope<_CharT,_Alloc>;
williamr@2
   865
  typedef  _Rope_const_iterator<_CharT, _Alloc> _Self;
williamr@2
   866
  typedef _Rope_iterator_base<_CharT,_Alloc> _Base;
williamr@2
   867
  //  protected:
williamr@2
   868
public:
williamr@2
   869
#   ifndef _STLP_HAS_NO_NAMESPACES
williamr@2
   870
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@2
   871
  // The one from the base class may not be directly visible.
williamr@2
   872
#   endif
williamr@2
   873
  _Rope_const_iterator(const _RopeRep* __root, size_t __pos):
williamr@4
   874
    _Rope_iterator_base<_CharT,_Alloc>(__CONST_CAST(_RopeRep*,__root), __pos)
williamr@2
   875
    // Only nonconst iterators modify root ref count
williamr@2
   876
  {}
williamr@2
   877
public:
williamr@2
   878
  typedef _CharT reference;   // Really a value.  Returning a reference
williamr@4
   879
                              // Would be a mess, since it would have
williamr@4
   880
                              // to be included in refcount.
williamr@2
   881
  typedef const _CharT* pointer;
williamr@2
   882
  typedef _CharT value_type;
williamr@2
   883
  typedef ptrdiff_t difference_type;
williamr@2
   884
  typedef random_access_iterator_tag iterator_category;
williamr@2
   885
williamr@2
   886
public:
williamr@4
   887
  _Rope_const_iterator() {}
williamr@2
   888
  _Rope_const_iterator(const _Self& __x) :
williamr@2
   889
    _Rope_iterator_base<_CharT,_Alloc>(__x) { }
williamr@4
   890
  _Rope_const_iterator(const _Rope_iterator<_CharT,_Alloc>& __x):
williamr@2
   891
    _Rope_iterator_base<_CharT,_Alloc>(__x) {}
williamr@2
   892
  _Rope_const_iterator(const rope<_CharT,_Alloc>& __r, size_t __pos) :
williamr@2
   893
    _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr._M_data, __pos) {}
williamr@2
   894
  _Self& operator= (const _Self& __x) {
williamr@4
   895
    _Base::operator=(__x);
williamr@4
   896
    return *this;
williamr@2
   897
  }
williamr@2
   898
  reference operator*() {
williamr@4
   899
    if (0 == this->_M_buf_ptr)
williamr@4
   900
#if !defined (__DMC__)
williamr@4
   901
      _Rope_iterator_base<_CharT, _Alloc>::_S_setcache(*this);
williamr@4
   902
#else
williamr@4
   903
    { _Rope_iterator_base<_CharT, _Alloc>* __x = this; _S_setcache(*__x); }
williamr@4
   904
#endif
williamr@2
   905
    return *(this->_M_buf_ptr);
williamr@2
   906
  }
williamr@2
   907
  _Self& operator++() {
williamr@4
   908
    _CharT* __next;
williamr@2
   909
    if (0 != this->_M_buf_ptr && (__next = this->_M_buf_ptr + 1) < this->_M_buf_end) {
williamr@2
   910
      this->_M_buf_ptr = __next;
williamr@2
   911
      ++this->_M_current_pos;
williamr@2
   912
    } else {
williamr@2
   913
      this->_M_incr(1);
williamr@2
   914
    }
williamr@2
   915
    return *this;
williamr@2
   916
  }
williamr@2
   917
  _Self& operator+=(ptrdiff_t __n) {
williamr@2
   918
    if (__n >= 0) {
williamr@2
   919
      this->_M_incr(__n);
williamr@2
   920
    } else {
williamr@2
   921
      this->_M_decr(-__n);
williamr@2
   922
    }
williamr@2
   923
    return *this;
williamr@2
   924
  }
williamr@2
   925
  _Self& operator--() {
williamr@2
   926
    this->_M_decr(1);
williamr@2
   927
    return *this;
williamr@2
   928
  }
williamr@2
   929
  _Self& operator-=(ptrdiff_t __n) {
williamr@2
   930
    if (__n >= 0) {
williamr@2
   931
      this->_M_decr(__n);
williamr@2
   932
    } else {
williamr@2
   933
      this->_M_incr(-__n);
williamr@2
   934
    }
williamr@2
   935
    return *this;
williamr@2
   936
  }
williamr@2
   937
  _Self operator++(int) {
williamr@2
   938
    size_t __old_pos = this->_M_current_pos;
williamr@2
   939
    this->_M_incr(1);
williamr@2
   940
    return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
williamr@2
   941
    // This makes a subsequent dereference expensive.
williamr@2
   942
    // Perhaps we should instead copy the iterator
williamr@2
   943
    // if it has a valid cache?
williamr@2
   944
  }
williamr@2
   945
  _Self operator--(int) {
williamr@2
   946
    size_t __old_pos = this->_M_current_pos;
williamr@2
   947
    this->_M_decr(1);
williamr@2
   948
    return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
williamr@2
   949
  }
williamr@2
   950
  inline reference operator[](size_t __n);
williamr@2
   951
};
williamr@2
   952
williamr@2
   953
template<class _CharT, class _Alloc>
williamr@2
   954
class _Rope_iterator : public _Rope_iterator_base<_CharT,_Alloc> {
williamr@2
   955
  friend class rope<_CharT,_Alloc>;
williamr@2
   956
  typedef _Rope_iterator<_CharT, _Alloc> _Self;
williamr@2
   957
  typedef _Rope_iterator_base<_CharT,_Alloc> _Base;
williamr@2
   958
  typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
williamr@4
   959
williamr@2
   960
public:
williamr@2
   961
  rope<_CharT,_Alloc>* _M_root_rope;
williamr@2
   962
  // root is treated as a cached version of this,
williamr@2
   963
  // and is used to detect changes to the underlying
williamr@2
   964
  // rope.
williamr@2
   965
  // Root is included in the reference count.
williamr@2
   966
  // This is necessary so that we can detect changes reliably.
williamr@2
   967
  // Unfortunately, it requires careful bookkeeping for the
williamr@2
   968
  // nonGC case.
williamr@2
   969
  _Rope_iterator(rope<_CharT,_Alloc>* __r, size_t __pos);
williamr@4
   970
williamr@2
   971
  void _M_check();
williamr@2
   972
public:
williamr@2
   973
  typedef _Rope_char_ref_proxy<_CharT,_Alloc>  reference;
williamr@2
   974
  typedef _Rope_char_ref_proxy<_CharT,_Alloc>* pointer;
williamr@2
   975
  typedef _CharT value_type;
williamr@2
   976
  typedef ptrdiff_t difference_type;
williamr@2
   977
  typedef random_access_iterator_tag iterator_category;
williamr@2
   978
public:
williamr@4
   979
  ~_Rope_iterator() {  //*TY 5/6/00 - added dtor to balance reference count
williamr@2
   980
    _RopeRep::_S_unref(this->_M_root);
williamr@2
   981
  }
williamr@4
   982
williamr@2
   983
  rope<_CharT,_Alloc>& container() { return *_M_root_rope; }
williamr@2
   984
  _Rope_iterator() {
williamr@2
   985
    this->_M_root = 0;  // Needed for reference counting.
williamr@4
   986
  }
williamr@2
   987
  _Rope_iterator(const  _Self& __x) :
williamr@2
   988
    _Rope_iterator_base<_CharT,_Alloc>(__x) {
williamr@2
   989
    _M_root_rope = __x._M_root_rope;
williamr@2
   990
    _RopeRep::_S_ref(this->_M_root);
williamr@2
   991
  }
williamr@2
   992
  _Rope_iterator(rope<_CharT,_Alloc>& __r, size_t __pos);
williamr@2
   993
  _Self& operator= (const  _Self& __x) {
williamr@2
   994
    _RopeRep* __old = this->_M_root;
williamr@2
   995
    _RopeRep::_S_ref(__x._M_root);
williamr@4
   996
    _Base::operator=(__x);
williamr@4
   997
    _M_root_rope = __x._M_root_rope;
williamr@2
   998
    _RopeRep::_S_unref(__old);
williamr@4
   999
    return *this;
williamr@2
  1000
  }
williamr@2
  1001
  reference operator*() {
williamr@2
  1002
    _M_check();
williamr@2
  1003
    if (0 == this->_M_buf_ptr) {
williamr@4
  1004
      return reference(_M_root_rope, this->_M_current_pos);
williamr@2
  1005
    } else {
williamr@4
  1006
      return reference(_M_root_rope, this->_M_current_pos, *(this->_M_buf_ptr));
williamr@2
  1007
    }
williamr@2
  1008
  }
williamr@2
  1009
  _Self& operator++() {
williamr@2
  1010
    this->_M_incr(1);
williamr@2
  1011
    return *this;
williamr@2
  1012
  }
williamr@2
  1013
  _Self& operator+=(ptrdiff_t __n) {
williamr@2
  1014
    if (__n >= 0) {
williamr@2
  1015
      this->_M_incr(__n);
williamr@2
  1016
    } else {
williamr@2
  1017
      this->_M_decr(-__n);
williamr@2
  1018
    }
williamr@2
  1019
    return *this;
williamr@2
  1020
  }
williamr@2
  1021
  _Self& operator--() {
williamr@2
  1022
    this->_M_decr(1);
williamr@2
  1023
    return *this;
williamr@2
  1024
  }
williamr@2
  1025
  _Self& operator-=(ptrdiff_t __n) {
williamr@2
  1026
    if (__n >= 0) {
williamr@2
  1027
      this->_M_decr(__n);
williamr@2
  1028
    } else {
williamr@2
  1029
      this->_M_incr(-__n);
williamr@2
  1030
    }
williamr@2
  1031
    return *this;
williamr@2
  1032
  }
williamr@2
  1033
  _Self operator++(int) {
williamr@2
  1034
    size_t __old_pos = this->_M_current_pos;
williamr@2
  1035
    this->_M_incr(1);
williamr@4
  1036
    return _Self(_M_root_rope, __old_pos);
williamr@2
  1037
  }
williamr@2
  1038
  _Self operator--(int) {
williamr@2
  1039
    size_t __old_pos = this->_M_current_pos;
williamr@2
  1040
    this->_M_decr(1);
williamr@4
  1041
    return _Self(_M_root_rope, __old_pos);
williamr@2
  1042
  }
williamr@2
  1043
  reference operator[](ptrdiff_t __n) {
williamr@4
  1044
    return reference(_M_root_rope, this->_M_current_pos + __n);
williamr@2
  1045
  }
williamr@2
  1046
};
williamr@2
  1047
williamr@2
  1048
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
williamr@2
  1049
template <class _CharT, class _Alloc>
williamr@2
  1050
inline random_access_iterator_tag
williamr@2
  1051
iterator_category(const _Rope_iterator<_CharT,_Alloc>&) {  return random_access_iterator_tag();}
williamr@2
  1052
template <class _CharT, class _Alloc>
williamr@2
  1053
inline _CharT* value_type(const _Rope_iterator<_CharT,_Alloc>&) { return 0; }
williamr@2
  1054
template <class _CharT, class _Alloc>
williamr@2
  1055
inline ptrdiff_t* distance_type(const _Rope_iterator<_CharT,_Alloc>&) { return 0; }
williamr@2
  1056
template <class _CharT, class _Alloc>
williamr@2
  1057
inline random_access_iterator_tag
williamr@2
  1058
iterator_category(const _Rope_const_iterator<_CharT,_Alloc>&) { return random_access_iterator_tag(); }
williamr@2
  1059
template <class _CharT, class _Alloc>
williamr@2
  1060
inline _CharT* value_type(const _Rope_const_iterator<_CharT,_Alloc>&) { return 0; }
williamr@2
  1061
template <class _CharT, class _Alloc>
williamr@2
  1062
inline ptrdiff_t* distance_type(const _Rope_const_iterator<_CharT,_Alloc>&) { return 0; }
williamr@4
  1063
#endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
williamr@4
  1064
williamr@4
  1065
template <class _CharT, class _Alloc, class _CharConsumer>
williamr@4
  1066
bool _S_apply_to_pieces(_CharConsumer& __c,
williamr@4
  1067
                        _Rope_RopeRep<_CharT, _Alloc> *__r,
williamr@4
  1068
                        size_t __begin, size_t __end);
williamr@4
  1069
                        // begin and end are assumed to be in range.
williamr@2
  1070
williamr@2
  1071
template <class _CharT, class _Alloc>
williamr@4
  1072
class rope
williamr@4
  1073
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
williamr@4
  1074
           : public __stlport_class<rope<_CharT, _Alloc> >
williamr@4
  1075
#endif
williamr@4
  1076
{
williamr@2
  1077
  typedef rope<_CharT,_Alloc> _Self;
williamr@2
  1078
public:
williamr@2
  1079
  typedef _CharT value_type;
williamr@2
  1080
  typedef ptrdiff_t difference_type;
williamr@2
  1081
  typedef size_t size_type;
williamr@2
  1082
  typedef _CharT const_reference;
williamr@2
  1083
  typedef const _CharT* const_pointer;
williamr@2
  1084
  typedef _Rope_iterator<_CharT,_Alloc> iterator;
williamr@2
  1085
  typedef _Rope_const_iterator<_CharT,_Alloc> const_iterator;
williamr@2
  1086
  typedef _Rope_char_ref_proxy<_CharT,_Alloc> reference;
williamr@2
  1087
  typedef _Rope_char_ptr_proxy<_CharT,_Alloc> pointer;
williamr@4
  1088
williamr@2
  1089
  friend class _Rope_iterator<_CharT,_Alloc>;
williamr@2
  1090
  friend class _Rope_const_iterator<_CharT,_Alloc>;
williamr@2
  1091
  friend struct _Rope_RopeRep<_CharT,_Alloc>;
williamr@2
  1092
  friend class _Rope_iterator_base<_CharT,_Alloc>;
williamr@2
  1093
  friend class _Rope_char_ptr_proxy<_CharT,_Alloc>;
williamr@2
  1094
  friend class _Rope_char_ref_proxy<_CharT,_Alloc>;
williamr@2
  1095
  friend struct _Rope_RopeSubstring<_CharT,_Alloc>;
williamr@2
  1096
williamr@2
  1097
  _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
williamr@4
  1098
williamr@2
  1099
protected:
williamr@4
  1100
  typedef _CharT* _Cstrptr;
williamr@4
  1101
williamr@2
  1102
  static _CharT _S_empty_c_str[1];
williamr@4
  1103
williamr@2
  1104
  enum { _S_copy_max = 23 };
williamr@2
  1105
  // For strings shorter than _S_copy_max, we copy to
williamr@2
  1106
  // concatenate.
williamr@4
  1107
williamr@4
  1108
  typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
williamr@4
  1109
  typedef typename _RopeRep::_IsBasicCharType _IsBasicCharType;
williamr@4
  1110
williamr@2
  1111
public:
williamr@2
  1112
  _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
williamr@2
  1113
  typedef typename _Alloc_traits<_CharT,_Alloc>::allocator_type  allocator_type;
williamr@4
  1114
williamr@2
  1115
public:
williamr@2
  1116
  // The only data member of a rope:
williamr@4
  1117
  _STLP_PRIV _STLP_alloc_proxy<_RopeRep*, _CharT, allocator_type> _M_tree_ptr;
williamr@2
  1118
williamr@4
  1119
public:
williamr@4
  1120
  allocator_type get_allocator() const { return allocator_type(_M_tree_ptr); }
williamr@4
  1121
williamr@4
  1122
public:
williamr@2
  1123
  typedef _Rope_RopeConcatenation<_CharT,_Alloc> _RopeConcatenation;
williamr@2
  1124
  typedef _Rope_RopeLeaf<_CharT,_Alloc> _RopeLeaf;
williamr@2
  1125
  typedef _Rope_RopeFunction<_CharT,_Alloc> _RopeFunction;
williamr@2
  1126
  typedef _Rope_RopeSubstring<_CharT,_Alloc> _RopeSubstring;
williamr@2
  1127
williamr@2
  1128
  // Retrieve a character at the indicated position.
williamr@2
  1129
  static _CharT _S_fetch(_RopeRep* __r, size_type __pos);
williamr@2
  1130
williamr@2
  1131
  // Obtain a pointer to the character at the indicated position.
williamr@2
  1132
  // The pointer can be used to change the character.
williamr@2
  1133
  // If such a pointer cannot be produced, as is frequently the
williamr@2
  1134
  // case, 0 is returned instead.
williamr@2
  1135
  // (Returns nonzero only if all nodes in the path have a refcount
williamr@2
  1136
  // of 1.)
williamr@2
  1137
  static _CharT* _S_fetch_ptr(_RopeRep* __r, size_type __pos);
williamr@2
  1138
williamr@4
  1139
  static void _S_unref(_RopeRep* __t) {
williamr@2
  1140
    _RopeRep::_S_unref(__t);
williamr@2
  1141
  }
williamr@4
  1142
  static void _S_ref(_RopeRep* __t) {
williamr@2
  1143
    _RopeRep::_S_ref(__t);
williamr@2
  1144
  }
williamr@2
  1145
williamr@2
  1146
  typedef _Rope_self_destruct_ptr<_CharT,_Alloc> _Self_destruct_ptr;
williamr@2
  1147
williamr@2
  1148
  // _Result is counted in refcount.
williamr@2
  1149
  static _RopeRep* _S_substring(_RopeRep* __base,
williamr@2
  1150
                                size_t __start, size_t __endp1);
williamr@2
  1151
williamr@2
  1152
  static _RopeRep* _S_concat_char_iter(_RopeRep* __r,
williamr@2
  1153
                                       const _CharT* __iter, size_t __slen);
williamr@2
  1154
  // Concatenate rope and char ptr, copying __s.
williamr@2
  1155
  // Should really take an arbitrary iterator.
williamr@2
  1156
  // Result is counted in refcount.
williamr@2
  1157
  static _RopeRep* _S_destr_concat_char_iter(_RopeRep* __r,
williamr@4
  1158
                                             const _CharT* __iter, size_t __slen);
williamr@2
  1159
    // As above, but one reference to __r is about to be
williamr@2
  1160
    // destroyed.  Thus the pieces may be recycled if all
williamr@2
  1161
    // relevent reference counts are 1.
williamr@2
  1162
williamr@2
  1163
  // General concatenation on _RopeRep.  _Result
williamr@2
  1164
  // has refcount of 1.  Adjusts argument refcounts.
williamr@4
  1165
  static _RopeRep* _S_concat_rep(_RopeRep* __left, _RopeRep* __right);
williamr@2
  1166
williamr@2
  1167
public:
williamr@4
  1168
#if defined (_STLP_MEMBER_TEMPLATES)
williamr@4
  1169
  template <class _CharConsumer>
williamr@4
  1170
#else
williamr@4
  1171
  typedef _Rope_char_consumer<_CharT> _CharConsumer;
williamr@4
  1172
#endif
williamr@4
  1173
  void apply_to_pieces(size_t __begin, size_t __end,
williamr@4
  1174
                       _CharConsumer& __c) const
williamr@4
  1175
  { _S_apply_to_pieces(__c, _M_tree_ptr._M_data, __begin, __end); }
williamr@2
  1176
williamr@2
  1177
protected:
williamr@2
  1178
williamr@4
  1179
  static size_t _S_rounded_up_size(size_t __n)
williamr@4
  1180
  { return _RopeRep::_S_rounded_up_size(__n); }
williamr@2
  1181
williamr@2
  1182
  // Allocate and construct a RopeLeaf using the supplied allocator
williamr@2
  1183
  // Takes ownership of s instead of copying.
williamr@4
  1184
  static _RopeLeaf* _S_new_RopeLeaf(_CharT *__s,
williamr@4
  1185
                                    size_t _p_size, allocator_type __a) {
williamr@4
  1186
    _RopeLeaf* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
williamr@4
  1187
                                                _RopeLeaf).allocate(1);
williamr@2
  1188
    _STLP_TRY {
williamr@2
  1189
      _STLP_PLACEMENT_NEW(__space) _RopeLeaf(__s, _p_size, __a);
williamr@2
  1190
    }
williamr@4
  1191
   _STLP_UNWIND(_STLP_CREATE_ALLOCATOR(allocator_type,__a,
williamr@4
  1192
                                       _RopeLeaf).deallocate(__space, 1))
williamr@4
  1193
    return __space;
williamr@2
  1194
  }
williamr@2
  1195
williamr@4
  1196
  static _RopeConcatenation* _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right,
williamr@4
  1197
                                                      allocator_type __a) {
williamr@4
  1198
   _RopeConcatenation* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
williamr@4
  1199
                                                        _RopeConcatenation).allocate(1);
williamr@2
  1200
    return _STLP_PLACEMENT_NEW(__space) _RopeConcatenation(__left, __right, __a);
williamr@2
  1201
  }
williamr@2
  1202
williamr@2
  1203
  static _RopeFunction* _S_new_RopeFunction(char_producer<_CharT>* __f,
williamr@4
  1204
                                            size_t _p_size, bool __d, allocator_type __a) {
williamr@4
  1205
   _RopeFunction* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
williamr@4
  1206
                                                   _RopeFunction).allocate(1);
williamr@2
  1207
    return _STLP_PLACEMENT_NEW(__space) _RopeFunction(__f, _p_size, __d, __a);
williamr@2
  1208
  }
williamr@2
  1209
williamr@4
  1210
  static _RopeSubstring* _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
williamr@4
  1211
                                              size_t __l, allocator_type __a) {
williamr@4
  1212
   _RopeSubstring* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
williamr@4
  1213
                                                    _RopeSubstring).allocate(1);
williamr@2
  1214
    return _STLP_PLACEMENT_NEW(__space) _RopeSubstring(__b, __s, __l, __a);
williamr@2
  1215
  }
williamr@2
  1216
williamr@2
  1217
  static
williamr@2
  1218
  _RopeLeaf* _S_RopeLeaf_from_unowned_char_ptr(const _CharT *__s,
williamr@4
  1219
                                               size_t _p_size, allocator_type __a) {
williamr@2
  1220
    if (0 == _p_size) return 0;
williamr@2
  1221
williamr@2
  1222
   _CharT* __buf = _STLP_CREATE_ALLOCATOR(allocator_type,__a, _CharT).allocate(_S_rounded_up_size(_p_size));
williamr@2
  1223
williamr@4
  1224
    _STLP_PRIV __ucopy_n(__s, _p_size, __buf);
williamr@4
  1225
    _S_construct_null(__buf + _p_size);
williamr@2
  1226
williamr@2
  1227
    _STLP_TRY {
williamr@2
  1228
      return _S_new_RopeLeaf(__buf, _p_size, __a);
williamr@2
  1229
    }
williamr@2
  1230
    _STLP_UNWIND(_RopeRep::_S_free_string(__buf, _p_size, __a))
williamr@4
  1231
    _STLP_RET_AFTER_THROW(0)
williamr@2
  1232
  }
williamr@4
  1233
williamr@2
  1234
williamr@2
  1235
  // Concatenation of nonempty strings.
williamr@2
  1236
  // Always builds a concatenation node.
williamr@2
  1237
  // Rebalances if the result is too deep.
williamr@2
  1238
  // Result has refcount 1.
williamr@2
  1239
  // Does not increment left and right ref counts even though
williamr@2
  1240
  // they are referenced.
williamr@2
  1241
  static _RopeRep*
williamr@2
  1242
  _S_tree_concat(_RopeRep* __left, _RopeRep* __right);
williamr@2
  1243
williamr@2
  1244
  // Concatenation helper functions
williamr@2
  1245
  static _RopeLeaf*
williamr@2
  1246
  _S_leaf_concat_char_iter(_RopeLeaf* __r,
williamr@2
  1247
                           const _CharT* __iter, size_t __slen);
williamr@2
  1248
  // Concatenate by copying leaf.
williamr@2
  1249
  // should take an arbitrary iterator
williamr@2
  1250
  // result has refcount 1.
williamr@2
  1251
  static _RopeLeaf* _S_destr_leaf_concat_char_iter
williamr@2
  1252
  (_RopeLeaf* __r, const _CharT* __iter, size_t __slen);
williamr@2
  1253
  // A version that potentially clobbers __r if __r->_M_ref_count == 1.
williamr@2
  1254
williamr@2
  1255
williamr@2
  1256
  // A helper function for exponentiating strings.
williamr@2
  1257
  // This uses a nonstandard refcount convention.
williamr@2
  1258
  // The result has refcount 0.
williamr@4
  1259
  typedef _STLP_PRIV _Rope_Concat_fn<_CharT,_Alloc> _Concat_fn;
williamr@4
  1260
#if !defined (__GNUC__) || (__GNUC__ < 3)
williamr@4
  1261
  friend _Concat_fn;
williamr@4
  1262
#else
williamr@4
  1263
  friend struct _STLP_PRIV _Rope_Concat_fn<_CharT,_Alloc>;
williamr@4
  1264
#endif
williamr@2
  1265
williamr@2
  1266
public:
williamr@2
  1267
  static size_t _S_char_ptr_len(const _CharT* __s) {
williamr@4
  1268
    return char_traits<_CharT>::length(__s);
williamr@2
  1269
  }
williamr@2
  1270
williamr@2
  1271
public: /* for operators */
williamr@2
  1272
  rope(_RopeRep* __t, const allocator_type& __a = allocator_type())
williamr@2
  1273
    : _M_tree_ptr(__a, __t) { }
williamr@2
  1274
private:
williamr@2
  1275
  // Copy __r to the _CharT buffer.
williamr@2
  1276
  // Returns __buffer + __r->_M_size._M_data.
williamr@2
  1277
  // Assumes that buffer is uninitialized.
williamr@2
  1278
  static _CharT* _S_flatten(_RopeRep* __r, _CharT* __buffer);
williamr@2
  1279
williamr@2
  1280
  // Again, with explicit starting position and length.
williamr@2
  1281
  // Assumes that buffer is uninitialized.
williamr@2
  1282
  static _CharT* _S_flatten(_RopeRep* __r,
williamr@2
  1283
                            size_t __start, size_t __len,
williamr@2
  1284
                            _CharT* __buffer);
williamr@2
  1285
williamr@2
  1286
  // fbp : HP aCC prohibits access to protected min_len from within static methods ( ?? )
williamr@2
  1287
public:
williamr@4
  1288
  static const unsigned long _S_min_len[__ROPE_DEPTH_SIZE];
williamr@2
  1289
protected:
williamr@2
  1290
  static bool _S_is_balanced(_RopeRep* __r)
williamr@2
  1291
  { return (__r->_M_size._M_data >= _S_min_len[__r->_M_depth]); }
williamr@2
  1292
williamr@4
  1293
  static bool _S_is_almost_balanced(_RopeRep* __r) {
williamr@4
  1294
    return (__r->_M_depth == 0 ||
williamr@4
  1295
            __r->_M_size._M_data >= _S_min_len[__r->_M_depth - 1]);
williamr@4
  1296
  }
williamr@2
  1297
williamr@4
  1298
  static bool _S_is_roughly_balanced(_RopeRep* __r) {
williamr@4
  1299
    return (__r->_M_depth <= 1 ||
williamr@4
  1300
            __r->_M_size._M_data >= _S_min_len[__r->_M_depth - 2]);
williamr@4
  1301
  }
williamr@2
  1302
williamr@2
  1303
  // Assumes the result is not empty.
williamr@2
  1304
  static _RopeRep* _S_concat_and_set_balanced(_RopeRep* __left,
williamr@4
  1305
                                              _RopeRep* __right) {
williamr@2
  1306
    _RopeRep* __result = _S_concat_rep(__left, __right);
williamr@2
  1307
    if (_S_is_balanced(__result)) __result->_M_is_balanced = true;
williamr@2
  1308
    return __result;
williamr@2
  1309
  }
williamr@2
  1310
williamr@2
  1311
  // The basic rebalancing operation.  Logically copies the
williamr@2
  1312
  // rope.  The result has refcount of 1.  The client will
williamr@2
  1313
  // usually decrement the reference count of __r.
williamr@2
  1314
  // The result is within height 2 of balanced by the above
williamr@2
  1315
  // definition.
williamr@2
  1316
  static _RopeRep* _S_balance(_RopeRep* __r);
williamr@2
  1317
williamr@2
  1318
  // Add all unbalanced subtrees to the forest of balanceed trees.
williamr@2
  1319
  // Used only by balance.
williamr@2
  1320
  static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest);
williamr@4
  1321
williamr@2
  1322
  // Add __r to forest, assuming __r is already balanced.
williamr@2
  1323
  static void _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest);
williamr@2
  1324
williamr@4
  1325
#ifdef _STLP_DEBUG
williamr@2
  1326
  // Print to stdout, exposing structure
williamr@2
  1327
  static void _S_dump(_RopeRep* __r, int __indent = 0);
williamr@4
  1328
#endif
williamr@2
  1329
williamr@2
  1330
  // Return -1, 0, or 1 if __x < __y, __x == __y, or __x > __y resp.
williamr@2
  1331
  static int _S_compare(const _RopeRep* __x, const _RopeRep* __y);
williamr@2
  1332
williamr@4
  1333
  void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const;
williamr@4
  1334
williamr@4
  1335
  void _M_reset(_RopeRep* __r) {
williamr@4
  1336
    //if (__r != _M_tree_ptr._M_data) {
williamr@4
  1337
      _S_unref(_M_tree_ptr._M_data);
williamr@4
  1338
      _M_tree_ptr._M_data = __r;
williamr@4
  1339
    //}
williamr@4
  1340
  }
williamr@4
  1341
williamr@2
  1342
public:
williamr@2
  1343
  bool empty() const { return 0 == _M_tree_ptr._M_data; }
williamr@2
  1344
williamr@2
  1345
  // Comparison member function.  This is public only for those
williamr@2
  1346
  // clients that need a ternary comparison.  Others
williamr@2
  1347
  // should use the comparison operators below.
williamr@2
  1348
  int compare(const _Self& __y) const {
williamr@2
  1349
    return _S_compare(_M_tree_ptr._M_data, __y._M_tree_ptr._M_data);
williamr@2
  1350
  }
williamr@2
  1351
williamr@2
  1352
  rope(const _CharT* __s, const allocator_type& __a = allocator_type())
williamr@4
  1353
    : _M_tree_ptr(__a, _S_RopeLeaf_from_unowned_char_ptr(__s, _S_char_ptr_len(__s),__a))
williamr@4
  1354
  {}
williamr@2
  1355
williamr@2
  1356
  rope(const _CharT* __s, size_t __len,
williamr@2
  1357
       const allocator_type& __a = allocator_type())
williamr@4
  1358
    : _M_tree_ptr(__a, (_S_RopeLeaf_from_unowned_char_ptr(__s, __len, __a)))
williamr@4
  1359
  {}
williamr@2
  1360
williamr@2
  1361
  // Should perhaps be templatized with respect to the iterator type
williamr@2
  1362
  // and use Sequence_buffer.  (It should perhaps use sequence_buffer
williamr@2
  1363
  // even now.)
williamr@2
  1364
  rope(const _CharT *__s, const _CharT *__e,
williamr@2
  1365
       const allocator_type& __a = allocator_type())
williamr@4
  1366
    : _M_tree_ptr(__a, _S_RopeLeaf_from_unowned_char_ptr(__s, __e - __s, __a))
williamr@4
  1367
  {}
williamr@2
  1368
williamr@2
  1369
  rope(const const_iterator& __s, const const_iterator& __e,
williamr@2
  1370
       const allocator_type& __a = allocator_type())
williamr@2
  1371
    : _M_tree_ptr(__a, _S_substring(__s._M_root, __s._M_current_pos,
williamr@2
  1372
                                    __e._M_current_pos))
williamr@4
  1373
  {}
williamr@2
  1374
williamr@2
  1375
  rope(const iterator& __s, const iterator& __e,
williamr@2
  1376
       const allocator_type& __a = allocator_type())
williamr@2
  1377
    : _M_tree_ptr(__a, _S_substring(__s._M_root, __s._M_current_pos,
williamr@2
  1378
                                    __e._M_current_pos))
williamr@4
  1379
  {}
williamr@2
  1380
williamr@2
  1381
  rope(_CharT __c, const allocator_type& __a = allocator_type())
williamr@4
  1382
    : _M_tree_ptr(__a, (_RopeRep*)0) {
williamr@2
  1383
    _CharT* __buf = _M_tree_ptr.allocate(_S_rounded_up_size(1));
williamr@2
  1384
williamr@4
  1385
    _Copy_Construct(__buf, __c);
williamr@4
  1386
    _S_construct_null(__buf + 1);
williamr@4
  1387
williamr@2
  1388
    _STLP_TRY {
williamr@2
  1389
      _M_tree_ptr._M_data = _S_new_RopeLeaf(__buf, 1, __a);
williamr@2
  1390
    }
williamr@2
  1391
    _STLP_UNWIND(_RopeRep::_S_free_string(__buf, 1, __a))
williamr@4
  1392
  }
williamr@2
  1393
williamr@4
  1394
  rope(size_t __n, _CharT __c,
williamr@2
  1395
       const allocator_type& __a = allocator_type()):
williamr@2
  1396
    _M_tree_ptr(__a, (_RopeRep*)0) {
williamr@4
  1397
    if (0 == __n)
williamr@4
  1398
      return;
williamr@4
  1399
williamr@2
  1400
    rope<_CharT,_Alloc> __result;
williamr@2
  1401
# define  __exponentiate_threshold size_t(32)
williamr@2
  1402
    _RopeRep* __remainder;
williamr@2
  1403
    rope<_CharT,_Alloc> __remainder_rope;
williamr@4
  1404
williamr@2
  1405
    // gcc-2.7.2 bugs
williamr@4
  1406
    typedef _STLP_PRIV _Rope_Concat_fn<_CharT,_Alloc> _Concat_fn;
williamr@4
  1407
williamr@2
  1408
    size_t __exponent = __n / __exponentiate_threshold;
williamr@2
  1409
    size_t __rest = __n % __exponentiate_threshold;
williamr@2
  1410
    if (0 == __rest) {
williamr@2
  1411
      __remainder = 0;
williamr@2
  1412
    } else {
williamr@2
  1413
      _CharT* __rest_buffer = _M_tree_ptr.allocate(_S_rounded_up_size(__rest));
williamr@2
  1414
      uninitialized_fill_n(__rest_buffer, __rest, __c);
williamr@4
  1415
      _S_construct_null(__rest_buffer + __rest);
williamr@2
  1416
      _STLP_TRY {
williamr@4
  1417
        __remainder = _S_new_RopeLeaf(__rest_buffer, __rest, __a);
williamr@2
  1418
      }
williamr@2
  1419
      _STLP_UNWIND(_RopeRep::_S_free_string(__rest_buffer, __rest, __a))
williamr@4
  1420
    }
williamr@2
  1421
    __remainder_rope._M_tree_ptr._M_data = __remainder;
williamr@2
  1422
    if (__exponent != 0) {
williamr@4
  1423
      _CharT* __base_buffer = _M_tree_ptr.allocate(_S_rounded_up_size(__exponentiate_threshold));
williamr@2
  1424
      _RopeLeaf* __base_leaf;
williamr@2
  1425
      rope<_CharT,_Alloc> __base_rope;
williamr@2
  1426
      uninitialized_fill_n(__base_buffer, __exponentiate_threshold, __c);
williamr@4
  1427
      _S_construct_null(__base_buffer + __exponentiate_threshold);
williamr@2
  1428
      _STLP_TRY {
williamr@4
  1429
        __base_leaf = _S_new_RopeLeaf(__base_buffer,
williamr@2
  1430
                                      __exponentiate_threshold, __a);
williamr@2
  1431
      }
williamr@4
  1432
      _STLP_UNWIND(_RopeRep::_S_free_string(__base_buffer,
williamr@2
  1433
                                            __exponentiate_threshold, __a))
williamr@4
  1434
      __base_rope._M_tree_ptr._M_data = __base_leaf;
williamr@2
  1435
      if (1 == __exponent) {
williamr@4
  1436
        __result = __base_rope;
williamr@4
  1437
        // One each for base_rope and __result
williamr@4
  1438
        //_STLP_ASSERT(2 == __result._M_tree_ptr._M_data->_M_ref_count)
williamr@2
  1439
      } else {
williamr@4
  1440
        __result = _STLP_PRIV __power(__base_rope, __exponent, _Concat_fn());
williamr@2
  1441
      }
williamr@2
  1442
      if (0 != __remainder) {
williamr@4
  1443
        __result += __remainder_rope;
williamr@2
  1444
      }
williamr@2
  1445
    } else {
williamr@2
  1446
      __result = __remainder_rope;
williamr@2
  1447
    }
williamr@2
  1448
    _M_tree_ptr._M_data = __result._M_tree_ptr._M_data;
williamr@2
  1449
    _M_tree_ptr._M_data->_M_ref_nonnil();
williamr@2
  1450
# undef __exponentiate_threshold
williamr@2
  1451
  }
williamr@2
  1452
williamr@2
  1453
  rope(const allocator_type& __a = allocator_type())
williamr@2
  1454
    : _M_tree_ptr(__a, (_RopeRep*)0) {}
williamr@2
  1455
williamr@2
  1456
  // Construct a rope from a function that can compute its members
williamr@2
  1457
  rope(char_producer<_CharT> *__fn, size_t __len, bool __delete_fn,
williamr@2
  1458
       const allocator_type& __a = allocator_type())
williamr@4
  1459
    : _M_tree_ptr(__a, (_RopeRep*)0) {
williamr@2
  1460
    _M_tree_ptr._M_data = (0 == __len) ?
williamr@2
  1461
      0 : _S_new_RopeFunction(__fn, __len, __delete_fn, __a);
williamr@2
  1462
  }
williamr@2
  1463
williamr@2
  1464
  rope(const _Self& __x)
williamr@4
  1465
    : _M_tree_ptr(__x._M_tree_ptr, __x._M_tree_ptr._M_data) {
williamr@2
  1466
    _S_ref(_M_tree_ptr._M_data);
williamr@2
  1467
  }
williamr@2
  1468
williamr@4
  1469
  rope(__move_source<_Self> __src)
williamr@4
  1470
    : _M_tree_ptr(__src.get()._M_tree_ptr, __src.get()._M_tree_ptr._M_data) {
williamr@4
  1471
    __src.get()._M_tree_ptr._M_data = 0;
williamr@4
  1472
  }
williamr@4
  1473
williamr@4
  1474
  ~rope() {
williamr@2
  1475
    _S_unref(_M_tree_ptr._M_data);
williamr@2
  1476
  }
williamr@2
  1477
williamr@4
  1478
  _Self& operator=(const _Self& __x) {
williamr@2
  1479
    _STLP_ASSERT(get_allocator() == __x.get_allocator())
williamr@4
  1480
    _S_ref(__x._M_tree_ptr._M_data);
williamr@4
  1481
    _M_reset(__x._M_tree_ptr._M_data);
williamr@4
  1482
    return *this;
williamr@2
  1483
  }
williamr@4
  1484
williamr@4
  1485
  void clear() {
williamr@2
  1486
    _S_unref(_M_tree_ptr._M_data);
williamr@2
  1487
    _M_tree_ptr._M_data = 0;
williamr@2
  1488
  }
williamr@4
  1489
  void push_back(_CharT __x) {
williamr@4
  1490
    _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, &__x, 1));
williamr@2
  1491
  }
williamr@2
  1492
williamr@4
  1493
  void pop_back() {
williamr@2
  1494
    _RopeRep* __old = _M_tree_ptr._M_data;
williamr@4
  1495
    _M_tree_ptr._M_data =
williamr@2
  1496
      _S_substring(_M_tree_ptr._M_data, 0, _M_tree_ptr._M_data->_M_size._M_data - 1);
williamr@2
  1497
    _S_unref(__old);
williamr@2
  1498
  }
williamr@2
  1499
williamr@4
  1500
  _CharT back() const {
williamr@2
  1501
    return _S_fetch(_M_tree_ptr._M_data, _M_tree_ptr._M_data->_M_size._M_data - 1);
williamr@2
  1502
  }
williamr@2
  1503
williamr@4
  1504
  void push_front(_CharT __x) {
williamr@2
  1505
    _RopeRep* __old = _M_tree_ptr._M_data;
williamr@2
  1506
    _RopeRep* __left =
williamr@4
  1507
      _S_RopeLeaf_from_unowned_char_ptr(&__x, 1, _M_tree_ptr);
williamr@2
  1508
    _STLP_TRY {
williamr@2
  1509
      _M_tree_ptr._M_data = _S_concat_rep(__left, _M_tree_ptr._M_data);
williamr@2
  1510
      _S_unref(__old);
williamr@2
  1511
      _S_unref(__left);
williamr@2
  1512
    }
williamr@2
  1513
    _STLP_UNWIND(_S_unref(__left))
williamr@4
  1514
  }
williamr@2
  1515
williamr@4
  1516
  void pop_front() {
williamr@2
  1517
    _RopeRep* __old = _M_tree_ptr._M_data;
williamr@2
  1518
    _M_tree_ptr._M_data = _S_substring(_M_tree_ptr._M_data, 1, _M_tree_ptr._M_data->_M_size._M_data);
williamr@2
  1519
    _S_unref(__old);
williamr@2
  1520
  }
williamr@2
  1521
williamr@4
  1522
  _CharT front() const {
williamr@2
  1523
    return _S_fetch(_M_tree_ptr._M_data, 0);
williamr@2
  1524
  }
williamr@2
  1525
williamr@4
  1526
  void balance() {
williamr@2
  1527
    _RopeRep* __old = _M_tree_ptr._M_data;
williamr@2
  1528
    _M_tree_ptr._M_data = _S_balance(_M_tree_ptr._M_data);
williamr@2
  1529
    _S_unref(__old);
williamr@2
  1530
  }
williamr@2
  1531
williamr@2
  1532
  void copy(_CharT* __buffer) const {
williamr@4
  1533
    _STLP_STD::_Destroy_Range(__buffer, __buffer + size());
williamr@2
  1534
    _S_flatten(_M_tree_ptr._M_data, __buffer);
williamr@2
  1535
  }
williamr@2
  1536
williamr@4
  1537
  /*
williamr@4
  1538
   * This is the copy function from the standard, but
williamr@4
  1539
   * with the arguments reordered to make it consistent with the
williamr@4
  1540
   * rest of the interface.
williamr@4
  1541
   * Note that this guaranteed not to compile if the draft standard
williamr@4
  1542
   * order is assumed.
williamr@4
  1543
   */
williamr@4
  1544
  size_type copy(size_type __pos, size_type __n, _CharT* __buffer) const {
williamr@2
  1545
    size_t _p_size = size();
williamr@2
  1546
    size_t __len = (__pos + __n > _p_size? _p_size - __pos : __n);
williamr@2
  1547
williamr@4
  1548
    _STLP_STD::_Destroy_Range(__buffer, __buffer + __len);
williamr@2
  1549
    _S_flatten(_M_tree_ptr._M_data, __pos, __len, __buffer);
williamr@2
  1550
    return __len;
williamr@2
  1551
  }
williamr@2
  1552
williamr@4
  1553
# ifdef _STLP_DEBUG
williamr@2
  1554
  // Print to stdout, exposing structure.  May be useful for
williamr@2
  1555
  // performance debugging.
williamr@2
  1556
  void dump() {
williamr@2
  1557
    _S_dump(_M_tree_ptr._M_data);
williamr@2
  1558
  }
williamr@4
  1559
# endif
williamr@2
  1560
williamr@2
  1561
  // Convert to 0 terminated string in new allocated memory.
williamr@2
  1562
  // Embedded 0s in the input do not terminate the copy.
williamr@2
  1563
  const _CharT* c_str() const;
williamr@2
  1564
williamr@4
  1565
  // As above, but also use the flattened representation as the
williamr@2
  1566
  // the new rope representation.
williamr@2
  1567
  const _CharT* replace_with_c_str();
williamr@2
  1568
williamr@2
  1569
  // Reclaim memory for the c_str generated flattened string.
williamr@2
  1570
  // Intentionally undocumented, since it's hard to say when this
williamr@2
  1571
  // is safe for multiple threads.
williamr@2
  1572
  void delete_c_str () {
williamr@2
  1573
    if (0 == _M_tree_ptr._M_data) return;
williamr@4
  1574
    if (_RopeRep::_S_leaf == _M_tree_ptr._M_data->_M_tag &&
williamr@4
  1575
        ((_RopeLeaf*)_M_tree_ptr._M_data)->_M_data ==
williamr@2
  1576
        _M_tree_ptr._M_data->_M_c_string) {
williamr@2
  1577
      // Representation shared
williamr@2
  1578
      return;
williamr@2
  1579
    }
williamr@2
  1580
    _M_tree_ptr._M_data->_M_free_c_string();
williamr@2
  1581
    _M_tree_ptr._M_data->_M_c_string = 0;
williamr@2
  1582
  }
williamr@2
  1583
williamr@2
  1584
  _CharT operator[] (size_type __pos) const {
williamr@2
  1585
    return _S_fetch(_M_tree_ptr._M_data, __pos);
williamr@2
  1586
  }
williamr@2
  1587
williamr@2
  1588
  _CharT at(size_type __pos) const {
williamr@4
  1589
    if (__pos >= size()) _M_throw_out_of_range();
williamr@2
  1590
    return (*this)[__pos];
williamr@2
  1591
  }
williamr@2
  1592
williamr@2
  1593
  const_iterator begin() const {
williamr@2
  1594
    return(const_iterator(_M_tree_ptr._M_data, 0));
williamr@2
  1595
  }
williamr@2
  1596
williamr@2
  1597
  // An easy way to get a const iterator from a non-const container.
williamr@2
  1598
  const_iterator const_begin() const {
williamr@2
  1599
    return(const_iterator(_M_tree_ptr._M_data, 0));
williamr@2
  1600
  }
williamr@2
  1601
williamr@2
  1602
  const_iterator end() const {
williamr@2
  1603
    return(const_iterator(_M_tree_ptr._M_data, size()));
williamr@2
  1604
  }
williamr@2
  1605
williamr@2
  1606
  const_iterator const_end() const {
williamr@2
  1607
    return(const_iterator(_M_tree_ptr._M_data, size()));
williamr@2
  1608
  }
williamr@2
  1609
williamr@4
  1610
  size_type size() const {
williamr@2
  1611
    return(0 == _M_tree_ptr._M_data? 0 : _M_tree_ptr._M_data->_M_size._M_data);
williamr@2
  1612
  }
williamr@2
  1613
williamr@2
  1614
  size_type length() const {
williamr@2
  1615
    return size();
williamr@2
  1616
  }
williamr@2
  1617
williamr@2
  1618
  size_type max_size() const {
williamr@2
  1619
    return _S_min_len[__ROPE_MAX_DEPTH-1] - 1;
williamr@4
  1620
    //  Guarantees that the result can be sufficiently
williamr@2
  1621
    //  balanced.  Longer ropes will probably still work,
williamr@2
  1622
    //  but it's harder to make guarantees.
williamr@2
  1623
  }
williamr@2
  1624
williamr@2
  1625
  const_reverse_iterator rbegin() const {
williamr@2
  1626
    return const_reverse_iterator(end());
williamr@2
  1627
  }
williamr@2
  1628
williamr@2
  1629
  const_reverse_iterator const_rbegin() const {
williamr@2
  1630
    return const_reverse_iterator(end());
williamr@2
  1631
  }
williamr@2
  1632
williamr@2
  1633
  const_reverse_iterator rend() const {
williamr@2
  1634
    return const_reverse_iterator(begin());
williamr@2
  1635
  }
williamr@2
  1636
williamr@2
  1637
  const_reverse_iterator const_rend() const {
williamr@2
  1638
    return const_reverse_iterator(begin());
williamr@2
  1639
  }
williamr@2
  1640
  // The symmetric cases are intentionally omitted, since they're presumed
williamr@2
  1641
  // to be less common, and we don't handle them as well.
williamr@2
  1642
williamr@2
  1643
  // The following should really be templatized.
williamr@2
  1644
  // The first argument should be an input iterator or
williamr@2
  1645
  // forward iterator with value_type _CharT.
williamr@2
  1646
  _Self& append(const _CharT* __iter, size_t __n) {
williamr@4
  1647
    _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, __iter, __n));
williamr@2
  1648
    return *this;
williamr@2
  1649
  }
williamr@2
  1650
williamr@2
  1651
  _Self& append(const _CharT* __c_string) {
williamr@2
  1652
    size_t __len = _S_char_ptr_len(__c_string);
williamr@2
  1653
    append(__c_string, __len);
williamr@4
  1654
    return *this;
williamr@2
  1655
  }
williamr@2
  1656
williamr@2
  1657
  _Self& append(const _CharT* __s, const _CharT* __e) {
williamr@4
  1658
    _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, __s, __e - __s));
williamr@2
  1659
    return *this;
williamr@2
  1660
  }
williamr@2
  1661
williamr@2
  1662
  _Self& append(const_iterator __s, const_iterator __e) {
williamr@2
  1663
    _STLP_ASSERT(__s._M_root == __e._M_root)
williamr@2
  1664
    _STLP_ASSERT(get_allocator() == __s._M_root->get_allocator())
williamr@4
  1665
    _Self_destruct_ptr __appendee(_S_substring(__s._M_root, __s._M_current_pos, __e._M_current_pos));
williamr@4
  1666
    _M_reset(_S_concat_rep(_M_tree_ptr._M_data, (_RopeRep*)__appendee));
williamr@2
  1667
    return *this;
williamr@2
  1668
  }
williamr@2
  1669
williamr@2
  1670
  _Self& append(_CharT __c) {
williamr@4
  1671
    _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, &__c, 1));
williamr@2
  1672
    return *this;
williamr@2
  1673
  }
williamr@2
  1674
williamr@2
  1675
  _Self& append() { return append(_CharT()); }  // XXX why?
williamr@2
  1676
williamr@2
  1677
  _Self& append(const _Self& __y) {
williamr@2
  1678
    _STLP_ASSERT(__y.get_allocator() == get_allocator())
williamr@4
  1679
    _M_reset(_S_concat_rep(_M_tree_ptr._M_data, __y._M_tree_ptr._M_data));
williamr@2
  1680
    return *this;
williamr@2
  1681
  }
williamr@2
  1682
williamr@2
  1683
  _Self& append(size_t __n, _CharT __c) {
williamr@2
  1684
    rope<_CharT,_Alloc> __last(__n, __c);
williamr@2
  1685
    return append(__last);
williamr@2
  1686
  }
williamr@2
  1687
williamr@2
  1688
  void swap(_Self& __b) {
williamr@4
  1689
    _M_tree_ptr.swap(__b._M_tree_ptr);
williamr@2
  1690
  }
williamr@2
  1691
williamr@2
  1692
protected:
williamr@2
  1693
  // Result is included in refcount.
williamr@2
  1694
  static _RopeRep* replace(_RopeRep* __old, size_t __pos1,
williamr@2
  1695
                           size_t __pos2, _RopeRep* __r) {
williamr@2
  1696
    if (0 == __old) { _S_ref(__r); return __r; }
williamr@4
  1697
    _Self_destruct_ptr __left(_S_substring(__old, 0, __pos1));
williamr@4
  1698
    _Self_destruct_ptr __right(_S_substring(__old, __pos2, __old->_M_size._M_data));
williamr@4
  1699
    _STLP_MPWFIX_TRY  //*TY 06/01/2000 -
williamr@2
  1700
    _RopeRep* __result;
williamr@2
  1701
williamr@2
  1702
    if (0 == __r) {
williamr@2
  1703
      __result = _S_concat_rep(__left, __right);
williamr@2
  1704
    } else {
williamr@2
  1705
      _STLP_ASSERT(__old->get_allocator() == __r->get_allocator())
williamr@2
  1706
      _Self_destruct_ptr __left_result(_S_concat_rep(__left, __r));
williamr@2
  1707
      __result = _S_concat_rep(__left_result, __right);
williamr@2
  1708
    }
williamr@2
  1709
    return __result;
williamr@4
  1710
    _STLP_MPWFIX_CATCH  //*TY 06/01/2000 -
williamr@2
  1711
  }
williamr@2
  1712
williamr@2
  1713
public:
williamr@2
  1714
  void insert(size_t __p, const _Self& __r) {
williamr@4
  1715
    if (__p > size()) _M_throw_out_of_range();
williamr@2
  1716
    _STLP_ASSERT(get_allocator() == __r.get_allocator())
williamr@4
  1717
    _M_reset(replace(_M_tree_ptr._M_data, __p, __p, __r._M_tree_ptr._M_data));
williamr@2
  1718
  }
williamr@2
  1719
williamr@2
  1720
  void insert(size_t __p, size_t __n, _CharT __c) {
williamr@2
  1721
    rope<_CharT,_Alloc> __r(__n,__c);
williamr@2
  1722
    insert(__p, __r);
williamr@2
  1723
  }
williamr@2
  1724
williamr@2
  1725
  void insert(size_t __p, const _CharT* __i, size_t __n) {
williamr@4
  1726
    if (__p > size()) _M_throw_out_of_range();
williamr@2
  1727
    _Self_destruct_ptr __left(_S_substring(_M_tree_ptr._M_data, 0, __p));
williamr@2
  1728
    _Self_destruct_ptr __right(_S_substring(_M_tree_ptr._M_data, __p, size()));
williamr@2
  1729
    _Self_destruct_ptr __left_result(
williamr@2
  1730
                                     _S_concat_char_iter(__left, __i, __n));
williamr@2
  1731
    // _S_ destr_concat_char_iter should be safe here.
williamr@2
  1732
    // But as it stands it's probably not a win, since __left
williamr@2
  1733
    // is likely to have additional references.
williamr@4
  1734
    _M_reset(_S_concat_rep(__left_result, __right));
williamr@2
  1735
  }
williamr@2
  1736
williamr@2
  1737
  void insert(size_t __p, const _CharT* __c_string) {
williamr@2
  1738
    insert(__p, __c_string, _S_char_ptr_len(__c_string));
williamr@2
  1739
  }
williamr@2
  1740
williamr@2
  1741
  void insert(size_t __p, _CharT __c) {
williamr@2
  1742
    insert(__p, &__c, 1);
williamr@2
  1743
  }
williamr@2
  1744
williamr@2
  1745
  void insert(size_t __p) {
williamr@2
  1746
    _CharT __c = _CharT();
williamr@2
  1747
    insert(__p, &__c, 1);
williamr@2
  1748
  }
williamr@2
  1749
williamr@2
  1750
  void insert(size_t __p, const _CharT* __i, const _CharT* __j) {
williamr@2
  1751
    _Self __r(__i, __j);
williamr@2
  1752
    insert(__p, __r);
williamr@2
  1753
  }
williamr@2
  1754
williamr@2
  1755
  void insert(size_t __p, const const_iterator& __i,
williamr@4
  1756
                          const const_iterator& __j) {
williamr@2
  1757
    _Self __r(__i, __j);
williamr@2
  1758
    insert(__p, __r);
williamr@2
  1759
  }
williamr@2
  1760
williamr@2
  1761
  void insert(size_t __p, const iterator& __i,
williamr@4
  1762
                          const iterator& __j) {
williamr@2
  1763
    _Self __r(__i, __j);
williamr@2
  1764
    insert(__p, __r);
williamr@2
  1765
  }
williamr@2
  1766
williamr@2
  1767
  // (position, length) versions of replace operations:
williamr@2
  1768
  void replace(size_t __p, size_t __n, const _Self& __r) {
williamr@4
  1769
    if (__p > size()) _M_throw_out_of_range();
williamr@4
  1770
    _M_reset(replace(_M_tree_ptr._M_data, __p, __p + __n, __r._M_tree_ptr._M_data));
williamr@2
  1771
  }
williamr@2
  1772
williamr@4
  1773
  void replace(size_t __p, size_t __n,
williamr@2
  1774
               const _CharT* __i, size_t __i_len) {
williamr@2
  1775
    _Self __r(__i, __i_len);
williamr@2
  1776
    replace(__p, __n, __r);
williamr@2
  1777
  }
williamr@2
  1778
williamr@2
  1779
  void replace(size_t __p, size_t __n, _CharT __c) {
williamr@2
  1780
    _Self __r(__c);
williamr@2
  1781
    replace(__p, __n, __r);
williamr@2
  1782
  }
williamr@2
  1783
williamr@2
  1784
  void replace(size_t __p, size_t __n, const _CharT* __c_string) {
williamr@2
  1785
    _Self __r(__c_string);
williamr@2
  1786
    replace(__p, __n, __r);
williamr@2
  1787
  }
williamr@2
  1788
williamr@4
  1789
  void replace(size_t __p, size_t __n,
williamr@2
  1790
               const _CharT* __i, const _CharT* __j) {
williamr@2
  1791
    _Self __r(__i, __j);
williamr@2
  1792
    replace(__p, __n, __r);
williamr@2
  1793
  }
williamr@2
  1794
williamr@2
  1795
  void replace(size_t __p, size_t __n,
williamr@2
  1796
               const const_iterator& __i, const const_iterator& __j) {
williamr@2
  1797
    _Self __r(__i, __j);
williamr@2
  1798
    replace(__p, __n, __r);
williamr@2
  1799
  }
williamr@2
  1800
williamr@2
  1801
  void replace(size_t __p, size_t __n,
williamr@2
  1802
               const iterator& __i, const iterator& __j) {
williamr@2
  1803
    _Self __r(__i, __j);
williamr@2
  1804
    replace(__p, __n, __r);
williamr@2
  1805
  }
williamr@2
  1806
williamr@2
  1807
  // Single character variants:
williamr@2
  1808
  void replace(size_t __p, _CharT __c) {
williamr@4
  1809
    if (__p > size()) _M_throw_out_of_range();
williamr@2
  1810
    iterator __i(this, __p);
williamr@2
  1811
    *__i = __c;
williamr@2
  1812
  }
williamr@2
  1813
williamr@2
  1814
  void replace(size_t __p, const _Self& __r) {
williamr@2
  1815
    replace(__p, 1, __r);
williamr@2
  1816
  }
williamr@2
  1817
williamr@2
  1818
  void replace(size_t __p, const _CharT* __i, size_t __i_len) {
williamr@2
  1819
    replace(__p, 1, __i, __i_len);
williamr@2
  1820
  }
williamr@2
  1821
williamr@2
  1822
  void replace(size_t __p, const _CharT* __c_string) {
williamr@2
  1823
    replace(__p, 1, __c_string);
williamr@2
  1824
  }
williamr@2
  1825
williamr@2
  1826
  void replace(size_t __p, const _CharT* __i, const _CharT* __j) {
williamr@2
  1827
    replace(__p, 1, __i, __j);
williamr@2
  1828
  }
williamr@2
  1829
williamr@2
  1830
  void replace(size_t __p, const const_iterator& __i,
williamr@4
  1831
                           const const_iterator& __j) {
williamr@2
  1832
    replace(__p, 1, __i, __j);
williamr@2
  1833
  }
williamr@2
  1834
williamr@2
  1835
  void replace(size_t __p, const iterator& __i,
williamr@4
  1836
                           const iterator& __j) {
williamr@2
  1837
    replace(__p, 1, __i, __j);
williamr@2
  1838
  }
williamr@2
  1839
williamr@2
  1840
  // Erase, (position, size) variant.
williamr@2
  1841
  void erase(size_t __p, size_t __n) {
williamr@4
  1842
    if (__p > size()) _M_throw_out_of_range();
williamr@4
  1843
    _M_reset(replace(_M_tree_ptr._M_data, __p, __p + __n, 0));
williamr@2
  1844
  }
williamr@2
  1845
williamr@2
  1846
  // Erase, single character
williamr@2
  1847
  void erase(size_t __p) {
williamr@2
  1848
    erase(__p, __p + 1);
williamr@2
  1849
  }
williamr@2
  1850
williamr@4
  1851
  // Insert, iterator variants.
williamr@2
  1852
  iterator insert(const iterator& __p, const _Self& __r)
williamr@2
  1853
  { insert(__p.index(), __r); return __p; }
williamr@2
  1854
  iterator insert(const iterator& __p, size_t __n, _CharT __c)
williamr@2
  1855
  { insert(__p.index(), __n, __c); return __p; }
williamr@4
  1856
  iterator insert(const iterator& __p, _CharT __c)
williamr@2
  1857
  { insert(__p.index(), __c); return __p; }
williamr@4
  1858
  iterator insert(const iterator& __p )
williamr@2
  1859
  { insert(__p.index()); return __p; }
williamr@4
  1860
  iterator insert(const iterator& __p, const _CharT* c_string)
williamr@2
  1861
  { insert(__p.index(), c_string); return __p; }
williamr@2
  1862
  iterator insert(const iterator& __p, const _CharT* __i, size_t __n)
williamr@2
  1863
  { insert(__p.index(), __i, __n); return __p; }
williamr@4
  1864
  iterator insert(const iterator& __p, const _CharT* __i,
williamr@2
  1865
                  const _CharT* __j)
williamr@2
  1866
  { insert(__p.index(), __i, __j);  return __p; }
williamr@2
  1867
  iterator insert(const iterator& __p,
williamr@2
  1868
                  const const_iterator& __i, const const_iterator& __j)
williamr@2
  1869
  { insert(__p.index(), __i, __j); return __p; }
williamr@2
  1870
  iterator insert(const iterator& __p,
williamr@2
  1871
                  const iterator& __i, const iterator& __j)
williamr@2
  1872
  { insert(__p.index(), __i, __j); return __p; }
williamr@2
  1873
williamr@2
  1874
  // Replace, range variants.
williamr@2
  1875
  void replace(const iterator& __p, const iterator& __q,
williamr@2
  1876
               const _Self& __r)
williamr@2
  1877
  { replace(__p.index(), __q.index() - __p.index(), __r); }
williamr@2
  1878
  void replace(const iterator& __p, const iterator& __q, _CharT __c)
williamr@2
  1879
  { replace(__p.index(), __q.index() - __p.index(), __c); }
williamr@2
  1880
  void replace(const iterator& __p, const iterator& __q,
williamr@2
  1881
               const _CharT* __c_string)
williamr@2
  1882
  { replace(__p.index(), __q.index() - __p.index(), __c_string); }
williamr@2
  1883
  void replace(const iterator& __p, const iterator& __q,
williamr@2
  1884
               const _CharT* __i, size_t __n)
williamr@2
  1885
  { replace(__p.index(), __q.index() - __p.index(), __i, __n); }
williamr@2
  1886
  void replace(const iterator& __p, const iterator& __q,
williamr@2
  1887
               const _CharT* __i, const _CharT* __j)
williamr@2
  1888
  { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
williamr@2
  1889
  void replace(const iterator& __p, const iterator& __q,
williamr@2
  1890
               const const_iterator& __i, const const_iterator& __j)
williamr@2
  1891
  { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
williamr@2
  1892
  void replace(const iterator& __p, const iterator& __q,
williamr@2
  1893
               const iterator& __i, const iterator& __j)
williamr@2
  1894
  { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
williamr@2
  1895
williamr@2
  1896
  // Replace, iterator variants.
williamr@2
  1897
  void replace(const iterator& __p, const _Self& __r)
williamr@2
  1898
  { replace(__p.index(), __r); }
williamr@2
  1899
  void replace(const iterator& __p, _CharT __c)
williamr@2
  1900
  { replace(__p.index(), __c); }
williamr@2
  1901
  void replace(const iterator& __p, const _CharT* __c_string)
williamr@2
  1902
  { replace(__p.index(), __c_string); }
williamr@2
  1903
  void replace(const iterator& __p, const _CharT* __i, size_t __n)
williamr@2
  1904
  { replace(__p.index(), __i, __n); }
williamr@2
  1905
  void replace(const iterator& __p, const _CharT* __i, const _CharT* __j)
williamr@2
  1906
  { replace(__p.index(), __i, __j); }
williamr@4
  1907
  void replace(const iterator& __p, const_iterator __i,
williamr@2
  1908
               const_iterator __j)
williamr@2
  1909
  { replace(__p.index(), __i, __j); }
williamr@2
  1910
  void replace(const iterator& __p, iterator __i, iterator __j)
williamr@2
  1911
  { replace(__p.index(), __i, __j); }
williamr@2
  1912
williamr@2
  1913
  // Iterator and range variants of erase
williamr@2
  1914
  iterator erase(const iterator& __p, const iterator& __q) {
williamr@2
  1915
    size_t __p_index = __p.index();
williamr@2
  1916
    erase(__p_index, __q.index() - __p_index);
williamr@2
  1917
    return iterator(this, __p_index);
williamr@2
  1918
  }
williamr@2
  1919
  iterator erase(const iterator& __p) {
williamr@2
  1920
    size_t __p_index = __p.index();
williamr@2
  1921
    erase(__p_index, 1);
williamr@2
  1922
    return iterator(this, __p_index);
williamr@2
  1923
  }
williamr@2
  1924
williamr@2
  1925
  _Self substr(size_t __start, size_t __len = 1) const {
williamr@4
  1926
    if (__start > size()) _M_throw_out_of_range();
williamr@4
  1927
    return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __start, __start + __len));
williamr@2
  1928
  }
williamr@2
  1929
williamr@2
  1930
  _Self substr(iterator __start, iterator __end) const {
williamr@4
  1931
    return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __start.index(), __end.index()));
williamr@2
  1932
  }
williamr@4
  1933
williamr@2
  1934
  _Self substr(iterator __start) const {
williamr@2
  1935
    size_t __pos = __start.index();
williamr@4
  1936
    return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __pos, __pos + 1));
williamr@2
  1937
  }
williamr@4
  1938
williamr@2
  1939
  _Self substr(const_iterator __start, const_iterator __end) const {
williamr@2
  1940
    // This might eventually take advantage of the cache in the
williamr@2
  1941
    // iterator.
williamr@4
  1942
    return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __start.index(), __end.index()));
williamr@2
  1943
  }
williamr@2
  1944
williamr@2
  1945
  rope<_CharT,_Alloc> substr(const_iterator __start) {
williamr@2
  1946
    size_t __pos = __start.index();
williamr@4
  1947
    return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __pos, __pos + 1));
williamr@2
  1948
  }
williamr@2
  1949
williamr@4
  1950
#include <stl/_string_npos.h>
williamr@2
  1951
williamr@4
  1952
  size_type find(const _Self& __s, size_type __pos = 0) const {
williamr@4
  1953
    if (__pos >= size())
williamr@4
  1954
# ifndef _STLP_OLD_ROPE_SEMANTICS
williamr@4
  1955
      return npos;
williamr@4
  1956
# else
williamr@4
  1957
      return size();
williamr@4
  1958
# endif
williamr@2
  1959
williamr@4
  1960
    size_type __result_pos;
williamr@4
  1961
    const_iterator __result = search(const_begin() + (ptrdiff_t)__pos, const_end(), __s.begin(), __s.end() );
williamr@4
  1962
    __result_pos = __result.index();
williamr@4
  1963
# ifndef _STLP_OLD_ROPE_SEMANTICS
williamr@4
  1964
    if (__result_pos == size()) __result_pos = npos;
williamr@4
  1965
# endif
williamr@4
  1966
    return __result_pos;
williamr@4
  1967
  }
williamr@2
  1968
  size_type find(_CharT __c, size_type __pos = 0) const;
williamr@2
  1969
  size_type find(const _CharT* __s, size_type __pos = 0) const {
williamr@2
  1970
    size_type __result_pos;
williamr@2
  1971
    const_iterator __result = search(const_begin() + (ptrdiff_t)__pos, const_end(),
williamr@2
  1972
                                     __s, __s + _S_char_ptr_len(__s));
williamr@2
  1973
    __result_pos = __result.index();
williamr@4
  1974
# ifndef _STLP_OLD_ROPE_SEMANTICS
williamr@2
  1975
    if (__result_pos == size()) __result_pos = npos;
williamr@4
  1976
# endif
williamr@2
  1977
    return __result_pos;
williamr@2
  1978
  }
williamr@2
  1979
williamr@2
  1980
  iterator mutable_begin() {
williamr@2
  1981
    return(iterator(this, 0));
williamr@2
  1982
  }
williamr@2
  1983
williamr@2
  1984
  iterator mutable_end() {
williamr@2
  1985
    return(iterator(this, size()));
williamr@2
  1986
  }
williamr@2
  1987
williamr@2
  1988
  reverse_iterator mutable_rbegin() {
williamr@2
  1989
    return reverse_iterator(mutable_end());
williamr@2
  1990
  }
williamr@2
  1991
williamr@2
  1992
  reverse_iterator mutable_rend() {
williamr@2
  1993
    return reverse_iterator(mutable_begin());
williamr@2
  1994
  }
williamr@2
  1995
williamr@2
  1996
  reference mutable_reference_at(size_type __pos) {
williamr@2
  1997
    return reference(this, __pos);
williamr@2
  1998
  }
williamr@2
  1999
williamr@4
  2000
# ifdef __STD_STUFF
williamr@2
  2001
  reference operator[] (size_type __pos) {
williamr@2
  2002
    return reference(this, __pos);
williamr@2
  2003
  }
williamr@2
  2004
williamr@2
  2005
  reference at(size_type __pos) {
williamr@4
  2006
    if (__pos >= size()) _M_throw_out_of_range();
williamr@2
  2007
    return (*this)[__pos];
williamr@2
  2008
  }
williamr@2
  2009
williamr@2
  2010
  void resize(size_type, _CharT) {}
williamr@2
  2011
  void resize(size_type) {}
williamr@2
  2012
  void reserve(size_type = 0) {}
williamr@2
  2013
  size_type capacity() const {
williamr@2
  2014
    return max_size();
williamr@2
  2015
  }
williamr@2
  2016
williamr@2
  2017
  // Stuff below this line is dangerous because it's error prone.
williamr@2
  2018
  // I would really like to get rid of it.
williamr@2
  2019
  // copy function with funny arg ordering.
williamr@4
  2020
  size_type copy(_CharT* __buffer, size_type __n,
williamr@2
  2021
                 size_type __pos = 0) const {
williamr@2
  2022
    return copy(__pos, __n, __buffer);
williamr@2
  2023
  }
williamr@2
  2024
williamr@2
  2025
  iterator end() { return mutable_end(); }
williamr@2
  2026
williamr@2
  2027
  iterator begin() { return mutable_begin(); }
williamr@2
  2028
williamr@2
  2029
  reverse_iterator rend() { return mutable_rend(); }
williamr@2
  2030
williamr@2
  2031
  reverse_iterator rbegin() { return mutable_rbegin(); }
williamr@2
  2032
williamr@4
  2033
# else
williamr@2
  2034
williamr@2
  2035
  const_iterator end() { return const_end(); }
williamr@2
  2036
williamr@2
  2037
  const_iterator begin() { return const_begin(); }
williamr@2
  2038
williamr@2
  2039
  const_reverse_iterator rend() { return const_rend(); }
williamr@4
  2040
williamr@2
  2041
  const_reverse_iterator rbegin() { return const_rbegin(); }
williamr@2
  2042
williamr@4
  2043
# endif
williamr@4
  2044
}; //class rope
williamr@2
  2045
williamr@4
  2046
#if !defined (_STLP_STATIC_CONST_INIT_BUG)
williamr@4
  2047
#  if defined (__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 96)
williamr@4
  2048
template <class _CharT, class _Alloc>
williamr@4
  2049
const size_t rope<_CharT, _Alloc>::npos = ~(size_t) 0;
williamr@4
  2050
#  endif
williamr@4
  2051
#endif
williamr@2
  2052
williamr@2
  2053
template <class _CharT, class _Alloc>
williamr@4
  2054
inline _CharT
williamr@2
  2055
_Rope_const_iterator< _CharT, _Alloc>::operator[](size_t __n)
williamr@4
  2056
{ return rope<_CharT,_Alloc>::_S_fetch(this->_M_root, this->_M_current_pos + __n); }
williamr@2
  2057
williamr@2
  2058
template <class _CharT, class _Alloc>
williamr@2
  2059
inline bool operator== (const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@2
  2060
                        const _Rope_const_iterator<_CharT,_Alloc>& __y) {
williamr@4
  2061
  return (__x._M_current_pos == __y._M_current_pos &&
williamr@2
  2062
          __x._M_root == __y._M_root);
williamr@2
  2063
}
williamr@2
  2064
williamr@2
  2065
template <class _CharT, class _Alloc>
williamr@2
  2066
inline bool operator< (const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@4
  2067
                       const _Rope_const_iterator<_CharT,_Alloc>& __y)
williamr@4
  2068
{ return (__x._M_current_pos < __y._M_current_pos); }
williamr@2
  2069
williamr@2
  2070
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
williamr@2
  2071
williamr@2
  2072
template <class _CharT, class _Alloc>
williamr@2
  2073
inline bool operator!= (const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@4
  2074
                        const _Rope_const_iterator<_CharT,_Alloc>& __y)
williamr@4
  2075
{ return !(__x == __y); }
williamr@2
  2076
williamr@2
  2077
template <class _CharT, class _Alloc>
williamr@2
  2078
inline bool operator> (const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@4
  2079
                       const _Rope_const_iterator<_CharT,_Alloc>& __y)
williamr@4
  2080
{ return __y < __x; }
williamr@2
  2081
williamr@2
  2082
template <class _CharT, class _Alloc>
williamr@2
  2083
inline bool operator<= (const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@4
  2084
                        const _Rope_const_iterator<_CharT,_Alloc>& __y)
williamr@4
  2085
{ return !(__y < __x); }
williamr@2
  2086
williamr@2
  2087
template <class _CharT, class _Alloc>
williamr@2
  2088
inline bool operator>= (const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@4
  2089
                        const _Rope_const_iterator<_CharT,_Alloc>& __y)
williamr@4
  2090
{ return !(__x < __y); }
williamr@2
  2091
williamr@2
  2092
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
williamr@2
  2093
williamr@2
  2094
template <class _CharT, class _Alloc>
williamr@2
  2095
inline ptrdiff_t operator-(const _Rope_const_iterator<_CharT,_Alloc>& __x,
williamr@4
  2096
                           const _Rope_const_iterator<_CharT,_Alloc>& __y)
williamr@4
  2097
{ return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; }
williamr@2
  2098
williamr@4
  2099
#if !defined( __MWERKS__ ) || __MWERKS__ >= 0x2000  // dwa 8/21/97  - "ambiguous access to overloaded function" bug.
williamr@2
  2100
template <class _CharT, class _Alloc>
williamr@2
  2101
inline _Rope_const_iterator<_CharT,_Alloc>
williamr@4
  2102
operator-(const _Rope_const_iterator<_CharT,_Alloc>& __x, ptrdiff_t __n)
williamr@4
  2103
{ return _Rope_const_iterator<_CharT,_Alloc>(__x._M_root, __x._M_current_pos - __n); }
williamr@2
  2104
# endif
williamr@2
  2105
williamr@2
  2106
template <class _CharT, class _Alloc>
williamr@2
  2107
inline _Rope_const_iterator<_CharT,_Alloc>
williamr@4
  2108
operator+(const _Rope_const_iterator<_CharT,_Alloc>& __x, ptrdiff_t __n)
williamr@4
  2109
{ return _Rope_const_iterator<_CharT,_Alloc>(__x._M_root, __x._M_current_pos + __n); }
williamr@2
  2110
williamr@2
  2111
template <class _CharT, class _Alloc>
williamr@2
  2112
inline _Rope_const_iterator<_CharT,_Alloc>
williamr@4
  2113
operator+(ptrdiff_t __n, const _Rope_const_iterator<_CharT,_Alloc>& __x)
williamr@4
  2114
{ return _Rope_const_iterator<_CharT,_Alloc>(__x._M_root, __x._M_current_pos + __n); }
williamr@2
  2115
williamr@2
  2116
template <class _CharT, class _Alloc>
williamr@2
  2117
inline bool operator== (const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@2
  2118
                        const _Rope_iterator<_CharT,_Alloc>& __y) {
williamr@4
  2119
  return (__x._M_current_pos == __y._M_current_pos &&
williamr@2
  2120
          __x._M_root_rope == __y._M_root_rope);
williamr@2
  2121
}
williamr@2
  2122
williamr@2
  2123
template <class _CharT, class _Alloc>
williamr@2
  2124
inline bool operator< (const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@4
  2125
                       const _Rope_iterator<_CharT,_Alloc>& __y)
williamr@4
  2126
{ return (__x._M_current_pos < __y._M_current_pos); }
williamr@2
  2127
williamr@4
  2128
#if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
williamr@2
  2129
template <class _CharT, class _Alloc>
williamr@2
  2130
inline bool operator!= (const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@4
  2131
                        const _Rope_iterator<_CharT,_Alloc>& __y)
williamr@4
  2132
{ return !(__x == __y); }
williamr@2
  2133
williamr@2
  2134
template <class _CharT, class _Alloc>
williamr@2
  2135
inline bool operator> (const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@4
  2136
                       const _Rope_iterator<_CharT,_Alloc>& __y)
williamr@4
  2137
{ return __y < __x; }
williamr@2
  2138
williamr@2
  2139
template <class _CharT, class _Alloc>
williamr@2
  2140
inline bool operator<= (const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@4
  2141
                        const _Rope_iterator<_CharT,_Alloc>& __y)
williamr@4
  2142
{ return !(__y < __x); }
williamr@2
  2143
williamr@2
  2144
template <class _CharT, class _Alloc>
williamr@2
  2145
inline bool operator>= (const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@4
  2146
                        const _Rope_iterator<_CharT,_Alloc>& __y)
williamr@4
  2147
{ return !(__x < __y); }
williamr@2
  2148
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
williamr@2
  2149
williamr@2
  2150
template <class _CharT, class _Alloc>
williamr@2
  2151
inline ptrdiff_t operator-(const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@4
  2152
                           const _Rope_iterator<_CharT,_Alloc>& __y)
williamr@4
  2153
{ return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; }
williamr@2
  2154
williamr@4
  2155
#if !defined( __MWERKS__ ) || __MWERKS__ >= 0x2000  // dwa 8/21/97  - "ambiguous access to overloaded function" bug.
williamr@2
  2156
template <class _CharT, class _Alloc>
williamr@2
  2157
inline _Rope_iterator<_CharT,_Alloc>
williamr@2
  2158
operator-(const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@2
  2159
          ptrdiff_t __n) {
williamr@4
  2160
  return _Rope_iterator<_CharT,_Alloc>(__x._M_root_rope, __x._M_current_pos - __n);
williamr@2
  2161
}
williamr@2
  2162
# endif
williamr@2
  2163
williamr@2
  2164
template <class _CharT, class _Alloc>
williamr@2
  2165
inline _Rope_iterator<_CharT,_Alloc>
williamr@2
  2166
operator+(const _Rope_iterator<_CharT,_Alloc>& __x,
williamr@2
  2167
          ptrdiff_t __n) {
williamr@4
  2168
  return _Rope_iterator<_CharT,_Alloc>(__x._M_root_rope, __x._M_current_pos + __n);
williamr@2
  2169
}
williamr@2
  2170
williamr@2
  2171
template <class _CharT, class _Alloc>
williamr@2
  2172
inline _Rope_iterator<_CharT,_Alloc>
williamr@2
  2173
operator+(ptrdiff_t __n, const _Rope_iterator<_CharT,_Alloc>& __x) {
williamr@4
  2174
  return _Rope_iterator<_CharT,_Alloc>(__x._M_root_rope, __x._M_current_pos + __n);
williamr@2
  2175
}
williamr@2
  2176
williamr@2
  2177
template <class _CharT, class _Alloc>
williamr@4
  2178
inline rope<_CharT,_Alloc>
williamr@2
  2179
operator+ (const rope<_CharT,_Alloc>& __left,
williamr@4
  2180
           const rope<_CharT,_Alloc>& __right) {
williamr@2
  2181
  _STLP_ASSERT(__left.get_allocator() == __right.get_allocator())
williamr@2
  2182
  return rope<_CharT,_Alloc>(rope<_CharT,_Alloc>::_S_concat_rep(__left._M_tree_ptr._M_data, __right._M_tree_ptr._M_data));
williamr@4
  2183
  // Inlining this should make it possible to keep __left and __right in registers.
williamr@2
  2184
}
williamr@2
  2185
williamr@2
  2186
template <class _CharT, class _Alloc>
williamr@4
  2187
inline rope<_CharT,_Alloc>&
williamr@4
  2188
operator+= (rope<_CharT,_Alloc>& __left,
williamr@4
  2189
            const rope<_CharT,_Alloc>& __right) {
williamr@2
  2190
  __left.append(__right);
williamr@2
  2191
  return __left;
williamr@2
  2192
}
williamr@2
  2193
williamr@2
  2194
template <class _CharT, class _Alloc>
williamr@4
  2195
inline rope<_CharT,_Alloc>
williamr@2
  2196
operator+ (const rope<_CharT,_Alloc>& __left,
williamr@2
  2197
           const _CharT* __right) {
williamr@2
  2198
  size_t __rlen = rope<_CharT,_Alloc>::_S_char_ptr_len(__right);
williamr@4
  2199
  return rope<_CharT,_Alloc>(rope<_CharT,_Alloc>::_S_concat_char_iter(__left._M_tree_ptr._M_data, __right, __rlen));
williamr@2
  2200
}
williamr@2
  2201
williamr@2
  2202
template <class _CharT, class _Alloc>
williamr@4
  2203
inline rope<_CharT,_Alloc>&
williamr@2
  2204
operator+= (rope<_CharT,_Alloc>& __left,
williamr@2
  2205
            const _CharT* __right) {
williamr@2
  2206
  __left.append(__right);
williamr@2
  2207
  return __left;
williamr@2
  2208
}
williamr@2
  2209
williamr@2
  2210
template <class _CharT, class _Alloc>
williamr@4
  2211
inline rope<_CharT,_Alloc>
williamr@4
  2212
operator+ (const rope<_CharT,_Alloc>& __left, _CharT __right) {
williamr@4
  2213
  return rope<_CharT,_Alloc>(rope<_CharT,_Alloc>::_S_concat_char_iter(__left._M_tree_ptr._M_data, &__right, 1));
williamr@2
  2214
}
williamr@2
  2215
williamr@2
  2216
template <class _CharT, class _Alloc>
williamr@4
  2217
inline rope<_CharT,_Alloc>&
williamr@4
  2218
operator+= (rope<_CharT,_Alloc>& __left, _CharT __right) {
williamr@2
  2219
  __left.append(__right);
williamr@2
  2220
  return __left;
williamr@2
  2221
}
williamr@2
  2222
williamr@2
  2223
template <class _CharT, class _Alloc>
williamr@2
  2224
inline bool
williamr@4
  2225
operator< (const rope<_CharT,_Alloc>& __left,
williamr@2
  2226
           const rope<_CharT,_Alloc>& __right) {
williamr@2
  2227
  return __left.compare(__right) < 0;
williamr@2
  2228
}
williamr@4
  2229
williamr@2
  2230
template <class _CharT, class _Alloc>
williamr@2
  2231
inline bool
williamr@4
  2232
operator== (const rope<_CharT,_Alloc>& __left,
williamr@2
  2233
            const rope<_CharT,_Alloc>& __right) {
williamr@2
  2234
  return __left.compare(__right) == 0;
williamr@2
  2235
}
williamr@2
  2236
williamr@2
  2237
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
williamr@2
  2238
williamr@2
  2239
template <class _CharT, class _Alloc>
williamr@2
  2240
inline bool
williamr@2
  2241
operator!= (const rope<_CharT,_Alloc>& __x, const rope<_CharT,_Alloc>& __y) {
williamr@2
  2242
  return !(__x == __y);
williamr@2
  2243
}
williamr@2
  2244
williamr@2
  2245
template <class _CharT, class _Alloc>
williamr@2
  2246
inline bool
williamr@2
  2247
operator> (const rope<_CharT,_Alloc>& __x, const rope<_CharT,_Alloc>& __y) {
williamr@2
  2248
  return __y < __x;
williamr@2
  2249
}
williamr@2
  2250
williamr@2
  2251
template <class _CharT, class _Alloc>
williamr@2
  2252
inline bool
williamr@2
  2253
operator<= (const rope<_CharT,_Alloc>& __x, const rope<_CharT,_Alloc>& __y) {
williamr@2
  2254
  return !(__y < __x);
williamr@2
  2255
}
williamr@2
  2256
williamr@2
  2257
template <class _CharT, class _Alloc>
williamr@2
  2258
inline bool
williamr@2
  2259
operator>= (const rope<_CharT,_Alloc>& __x, const rope<_CharT,_Alloc>& __y) {
williamr@2
  2260
  return !(__x < __y);
williamr@2
  2261
}
williamr@2
  2262
williamr@2
  2263
template <class _CharT, class _Alloc>
williamr@2
  2264
inline bool operator!= (const _Rope_char_ptr_proxy<_CharT,_Alloc>& __x,
williamr@2
  2265
                        const _Rope_char_ptr_proxy<_CharT,_Alloc>& __y) {
williamr@2
  2266
  return !(__x == __y);
williamr@2
  2267
}
williamr@2
  2268
williamr@2
  2269
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
williamr@2
  2270
williamr@2
  2271
template <class _CharT, class _Alloc>
williamr@2
  2272
inline bool operator== (const _Rope_char_ptr_proxy<_CharT,_Alloc>& __x,
williamr@2
  2273
                        const _Rope_char_ptr_proxy<_CharT,_Alloc>& __y) {
williamr@2
  2274
  return (__x._M_pos == __y._M_pos && __x._M_root == __y._M_root);
williamr@2
  2275
}
williamr@2
  2276
williamr@4
  2277
#if !defined (_STLP_USE_NO_IOSTREAMS)
williamr@2
  2278
template<class _CharT, class _Traits, class _Alloc>
williamr@4
  2279
basic_ostream<_CharT, _Traits>& operator<< (basic_ostream<_CharT, _Traits>& __o,
williamr@2
  2280
                                            const rope<_CharT, _Alloc>& __r);
williamr@2
  2281
#endif
williamr@4
  2282
williamr@2
  2283
typedef rope<char, _STLP_DEFAULT_ALLOCATOR(char) > crope;
williamr@4
  2284
#if defined (_STLP_HAS_WCHAR_T)
williamr@2
  2285
typedef rope<wchar_t, _STLP_DEFAULT_ALLOCATOR(wchar_t) > wrope;
williamr@4
  2286
#endif
williamr@2
  2287
williamr@2
  2288
inline crope::reference __mutable_reference_at(crope& __c, size_t __i)
williamr@4
  2289
{ return __c.mutable_reference_at(__i); }
williamr@2
  2290
williamr@4
  2291
#if defined (_STLP_HAS_WCHAR_T)
williamr@2
  2292
inline wrope::reference __mutable_reference_at(wrope& __c, size_t __i)
williamr@4
  2293
{ return __c.mutable_reference_at(__i); }
williamr@4
  2294
#endif
williamr@2
  2295
williamr@4
  2296
#if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
williamr@2
  2297
template <class _CharT, class _Alloc>
williamr@4
  2298
inline void swap(rope<_CharT,_Alloc>& __x, rope<_CharT,_Alloc>& __y)
williamr@4
  2299
{ __x.swap(__y); }
williamr@2
  2300
#else
williamr@2
  2301
williamr@2
  2302
inline void swap(crope& __x, crope& __y) { __x.swap(__y); }
williamr@4
  2303
# ifdef _STLP_HAS_WCHAR_T  // dwa 8/21/97
williamr@2
  2304
inline void swap(wrope& __x, wrope& __y) { __x.swap(__y); }
williamr@2
  2305
# endif
williamr@2
  2306
williamr@2
  2307
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
williamr@2
  2308
williamr@2
  2309
williamr@2
  2310
// Hash functions should probably be revisited later:
williamr@4
  2311
_STLP_TEMPLATE_NULL struct hash<crope> {
williamr@4
  2312
  size_t operator()(const crope& __str) const {
williamr@2
  2313
    size_t _p_size = __str.size();
williamr@2
  2314
williamr@2
  2315
    if (0 == _p_size) return 0;
williamr@2
  2316
    return 13*__str[0] + 5*__str[_p_size - 1] + _p_size;
williamr@2
  2317
  }
williamr@2
  2318
};
williamr@2
  2319
williamr@4
  2320
#if defined (_STLP_HAS_WCHAR_T)  // dwa 8/21/97
williamr@4
  2321
_STLP_TEMPLATE_NULL struct hash<wrope> {
williamr@4
  2322
  size_t operator()(const wrope& __str) const {
williamr@2
  2323
    size_t _p_size = __str.size();
williamr@2
  2324
williamr@2
  2325
    if (0 == _p_size) return 0;
williamr@2
  2326
    return 13*__str[0] + 5*__str[_p_size - 1] + _p_size;
williamr@2
  2327
  }
williamr@2
  2328
};
williamr@2
  2329
#endif
williamr@2
  2330
williamr@4
  2331
#if (!defined (_STLP_MSVC) || (_STLP_MSVC >= 1310))
williamr@2
  2332
// I couldn't get this to work with VC++
williamr@2
  2333
template<class _CharT,class _Alloc>
williamr@4
  2334
#  if defined (__DMC__) && !defined (__PUT_STATIC_DATA_MEMBERS_HERE)
williamr@4
  2335
extern
williamr@4
  2336
#  endif
williamr@4
  2337
void _Rope_rotate(_Rope_iterator<_CharT, _Alloc> __first,
williamr@4
  2338
                  _Rope_iterator<_CharT, _Alloc> __middle,
williamr@4
  2339
                  _Rope_iterator<_CharT, _Alloc> __last);
williamr@2
  2340
williamr@4
  2341
inline void rotate(_Rope_iterator<char, _STLP_DEFAULT_ALLOCATOR(char) > __first,
williamr@4
  2342
                   _Rope_iterator<char, _STLP_DEFAULT_ALLOCATOR(char) > __middle,
williamr@4
  2343
                   _Rope_iterator<char, _STLP_DEFAULT_ALLOCATOR(char) > __last)
williamr@4
  2344
{ _Rope_rotate(__first, __middle, __last); }
williamr@2
  2345
#endif
williamr@2
  2346
williamr@2
  2347
template <class _CharT, class _Alloc>
williamr@4
  2348
inline _Rope_char_ref_proxy<_CharT, _Alloc>::operator _CharT () const {
williamr@2
  2349
  if (_M_current_valid) {
williamr@4
  2350
    return _M_current;
williamr@2
  2351
  } else {
williamr@2
  2352
    return _My_rope::_S_fetch(_M_root->_M_tree_ptr._M_data, _M_pos);
williamr@2
  2353
  }
williamr@2
  2354
}
williamr@4
  2355
williamr@4
  2356
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
williamr@4
  2357
template <class _CharT, class _Alloc>
williamr@4
  2358
struct __move_traits<rope<_CharT, _Alloc> > {
williamr@4
  2359
  typedef __stlp_movable implemented;
williamr@4
  2360
  //Completness depends on the allocator:
williamr@4
  2361
  typedef typename __move_traits<_Alloc>::complete complete;
williamr@4
  2362
};
williamr@4
  2363
#endif
williamr@4
  2364
williamr@2
  2365
_STLP_END_NAMESPACE
williamr@2
  2366
williamr@4
  2367
#if !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@2
  2368
#  include <stl/_rope.c>
williamr@4
  2369
#endif
williamr@2
  2370
williamr@4
  2371
#endif /* _STLP_INTERNAL_ROPE_H */
williamr@2
  2372
williamr@2
  2373
// Local Variables:
williamr@2
  2374
// mode:C++
williamr@2
  2375
// End: