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