1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_rope.h Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_rope.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,18 +1,19 @@
1.4 /*
1.5 - * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 + * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.7 + *
1.8 * Copyright (c) 1996,1997
1.9 * Silicon Graphics Computer Systems, Inc.
1.10 *
1.11 * Copyright (c) 1997
1.12 * Moscow Center for SPARC Technology
1.13 *
1.14 - * Copyright (c) 1999
1.15 + * Copyright (c) 1999
1.16 * Boris Fomitchev
1.17 *
1.18 * This material is provided "as is", with absolutely no warranty expressed
1.19 * or implied. Any use is at your own risk.
1.20 *
1.21 - * Permission to use or copy this software for any purpose is hereby granted
1.22 + * Permission to use or copy this software for any purpose is hereby granted
1.23 * without fee, provided the above notices are retained on all copies.
1.24 * Permission to modify the code and to distribute modified code is granted,
1.25 * provided the above notices are retained, and a notice that the code was
1.26 @@ -31,57 +32,59 @@
1.27 // a pointer value.
1.28
1.29 #ifndef _STLP_INTERNAL_ROPE_H
1.30 -# define _STLP_INTERNAL_ROPE_H
1.31 +#define _STLP_INTERNAL_ROPE_H
1.32
1.33 -# ifndef _STLP_INTERNAL_ALGOBASE_H
1.34 +#ifndef _STLP_INTERNAL_ALGOBASE_H
1.35 # include <stl/_algobase.h>
1.36 -# endif
1.37 +#endif
1.38
1.39 -# ifndef _STLP_IOSFWD
1.40 +#ifndef _STLP_IOSFWD
1.41 # include <iosfwd>
1.42 -# endif
1.43 +#endif
1.44
1.45 -# ifndef _STLP_INTERNAL_ALLOC_H
1.46 +#ifndef _STLP_INTERNAL_ALLOC_H
1.47 # include <stl/_alloc.h>
1.48 -# endif
1.49 +#endif
1.50
1.51 -# ifndef _STLP_INTERNAL_ITERATOR_H
1.52 +#ifndef _STLP_INTERNAL_ITERATOR_H
1.53 # include <stl/_iterator.h>
1.54 -# endif
1.55 +#endif
1.56
1.57 -# ifndef _STLP_INTERNAL_ALGO_H
1.58 +#ifndef _STLP_INTERNAL_ALGO_H
1.59 # include <stl/_algo.h>
1.60 -# endif
1.61 +#endif
1.62
1.63 -# ifndef _STLP_INTERNAL_FUNCTION_H
1.64 -# include <stl/_function.h>
1.65 -# endif
1.66 +#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
1.67 +# include <stl/_function_base.h>
1.68 +#endif
1.69
1.70 -# ifndef _STLP_INTERNAL_NUMERIC_H
1.71 +#ifndef _STLP_INTERNAL_NUMERIC_H
1.72 # include <stl/_numeric.h>
1.73 -# endif
1.74 +#endif
1.75
1.76 -# ifndef _STLP_INTERNAL_HASH_FUN_H
1.77 +#ifndef _STLP_INTERNAL_HASH_FUN_H
1.78 # include <stl/_hash_fun.h>
1.79 -# endif
1.80 +#endif
1.81
1.82 -# ifdef __GC
1.83 -# define __GC_CONST const
1.84 -# else
1.85 -# include <stl/_threads.h>
1.86 -# define __GC_CONST // constant except for deallocation
1.87 -# endif
1.88 -# ifdef _STLP_SGI_THREADS
1.89 -# include <mutex.h>
1.90 -# endif
1.91 +#ifndef _STLP_CHAR_TRAITS_H
1.92 +# include <stl/char_traits.h>
1.93 +#endif
1.94
1.95 -#ifdef _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM
1.96 -# define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) (_Alloc_traits<_Tp,__atype>::create_allocator(__a))
1.97 -#elif defined(__MRC__)||defined(__SC__)
1.98 -# define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) __stl_alloc_create<_Tp,__atype>(__a,(_Tp*)0)
1.99 -#else
1.100 -# define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
1.101 -#endif
1.102 +#ifndef _STLP_INTERNAL_THREADS_H
1.103 +# include <stl/_threads.h>
1.104 +#endif
1.105 +
1.106 +#ifdef _STLP_SGI_THREADS
1.107 +# include <mutex.h>
1.108 +#endif
1.109 +
1.110 +#ifndef _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE
1.111 +# define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) (_Alloc_traits<_Tp,__atype>::create_allocator(__a))
1.112 +#elif defined(__MRC__)||defined(__SC__)
1.113 +# define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) __stl_alloc_create<_Tp,__atype>(__a,(_Tp*)0)
1.114 +#else
1.115 +# define _STLP_CREATE_ALLOCATOR(__atype,__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
1.116 +#endif
1.117
1.118 _STLP_BEGIN_NAMESPACE
1.119
1.120 @@ -99,7 +102,9 @@
1.121 template<class _CharT, class _Alloc> class _Rope_char_ref_proxy;
1.122 template<class _CharT, class _Alloc> class _Rope_char_ptr_proxy;
1.123
1.124 -// Some helpers, so we can use power on ropes.
1.125 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.126 +
1.127 +// Some helpers, so we can use the power algorithm on ropes.
1.128 // See below for why this isn't local to the implementation.
1.129
1.130 // This uses a nonstandard refcount convention.
1.131 @@ -107,7 +112,7 @@
1.132 template<class _CharT, class _Alloc>
1.133 struct _Rope_Concat_fn
1.134 : public binary_function<rope<_CharT,_Alloc>, rope<_CharT,_Alloc>,
1.135 - rope<_CharT,_Alloc> > {
1.136 + rope<_CharT,_Alloc> > {
1.137 rope<_CharT,_Alloc> operator() (const rope<_CharT,_Alloc>& __x,
1.138 const rope<_CharT,_Alloc>& __y) {
1.139 return __x + __y;
1.140 @@ -118,56 +123,34 @@
1.141 inline
1.142 rope<_CharT,_Alloc>
1.143 __identity_element(_Rope_Concat_fn<_CharT, _Alloc>)
1.144 -{
1.145 - return rope<_CharT,_Alloc>();
1.146 +{ return rope<_CharT,_Alloc>(); }
1.147 +
1.148 +_STLP_MOVE_TO_STD_NAMESPACE
1.149 +
1.150 +// Store an eos
1.151 +template <class _CharT>
1.152 +inline void _S_construct_null_aux(_CharT *__p, const __true_type&)
1.153 +{ *__p = 0; }
1.154 +
1.155 +template <class _CharT>
1.156 +inline void _S_construct_null_aux(_CharT *__p, const __false_type&)
1.157 +{ _STLP_STD::_Construct(__p); }
1.158 +
1.159 +template <class _CharT>
1.160 +inline void _S_construct_null(_CharT *__p) {
1.161 + typedef typename _IsIntegral<_CharT>::_Ret _Char_Is_Integral;
1.162 + _S_construct_null_aux(__p, _Char_Is_Integral());
1.163 }
1.164
1.165 -// The _S_eos function is used for those functions that
1.166 -// convert to/from C-like strings to detect the end of the string.
1.167 -
1.168 -// The end-of-C-string character.
1.169 -// This is what the draft standard says it should be.
1.170 -template <class _CharT>
1.171 -inline _CharT _S_eos(_CharT*) { return _CharT(); }
1.172 -
1.173 -// fbp : some compilers fail to zero-initialize builtins ;(
1.174 -inline const char _S_eos(const char*) { return 0; }
1.175 -# ifdef _STLP_HAS_WCHAR_T
1.176 -inline const wchar_t _S_eos(const wchar_t*) { return 0; }
1.177 -# endif
1.178 -
1.179 -// Test for basic character types.
1.180 -// For basic character types leaves having a trailing eos.
1.181 -template <class _CharT>
1.182 -inline bool _S_is_basic_char_type(_CharT*) { return false; }
1.183 -template <class _CharT>
1.184 -inline bool _S_is_one_byte_char_type(_CharT*) { return false; }
1.185 -
1.186 -inline bool _S_is_basic_char_type(char*) { return true; }
1.187 -inline bool _S_is_one_byte_char_type(char*) { return true; }
1.188 -# ifdef _STLP_HAS_WCHAR_T
1.189 -inline bool _S_is_basic_char_type(wchar_t*) { return true; }
1.190 -# endif
1.191 -
1.192 -// Store an eos iff _CharT is a basic character type.
1.193 -// Do not reference _S_eos if it isn't.
1.194 -template <class _CharT>
1.195 -inline void _S_cond_store_eos(_CharT&) {}
1.196 -
1.197 -inline void _S_cond_store_eos(char& __c) { __c = 0; }
1.198 -# ifdef _STLP_HAS_WCHAR_T
1.199 -inline void _S_cond_store_eos(wchar_t& __c) { __c = 0; }
1.200 -# endif
1.201 -
1.202 // char_producers are logically functions that generate a section of
1.203 -// a string. These can be convereted to ropes. The resulting rope
1.204 +// a string. These can be converted to ropes. The resulting rope
1.205 // invokes the char_producer on demand. This allows, for example,
1.206 // files to be viewed as ropes without reading the entire file.
1.207 template <class _CharT>
1.208 class char_producer {
1.209 public:
1.210 - virtual ~char_producer() {};
1.211 - virtual void operator()(size_t __start_pos, size_t __len,
1.212 + virtual ~char_producer() {}
1.213 + virtual void operator()(size_t __start_pos, size_t __len,
1.214 _CharT* __buffer) = 0;
1.215 // Buffer should really be an arbitrary output iterator.
1.216 // That way we could flatten directly into an ostream, etc.
1.217 @@ -192,17 +175,17 @@
1.218 template<class _Sequence
1.219 # if !(defined (_STLP_NON_TYPE_TMPL_PARAM_BUG) || \
1.220 defined ( _STLP_NO_DEFAULT_NON_TYPE_PARAM ))
1.221 -, size_t _Buf_sz = 100
1.222 + , size_t _Buf_sz = 100
1.223 # if defined(__sgi) && !defined(__GNUC__)
1.224 -# define __TYPEDEF_WORKAROUND
1.225 -,class _V = typename _Sequence::value_type
1.226 +# define __TYPEDEF_WORKAROUND
1.227 + ,class _V = typename _Sequence::value_type
1.228 # endif /* __sgi */
1.229 # endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
1.230 ->
1.231 + >
1.232 // The 3rd parameter works around a common compiler bug.
1.233 class sequence_buffer : public iterator <output_iterator_tag, void, void, void, void> {
1.234 public:
1.235 -# ifndef __TYPEDEF_WORKAROUND
1.236 +# ifndef __TYPEDEF_WORKAROUND
1.237 typedef typename _Sequence::value_type value_type;
1.238 typedef sequence_buffer<_Sequence
1.239 # if !(defined (_STLP_NON_TYPE_TMPL_PARAM_BUG) || \
1.240 @@ -211,13 +194,13 @@
1.241 > _Self;
1.242 # else /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
1.243 > _Self;
1.244 - enum { _Buf_sz = 100};
1.245 + enum { _Buf_sz = 100};
1.246 # endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
1.247 // # endif
1.248 -# else /* __TYPEDEF_WORKAROUND */
1.249 +# else /* __TYPEDEF_WORKAROUND */
1.250 typedef _V value_type;
1.251 typedef sequence_buffer<_Sequence, _Buf_sz, _V> _Self;
1.252 -# endif /* __TYPEDEF_WORKAROUND */
1.253 +# endif /* __TYPEDEF_WORKAROUND */
1.254 protected:
1.255 _Sequence* _M_prefix;
1.256 value_type _M_buffer[_Buf_sz];
1.257 @@ -252,8 +235,7 @@
1.258 copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
1.259 return *this;
1.260 }
1.261 - void push_back(value_type __x)
1.262 - {
1.263 + void push_back(value_type __x) {
1.264 if (_M_buf_count < _Buf_sz) {
1.265 _M_buffer[_M_buf_count] = __x;
1.266 ++_M_buf_count;
1.267 @@ -263,8 +245,7 @@
1.268 _M_buf_count = 1;
1.269 }
1.270 }
1.271 - void append(value_type* __s, size_t __len)
1.272 - {
1.273 + void append(const value_type *__s, size_t __len) {
1.274 if (__len + _M_buf_count <= _Buf_sz) {
1.275 size_t __i = _M_buf_count;
1.276 size_t __j = 0;
1.277 @@ -279,18 +260,15 @@
1.278 append(__s, __len);
1.279 }
1.280 }
1.281 - _Self& write(value_type* __s, size_t __len)
1.282 - {
1.283 + _Self& write(const value_type *__s, size_t __len) {
1.284 append(__s, __len);
1.285 return *this;
1.286 }
1.287 - _Self& put(value_type __x)
1.288 - {
1.289 + _Self& put(value_type __x) {
1.290 push_back(__x);
1.291 return *this;
1.292 }
1.293 - _Self& operator=(const value_type& __rhs)
1.294 - {
1.295 + _Self& operator=(const value_type& __rhs) {
1.296 push_back(__rhs);
1.297 return *this;
1.298 }
1.299 @@ -302,14 +280,13 @@
1.300 // The following should be treated as private, at least for now.
1.301 template<class _CharT>
1.302 class _Rope_char_consumer {
1.303 +#if !defined (_STLP_MEMBER_TEMPLATES)
1.304 public:
1.305 - // If we had member templates, these should not be virtual.
1.306 - // For now we need to use run-time parametrization where
1.307 - // compile-time would do. _Hence this should all be private
1.308 - // for now.
1.309 + //Without member templates we have to use run-time parameterization.
1.310 // The symmetry with char_producer is accidental and temporary.
1.311 - virtual ~_Rope_char_consumer() {};
1.312 + virtual ~_Rope_char_consumer() {}
1.313 virtual bool operator()(const _CharT* __buffer, size_t __len) = 0;
1.314 +#endif
1.315 };
1.316
1.317 //
1.318 @@ -337,43 +314,25 @@
1.319 // Some of the static member functions of _RopeRep have identically
1.320 // named functions in rope that simply invoke the _RopeRep versions.
1.321 //
1.322 -// A macro to introduce various allocation and deallocation functions
1.323 -// These need to be defined differently depending on whether or not
1.324 -// we are using standard conforming allocators, and whether the allocator
1.325 -// instances have real state. Thus this macro is invoked repeatedly
1.326 -// with different definitions of __ROPE_DEFINE_ALLOC.
1.327 -
1.328 -#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
1.329 -# define __ROPE_DEFINE_ALLOC(_Tp, __name, _M_proxy) \
1.330 - typedef typename \
1.331 - _Alloc_traits<_Tp,_Alloc>::allocator_type __name##Allocator;
1.332 -
1.333 -#define __ROPE_DEFINE_ALLOCS(__a, _M_proxy) \
1.334 - __ROPE_DEFINE_ALLOC(_CharT,_Data, _M_proxy) /* character data */ \
1.335 - typedef _Rope_RopeConcatenation<_CharT,__a> __C; \
1.336 - __ROPE_DEFINE_ALLOC(__C,_C, _M_proxy) \
1.337 - typedef _Rope_RopeLeaf<_CharT,__a> __L; \
1.338 - __ROPE_DEFINE_ALLOC(__L,_L, _M_proxy) \
1.339 - typedef _Rope_RopeFunction<_CharT,__a> __F; \
1.340 - __ROPE_DEFINE_ALLOC(__F,_F, _M_proxy) \
1.341 - typedef _Rope_RopeSubstring<_CharT,__a> __S; \
1.342 - __ROPE_DEFINE_ALLOC(__S,_S,_M_proxy)
1.343 -#else
1.344 -#define __ROPE_DEFINE_ALLOC(_Tp, __name, _M_proxy)
1.345 -#define __ROPE_DEFINE_ALLOCS(__a, _M_proxy)
1.346 -#endif
1.347 -
1.348
1.349 template<class _CharT, class _Alloc>
1.350 struct _Rope_RopeRep
1.351 -# ifndef __GC
1.352 : public _Refcount_Base
1.353 -# endif
1.354 {
1.355 typedef _Rope_RopeRep<_CharT, _Alloc> _Self;
1.356 public:
1.357 + //
1.358 + // GAB: 11/09/05
1.359 + //
1.360 + // "__ROPE_DEPTH_SIZE" is set to one more then the "__ROPE_MAX_DEPTH".
1.361 + // This was originally just an addition of "__ROPE_MAX_DEPTH + 1"
1.362 + // but this addition causes the sunpro compiler to complain about
1.363 + // multiple declarations during the initialization of "_S_min_len".
1.364 + // Changed to be a fixed value and the sunpro compiler appears to
1.365 + // be happy???
1.366 + //
1.367 # define __ROPE_MAX_DEPTH 45
1.368 -# define __ROPE_DEPTH_SIZE 46
1.369 +# define __ROPE_DEPTH_SIZE 46 // __ROPE_MAX_DEPTH + 1
1.370 enum { _S_max_rope_depth = __ROPE_MAX_DEPTH };
1.371 enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
1.372 // Apparently needed by VC++
1.373 @@ -382,19 +341,17 @@
1.374 // character types, to hold a trailing eos character.
1.375 enum { _S_alloc_granularity = 8 };
1.376
1.377 -
1.378 _Tag _M_tag:8;
1.379 bool _M_is_balanced:8;
1.380
1.381 _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
1.382 - typedef typename _Alloc_traits<_CharT,_Alloc>::allocator_type
1.383 - allocator_type;
1.384 -
1.385 + typedef typename _Alloc_traits<_CharT,_Alloc>::allocator_type allocator_type;
1.386 +
1.387 allocator_type get_allocator() const { return allocator_type(_M_size); }
1.388
1.389 unsigned char _M_depth;
1.390 - __GC_CONST _CharT* _M_c_string;
1.391 - _STLP_alloc_proxy<size_t, _CharT, allocator_type> _M_size;
1.392 + _CharT* _STLP_VOLATILE _M_c_string;
1.393 + _STLP_PRIV _STLP_alloc_proxy<size_t, _CharT, allocator_type> _M_size;
1.394
1.395 # ifdef _STLP_NO_ARROW_OPERATOR
1.396 _Rope_RopeRep() : _Refcount_Base(1), _M_size(allocator_type(), 0) {}
1.397 @@ -406,179 +363,165 @@
1.398 /* by this node. */
1.399 /* In the case of a leaf, this may point to */
1.400 /* the same memory as the data field. */
1.401 - _Rope_RopeRep(_Tag __t, int __d, bool __b, size_t _p_size,
1.402 + _Rope_RopeRep(_Tag __t, unsigned char __d, bool __b, size_t _p_size,
1.403 allocator_type __a) :
1.404 -# ifndef __GC
1.405 _Refcount_Base(1),
1.406 -# endif
1.407 _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0), _M_size(__a, _p_size)
1.408 { }
1.409 -# ifdef __GC
1.410 - void _M_incr () {}
1.411 -# endif
1.412
1.413 - // fbp : moved from RopeLeaf
1.414 - static size_t _S_rounded_up_size(size_t __n) {
1.415 - size_t __size_with_eos;
1.416 -
1.417 - if (_S_is_basic_char_type((_CharT*)0)) {
1.418 - __size_with_eos = __n + 1;
1.419 - } else {
1.420 - __size_with_eos = __n;
1.421 - }
1.422 -# ifdef __GC
1.423 - return __size_with_eos;
1.424 -# else
1.425 + typedef typename _AreSameUnCVTypes<_CharT, char>::_Ret _IsChar;
1.426 +# ifdef _STLP_HAS_WCHAR_T
1.427 + typedef typename _AreSameUnCVTypes<_CharT, wchar_t>::_Ret _IsWCharT;
1.428 +# else
1.429 + typedef __false_type _IsWCharT;
1.430 +# endif
1.431 +
1.432 + typedef typename _Lor2<_IsChar, _IsWCharT>::_Ret _IsBasicCharType;
1.433 +
1.434 +#if 0
1.435 + /* Please tell why this code is necessary if you uncomment it.
1.436 + * Problem with it is that rope implementation expect that _S_rounded_up_size(n)
1.437 + * returns a size > n in order to store the terminating null charater. When
1.438 + * instanciation type is not a char or wchar_t this is not guaranty resulting in
1.439 + * memory overrun.
1.440 + */
1.441 + static size_t _S_rounded_up_size_aux(size_t __n, __true_type const& /*_IsBasicCharType*/) {
1.442 // Allow slop for in-place expansion.
1.443 - return (__size_with_eos + _S_alloc_granularity-1)
1.444 - &~ (_S_alloc_granularity-1);
1.445 -# endif
1.446 + return (__n + _S_alloc_granularity) & ~(_S_alloc_granularity - 1);
1.447 }
1.448
1.449 - static void _S_free_string(__GC_CONST _CharT* __s, size_t __len,
1.450 + static size_t _S_rounded_up_size_aux(size_t __n, __false_type const& /*_IsBasicCharType*/) {
1.451 + // Allow slop for in-place expansion.
1.452 + return (__n + _S_alloc_granularity - 1) & ~(_S_alloc_granularity - 1);
1.453 + }
1.454 +#endif
1.455 + // fbp : moved from RopeLeaf
1.456 + static size_t _S_rounded_up_size(size_t __n)
1.457 + //{ return _S_rounded_up_size_aux(__n, _IsBasicCharType()); }
1.458 + { return (__n + _S_alloc_granularity) & ~(_S_alloc_granularity - 1); }
1.459 +
1.460 + static void _S_free_string( _CharT* __s, size_t __len,
1.461 allocator_type __a) {
1.462 -
1.463 - if (!_S_is_basic_char_type((_CharT*)0)) {
1.464 - _STLP_STD::_Destroy(__s, __s + __len);
1.465 - }
1.466 + _STLP_STD::_Destroy_Range(__s, __s + __len);
1.467 // This has to be a static member, so this gets a bit messy
1.468 -# ifdef _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM
1.469 - __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
1.470 +# ifndef _STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE
1.471 + __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
1.472 # else
1.473 __stl_alloc_rebind (__a, (_CharT*)0).deallocate(__s, _S_rounded_up_size(__len));
1.474 # endif
1.475 }
1.476 -
1.477 +
1.478 // Deallocate data section of a leaf.
1.479 // This shouldn't be a member function.
1.480 // But its hard to do anything else at the
1.481 // moment, because it's templatized w.r.t.
1.482 // an allocator.
1.483 // Does nothing if __GC is defined.
1.484 -# ifndef __GC
1.485 void _M_free_c_string();
1.486 void _M_free_tree();
1.487 // Deallocate t. Assumes t is not 0.
1.488 - void _M_unref_nonnil()
1.489 - {
1.490 - _M_decr(); if (!_M_ref_count) _M_free_tree();
1.491 + void _M_unref_nonnil() {
1.492 + if (_M_decr() == 0) _M_free_tree();
1.493 }
1.494 - void _M_ref_nonnil()
1.495 - {
1.496 + void _M_ref_nonnil() {
1.497 _M_incr();
1.498 }
1.499 - static void _S_unref(_Self* __t)
1.500 - {
1.501 + static void _S_unref(_Self* __t) {
1.502 if (0 != __t) {
1.503 __t->_M_unref_nonnil();
1.504 }
1.505 }
1.506 - static void _S_ref(_Self* __t)
1.507 - {
1.508 + static void _S_ref(_Self* __t) {
1.509 if (0 != __t) __t->_M_incr();
1.510 }
1.511 - static void _S_free_if_unref(_Self* __t)
1.512 - {
1.513 - if (0 != __t && 0 == __t->_M_ref_count) __t->_M_free_tree();
1.514 - }
1.515 -# else /* __GC */
1.516 - void _M_unref_nonnil() {}
1.517 - void _M_ref_nonnil() {}
1.518 - static void _S_unref(_Self*) {}
1.519 - static void _S_ref(_Self*) {}
1.520 - static void _S_free_if_unref(_Self*) {}
1.521 -# endif
1.522 -
1.523 - __ROPE_DEFINE_ALLOCS(_Alloc, _M_size)
1.524 - };
1.525 + //static void _S_free_if_unref(_Self* __t) {
1.526 + // if (0 != __t && 0 == __t->_M_ref_count) __t->_M_free_tree();
1.527 + //}
1.528 +};
1.529
1.530 template<class _CharT, class _Alloc>
1.531 struct _Rope_RopeLeaf : public _Rope_RopeRep<_CharT,_Alloc> {
1.532 public:
1.533 - __GC_CONST _CharT* _M_data; /* Not necessarily 0 terminated. */
1.534 + _CharT* _M_data; /* Not necessarily 0 terminated. */
1.535 /* The allocated size is */
1.536 /* _S_rounded_up_size(size), except */
1.537 /* in the GC case, in which it */
1.538 /* doesn't matter. */
1.539 +private:
1.540 + typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.541 + typedef typename _RopeRep::_IsBasicCharType _IsBasicCharType;
1.542 + void _M_init(__true_type const& /*_IsBasicCharType*/) {
1.543 + this->_M_c_string = _M_data;
1.544 + }
1.545 + void _M_init(__false_type const& /*_IsBasicCharType*/) {}
1.546 +
1.547 +public:
1.548 _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
1.549 - typedef typename _Rope_RopeRep<_CharT,_Alloc>::allocator_type allocator_type;
1.550 - _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t _p_size, allocator_type __a)
1.551 - : _Rope_RopeRep<_CharT,_Alloc>(_Rope_RopeRep<_CharT,_Alloc>::_S_leaf, 0, true, _p_size, __a),
1.552 - _M_data(__d)
1.553 - {
1.554 + typedef typename _RopeRep::allocator_type allocator_type;
1.555 +
1.556 + _Rope_RopeLeaf( _CharT* __d, size_t _p_size, allocator_type __a)
1.557 + : _Rope_RopeRep<_CharT,_Alloc>(_RopeRep::_S_leaf, 0, true, _p_size, __a),
1.558 + _M_data(__d) {
1.559 _STLP_ASSERT(_p_size > 0)
1.560 - if (_S_is_basic_char_type((_CharT *)0)) {
1.561 - // already eos terminated.
1.562 - this->_M_c_string = __d;
1.563 - }
1.564 + _M_init(_IsBasicCharType());
1.565 }
1.566
1.567 # ifdef _STLP_NO_ARROW_OPERATOR
1.568 _Rope_RopeLeaf() {}
1.569 _Rope_RopeLeaf(const _Rope_RopeLeaf<_CharT, _Alloc>& ) {}
1.570 # endif
1.571 -
1.572 +
1.573 // The constructor assumes that d has been allocated with
1.574 // the proper allocator and the properly padded size.
1.575 // In contrast, the destructor deallocates the data:
1.576 -# ifndef __GC
1.577 ~_Rope_RopeLeaf() {
1.578 if (_M_data != this->_M_c_string) {
1.579 this->_M_free_c_string();
1.580 }
1.581 - _Rope_RopeRep<_CharT,_Alloc>::_S_free_string(_M_data, this->_M_size._M_data, this->get_allocator());
1.582 + _RopeRep::_S_free_string(_M_data, this->_M_size._M_data, this->get_allocator());
1.583 }
1.584 -# endif
1.585 };
1.586
1.587 template<class _CharT, class _Alloc>
1.588 -struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT,_Alloc> {
1.589 +struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT, _Alloc> {
1.590 +private:
1.591 + typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.592 +
1.593 public:
1.594 - _Rope_RopeRep<_CharT,_Alloc>* _M_left;
1.595 - _Rope_RopeRep<_CharT,_Alloc>* _M_right;
1.596 + _RopeRep* _M_left;
1.597 + _RopeRep* _M_right;
1.598 _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
1.599 - typedef typename _Rope_RopeRep<_CharT,_Alloc>::allocator_type allocator_type;
1.600 - _Rope_RopeConcatenation(_Rope_RopeRep<_CharT,_Alloc>* __l,
1.601 - _Rope_RopeRep<_CharT,_Alloc>* __r,
1.602 - allocator_type __a)
1.603 - : _Rope_RopeRep<_CharT,_Alloc>(
1.604 - _Rope_RopeRep<_CharT,_Alloc>::_S_concat,
1.605 - (max)(__l->_M_depth, __r->_M_depth) + 1, false,
1.606 - __l->_M_size._M_data + __r->_M_size._M_data, __a), _M_left(__l), _M_right(__r)
1.607 + typedef typename _RopeRep::allocator_type allocator_type;
1.608 + _Rope_RopeConcatenation(_RopeRep* __l, _RopeRep* __r, allocator_type __a)
1.609 + : _Rope_RopeRep<_CharT,_Alloc>(_RopeRep::_S_concat,
1.610 + (max)(__l->_M_depth, __r->_M_depth) + 1, false,
1.611 + __l->_M_size._M_data + __r->_M_size._M_data, __a), _M_left(__l), _M_right(__r)
1.612 {}
1.613 # ifdef _STLP_NO_ARROW_OPERATOR
1.614 _Rope_RopeConcatenation() {}
1.615 _Rope_RopeConcatenation(const _Rope_RopeConcatenation<_CharT, _Alloc>&) {}
1.616 # endif
1.617
1.618 -# ifndef __GC
1.619 ~_Rope_RopeConcatenation() {
1.620 this->_M_free_c_string();
1.621 _M_left->_M_unref_nonnil();
1.622 _M_right->_M_unref_nonnil();
1.623 }
1.624 -# endif
1.625 };
1.626
1.627 -template<class _CharT, class _Alloc>
1.628 -struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT,_Alloc> {
1.629 +template <class _CharT, class _Alloc>
1.630 +struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT, _Alloc> {
1.631 +private:
1.632 + typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.633 public:
1.634 char_producer<_CharT>* _M_fn;
1.635 -# ifndef __GC
1.636 - bool _M_delete_when_done; // Char_producer is owned by the
1.637 - // rope and should be explicitly
1.638 - // deleted when the rope becomes
1.639 - // inaccessible.
1.640 -# else
1.641 - // In the GC case, we either register the rope for
1.642 - // finalization, or not. Thus the field is unnecessary;
1.643 - // the information is stored in the collector data structures.
1.644 - // We do need a finalization procedure to be invoked by the
1.645 - // collector.
1.646 - static void _S_fn_finalization_proc(void * __tree, void *) {
1.647 - delete ((_Rope_RopeFunction *)__tree) -> _M_fn;
1.648 - }
1.649 -# endif
1.650 + /*
1.651 + * Char_producer is owned by the
1.652 + * rope and should be explicitly
1.653 + * deleted when the rope becomes
1.654 + * inaccessible.
1.655 + */
1.656 + bool _M_delete_when_done;
1.657 _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
1.658 typedef typename _Rope_RopeRep<_CharT,_Alloc>::allocator_type allocator_type;
1.659 # ifdef _STLP_NO_ARROW_OPERATOR
1.660 @@ -588,69 +531,54 @@
1.661
1.662 _Rope_RopeFunction(char_producer<_CharT>* __f, size_t _p_size,
1.663 bool __d, allocator_type __a)
1.664 - :
1.665 - _Rope_RopeRep<_CharT,_Alloc>(_Rope_RopeRep<_CharT,_Alloc>::_S_function, 0, true, _p_size, __a),
1.666 - _M_fn(__f)
1.667 -# ifndef __GC
1.668 + : _Rope_RopeRep<_CharT,_Alloc>(_RopeRep::_S_function, 0, true, _p_size, __a), _M_fn(__f)
1.669 , _M_delete_when_done(__d)
1.670 -# endif
1.671 - {
1.672 - _STLP_ASSERT(_p_size > 0)
1.673 -# ifdef __GC
1.674 - if (__d) {
1.675 - GC_REGISTER_FINALIZER(
1.676 - this, _Rope_RopeFunction::_S_fn_finalization_proc, 0, 0, 0);
1.677 - }
1.678 -# endif
1.679 - }
1.680 -# ifndef __GC
1.681 + { _STLP_ASSERT(_p_size > 0) }
1.682 +
1.683 ~_Rope_RopeFunction() {
1.684 this->_M_free_c_string();
1.685 if (_M_delete_when_done) {
1.686 delete _M_fn;
1.687 }
1.688 }
1.689 -# endif
1.690 };
1.691 -// Substring results are usually represented using just
1.692 -// concatenation nodes. But in the case of very long flat ropes
1.693 -// or ropes with a functional representation that isn't practical.
1.694 -// In that case, we represent the __result as a special case of
1.695 -// RopeFunction, whose char_producer points back to the rope itself.
1.696 -// In all cases except repeated substring operations and
1.697 -// deallocation, we treat the __result as a RopeFunction.
1.698 +
1.699 +/*
1.700 + * Substring results are usually represented using just
1.701 + * concatenation nodes. But in the case of very long flat ropes
1.702 + * or ropes with a functional representation that isn't practical.
1.703 + * In that case, we represent the __result as a special case of
1.704 + * RopeFunction, whose char_producer points back to the rope itself.
1.705 + * In all cases except repeated substring operations and
1.706 + * deallocation, we treat the __result as a RopeFunction.
1.707 + */
1.708 template<class _CharT, class _Alloc>
1.709 -# if ( defined (__IBMCPP__) && (__IBMCPP__ == 500) ) // JFA 10-Aug-2000 for some reason xlC cares about the order
1.710 -struct _Rope_RopeSubstring : public char_producer<_CharT> , public _Rope_RopeFunction<_CharT,_Alloc>
1.711 -# else
1.712 -struct _Rope_RopeSubstring : public _Rope_RopeFunction<_CharT,_Alloc>,
1.713 - public char_producer<_CharT>
1.714 -# endif
1.715 -{
1.716 +struct _Rope_RopeSubstring : public char_producer<_CharT>, public _Rope_RopeFunction<_CharT,_Alloc> {
1.717 public:
1.718 // XXX this whole class should be rewritten.
1.719 - typedef _Rope_RopeRep<_CharT,_Alloc> _Base;
1.720 - _Rope_RopeRep<_CharT,_Alloc>* _M_base; // not 0
1.721 + typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.722 + _RopeRep *_M_base; // not 0
1.723 size_t _M_start;
1.724 - virtual void operator()(size_t __start_pos, size_t __req_len,
1.725 - _CharT* __buffer) {
1.726 - switch(_M_base->_M_tag) {
1.727 - case _Base::_S_function:
1.728 - case _Base::_S_substringfn:
1.729 + /* virtual */ void operator()(size_t __start_pos, size_t __req_len,
1.730 + _CharT* __buffer) {
1.731 + typedef _Rope_RopeFunction<_CharT,_Alloc> _RopeFunction;
1.732 + typedef _Rope_RopeLeaf<_CharT,_Alloc> _RopeLeaf;
1.733 + switch (_M_base->_M_tag) {
1.734 + case _RopeRep::_S_function:
1.735 + case _RopeRep::_S_substringfn:
1.736 {
1.737 char_producer<_CharT>* __fn =
1.738 - ((_Rope_RopeFunction<_CharT,_Alloc>*)_M_base)->_M_fn;
1.739 + __STATIC_CAST(_RopeFunction*, _M_base)->_M_fn;
1.740 _STLP_ASSERT(__start_pos + __req_len <= this->_M_size._M_data)
1.741 _STLP_ASSERT(_M_start + this->_M_size._M_data <= _M_base->_M_size._M_data)
1.742 (*__fn)(__start_pos + _M_start, __req_len, __buffer);
1.743 }
1.744 break;
1.745 - case _Base::_S_leaf:
1.746 + case _RopeRep::_S_leaf:
1.747 {
1.748 - __GC_CONST _CharT* __s =
1.749 - ((_Rope_RopeLeaf<_CharT,_Alloc>*)_M_base)->_M_data;
1.750 - uninitialized_copy_n(__s + __start_pos + _M_start, __req_len,
1.751 - __buffer);
1.752 + _CharT* __s =
1.753 + __STATIC_CAST(_RopeLeaf*, _M_base)->_M_data;
1.754 + _STLP_PRIV __ucopy_n(__s + __start_pos + _M_start, __req_len, __buffer);
1.755 }
1.756 break;
1.757 default:
1.758 @@ -660,76 +588,64 @@
1.759 }
1.760
1.761 _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
1.762 - typedef typename _Rope_RopeRep<_CharT,_Alloc>::allocator_type allocator_type;
1.763 + typedef typename _RopeRep::allocator_type allocator_type;
1.764
1.765 - _Rope_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
1.766 - size_t __l, allocator_type __a)
1.767 + _Rope_RopeSubstring(_RopeRep* __b, size_t __s, size_t __l, allocator_type __a)
1.768 : _Rope_RopeFunction<_CharT,_Alloc>(this, __l, false, __a),
1.769 - _M_base(__b),
1.770 - _M_start(__s)
1.771 -
1.772 - {
1.773 + _M_base(__b), _M_start(__s) {
1.774 _STLP_ASSERT(__l > 0)
1.775 _STLP_ASSERT(__s + __l <= __b->_M_size._M_data)
1.776 -# ifndef __GC
1.777 _M_base->_M_ref_nonnil();
1.778 -# endif
1.779 - this->_M_tag = _Base::_S_substringfn;
1.780 + this->_M_tag = _RopeRep::_S_substringfn;
1.781 }
1.782 virtual ~_Rope_RopeSubstring()
1.783 - {
1.784 -# ifndef __GC
1.785 - _M_base->_M_unref_nonnil();
1.786 -# endif
1.787 - }
1.788 + { _M_base->_M_unref_nonnil(); }
1.789 };
1.790
1.791 -// Self-destructing pointers to Rope_rep.
1.792 -// These are not conventional smart pointers. Their
1.793 -// only purpose in life is to ensure that unref is called
1.794 -// on the pointer either at normal exit or if an exception
1.795 -// is raised. It is the caller's responsibility to
1.796 -// adjust reference counts when these pointers are initialized
1.797 -// or assigned to. (This convention significantly reduces
1.798 -// the number of potentially expensive reference count
1.799 -// updates.)
1.800 -#ifndef __GC
1.801 +/*
1.802 + * Self-destructing pointers to Rope_rep.
1.803 + * These are not conventional smart pointers. Their
1.804 + * only purpose in life is to ensure that unref is called
1.805 + * on the pointer either at normal exit or if an exception
1.806 + * is raised. It is the caller's responsibility to
1.807 + * adjust reference counts when these pointers are initialized
1.808 + * or assigned to. (This convention significantly reduces
1.809 + * the number of potentially expensive reference count
1.810 + * updates.)
1.811 + */
1.812 template<class _CharT, class _Alloc>
1.813 struct _Rope_self_destruct_ptr {
1.814 _Rope_RopeRep<_CharT,_Alloc>* _M_ptr;
1.815 - ~_Rope_self_destruct_ptr()
1.816 + ~_Rope_self_destruct_ptr()
1.817 { _Rope_RopeRep<_CharT,_Alloc>::_S_unref(_M_ptr); }
1.818 # ifdef _STLP_USE_EXCEPTIONS
1.819 - _Rope_self_destruct_ptr() : _M_ptr(0) {};
1.820 + _Rope_self_destruct_ptr() : _M_ptr(0) {}
1.821 # else
1.822 - _Rope_self_destruct_ptr() {};
1.823 + _Rope_self_destruct_ptr() {}
1.824 # endif
1.825 _Rope_self_destruct_ptr(_Rope_RopeRep<_CharT,_Alloc>* __p) : _M_ptr(__p) {}
1.826 _Rope_RopeRep<_CharT,_Alloc>& operator*() { return *_M_ptr; }
1.827 _Rope_RopeRep<_CharT,_Alloc>* operator->() { return _M_ptr; }
1.828 operator _Rope_RopeRep<_CharT,_Alloc>*() { return _M_ptr; }
1.829 - _Rope_self_destruct_ptr<_CharT, _Alloc>&
1.830 + _Rope_self_destruct_ptr<_CharT, _Alloc>&
1.831 operator= (_Rope_RopeRep<_CharT,_Alloc>* __x)
1.832 { _M_ptr = __x; return *this; }
1.833 };
1.834 -#endif
1.835
1.836 -// Dereferencing a nonconst iterator has to return something
1.837 -// that behaves almost like a reference. It's not possible to
1.838 -// return an actual reference since assignment requires extra
1.839 -// work. And we would get into the same problems as with the
1.840 -// CD2 version of basic_string.
1.841 +/*
1.842 + * Dereferencing a nonconst iterator has to return something
1.843 + * that behaves almost like a reference. It's not possible to
1.844 + * return an actual reference since assignment requires extra
1.845 + * work. And we would get into the same problems as with the
1.846 + * CD2 version of basic_string.
1.847 + */
1.848 template<class _CharT, class _Alloc>
1.849 class _Rope_char_ref_proxy {
1.850 typedef _Rope_char_ref_proxy<_CharT, _Alloc> _Self;
1.851 friend class rope<_CharT,_Alloc>;
1.852 friend class _Rope_iterator<_CharT,_Alloc>;
1.853 friend class _Rope_char_ptr_proxy<_CharT,_Alloc>;
1.854 -# ifdef __GC
1.855 - typedef _Rope_RopeRep<_CharT,_Alloc>* _Self_destruct_ptr;
1.856 -# else
1.857 typedef _Rope_self_destruct_ptr<_CharT,_Alloc> _Self_destruct_ptr;
1.858 -# endif
1.859 typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.860 typedef rope<_CharT,_Alloc> _My_rope;
1.861 size_t _M_pos;
1.862 @@ -745,14 +661,13 @@
1.863 // expression. We claim that's not possible without calling
1.864 // a copy constructor or generating reference to a proxy
1.865 // reference. We declare the latter to have undefined semantics.
1.866 - _Rope_char_ref_proxy(_My_rope* __r, size_t __p,
1.867 - _CharT __c) :
1.868 - _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
1.869 + _Rope_char_ref_proxy(_My_rope* __r, size_t __p, _CharT __c)
1.870 + : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
1.871 inline operator _CharT () const;
1.872 _Self& operator= (_CharT __c);
1.873 _Rope_char_ptr_proxy<_CharT, _Alloc> operator& () const;
1.874 _Self& operator= (const _Self& __c) {
1.875 - return operator=((_CharT)__c);
1.876 + return operator=((_CharT)__c);
1.877 }
1.878 };
1.879
1.880 @@ -781,9 +696,13 @@
1.881
1.882 _ROPE_SWAP_SPECIALIZATION(char,_STLP_DEFAULT_ALLOCATOR(char) )
1.883
1.884 +# ifndef _STLP_NO_WCHAR_T
1.885 +_ROPE_SWAP_SPECIALIZATION(wchar_t,_STLP_DEFAULT_ALLOCATOR(wchar_t) )
1.886 +# endif
1.887 +
1.888 #endif /* !_STLP_FUNCTION_TMPL_PARTIAL_ORDER */
1.889
1.890 - template<class _CharT, class _Alloc>
1.891 +template<class _CharT, class _Alloc>
1.892 class _Rope_char_ptr_proxy {
1.893 // XXX this class should be rewritten.
1.894 public:
1.895 @@ -792,7 +711,7 @@
1.896 size_t _M_pos;
1.897 rope<_CharT,_Alloc>* _M_root; // The whole rope.
1.898
1.899 - _Rope_char_ptr_proxy(const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
1.900 + _Rope_char_ptr_proxy(const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
1.901 : _M_pos(__x._M_pos), _M_root(__x._M_root) {}
1.902 _Rope_char_ptr_proxy(const _Self& __x)
1.903 : _M_pos(__x._M_pos), _M_root(__x._M_root) {}
1.904 @@ -800,8 +719,7 @@
1.905 _Rope_char_ptr_proxy(_CharT* __x) : _M_pos(0), _M_root(0) {
1.906 _STLP_ASSERT(0 == __x)
1.907 }
1.908 - _Self&
1.909 - operator= (const _Self& __x) {
1.910 + _Self& operator= (const _Self& __x) {
1.911 _M_pos = __x._M_pos;
1.912 _M_root = __x._M_root;
1.913 return *this;
1.914 @@ -813,68 +731,81 @@
1.915 };
1.916
1.917
1.918 -// Rope iterators:
1.919 -// Unlike in the C version, we cache only part of the stack
1.920 -// for rope iterators, since they must be efficiently copyable.
1.921 -// When we run out of cache, we have to reconstruct the iterator
1.922 -// value.
1.923 -// Pointers from iterators are not included in reference counts.
1.924 -// Iterators are assumed to be thread private. Ropes can
1.925 -// be shared.
1.926 -
1.927 +/*
1.928 + * Rope iterators:
1.929 + * Unlike in the C version, we cache only part of the stack
1.930 + * for rope iterators, since they must be efficiently copyable.
1.931 + * When we run out of cache, we have to reconstruct the iterator
1.932 + * value.
1.933 + * Pointers from iterators are not included in reference counts.
1.934 + * Iterators are assumed to be thread private. Ropes can
1.935 + * be shared.
1.936 + */
1.937 template<class _CharT, class _Alloc>
1.938 class _Rope_iterator_base
1.939 /* : public random_access_iterator<_CharT, ptrdiff_t> */
1.940 {
1.941 friend class rope<_CharT,_Alloc>;
1.942 typedef _Rope_iterator_base<_CharT, _Alloc> _Self;
1.943 + typedef _Rope_RopeConcatenation<_CharT,_Alloc> _RopeConcat;
1.944 public:
1.945 typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.946 - // Borland doesnt want this to be protected.
1.947 - // protected:
1.948 - enum { _S_path_cache_len = 4 }; // Must be <= 9.
1.949 +
1.950 + enum { _S_path_cache_len = 4 }; // Must be <= 9 because of _M_path_direction.
1.951 enum { _S_iterator_buf_len = 15 };
1.952 size_t _M_current_pos;
1.953 - _RopeRep* _M_root; // The whole rope.
1.954 - size_t _M_leaf_pos; // Starting position for current leaf
1.955 - __GC_CONST _CharT* _M_buf_start;
1.956 - // Buffer possibly
1.957 - // containing current char.
1.958 - __GC_CONST _CharT* _M_buf_ptr;
1.959 - // Pointer to current char in buffer.
1.960 - // != 0 ==> buffer valid.
1.961 - __GC_CONST _CharT* _M_buf_end;
1.962 + // The whole rope.
1.963 + _RopeRep* _M_root;
1.964 + // Starting position for current leaf
1.965 + size_t _M_leaf_pos;
1.966 + // Buffer possibly containing current char.
1.967 + _CharT* _M_buf_start;
1.968 + // Pointer to current char in buffer, != 0 ==> buffer valid.
1.969 + _CharT* _M_buf_ptr;
1.970 // One past __last valid char in buffer.
1.971 + _CharT* _M_buf_end;
1.972 +
1.973 // What follows is the path cache. We go out of our
1.974 // way to make this compact.
1.975 // Path_end contains the bottom section of the path from
1.976 // the root to the current leaf.
1.977 - const _RopeRep* _M_path_end[_S_path_cache_len];
1.978 - int _M_leaf_index; // Last valid __pos in path_end;
1.979 - // _M_path_end[0] ... _M_path_end[leaf_index-1]
1.980 + struct {
1.981 +# if defined (__BORLANDC__) && (__BORLANDC__ < 0x560)
1.982 + _RopeRep const*_M_data[4];
1.983 +# else
1.984 + _RopeRep const*_M_data[_S_path_cache_len];
1.985 +# endif
1.986 + } _M_path_end;
1.987 + // Last valid __pos in path_end;
1.988 + // _M_path_end[0] ... _M_path_end[_M_leaf_index-1]
1.989 // point to concatenation nodes.
1.990 - unsigned char _M_path_directions;
1.991 - // (path_directions >> __i) & 1 is 1
1.992 - // iff we got from _M_path_end[leaf_index - __i - 1]
1.993 + int _M_leaf_index;
1.994 + // (_M_path_directions >> __i) & 1 is 1
1.995 + // if we got from _M_path_end[leaf_index - __i - 1]
1.996 // to _M_path_end[leaf_index - __i] by going to the
1.997 // __right. Assumes path_cache_len <= 9.
1.998 - _CharT _M_tmp_buf[_S_iterator_buf_len];
1.999 + unsigned char _M_path_directions;
1.1000 // Short buffer for surrounding chars.
1.1001 - // This is useful primarily for
1.1002 + // This is useful primarily for
1.1003 // RopeFunctions. We put the buffer
1.1004 // here to avoid locking in the
1.1005 // multithreaded case.
1.1006 // The cached path is generally assumed to be valid
1.1007 // only if the buffer is valid.
1.1008 + struct {
1.1009 +# if defined (__BORLANDC__) && (__BORLANDC__ < 0x560)
1.1010 + _CharT _M_data[15];
1.1011 +# else
1.1012 + _CharT _M_data[_S_iterator_buf_len];
1.1013 +# endif
1.1014 + } _M_tmp_buf;
1.1015 +
1.1016 + // Set buffer contents given path cache.
1.1017 static void _S_setbuf(_Rope_iterator_base<_CharT, _Alloc>& __x);
1.1018 - // Set buffer contents given
1.1019 - // path cache.
1.1020 + // Set buffer contents and path cache.
1.1021 static void _S_setcache(_Rope_iterator_base<_CharT, _Alloc>& __x);
1.1022 - // Set buffer contents and
1.1023 - // path cache.
1.1024 + // As above, but assumes path cache is valid for previous posn.
1.1025 static void _S_setcache_for_incr(_Rope_iterator_base<_CharT, _Alloc>& __x);
1.1026 - // As above, but assumes path
1.1027 - // cache is valid for previous posn.
1.1028 _Rope_iterator_base() {}
1.1029 _Rope_iterator_base(_RopeRep* __root, size_t __pos)
1.1030 : _M_current_pos(__pos),_M_root(__root), _M_buf_ptr(0) {}
1.1031 @@ -882,15 +813,48 @@
1.1032 void _M_decr(size_t __n);
1.1033 public:
1.1034 size_t index() const { return _M_current_pos; }
1.1035 - _Rope_iterator_base(const _Self& __x) {
1.1036 - if (0 != __x._M_buf_ptr) {
1.1037 - *this = __x;
1.1038 +private:
1.1039 + void _M_copy_buf(const _Self& __x) {
1.1040 + _M_tmp_buf = __x._M_tmp_buf;
1.1041 + if (__x._M_buf_start == __x._M_tmp_buf._M_data) {
1.1042 + _M_buf_start = _M_tmp_buf._M_data;
1.1043 + _M_buf_end = _M_buf_start + (__x._M_buf_end - __x._M_buf_start);
1.1044 + _M_buf_ptr = _M_buf_start + (__x._M_buf_ptr - __x._M_buf_start);
1.1045 } else {
1.1046 - _M_current_pos = __x._M_current_pos;
1.1047 - _M_root = __x._M_root;
1.1048 - _M_buf_ptr = 0;
1.1049 + _M_buf_end = __x._M_buf_end;
1.1050 }
1.1051 }
1.1052 +
1.1053 +public:
1.1054 + _Rope_iterator_base(const _Self& __x) :
1.1055 + _M_current_pos(__x._M_current_pos),
1.1056 + _M_root(__x._M_root),
1.1057 + _M_leaf_pos( __x._M_leaf_pos ),
1.1058 + _M_buf_start(__x._M_buf_start),
1.1059 + _M_buf_ptr(__x._M_buf_ptr),
1.1060 + _M_path_end(__x._M_path_end),
1.1061 + _M_leaf_index(__x._M_leaf_index),
1.1062 + _M_path_directions(__x._M_path_directions)
1.1063 + {
1.1064 + if (0 != __x._M_buf_ptr) {
1.1065 + _M_copy_buf(__x);
1.1066 + }
1.1067 + }
1.1068 + _Self& operator = (const _Self& __x)
1.1069 + {
1.1070 + _M_current_pos = __x._M_current_pos;
1.1071 + _M_root = __x._M_root;
1.1072 + _M_buf_start = __x._M_buf_start;
1.1073 + _M_buf_ptr = __x._M_buf_ptr;
1.1074 + _M_path_end = __x._M_path_end;
1.1075 + _M_leaf_index = __x._M_leaf_index;
1.1076 + _M_path_directions = __x._M_path_directions;
1.1077 + _M_leaf_pos = __x._M_leaf_pos;
1.1078 + if (0 != __x._M_buf_ptr) {
1.1079 + _M_copy_buf(__x);
1.1080 + }
1.1081 + return *this;
1.1082 + }
1.1083 };
1.1084
1.1085 template<class _CharT, class _Alloc> class _Rope_iterator;
1.1086 @@ -907,43 +871,41 @@
1.1087 // The one from the base class may not be directly visible.
1.1088 # endif
1.1089 _Rope_const_iterator(const _RopeRep* __root, size_t __pos):
1.1090 - _Rope_iterator_base<_CharT,_Alloc>(
1.1091 - __CONST_CAST(_RopeRep*,__root), __pos)
1.1092 + _Rope_iterator_base<_CharT,_Alloc>(__CONST_CAST(_RopeRep*,__root), __pos)
1.1093 // Only nonconst iterators modify root ref count
1.1094 {}
1.1095 public:
1.1096 typedef _CharT reference; // Really a value. Returning a reference
1.1097 - // Would be a mess, since it would have
1.1098 - // to be included in refcount.
1.1099 + // Would be a mess, since it would have
1.1100 + // to be included in refcount.
1.1101 typedef const _CharT* pointer;
1.1102 typedef _CharT value_type;
1.1103 typedef ptrdiff_t difference_type;
1.1104 typedef random_access_iterator_tag iterator_category;
1.1105
1.1106 public:
1.1107 - _Rope_const_iterator() {};
1.1108 + _Rope_const_iterator() {}
1.1109 _Rope_const_iterator(const _Self& __x) :
1.1110 _Rope_iterator_base<_CharT,_Alloc>(__x) { }
1.1111 - _Rope_const_iterator(const _Rope_iterator<_CharT,_Alloc>& __x):
1.1112 + _Rope_const_iterator(const _Rope_iterator<_CharT,_Alloc>& __x):
1.1113 _Rope_iterator_base<_CharT,_Alloc>(__x) {}
1.1114 _Rope_const_iterator(const rope<_CharT,_Alloc>& __r, size_t __pos) :
1.1115 _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr._M_data, __pos) {}
1.1116 _Self& operator= (const _Self& __x) {
1.1117 - if (0 != __x._M_buf_ptr) {
1.1118 - *(__STATIC_CAST(_Base*,this)) = __x;
1.1119 - } else {
1.1120 - this->_M_current_pos = __x._M_current_pos;
1.1121 - this->_M_root = __x._M_root;
1.1122 - this->_M_buf_ptr = 0;
1.1123 - }
1.1124 - return(*this);
1.1125 + _Base::operator=(__x);
1.1126 + return *this;
1.1127 }
1.1128 reference operator*() {
1.1129 - if (0 == this->_M_buf_ptr) _S_setcache(*this);
1.1130 + if (0 == this->_M_buf_ptr)
1.1131 +#if !defined (__DMC__)
1.1132 + _Rope_iterator_base<_CharT, _Alloc>::_S_setcache(*this);
1.1133 +#else
1.1134 + { _Rope_iterator_base<_CharT, _Alloc>* __x = this; _S_setcache(*__x); }
1.1135 +#endif
1.1136 return *(this->_M_buf_ptr);
1.1137 }
1.1138 _Self& operator++() {
1.1139 - __GC_CONST _CharT* __next;
1.1140 + _CharT* __next;
1.1141 if (0 != this->_M_buf_ptr && (__next = this->_M_buf_ptr + 1) < this->_M_buf_end) {
1.1142 this->_M_buf_ptr = __next;
1.1143 ++this->_M_current_pos;
1.1144 @@ -994,7 +956,7 @@
1.1145 typedef _Rope_iterator<_CharT, _Alloc> _Self;
1.1146 typedef _Rope_iterator_base<_CharT,_Alloc> _Base;
1.1147 typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
1.1148 - // protected:
1.1149 +
1.1150 public:
1.1151 rope<_CharT,_Alloc>* _M_root_rope;
1.1152 // root is treated as a cached version of this,
1.1153 @@ -1005,7 +967,7 @@
1.1154 // Unfortunately, it requires careful bookkeeping for the
1.1155 // nonGC case.
1.1156 _Rope_iterator(rope<_CharT,_Alloc>* __r, size_t __pos);
1.1157 -
1.1158 +
1.1159 void _M_check();
1.1160 public:
1.1161 typedef _Rope_char_ref_proxy<_CharT,_Alloc> reference;
1.1162 @@ -1014,15 +976,14 @@
1.1163 typedef ptrdiff_t difference_type;
1.1164 typedef random_access_iterator_tag iterator_category;
1.1165 public:
1.1166 - ~_Rope_iterator() //*TY 5/6/00 - added dtor to balance reference count
1.1167 - {
1.1168 + ~_Rope_iterator() { //*TY 5/6/00 - added dtor to balance reference count
1.1169 _RopeRep::_S_unref(this->_M_root);
1.1170 }
1.1171 -
1.1172 +
1.1173 rope<_CharT,_Alloc>& container() { return *_M_root_rope; }
1.1174 _Rope_iterator() {
1.1175 this->_M_root = 0; // Needed for reference counting.
1.1176 - };
1.1177 + }
1.1178 _Rope_iterator(const _Self& __x) :
1.1179 _Rope_iterator_base<_CharT,_Alloc>(__x) {
1.1180 _M_root_rope = __x._M_root_rope;
1.1181 @@ -1031,28 +992,18 @@
1.1182 _Rope_iterator(rope<_CharT,_Alloc>& __r, size_t __pos);
1.1183 _Self& operator= (const _Self& __x) {
1.1184 _RopeRep* __old = this->_M_root;
1.1185 -
1.1186 _RopeRep::_S_ref(__x._M_root);
1.1187 - if (0 != __x._M_buf_ptr) {
1.1188 - _M_root_rope = __x._M_root_rope;
1.1189 - *(__STATIC_CAST(_Base*,this)) = __x;
1.1190 - } else {
1.1191 - this->_M_current_pos = __x._M_current_pos;
1.1192 - this->_M_root = __x._M_root;
1.1193 - _M_root_rope = __x._M_root_rope;
1.1194 - this->_M_buf_ptr = 0;
1.1195 - }
1.1196 + _Base::operator=(__x);
1.1197 + _M_root_rope = __x._M_root_rope;
1.1198 _RopeRep::_S_unref(__old);
1.1199 - return(*this);
1.1200 + return *this;
1.1201 }
1.1202 reference operator*() {
1.1203 _M_check();
1.1204 if (0 == this->_M_buf_ptr) {
1.1205 - return _Rope_char_ref_proxy<_CharT,_Alloc>(
1.1206 - _M_root_rope, this->_M_current_pos);
1.1207 + return reference(_M_root_rope, this->_M_current_pos);
1.1208 } else {
1.1209 - return _Rope_char_ref_proxy<_CharT,_Alloc>(
1.1210 - _M_root_rope, this->_M_current_pos, *(this->_M_buf_ptr));
1.1211 + return reference(_M_root_rope, this->_M_current_pos, *(this->_M_buf_ptr));
1.1212 }
1.1213 }
1.1214 _Self& operator++() {
1.1215 @@ -1082,16 +1033,15 @@
1.1216 _Self operator++(int) {
1.1217 size_t __old_pos = this->_M_current_pos;
1.1218 this->_M_incr(1);
1.1219 - return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1.1220 + return _Self(_M_root_rope, __old_pos);
1.1221 }
1.1222 _Self operator--(int) {
1.1223 size_t __old_pos = this->_M_current_pos;
1.1224 this->_M_decr(1);
1.1225 - return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1.1226 + return _Self(_M_root_rope, __old_pos);
1.1227 }
1.1228 reference operator[](ptrdiff_t __n) {
1.1229 - return _Rope_char_ref_proxy<_CharT,_Alloc>(
1.1230 - _M_root_rope, this->_M_current_pos + __n);
1.1231 + return reference(_M_root_rope, this->_M_current_pos + __n);
1.1232 }
1.1233 };
1.1234
1.1235 @@ -1110,10 +1060,20 @@
1.1236 inline _CharT* value_type(const _Rope_const_iterator<_CharT,_Alloc>&) { return 0; }
1.1237 template <class _CharT, class _Alloc>
1.1238 inline ptrdiff_t* distance_type(const _Rope_const_iterator<_CharT,_Alloc>&) { return 0; }
1.1239 -#endif
1.1240 +#endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
1.1241 +
1.1242 +template <class _CharT, class _Alloc, class _CharConsumer>
1.1243 +bool _S_apply_to_pieces(_CharConsumer& __c,
1.1244 + _Rope_RopeRep<_CharT, _Alloc> *__r,
1.1245 + size_t __begin, size_t __end);
1.1246 + // begin and end are assumed to be in range.
1.1247
1.1248 template <class _CharT, class _Alloc>
1.1249 -class rope {
1.1250 +class rope
1.1251 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
1.1252 + : public __stlport_class<rope<_CharT, _Alloc> >
1.1253 +#endif
1.1254 +{
1.1255 typedef rope<_CharT,_Alloc> _Self;
1.1256 public:
1.1257 typedef _CharT value_type;
1.1258 @@ -1125,7 +1085,7 @@
1.1259 typedef _Rope_const_iterator<_CharT,_Alloc> const_iterator;
1.1260 typedef _Rope_char_ref_proxy<_CharT,_Alloc> reference;
1.1261 typedef _Rope_char_ptr_proxy<_CharT,_Alloc> pointer;
1.1262 -
1.1263 +
1.1264 friend class _Rope_iterator<_CharT,_Alloc>;
1.1265 friend class _Rope_const_iterator<_CharT,_Alloc>;
1.1266 friend struct _Rope_RopeRep<_CharT,_Alloc>;
1.1267 @@ -1135,37 +1095,39 @@
1.1268 friend struct _Rope_RopeSubstring<_CharT,_Alloc>;
1.1269
1.1270 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
1.1271 -
1.1272 +
1.1273 protected:
1.1274 - typedef __GC_CONST _CharT* _Cstrptr;
1.1275 -
1.1276 + typedef _CharT* _Cstrptr;
1.1277 +
1.1278 static _CharT _S_empty_c_str[1];
1.1279 -
1.1280 - static bool _S_is0(_CharT __c) { return __c == _S_eos((_CharT*)0); }
1.1281 +
1.1282 enum { _S_copy_max = 23 };
1.1283 // For strings shorter than _S_copy_max, we copy to
1.1284 // concatenate.
1.1285 -
1.1286 +
1.1287 + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1.1288 + typedef typename _RopeRep::_IsBasicCharType _IsBasicCharType;
1.1289 +
1.1290 public:
1.1291 - typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1.1292 _STLP_FORCE_ALLOCATORS(_CharT, _Alloc)
1.1293 typedef typename _Alloc_traits<_CharT,_Alloc>::allocator_type allocator_type;
1.1294 - allocator_type get_allocator() const { return allocator_type(_M_tree_ptr); }
1.1295 +
1.1296 public:
1.1297 // The only data member of a rope:
1.1298 - _STLP_alloc_proxy<_RopeRep*, _CharT, allocator_type> _M_tree_ptr;
1.1299 + _STLP_PRIV _STLP_alloc_proxy<_RopeRep*, _CharT, allocator_type> _M_tree_ptr;
1.1300
1.1301 +public:
1.1302 + allocator_type get_allocator() const { return allocator_type(_M_tree_ptr); }
1.1303 +
1.1304 +public:
1.1305 typedef _Rope_RopeConcatenation<_CharT,_Alloc> _RopeConcatenation;
1.1306 typedef _Rope_RopeLeaf<_CharT,_Alloc> _RopeLeaf;
1.1307 typedef _Rope_RopeFunction<_CharT,_Alloc> _RopeFunction;
1.1308 typedef _Rope_RopeSubstring<_CharT,_Alloc> _RopeSubstring;
1.1309
1.1310 -
1.1311 -
1.1312 // Retrieve a character at the indicated position.
1.1313 static _CharT _S_fetch(_RopeRep* __r, size_type __pos);
1.1314
1.1315 -# ifndef __GC
1.1316 // Obtain a pointer to the character at the indicated position.
1.1317 // The pointer can be used to change the character.
1.1318 // If such a pointer cannot be produced, as is frequently the
1.1319 @@ -1173,35 +1135,15 @@
1.1320 // (Returns nonzero only if all nodes in the path have a refcount
1.1321 // of 1.)
1.1322 static _CharT* _S_fetch_ptr(_RopeRep* __r, size_type __pos);
1.1323 -# endif
1.1324
1.1325 - static bool _S_apply_to_pieces(
1.1326 - // should be template parameter
1.1327 - _Rope_char_consumer<_CharT>& __c,
1.1328 - const _RopeRep* __r,
1.1329 - size_t __begin, size_t __end);
1.1330 - // begin and end are assumed to be in range.
1.1331 -
1.1332 -# ifndef __GC
1.1333 - static void _S_unref(_RopeRep* __t)
1.1334 - {
1.1335 + static void _S_unref(_RopeRep* __t) {
1.1336 _RopeRep::_S_unref(__t);
1.1337 }
1.1338 - static void _S_ref(_RopeRep* __t)
1.1339 - {
1.1340 + static void _S_ref(_RopeRep* __t) {
1.1341 _RopeRep::_S_ref(__t);
1.1342 }
1.1343 -# else /* __GC */
1.1344 - static void _S_unref(_RopeRep*) {}
1.1345 - static void _S_ref(_RopeRep*) {}
1.1346 -# endif
1.1347
1.1348 -
1.1349 -# ifdef __GC
1.1350 - typedef _Rope_RopeRep<_CharT,_Alloc>* _Self_destruct_ptr;
1.1351 -# else
1.1352 typedef _Rope_self_destruct_ptr<_CharT,_Alloc> _Self_destruct_ptr;
1.1353 -# endif
1.1354
1.1355 // _Result is counted in refcount.
1.1356 static _RopeRep* _S_substring(_RopeRep* __base,
1.1357 @@ -1213,106 +1155,82 @@
1.1358 // Should really take an arbitrary iterator.
1.1359 // Result is counted in refcount.
1.1360 static _RopeRep* _S_destr_concat_char_iter(_RopeRep* __r,
1.1361 - const _CharT* __iter, size_t __slen)
1.1362 + const _CharT* __iter, size_t __slen);
1.1363 // As above, but one reference to __r is about to be
1.1364 // destroyed. Thus the pieces may be recycled if all
1.1365 // relevent reference counts are 1.
1.1366 -# ifdef __GC
1.1367 - // We can't really do anything since refcounts are unavailable.
1.1368 - { return _S_concat_char_iter(__r, __iter, __slen); }
1.1369 -# else
1.1370 - ;
1.1371 -# endif
1.1372
1.1373 - static _RopeRep* _S_concat_rep(_RopeRep* __left, _RopeRep* __right);
1.1374 // General concatenation on _RopeRep. _Result
1.1375 // has refcount of 1. Adjusts argument refcounts.
1.1376 + static _RopeRep* _S_concat_rep(_RopeRep* __left, _RopeRep* __right);
1.1377
1.1378 public:
1.1379 - void apply_to_pieces( size_t __begin, size_t __end,
1.1380 - _Rope_char_consumer<_CharT>& __c) const {
1.1381 - _S_apply_to_pieces(__c, _M_tree_ptr._M_data, __begin, __end);
1.1382 - }
1.1383 -
1.1384 +#if defined (_STLP_MEMBER_TEMPLATES)
1.1385 + template <class _CharConsumer>
1.1386 +#else
1.1387 + typedef _Rope_char_consumer<_CharT> _CharConsumer;
1.1388 +#endif
1.1389 + void apply_to_pieces(size_t __begin, size_t __end,
1.1390 + _CharConsumer& __c) const
1.1391 + { _S_apply_to_pieces(__c, _M_tree_ptr._M_data, __begin, __end); }
1.1392
1.1393 protected:
1.1394
1.1395 - static size_t _S_rounded_up_size(size_t __n) {
1.1396 - return _RopeRep::_S_rounded_up_size(__n);
1.1397 - }
1.1398 + static size_t _S_rounded_up_size(size_t __n)
1.1399 + { return _RopeRep::_S_rounded_up_size(__n); }
1.1400
1.1401 - static size_t _S_allocated_capacity(size_t __n) {
1.1402 - if (_S_is_basic_char_type((_CharT*)0)) {
1.1403 - return _S_rounded_up_size(__n) - 1;
1.1404 - } else {
1.1405 - return _S_rounded_up_size(__n);
1.1406 - }
1.1407 - }
1.1408 -
1.1409 // Allocate and construct a RopeLeaf using the supplied allocator
1.1410 // Takes ownership of s instead of copying.
1.1411 - static _RopeLeaf* _S_new_RopeLeaf(__GC_CONST _CharT *__s,
1.1412 - size_t _p_size, allocator_type __a)
1.1413 - {
1.1414 - _RopeLeaf* __space = _STLP_CREATE_ALLOCATOR(allocator_type,__a, _RopeLeaf).allocate(1,(const void*)0);
1.1415 + static _RopeLeaf* _S_new_RopeLeaf(_CharT *__s,
1.1416 + size_t _p_size, allocator_type __a) {
1.1417 + _RopeLeaf* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
1.1418 + _RopeLeaf).allocate(1);
1.1419 _STLP_TRY {
1.1420 _STLP_PLACEMENT_NEW(__space) _RopeLeaf(__s, _p_size, __a);
1.1421 }
1.1422 - _STLP_UNWIND(_STLP_CREATE_ALLOCATOR(allocator_type,__a,
1.1423 - _RopeLeaf).deallocate(__space, 1))
1.1424 - return __space;
1.1425 + _STLP_UNWIND(_STLP_CREATE_ALLOCATOR(allocator_type,__a,
1.1426 + _RopeLeaf).deallocate(__space, 1))
1.1427 + return __space;
1.1428 }
1.1429
1.1430 - static _RopeConcatenation* _S_new_RopeConcatenation(
1.1431 - _RopeRep* __left, _RopeRep* __right,
1.1432 - allocator_type __a)
1.1433 - {
1.1434 - _RopeConcatenation* __space = _STLP_CREATE_ALLOCATOR(allocator_type,__a,
1.1435 - _RopeConcatenation).allocate(1,(const void*)0);
1.1436 + static _RopeConcatenation* _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right,
1.1437 + allocator_type __a) {
1.1438 + _RopeConcatenation* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
1.1439 + _RopeConcatenation).allocate(1);
1.1440 return _STLP_PLACEMENT_NEW(__space) _RopeConcatenation(__left, __right, __a);
1.1441 }
1.1442
1.1443 static _RopeFunction* _S_new_RopeFunction(char_producer<_CharT>* __f,
1.1444 - size_t _p_size, bool __d, allocator_type __a)
1.1445 - {
1.1446 - _RopeFunction* __space = _STLP_CREATE_ALLOCATOR(allocator_type,__a,
1.1447 - _RopeFunction).allocate(1,(const void*)0);
1.1448 + size_t _p_size, bool __d, allocator_type __a) {
1.1449 + _RopeFunction* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
1.1450 + _RopeFunction).allocate(1);
1.1451 return _STLP_PLACEMENT_NEW(__space) _RopeFunction(__f, _p_size, __d, __a);
1.1452 }
1.1453
1.1454 - static _RopeSubstring* _S_new_RopeSubstring(
1.1455 - _Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
1.1456 - size_t __l, allocator_type __a)
1.1457 - {
1.1458 - _RopeSubstring* __space = _STLP_CREATE_ALLOCATOR(allocator_type,__a,
1.1459 - _RopeSubstring).allocate(1,(const void*)0);
1.1460 + static _RopeSubstring* _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
1.1461 + size_t __l, allocator_type __a) {
1.1462 + _RopeSubstring* __space = _STLP_CREATE_ALLOCATOR(allocator_type, __a,
1.1463 + _RopeSubstring).allocate(1);
1.1464 return _STLP_PLACEMENT_NEW(__space) _RopeSubstring(__b, __s, __l, __a);
1.1465 }
1.1466
1.1467 -# define _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _p_size, __a) \
1.1468 - _S_RopeLeaf_from_unowned_char_ptr(__s, _p_size, __a)
1.1469 -
1.1470 static
1.1471 _RopeLeaf* _S_RopeLeaf_from_unowned_char_ptr(const _CharT *__s,
1.1472 - size_t _p_size, allocator_type __a)
1.1473 - {
1.1474 + size_t _p_size, allocator_type __a) {
1.1475 if (0 == _p_size) return 0;
1.1476
1.1477 _CharT* __buf = _STLP_CREATE_ALLOCATOR(allocator_type,__a, _CharT).allocate(_S_rounded_up_size(_p_size));
1.1478
1.1479 - uninitialized_copy_n(__s, _p_size, __buf);
1.1480 - _S_cond_store_eos(__buf[_p_size]);
1.1481 + _STLP_PRIV __ucopy_n(__s, _p_size, __buf);
1.1482 + _S_construct_null(__buf + _p_size);
1.1483
1.1484 _STLP_TRY {
1.1485 return _S_new_RopeLeaf(__buf, _p_size, __a);
1.1486 }
1.1487 _STLP_UNWIND(_RopeRep::_S_free_string(__buf, _p_size, __a))
1.1488 -
1.1489 -# if defined (_STLP_THROW_RETURN_BUG)
1.1490 - return 0;
1.1491 -# endif
1.1492 + _STLP_RET_AFTER_THROW(0)
1.1493 }
1.1494 -
1.1495 +
1.1496
1.1497 // Concatenation of nonempty strings.
1.1498 // Always builds a concatenation node.
1.1499 @@ -1330,25 +1248,24 @@
1.1500 // Concatenate by copying leaf.
1.1501 // should take an arbitrary iterator
1.1502 // result has refcount 1.
1.1503 -# ifndef __GC
1.1504 static _RopeLeaf* _S_destr_leaf_concat_char_iter
1.1505 (_RopeLeaf* __r, const _CharT* __iter, size_t __slen);
1.1506 // A version that potentially clobbers __r if __r->_M_ref_count == 1.
1.1507 -# endif
1.1508
1.1509
1.1510 // A helper function for exponentiating strings.
1.1511 // This uses a nonstandard refcount convention.
1.1512 // The result has refcount 0.
1.1513 - friend struct _Rope_Concat_fn<_CharT,_Alloc>;
1.1514 - typedef _Rope_Concat_fn<_CharT,_Alloc> _Concat_fn;
1.1515 + typedef _STLP_PRIV _Rope_Concat_fn<_CharT,_Alloc> _Concat_fn;
1.1516 +#if !defined (__GNUC__) || (__GNUC__ < 3)
1.1517 + friend _Concat_fn;
1.1518 +#else
1.1519 + friend struct _STLP_PRIV _Rope_Concat_fn<_CharT,_Alloc>;
1.1520 +#endif
1.1521
1.1522 public:
1.1523 static size_t _S_char_ptr_len(const _CharT* __s) {
1.1524 - const _CharT* __p = __s;
1.1525 -
1.1526 - while (!_S_is0(*__p)) { ++__p; }
1.1527 - return (__p - __s);
1.1528 + return char_traits<_CharT>::length(__s);
1.1529 }
1.1530
1.1531 public: /* for operators */
1.1532 @@ -1368,23 +1285,24 @@
1.1533
1.1534 // fbp : HP aCC prohibits access to protected min_len from within static methods ( ?? )
1.1535 public:
1.1536 - static const unsigned long _S_min_len[46];
1.1537 + static const unsigned long _S_min_len[__ROPE_DEPTH_SIZE];
1.1538 protected:
1.1539 static bool _S_is_balanced(_RopeRep* __r)
1.1540 { return (__r->_M_size._M_data >= _S_min_len[__r->_M_depth]); }
1.1541
1.1542 - static bool _S_is_almost_balanced(_RopeRep* __r)
1.1543 - { return (__r->_M_depth == 0 ||
1.1544 - __r->_M_size._M_data >= _S_min_len[__r->_M_depth - 1]); }
1.1545 + static bool _S_is_almost_balanced(_RopeRep* __r) {
1.1546 + return (__r->_M_depth == 0 ||
1.1547 + __r->_M_size._M_data >= _S_min_len[__r->_M_depth - 1]);
1.1548 + }
1.1549
1.1550 - static bool _S_is_roughly_balanced(_RopeRep* __r)
1.1551 - { return (__r->_M_depth <= 1 ||
1.1552 - __r->_M_size._M_data >= _S_min_len[__r->_M_depth - 2]); }
1.1553 + static bool _S_is_roughly_balanced(_RopeRep* __r) {
1.1554 + return (__r->_M_depth <= 1 ||
1.1555 + __r->_M_size._M_data >= _S_min_len[__r->_M_depth - 2]);
1.1556 + }
1.1557
1.1558 // Assumes the result is not empty.
1.1559 static _RopeRep* _S_concat_and_set_balanced(_RopeRep* __left,
1.1560 - _RopeRep* __right)
1.1561 - {
1.1562 + _RopeRep* __right) {
1.1563 _RopeRep* __result = _S_concat_rep(__left, __right);
1.1564 if (_S_is_balanced(__result)) __result->_M_is_balanced = true;
1.1565 return __result;
1.1566 @@ -1400,16 +1318,27 @@
1.1567 // Add all unbalanced subtrees to the forest of balanceed trees.
1.1568 // Used only by balance.
1.1569 static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest);
1.1570 -
1.1571 +
1.1572 // Add __r to forest, assuming __r is already balanced.
1.1573 static void _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest);
1.1574
1.1575 +#ifdef _STLP_DEBUG
1.1576 // Print to stdout, exposing structure
1.1577 static void _S_dump(_RopeRep* __r, int __indent = 0);
1.1578 +#endif
1.1579
1.1580 // Return -1, 0, or 1 if __x < __y, __x == __y, or __x > __y resp.
1.1581 static int _S_compare(const _RopeRep* __x, const _RopeRep* __y);
1.1582
1.1583 + void _STLP_FUNCTION_THROWS _M_throw_out_of_range() const;
1.1584 +
1.1585 + void _M_reset(_RopeRep* __r) {
1.1586 + //if (__r != _M_tree_ptr._M_data) {
1.1587 + _S_unref(_M_tree_ptr._M_data);
1.1588 + _M_tree_ptr._M_data = __r;
1.1589 + //}
1.1590 + }
1.1591 +
1.1592 public:
1.1593 bool empty() const { return 0 == _M_tree_ptr._M_data; }
1.1594
1.1595 @@ -1421,60 +1350,61 @@
1.1596 }
1.1597
1.1598 rope(const _CharT* __s, const allocator_type& __a = allocator_type())
1.1599 - : _M_tree_ptr(__a, _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s),__a))
1.1600 - { }
1.1601 + : _M_tree_ptr(__a, _S_RopeLeaf_from_unowned_char_ptr(__s, _S_char_ptr_len(__s),__a))
1.1602 + {}
1.1603
1.1604 rope(const _CharT* __s, size_t __len,
1.1605 const allocator_type& __a = allocator_type())
1.1606 - : _M_tree_ptr(__a, (_STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, __a)))
1.1607 - { }
1.1608 + : _M_tree_ptr(__a, (_S_RopeLeaf_from_unowned_char_ptr(__s, __len, __a)))
1.1609 + {}
1.1610
1.1611 // Should perhaps be templatized with respect to the iterator type
1.1612 // and use Sequence_buffer. (It should perhaps use sequence_buffer
1.1613 // even now.)
1.1614 rope(const _CharT *__s, const _CharT *__e,
1.1615 const allocator_type& __a = allocator_type())
1.1616 - : _M_tree_ptr(__a, _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, __a))
1.1617 - { }
1.1618 + : _M_tree_ptr(__a, _S_RopeLeaf_from_unowned_char_ptr(__s, __e - __s, __a))
1.1619 + {}
1.1620
1.1621 rope(const const_iterator& __s, const const_iterator& __e,
1.1622 const allocator_type& __a = allocator_type())
1.1623 : _M_tree_ptr(__a, _S_substring(__s._M_root, __s._M_current_pos,
1.1624 __e._M_current_pos))
1.1625 - { }
1.1626 + {}
1.1627
1.1628 rope(const iterator& __s, const iterator& __e,
1.1629 const allocator_type& __a = allocator_type())
1.1630 : _M_tree_ptr(__a, _S_substring(__s._M_root, __s._M_current_pos,
1.1631 __e._M_current_pos))
1.1632 - { }
1.1633 + {}
1.1634
1.1635 rope(_CharT __c, const allocator_type& __a = allocator_type())
1.1636 - : _M_tree_ptr(__a, (_RopeRep*)0)
1.1637 - {
1.1638 + : _M_tree_ptr(__a, (_RopeRep*)0) {
1.1639 _CharT* __buf = _M_tree_ptr.allocate(_S_rounded_up_size(1));
1.1640
1.1641 - _Construct(__buf, __c);
1.1642 + _Copy_Construct(__buf, __c);
1.1643 + _S_construct_null(__buf + 1);
1.1644 +
1.1645 _STLP_TRY {
1.1646 _M_tree_ptr._M_data = _S_new_RopeLeaf(__buf, 1, __a);
1.1647 }
1.1648 _STLP_UNWIND(_RopeRep::_S_free_string(__buf, 1, __a))
1.1649 - }
1.1650 + }
1.1651
1.1652 - rope(size_t __n, _CharT __c,
1.1653 + rope(size_t __n, _CharT __c,
1.1654 const allocator_type& __a = allocator_type()):
1.1655 _M_tree_ptr(__a, (_RopeRep*)0) {
1.1656 + if (0 == __n)
1.1657 + return;
1.1658 +
1.1659 rope<_CharT,_Alloc> __result;
1.1660 # define __exponentiate_threshold size_t(32)
1.1661 _RopeRep* __remainder;
1.1662 rope<_CharT,_Alloc> __remainder_rope;
1.1663 -
1.1664 +
1.1665 // gcc-2.7.2 bugs
1.1666 - typedef _Rope_Concat_fn<_CharT,_Alloc> _Concat_fn;
1.1667 -
1.1668 - if (0 == __n)
1.1669 - return;
1.1670 -
1.1671 + typedef _STLP_PRIV _Rope_Concat_fn<_CharT,_Alloc> _Concat_fn;
1.1672 +
1.1673 size_t __exponent = __n / __exponentiate_threshold;
1.1674 size_t __rest = __n % __exponentiate_threshold;
1.1675 if (0 == __rest) {
1.1676 @@ -1482,38 +1412,35 @@
1.1677 } else {
1.1678 _CharT* __rest_buffer = _M_tree_ptr.allocate(_S_rounded_up_size(__rest));
1.1679 uninitialized_fill_n(__rest_buffer, __rest, __c);
1.1680 - _S_cond_store_eos(__rest_buffer[__rest]);
1.1681 + _S_construct_null(__rest_buffer + __rest);
1.1682 _STLP_TRY {
1.1683 - __remainder = _S_new_RopeLeaf(__rest_buffer, __rest, __a);
1.1684 + __remainder = _S_new_RopeLeaf(__rest_buffer, __rest, __a);
1.1685 }
1.1686 _STLP_UNWIND(_RopeRep::_S_free_string(__rest_buffer, __rest, __a))
1.1687 - }
1.1688 + }
1.1689 __remainder_rope._M_tree_ptr._M_data = __remainder;
1.1690 if (__exponent != 0) {
1.1691 - _CharT* __base_buffer =
1.1692 - _M_tree_ptr.allocate(_S_rounded_up_size(__exponentiate_threshold));
1.1693 + _CharT* __base_buffer = _M_tree_ptr.allocate(_S_rounded_up_size(__exponentiate_threshold));
1.1694 _RopeLeaf* __base_leaf;
1.1695 rope<_CharT,_Alloc> __base_rope;
1.1696 uninitialized_fill_n(__base_buffer, __exponentiate_threshold, __c);
1.1697 - _S_cond_store_eos(__base_buffer[__exponentiate_threshold]);
1.1698 + _S_construct_null(__base_buffer + __exponentiate_threshold);
1.1699 _STLP_TRY {
1.1700 - __base_leaf = _S_new_RopeLeaf(__base_buffer,
1.1701 + __base_leaf = _S_new_RopeLeaf(__base_buffer,
1.1702 __exponentiate_threshold, __a);
1.1703 }
1.1704 - _STLP_UNWIND(_RopeRep::_S_free_string(__base_buffer,
1.1705 + _STLP_UNWIND(_RopeRep::_S_free_string(__base_buffer,
1.1706 __exponentiate_threshold, __a))
1.1707 - __base_rope._M_tree_ptr._M_data = __base_leaf;
1.1708 + __base_rope._M_tree_ptr._M_data = __base_leaf;
1.1709 if (1 == __exponent) {
1.1710 - __result = __base_rope;
1.1711 -# ifndef __GC
1.1712 - _STLP_ASSERT(2 == __result._M_tree_ptr._M_data->_M_ref_count)
1.1713 - // One each for base_rope and __result
1.1714 -# endif
1.1715 + __result = __base_rope;
1.1716 + // One each for base_rope and __result
1.1717 + //_STLP_ASSERT(2 == __result._M_tree_ptr._M_data->_M_ref_count)
1.1718 } else {
1.1719 - __result = power(__base_rope, __exponent, _Concat_fn());
1.1720 + __result = _STLP_PRIV __power(__base_rope, __exponent, _Concat_fn());
1.1721 }
1.1722 if (0 != __remainder) {
1.1723 - __result += __remainder_rope;
1.1724 + __result += __remainder_rope;
1.1725 }
1.1726 } else {
1.1727 __result = __remainder_rope;
1.1728 @@ -1529,120 +1456,113 @@
1.1729 // Construct a rope from a function that can compute its members
1.1730 rope(char_producer<_CharT> *__fn, size_t __len, bool __delete_fn,
1.1731 const allocator_type& __a = allocator_type())
1.1732 - : _M_tree_ptr(__a, (_RopeRep*)0)
1.1733 - {
1.1734 + : _M_tree_ptr(__a, (_RopeRep*)0) {
1.1735 _M_tree_ptr._M_data = (0 == __len) ?
1.1736 0 : _S_new_RopeFunction(__fn, __len, __delete_fn, __a);
1.1737 }
1.1738
1.1739 rope(const _Self& __x)
1.1740 - : _M_tree_ptr(__x.get_allocator(), __x._M_tree_ptr._M_data)
1.1741 - {
1.1742 + : _M_tree_ptr(__x._M_tree_ptr, __x._M_tree_ptr._M_data) {
1.1743 _S_ref(_M_tree_ptr._M_data);
1.1744 }
1.1745
1.1746 - ~rope()
1.1747 - {
1.1748 + rope(__move_source<_Self> __src)
1.1749 + : _M_tree_ptr(__src.get()._M_tree_ptr, __src.get()._M_tree_ptr._M_data) {
1.1750 + __src.get()._M_tree_ptr._M_data = 0;
1.1751 + }
1.1752 +
1.1753 + ~rope() {
1.1754 _S_unref(_M_tree_ptr._M_data);
1.1755 }
1.1756
1.1757 - _Self& operator=(const _Self& __x)
1.1758 - {
1.1759 - _RopeRep* __old = _M_tree_ptr._M_data;
1.1760 + _Self& operator=(const _Self& __x) {
1.1761 _STLP_ASSERT(get_allocator() == __x.get_allocator())
1.1762 - _M_tree_ptr._M_data = __x._M_tree_ptr._M_data;
1.1763 - _S_ref(_M_tree_ptr._M_data);
1.1764 - _S_unref(__old);
1.1765 - return(*this);
1.1766 + _S_ref(__x._M_tree_ptr._M_data);
1.1767 + _M_reset(__x._M_tree_ptr._M_data);
1.1768 + return *this;
1.1769 }
1.1770 - void clear()
1.1771 - {
1.1772 +
1.1773 + void clear() {
1.1774 _S_unref(_M_tree_ptr._M_data);
1.1775 _M_tree_ptr._M_data = 0;
1.1776 }
1.1777 - void push_back(_CharT __x)
1.1778 - {
1.1779 - _RopeRep* __old = _M_tree_ptr._M_data;
1.1780 - _M_tree_ptr._M_data = _S_destr_concat_char_iter(_M_tree_ptr._M_data, &__x, 1);
1.1781 - _S_unref(__old);
1.1782 + void push_back(_CharT __x) {
1.1783 + _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, &__x, 1));
1.1784 }
1.1785
1.1786 - void pop_back()
1.1787 - {
1.1788 + void pop_back() {
1.1789 _RopeRep* __old = _M_tree_ptr._M_data;
1.1790 - _M_tree_ptr._M_data =
1.1791 + _M_tree_ptr._M_data =
1.1792 _S_substring(_M_tree_ptr._M_data, 0, _M_tree_ptr._M_data->_M_size._M_data - 1);
1.1793 _S_unref(__old);
1.1794 }
1.1795
1.1796 - _CharT back() const
1.1797 - {
1.1798 + _CharT back() const {
1.1799 return _S_fetch(_M_tree_ptr._M_data, _M_tree_ptr._M_data->_M_size._M_data - 1);
1.1800 }
1.1801
1.1802 - void push_front(_CharT __x)
1.1803 - {
1.1804 + void push_front(_CharT __x) {
1.1805 _RopeRep* __old = _M_tree_ptr._M_data;
1.1806 _RopeRep* __left =
1.1807 - _STLP_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, get_allocator());
1.1808 + _S_RopeLeaf_from_unowned_char_ptr(&__x, 1, _M_tree_ptr);
1.1809 _STLP_TRY {
1.1810 _M_tree_ptr._M_data = _S_concat_rep(__left, _M_tree_ptr._M_data);
1.1811 _S_unref(__old);
1.1812 _S_unref(__left);
1.1813 }
1.1814 _STLP_UNWIND(_S_unref(__left))
1.1815 - }
1.1816 + }
1.1817
1.1818 - void pop_front()
1.1819 - {
1.1820 + void pop_front() {
1.1821 _RopeRep* __old = _M_tree_ptr._M_data;
1.1822 _M_tree_ptr._M_data = _S_substring(_M_tree_ptr._M_data, 1, _M_tree_ptr._M_data->_M_size._M_data);
1.1823 _S_unref(__old);
1.1824 }
1.1825
1.1826 - _CharT front() const
1.1827 - {
1.1828 + _CharT front() const {
1.1829 return _S_fetch(_M_tree_ptr._M_data, 0);
1.1830 }
1.1831
1.1832 - void balance()
1.1833 - {
1.1834 + void balance() {
1.1835 _RopeRep* __old = _M_tree_ptr._M_data;
1.1836 _M_tree_ptr._M_data = _S_balance(_M_tree_ptr._M_data);
1.1837 _S_unref(__old);
1.1838 }
1.1839
1.1840 void copy(_CharT* __buffer) const {
1.1841 - _STLP_STD::_Destroy(__buffer, __buffer + size());
1.1842 + _STLP_STD::_Destroy_Range(__buffer, __buffer + size());
1.1843 _S_flatten(_M_tree_ptr._M_data, __buffer);
1.1844 }
1.1845
1.1846 - // This is the copy function from the standard, but
1.1847 - // with the arguments reordered to make it consistent with the
1.1848 - // rest of the interface.
1.1849 - // Note that this guaranteed not to compile if the draft standard
1.1850 - // order is assumed.
1.1851 - size_type copy(size_type __pos, size_type __n, _CharT* __buffer) const
1.1852 - {
1.1853 + /*
1.1854 + * This is the copy function from the standard, but
1.1855 + * with the arguments reordered to make it consistent with the
1.1856 + * rest of the interface.
1.1857 + * Note that this guaranteed not to compile if the draft standard
1.1858 + * order is assumed.
1.1859 + */
1.1860 + size_type copy(size_type __pos, size_type __n, _CharT* __buffer) const {
1.1861 size_t _p_size = size();
1.1862 size_t __len = (__pos + __n > _p_size? _p_size - __pos : __n);
1.1863
1.1864 - _STLP_STD::_Destroy(__buffer, __buffer + __len);
1.1865 + _STLP_STD::_Destroy_Range(__buffer, __buffer + __len);
1.1866 _S_flatten(_M_tree_ptr._M_data, __pos, __len, __buffer);
1.1867 return __len;
1.1868 }
1.1869
1.1870 +# ifdef _STLP_DEBUG
1.1871 // Print to stdout, exposing structure. May be useful for
1.1872 // performance debugging.
1.1873 void dump() {
1.1874 _S_dump(_M_tree_ptr._M_data);
1.1875 }
1.1876 +# endif
1.1877
1.1878 // Convert to 0 terminated string in new allocated memory.
1.1879 // Embedded 0s in the input do not terminate the copy.
1.1880 const _CharT* c_str() const;
1.1881
1.1882 - // As above, but lso use the flattened representation as the
1.1883 + // As above, but also use the flattened representation as the
1.1884 // the new rope representation.
1.1885 const _CharT* replace_with_c_str();
1.1886
1.1887 @@ -1651,15 +1571,13 @@
1.1888 // is safe for multiple threads.
1.1889 void delete_c_str () {
1.1890 if (0 == _M_tree_ptr._M_data) return;
1.1891 - if (_RopeRep::_S_leaf == _M_tree_ptr._M_data->_M_tag &&
1.1892 - ((_RopeLeaf*)_M_tree_ptr._M_data)->_M_data ==
1.1893 + if (_RopeRep::_S_leaf == _M_tree_ptr._M_data->_M_tag &&
1.1894 + ((_RopeLeaf*)_M_tree_ptr._M_data)->_M_data ==
1.1895 _M_tree_ptr._M_data->_M_c_string) {
1.1896 // Representation shared
1.1897 return;
1.1898 }
1.1899 -# ifndef __GC
1.1900 _M_tree_ptr._M_data->_M_free_c_string();
1.1901 -# endif
1.1902 _M_tree_ptr._M_data->_M_c_string = 0;
1.1903 }
1.1904
1.1905 @@ -1668,7 +1586,7 @@
1.1906 }
1.1907
1.1908 _CharT at(size_type __pos) const {
1.1909 - // if (__pos >= size()) throw out_of_range; // XXX
1.1910 + if (__pos >= size()) _M_throw_out_of_range();
1.1911 return (*this)[__pos];
1.1912 }
1.1913
1.1914 @@ -1689,7 +1607,7 @@
1.1915 return(const_iterator(_M_tree_ptr._M_data, size()));
1.1916 }
1.1917
1.1918 - size_type size() const {
1.1919 + size_type size() const {
1.1920 return(0 == _M_tree_ptr._M_data? 0 : _M_tree_ptr._M_data->_M_size._M_data);
1.1921 }
1.1922
1.1923 @@ -1699,7 +1617,7 @@
1.1924
1.1925 size_type max_size() const {
1.1926 return _S_min_len[__ROPE_MAX_DEPTH-1] - 1;
1.1927 - // Guarantees that the result can be sufficirntly
1.1928 + // Guarantees that the result can be sufficiently
1.1929 // balanced. Longer ropes will probably still work,
1.1930 // but it's harder to make guarantees.
1.1931 }
1.1932 @@ -1726,44 +1644,31 @@
1.1933 // The first argument should be an input iterator or
1.1934 // forward iterator with value_type _CharT.
1.1935 _Self& append(const _CharT* __iter, size_t __n) {
1.1936 - _RopeRep* __result =
1.1937 - _S_destr_concat_char_iter(_M_tree_ptr._M_data, __iter, __n);
1.1938 - _S_unref(_M_tree_ptr._M_data);
1.1939 - _M_tree_ptr._M_data = __result;
1.1940 + _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, __iter, __n));
1.1941 return *this;
1.1942 }
1.1943
1.1944 _Self& append(const _CharT* __c_string) {
1.1945 size_t __len = _S_char_ptr_len(__c_string);
1.1946 append(__c_string, __len);
1.1947 - return(*this);
1.1948 + return *this;
1.1949 }
1.1950
1.1951 _Self& append(const _CharT* __s, const _CharT* __e) {
1.1952 - _RopeRep* __result =
1.1953 - _S_destr_concat_char_iter(_M_tree_ptr._M_data, __s, __e - __s);
1.1954 - _S_unref(_M_tree_ptr._M_data);
1.1955 - _M_tree_ptr._M_data = __result;
1.1956 + _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, __s, __e - __s));
1.1957 return *this;
1.1958 }
1.1959
1.1960 _Self& append(const_iterator __s, const_iterator __e) {
1.1961 _STLP_ASSERT(__s._M_root == __e._M_root)
1.1962 _STLP_ASSERT(get_allocator() == __s._M_root->get_allocator())
1.1963 - _Self_destruct_ptr __appendee(_S_substring(
1.1964 - __s._M_root, __s._M_current_pos, __e._M_current_pos));
1.1965 - _RopeRep* __result =
1.1966 - _S_concat_rep(_M_tree_ptr._M_data, (_RopeRep*)__appendee);
1.1967 - _S_unref(_M_tree_ptr._M_data);
1.1968 - _M_tree_ptr._M_data = __result;
1.1969 + _Self_destruct_ptr __appendee(_S_substring(__s._M_root, __s._M_current_pos, __e._M_current_pos));
1.1970 + _M_reset(_S_concat_rep(_M_tree_ptr._M_data, (_RopeRep*)__appendee));
1.1971 return *this;
1.1972 }
1.1973
1.1974 _Self& append(_CharT __c) {
1.1975 - _RopeRep* __result =
1.1976 - _S_destr_concat_char_iter(_M_tree_ptr._M_data, &__c, 1);
1.1977 - _S_unref(_M_tree_ptr._M_data);
1.1978 - _M_tree_ptr._M_data = __result;
1.1979 + _M_reset(_S_destr_concat_char_iter(_M_tree_ptr._M_data, &__c, 1));
1.1980 return *this;
1.1981 }
1.1982
1.1983 @@ -1771,9 +1676,7 @@
1.1984
1.1985 _Self& append(const _Self& __y) {
1.1986 _STLP_ASSERT(__y.get_allocator() == get_allocator())
1.1987 - _RopeRep* __result = _S_concat_rep(_M_tree_ptr._M_data, __y._M_tree_ptr._M_data);
1.1988 - _S_unref(_M_tree_ptr._M_data);
1.1989 - _M_tree_ptr._M_data = __result;
1.1990 + _M_reset(_S_concat_rep(_M_tree_ptr._M_data, __y._M_tree_ptr._M_data));
1.1991 return *this;
1.1992 }
1.1993
1.1994 @@ -1783,23 +1686,17 @@
1.1995 }
1.1996
1.1997 void swap(_Self& __b) {
1.1998 - _STLP_ASSERT(get_allocator() == __b.get_allocator())
1.1999 - _RopeRep* __tmp = _M_tree_ptr._M_data;
1.2000 - _M_tree_ptr._M_data = __b._M_tree_ptr._M_data;
1.2001 - __b._M_tree_ptr._M_data = __tmp;
1.2002 + _M_tree_ptr.swap(__b._M_tree_ptr);
1.2003 }
1.2004
1.2005 -
1.2006 protected:
1.2007 // Result is included in refcount.
1.2008 static _RopeRep* replace(_RopeRep* __old, size_t __pos1,
1.2009 size_t __pos2, _RopeRep* __r) {
1.2010 if (0 == __old) { _S_ref(__r); return __r; }
1.2011 - _Self_destruct_ptr __left(
1.2012 - _S_substring(__old, 0, __pos1));
1.2013 - _Self_destruct_ptr __right(
1.2014 - _S_substring(__old, __pos2, __old->_M_size._M_data));
1.2015 - _STLP_MPWFIX_TRY //*TY 06/01/2000 -
1.2016 + _Self_destruct_ptr __left(_S_substring(__old, 0, __pos1));
1.2017 + _Self_destruct_ptr __right(_S_substring(__old, __pos2, __old->_M_size._M_data));
1.2018 + _STLP_MPWFIX_TRY //*TY 06/01/2000 -
1.2019 _RopeRep* __result;
1.2020
1.2021 if (0 == __r) {
1.2022 @@ -1810,16 +1707,14 @@
1.2023 __result = _S_concat_rep(__left_result, __right);
1.2024 }
1.2025 return __result;
1.2026 - _STLP_MPWFIX_CATCH //*TY 06/01/2000 -
1.2027 + _STLP_MPWFIX_CATCH //*TY 06/01/2000 -
1.2028 }
1.2029
1.2030 public:
1.2031 void insert(size_t __p, const _Self& __r) {
1.2032 - _RopeRep* __result =
1.2033 - replace(_M_tree_ptr._M_data, __p, __p, __r._M_tree_ptr._M_data);
1.2034 + if (__p > size()) _M_throw_out_of_range();
1.2035 _STLP_ASSERT(get_allocator() == __r.get_allocator())
1.2036 - _S_unref(_M_tree_ptr._M_data);
1.2037 - _M_tree_ptr._M_data = __result;
1.2038 + _M_reset(replace(_M_tree_ptr._M_data, __p, __p, __r._M_tree_ptr._M_data));
1.2039 }
1.2040
1.2041 void insert(size_t __p, size_t __n, _CharT __c) {
1.2042 @@ -1828,6 +1723,7 @@
1.2043 }
1.2044
1.2045 void insert(size_t __p, const _CharT* __i, size_t __n) {
1.2046 + if (__p > size()) _M_throw_out_of_range();
1.2047 _Self_destruct_ptr __left(_S_substring(_M_tree_ptr._M_data, 0, __p));
1.2048 _Self_destruct_ptr __right(_S_substring(_M_tree_ptr._M_data, __p, size()));
1.2049 _Self_destruct_ptr __left_result(
1.2050 @@ -1835,9 +1731,7 @@
1.2051 // _S_ destr_concat_char_iter should be safe here.
1.2052 // But as it stands it's probably not a win, since __left
1.2053 // is likely to have additional references.
1.2054 - _RopeRep* __result = _S_concat_rep(__left_result, __right);
1.2055 - _S_unref(_M_tree_ptr._M_data);
1.2056 - _M_tree_ptr._M_data = __result;
1.2057 + _M_reset(_S_concat_rep(__left_result, __right));
1.2058 }
1.2059
1.2060 void insert(size_t __p, const _CharT* __c_string) {
1.2061 @@ -1859,27 +1753,24 @@
1.2062 }
1.2063
1.2064 void insert(size_t __p, const const_iterator& __i,
1.2065 - const const_iterator& __j) {
1.2066 + const const_iterator& __j) {
1.2067 _Self __r(__i, __j);
1.2068 insert(__p, __r);
1.2069 }
1.2070
1.2071 void insert(size_t __p, const iterator& __i,
1.2072 - const iterator& __j) {
1.2073 + const iterator& __j) {
1.2074 _Self __r(__i, __j);
1.2075 insert(__p, __r);
1.2076 }
1.2077
1.2078 // (position, length) versions of replace operations:
1.2079 -
1.2080 void replace(size_t __p, size_t __n, const _Self& __r) {
1.2081 - _RopeRep* __result =
1.2082 - replace(_M_tree_ptr._M_data, __p, __p + __n, __r._M_tree_ptr._M_data);
1.2083 - _S_unref(_M_tree_ptr._M_data);
1.2084 - _M_tree_ptr._M_data = __result;
1.2085 + if (__p > size()) _M_throw_out_of_range();
1.2086 + _M_reset(replace(_M_tree_ptr._M_data, __p, __p + __n, __r._M_tree_ptr._M_data));
1.2087 }
1.2088
1.2089 - void replace(size_t __p, size_t __n,
1.2090 + void replace(size_t __p, size_t __n,
1.2091 const _CharT* __i, size_t __i_len) {
1.2092 _Self __r(__i, __i_len);
1.2093 replace(__p, __n, __r);
1.2094 @@ -1895,7 +1786,7 @@
1.2095 replace(__p, __n, __r);
1.2096 }
1.2097
1.2098 - void replace(size_t __p, size_t __n,
1.2099 + void replace(size_t __p, size_t __n,
1.2100 const _CharT* __i, const _CharT* __j) {
1.2101 _Self __r(__i, __j);
1.2102 replace(__p, __n, __r);
1.2103 @@ -1915,6 +1806,7 @@
1.2104
1.2105 // Single character variants:
1.2106 void replace(size_t __p, _CharT __c) {
1.2107 + if (__p > size()) _M_throw_out_of_range();
1.2108 iterator __i(this, __p);
1.2109 *__i = __c;
1.2110 }
1.2111 @@ -1936,20 +1828,19 @@
1.2112 }
1.2113
1.2114 void replace(size_t __p, const const_iterator& __i,
1.2115 - const const_iterator& __j) {
1.2116 + const const_iterator& __j) {
1.2117 replace(__p, 1, __i, __j);
1.2118 }
1.2119
1.2120 void replace(size_t __p, const iterator& __i,
1.2121 - const iterator& __j) {
1.2122 + const iterator& __j) {
1.2123 replace(__p, 1, __i, __j);
1.2124 }
1.2125
1.2126 // Erase, (position, size) variant.
1.2127 void erase(size_t __p, size_t __n) {
1.2128 - _RopeRep* __result = replace(_M_tree_ptr._M_data, __p, __p + __n, 0);
1.2129 - _S_unref(_M_tree_ptr._M_data);
1.2130 - _M_tree_ptr._M_data = __result;
1.2131 + if (__p > size()) _M_throw_out_of_range();
1.2132 + _M_reset(replace(_M_tree_ptr._M_data, __p, __p + __n, 0));
1.2133 }
1.2134
1.2135 // Erase, single character
1.2136 @@ -1957,20 +1848,20 @@
1.2137 erase(__p, __p + 1);
1.2138 }
1.2139
1.2140 - // Insert, iterator variants.
1.2141 + // Insert, iterator variants.
1.2142 iterator insert(const iterator& __p, const _Self& __r)
1.2143 { insert(__p.index(), __r); return __p; }
1.2144 iterator insert(const iterator& __p, size_t __n, _CharT __c)
1.2145 { insert(__p.index(), __n, __c); return __p; }
1.2146 - iterator insert(const iterator& __p, _CharT __c)
1.2147 + iterator insert(const iterator& __p, _CharT __c)
1.2148 { insert(__p.index(), __c); return __p; }
1.2149 - iterator insert(const iterator& __p )
1.2150 + iterator insert(const iterator& __p )
1.2151 { insert(__p.index()); return __p; }
1.2152 - iterator insert(const iterator& __p, const _CharT* c_string)
1.2153 + iterator insert(const iterator& __p, const _CharT* c_string)
1.2154 { insert(__p.index(), c_string); return __p; }
1.2155 iterator insert(const iterator& __p, const _CharT* __i, size_t __n)
1.2156 { insert(__p.index(), __i, __n); return __p; }
1.2157 - iterator insert(const iterator& __p, const _CharT* __i,
1.2158 + iterator insert(const iterator& __p, const _CharT* __i,
1.2159 const _CharT* __j)
1.2160 { insert(__p.index(), __i, __j); return __p; }
1.2161 iterator insert(const iterator& __p,
1.2162 @@ -2013,7 +1904,7 @@
1.2163 { replace(__p.index(), __i, __n); }
1.2164 void replace(const iterator& __p, const _CharT* __i, const _CharT* __j)
1.2165 { replace(__p.index(), __i, __j); }
1.2166 - void replace(const iterator& __p, const_iterator __i,
1.2167 + void replace(const iterator& __p, const_iterator __i,
1.2168 const_iterator __j)
1.2169 { replace(__p.index(), __i, __j); }
1.2170 void replace(const iterator& __p, iterator __i, iterator __j)
1.2171 @@ -2032,47 +1923,57 @@
1.2172 }
1.2173
1.2174 _Self substr(size_t __start, size_t __len = 1) const {
1.2175 - return rope<_CharT,_Alloc>(
1.2176 - _S_substring(_M_tree_ptr._M_data, __start, __start + __len));
1.2177 + if (__start > size()) _M_throw_out_of_range();
1.2178 + return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __start, __start + __len));
1.2179 }
1.2180
1.2181 _Self substr(iterator __start, iterator __end) const {
1.2182 - return rope<_CharT,_Alloc>(
1.2183 - _S_substring(_M_tree_ptr._M_data, __start.index(), __end.index()));
1.2184 + return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __start.index(), __end.index()));
1.2185 }
1.2186 -
1.2187 +
1.2188 _Self substr(iterator __start) const {
1.2189 size_t __pos = __start.index();
1.2190 - return rope<_CharT,_Alloc>(
1.2191 - _S_substring(_M_tree_ptr._M_data, __pos, __pos + 1));
1.2192 + return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __pos, __pos + 1));
1.2193 }
1.2194 -
1.2195 +
1.2196 _Self substr(const_iterator __start, const_iterator __end) const {
1.2197 // This might eventually take advantage of the cache in the
1.2198 // iterator.
1.2199 - return rope<_CharT,_Alloc>(
1.2200 - _S_substring(_M_tree_ptr._M_data, __start.index(), __end.index()));
1.2201 + return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __start.index(), __end.index()));
1.2202 }
1.2203
1.2204 rope<_CharT,_Alloc> substr(const_iterator __start) {
1.2205 size_t __pos = __start.index();
1.2206 - return rope<_CharT,_Alloc>(
1.2207 - _S_substring(_M_tree_ptr._M_data, __pos, __pos + 1));
1.2208 + return rope<_CharT,_Alloc>(_S_substring(_M_tree_ptr._M_data, __pos, __pos + 1));
1.2209 }
1.2210
1.2211 - enum { npos = -1 };
1.2212 +#include <stl/_string_npos.h>
1.2213
1.2214 - // static const size_type npos;
1.2215 + size_type find(const _Self& __s, size_type __pos = 0) const {
1.2216 + if (__pos >= size())
1.2217 +# ifndef _STLP_OLD_ROPE_SEMANTICS
1.2218 + return npos;
1.2219 +# else
1.2220 + return size();
1.2221 +# endif
1.2222
1.2223 + size_type __result_pos;
1.2224 + const_iterator __result = search(const_begin() + (ptrdiff_t)__pos, const_end(), __s.begin(), __s.end() );
1.2225 + __result_pos = __result.index();
1.2226 +# ifndef _STLP_OLD_ROPE_SEMANTICS
1.2227 + if (__result_pos == size()) __result_pos = npos;
1.2228 +# endif
1.2229 + return __result_pos;
1.2230 + }
1.2231 size_type find(_CharT __c, size_type __pos = 0) const;
1.2232 size_type find(const _CharT* __s, size_type __pos = 0) const {
1.2233 size_type __result_pos;
1.2234 const_iterator __result = search(const_begin() + (ptrdiff_t)__pos, const_end(),
1.2235 __s, __s + _S_char_ptr_len(__s));
1.2236 __result_pos = __result.index();
1.2237 -# ifndef _STLP_OLD_ROPE_SEMANTICS
1.2238 +# ifndef _STLP_OLD_ROPE_SEMANTICS
1.2239 if (__result_pos == size()) __result_pos = npos;
1.2240 -# endif
1.2241 +# endif
1.2242 return __result_pos;
1.2243 }
1.2244
1.2245 @@ -2096,13 +1997,13 @@
1.2246 return reference(this, __pos);
1.2247 }
1.2248
1.2249 -# ifdef __STD_STUFF
1.2250 +# ifdef __STD_STUFF
1.2251 reference operator[] (size_type __pos) {
1.2252 return reference(this, __pos);
1.2253 }
1.2254
1.2255 reference at(size_type __pos) {
1.2256 - // if (__pos >= size()) throw out_of_range; // XXX
1.2257 + if (__pos >= size()) _M_throw_out_of_range();
1.2258 return (*this)[__pos];
1.2259 }
1.2260
1.2261 @@ -2116,7 +2017,7 @@
1.2262 // Stuff below this line is dangerous because it's error prone.
1.2263 // I would really like to get rid of it.
1.2264 // copy function with funny arg ordering.
1.2265 - size_type copy(_CharT* __buffer, size_type __n,
1.2266 + size_type copy(_CharT* __buffer, size_type __n,
1.2267 size_type __pos = 0) const {
1.2268 return copy(__pos, __n, __buffer);
1.2269 }
1.2270 @@ -2129,155 +2030,134 @@
1.2271
1.2272 reverse_iterator rbegin() { return mutable_rbegin(); }
1.2273
1.2274 -# else
1.2275 +# else
1.2276
1.2277 const_iterator end() { return const_end(); }
1.2278
1.2279 const_iterator begin() { return const_begin(); }
1.2280
1.2281 const_reverse_iterator rend() { return const_rend(); }
1.2282 -
1.2283 +
1.2284 const_reverse_iterator rbegin() { return const_rbegin(); }
1.2285
1.2286 -# endif
1.2287 +# endif
1.2288 +}; //class rope
1.2289
1.2290 - __ROPE_DEFINE_ALLOCS(_Alloc, _M_tree_ptr)
1.2291 - };
1.2292 -
1.2293 -# undef __ROPE_DEFINE_ALLOC
1.2294 -# undef __ROPE_DEFINE_ALLOCS
1.2295 +#if !defined (_STLP_STATIC_CONST_INIT_BUG)
1.2296 +# if defined (__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 96)
1.2297 +template <class _CharT, class _Alloc>
1.2298 +const size_t rope<_CharT, _Alloc>::npos = ~(size_t) 0;
1.2299 +# endif
1.2300 +#endif
1.2301
1.2302 template <class _CharT, class _Alloc>
1.2303 -inline _CharT
1.2304 +inline _CharT
1.2305 _Rope_const_iterator< _CharT, _Alloc>::operator[](size_t __n)
1.2306 -{
1.2307 - return rope<_CharT,_Alloc>::_S_fetch(this->_M_root, this->_M_current_pos + __n);
1.2308 -}
1.2309 +{ return rope<_CharT,_Alloc>::_S_fetch(this->_M_root, this->_M_current_pos + __n); }
1.2310
1.2311 template <class _CharT, class _Alloc>
1.2312 inline bool operator== (const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2313 const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2314 - return (__x._M_current_pos == __y._M_current_pos &&
1.2315 + return (__x._M_current_pos == __y._M_current_pos &&
1.2316 __x._M_root == __y._M_root);
1.2317 }
1.2318
1.2319 template <class _CharT, class _Alloc>
1.2320 inline bool operator< (const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2321 - const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2322 - return (__x._M_current_pos < __y._M_current_pos);
1.2323 -}
1.2324 + const _Rope_const_iterator<_CharT,_Alloc>& __y)
1.2325 +{ return (__x._M_current_pos < __y._M_current_pos); }
1.2326
1.2327 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
1.2328
1.2329 template <class _CharT, class _Alloc>
1.2330 inline bool operator!= (const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2331 - const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2332 - return !(__x == __y);
1.2333 -}
1.2334 + const _Rope_const_iterator<_CharT,_Alloc>& __y)
1.2335 +{ return !(__x == __y); }
1.2336
1.2337 template <class _CharT, class _Alloc>
1.2338 inline bool operator> (const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2339 - const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2340 - return __y < __x;
1.2341 -}
1.2342 + const _Rope_const_iterator<_CharT,_Alloc>& __y)
1.2343 +{ return __y < __x; }
1.2344
1.2345 template <class _CharT, class _Alloc>
1.2346 inline bool operator<= (const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2347 - const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2348 - return !(__y < __x);
1.2349 -}
1.2350 + const _Rope_const_iterator<_CharT,_Alloc>& __y)
1.2351 +{ return !(__y < __x); }
1.2352
1.2353 template <class _CharT, class _Alloc>
1.2354 inline bool operator>= (const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2355 - const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2356 - return !(__x < __y);
1.2357 -}
1.2358 + const _Rope_const_iterator<_CharT,_Alloc>& __y)
1.2359 +{ return !(__x < __y); }
1.2360
1.2361 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
1.2362
1.2363 template <class _CharT, class _Alloc>
1.2364 inline ptrdiff_t operator-(const _Rope_const_iterator<_CharT,_Alloc>& __x,
1.2365 - const _Rope_const_iterator<_CharT,_Alloc>& __y) {
1.2366 - return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos;
1.2367 -}
1.2368 + const _Rope_const_iterator<_CharT,_Alloc>& __y)
1.2369 +{ return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; }
1.2370
1.2371 -#if !defined( __MWERKS__ ) || __MWERKS__ >= 0x2000 // dwa 8/21/97 - "ambiguous access to overloaded function" bug.
1.2372 +#if !defined( __MWERKS__ ) || __MWERKS__ >= 0x2000 // dwa 8/21/97 - "ambiguous access to overloaded function" bug.
1.2373 template <class _CharT, class _Alloc>
1.2374 inline _Rope_const_iterator<_CharT,_Alloc>
1.2375 -operator-(const _Rope_const_iterator<_CharT,_Alloc>& __x, ptrdiff_t __n) {
1.2376 - return _Rope_const_iterator<_CharT,_Alloc>(
1.2377 - __x._M_root, __x._M_current_pos - __n);
1.2378 -}
1.2379 +operator-(const _Rope_const_iterator<_CharT,_Alloc>& __x, ptrdiff_t __n)
1.2380 +{ return _Rope_const_iterator<_CharT,_Alloc>(__x._M_root, __x._M_current_pos - __n); }
1.2381 # endif
1.2382
1.2383 template <class _CharT, class _Alloc>
1.2384 inline _Rope_const_iterator<_CharT,_Alloc>
1.2385 -operator+(const _Rope_const_iterator<_CharT,_Alloc>& __x, ptrdiff_t __n) {
1.2386 - return _Rope_const_iterator<_CharT,_Alloc>(
1.2387 - __x._M_root, __x._M_current_pos + __n);
1.2388 -}
1.2389 +operator+(const _Rope_const_iterator<_CharT,_Alloc>& __x, ptrdiff_t __n)
1.2390 +{ return _Rope_const_iterator<_CharT,_Alloc>(__x._M_root, __x._M_current_pos + __n); }
1.2391
1.2392 template <class _CharT, class _Alloc>
1.2393 inline _Rope_const_iterator<_CharT,_Alloc>
1.2394 -operator+(ptrdiff_t __n, const _Rope_const_iterator<_CharT,_Alloc>& __x) {
1.2395 - return _Rope_const_iterator<_CharT,_Alloc>(
1.2396 - __x._M_root, __x._M_current_pos + __n);
1.2397 -}
1.2398 +operator+(ptrdiff_t __n, const _Rope_const_iterator<_CharT,_Alloc>& __x)
1.2399 +{ return _Rope_const_iterator<_CharT,_Alloc>(__x._M_root, __x._M_current_pos + __n); }
1.2400
1.2401 template <class _CharT, class _Alloc>
1.2402 inline bool operator== (const _Rope_iterator<_CharT,_Alloc>& __x,
1.2403 const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2404 - return (__x._M_current_pos == __y._M_current_pos &&
1.2405 + return (__x._M_current_pos == __y._M_current_pos &&
1.2406 __x._M_root_rope == __y._M_root_rope);
1.2407 }
1.2408
1.2409 template <class _CharT, class _Alloc>
1.2410 inline bool operator< (const _Rope_iterator<_CharT,_Alloc>& __x,
1.2411 - const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2412 - return (__x._M_current_pos < __y._M_current_pos);
1.2413 -}
1.2414 + const _Rope_iterator<_CharT,_Alloc>& __y)
1.2415 +{ return (__x._M_current_pos < __y._M_current_pos); }
1.2416
1.2417 -#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
1.2418 -
1.2419 +#if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
1.2420 template <class _CharT, class _Alloc>
1.2421 inline bool operator!= (const _Rope_iterator<_CharT,_Alloc>& __x,
1.2422 - const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2423 - return !(__x == __y);
1.2424 -}
1.2425 + const _Rope_iterator<_CharT,_Alloc>& __y)
1.2426 +{ return !(__x == __y); }
1.2427
1.2428 template <class _CharT, class _Alloc>
1.2429 inline bool operator> (const _Rope_iterator<_CharT,_Alloc>& __x,
1.2430 - const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2431 - return __y < __x;
1.2432 -}
1.2433 + const _Rope_iterator<_CharT,_Alloc>& __y)
1.2434 +{ return __y < __x; }
1.2435
1.2436 template <class _CharT, class _Alloc>
1.2437 inline bool operator<= (const _Rope_iterator<_CharT,_Alloc>& __x,
1.2438 - const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2439 - return !(__y < __x);
1.2440 -}
1.2441 + const _Rope_iterator<_CharT,_Alloc>& __y)
1.2442 +{ return !(__y < __x); }
1.2443
1.2444 template <class _CharT, class _Alloc>
1.2445 inline bool operator>= (const _Rope_iterator<_CharT,_Alloc>& __x,
1.2446 - const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2447 - return !(__x < __y);
1.2448 -}
1.2449 -
1.2450 + const _Rope_iterator<_CharT,_Alloc>& __y)
1.2451 +{ return !(__x < __y); }
1.2452 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
1.2453
1.2454 template <class _CharT, class _Alloc>
1.2455 inline ptrdiff_t operator-(const _Rope_iterator<_CharT,_Alloc>& __x,
1.2456 - const _Rope_iterator<_CharT,_Alloc>& __y) {
1.2457 - return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos;
1.2458 -}
1.2459 + const _Rope_iterator<_CharT,_Alloc>& __y)
1.2460 +{ return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; }
1.2461
1.2462 -#if !defined( __MWERKS__ ) || __MWERKS__ >= 0x2000 // dwa 8/21/97 - "ambiguous access to overloaded function" bug.
1.2463 +#if !defined( __MWERKS__ ) || __MWERKS__ >= 0x2000 // dwa 8/21/97 - "ambiguous access to overloaded function" bug.
1.2464 template <class _CharT, class _Alloc>
1.2465 inline _Rope_iterator<_CharT,_Alloc>
1.2466 operator-(const _Rope_iterator<_CharT,_Alloc>& __x,
1.2467 ptrdiff_t __n) {
1.2468 - return _Rope_iterator<_CharT,_Alloc>(
1.2469 - __x._M_root_rope, __x._M_current_pos - __n);
1.2470 + return _Rope_iterator<_CharT,_Alloc>(__x._M_root_rope, __x._M_current_pos - __n);
1.2471 }
1.2472 # endif
1.2473
1.2474 @@ -2285,53 +2165,42 @@
1.2475 inline _Rope_iterator<_CharT,_Alloc>
1.2476 operator+(const _Rope_iterator<_CharT,_Alloc>& __x,
1.2477 ptrdiff_t __n) {
1.2478 - return _Rope_iterator<_CharT,_Alloc>(
1.2479 - __x._M_root_rope, __x._M_current_pos + __n);
1.2480 + return _Rope_iterator<_CharT,_Alloc>(__x._M_root_rope, __x._M_current_pos + __n);
1.2481 }
1.2482
1.2483 template <class _CharT, class _Alloc>
1.2484 inline _Rope_iterator<_CharT,_Alloc>
1.2485 operator+(ptrdiff_t __n, const _Rope_iterator<_CharT,_Alloc>& __x) {
1.2486 - return _Rope_iterator<_CharT,_Alloc>(
1.2487 - __x._M_root_rope, __x._M_current_pos + __n);
1.2488 + return _Rope_iterator<_CharT,_Alloc>(__x._M_root_rope, __x._M_current_pos + __n);
1.2489 }
1.2490
1.2491 template <class _CharT, class _Alloc>
1.2492 -inline
1.2493 -rope<_CharT,_Alloc>
1.2494 +inline rope<_CharT,_Alloc>
1.2495 operator+ (const rope<_CharT,_Alloc>& __left,
1.2496 - const rope<_CharT,_Alloc>& __right)
1.2497 -{
1.2498 + const rope<_CharT,_Alloc>& __right) {
1.2499 _STLP_ASSERT(__left.get_allocator() == __right.get_allocator())
1.2500 return rope<_CharT,_Alloc>(rope<_CharT,_Alloc>::_S_concat_rep(__left._M_tree_ptr._M_data, __right._M_tree_ptr._M_data));
1.2501 - // Inlining this should make it possible to keep __left and
1.2502 - // __right in registers.
1.2503 + // Inlining this should make it possible to keep __left and __right in registers.
1.2504 }
1.2505
1.2506 template <class _CharT, class _Alloc>
1.2507 -inline
1.2508 -rope<_CharT,_Alloc>&
1.2509 -operator+= (rope<_CharT,_Alloc>& __left,
1.2510 - const rope<_CharT,_Alloc>& __right)
1.2511 -{
1.2512 +inline rope<_CharT,_Alloc>&
1.2513 +operator+= (rope<_CharT,_Alloc>& __left,
1.2514 + const rope<_CharT,_Alloc>& __right) {
1.2515 __left.append(__right);
1.2516 return __left;
1.2517 }
1.2518
1.2519 template <class _CharT, class _Alloc>
1.2520 -inline
1.2521 -rope<_CharT,_Alloc>
1.2522 +inline rope<_CharT,_Alloc>
1.2523 operator+ (const rope<_CharT,_Alloc>& __left,
1.2524 const _CharT* __right) {
1.2525 size_t __rlen = rope<_CharT,_Alloc>::_S_char_ptr_len(__right);
1.2526 - return rope<_CharT,_Alloc>(
1.2527 - rope<_CharT,_Alloc>::_S_concat_char_iter(
1.2528 - __left._M_tree_ptr._M_data, __right, __rlen));
1.2529 + return rope<_CharT,_Alloc>(rope<_CharT,_Alloc>::_S_concat_char_iter(__left._M_tree_ptr._M_data, __right, __rlen));
1.2530 }
1.2531
1.2532 template <class _CharT, class _Alloc>
1.2533 -inline
1.2534 -rope<_CharT,_Alloc>&
1.2535 +inline rope<_CharT,_Alloc>&
1.2536 operator+= (rope<_CharT,_Alloc>& __left,
1.2537 const _CharT* __right) {
1.2538 __left.append(__right);
1.2539 @@ -2339,32 +2208,28 @@
1.2540 }
1.2541
1.2542 template <class _CharT, class _Alloc>
1.2543 -inline
1.2544 -rope<_CharT,_Alloc>
1.2545 -operator+ (const rope<_CharT,_Alloc>& __left, _STLP_SIMPLE_TYPE(_CharT) __right) {
1.2546 - return rope<_CharT,_Alloc>(
1.2547 - rope<_CharT,_Alloc>::_S_concat_char_iter(
1.2548 - __left._M_tree_ptr._M_data, &__right, 1));
1.2549 +inline rope<_CharT,_Alloc>
1.2550 +operator+ (const rope<_CharT,_Alloc>& __left, _CharT __right) {
1.2551 + return rope<_CharT,_Alloc>(rope<_CharT,_Alloc>::_S_concat_char_iter(__left._M_tree_ptr._M_data, &__right, 1));
1.2552 }
1.2553
1.2554 template <class _CharT, class _Alloc>
1.2555 -inline
1.2556 -rope<_CharT,_Alloc>&
1.2557 -operator+= (rope<_CharT,_Alloc>& __left, _STLP_SIMPLE_TYPE(_CharT) __right) {
1.2558 +inline rope<_CharT,_Alloc>&
1.2559 +operator+= (rope<_CharT,_Alloc>& __left, _CharT __right) {
1.2560 __left.append(__right);
1.2561 return __left;
1.2562 }
1.2563
1.2564 template <class _CharT, class _Alloc>
1.2565 inline bool
1.2566 -operator< (const rope<_CharT,_Alloc>& __left,
1.2567 +operator< (const rope<_CharT,_Alloc>& __left,
1.2568 const rope<_CharT,_Alloc>& __right) {
1.2569 return __left.compare(__right) < 0;
1.2570 }
1.2571 -
1.2572 +
1.2573 template <class _CharT, class _Alloc>
1.2574 inline bool
1.2575 -operator== (const rope<_CharT,_Alloc>& __left,
1.2576 +operator== (const rope<_CharT,_Alloc>& __left,
1.2577 const rope<_CharT,_Alloc>& __right) {
1.2578 return __left.compare(__right) == 0;
1.2579 }
1.2580 @@ -2409,43 +2274,33 @@
1.2581 return (__x._M_pos == __y._M_pos && __x._M_root == __y._M_root);
1.2582 }
1.2583
1.2584 -#ifdef _STLP_USE_NEW_IOSTREAMS
1.2585 +#if !defined (_STLP_USE_NO_IOSTREAMS)
1.2586 template<class _CharT, class _Traits, class _Alloc>
1.2587 -basic_ostream<_CharT, _Traits>& operator<< (
1.2588 - basic_ostream<_CharT, _Traits>& __o,
1.2589 +basic_ostream<_CharT, _Traits>& operator<< (basic_ostream<_CharT, _Traits>& __o,
1.2590 const rope<_CharT, _Alloc>& __r);
1.2591 -#elif ! defined (_STLP_USE_NO_IOSTREAMS)
1.2592 -template<class _CharT, class _Alloc>
1.2593 -ostream& operator<< (ostream& __o, const rope<_CharT,_Alloc>& __r);
1.2594 #endif
1.2595 -
1.2596 +
1.2597 typedef rope<char, _STLP_DEFAULT_ALLOCATOR(char) > crope;
1.2598 -# ifdef _STLP_HAS_WCHAR_T
1.2599 +#if defined (_STLP_HAS_WCHAR_T)
1.2600 typedef rope<wchar_t, _STLP_DEFAULT_ALLOCATOR(wchar_t) > wrope;
1.2601 -# endif
1.2602 +#endif
1.2603
1.2604 inline crope::reference __mutable_reference_at(crope& __c, size_t __i)
1.2605 -{
1.2606 - return __c.mutable_reference_at(__i);
1.2607 -}
1.2608 +{ return __c.mutable_reference_at(__i); }
1.2609
1.2610 -# ifdef _STLP_HAS_WCHAR_T
1.2611 +#if defined (_STLP_HAS_WCHAR_T)
1.2612 inline wrope::reference __mutable_reference_at(wrope& __c, size_t __i)
1.2613 -{
1.2614 - return __c.mutable_reference_at(__i);
1.2615 -}
1.2616 -# endif
1.2617 +{ return __c.mutable_reference_at(__i); }
1.2618 +#endif
1.2619
1.2620 -#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
1.2621 -
1.2622 +#if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
1.2623 template <class _CharT, class _Alloc>
1.2624 -inline void swap(rope<_CharT,_Alloc>& __x, rope<_CharT,_Alloc>& __y) {
1.2625 - __x.swap(__y);
1.2626 -}
1.2627 +inline void swap(rope<_CharT,_Alloc>& __x, rope<_CharT,_Alloc>& __y)
1.2628 +{ __x.swap(__y); }
1.2629 #else
1.2630
1.2631 inline void swap(crope& __x, crope& __y) { __x.swap(__y); }
1.2632 -# ifdef _STLP_HAS_WCHAR_T // dwa 8/21/97
1.2633 +# ifdef _STLP_HAS_WCHAR_T // dwa 8/21/97
1.2634 inline void swap(wrope& __x, wrope& __y) { __x.swap(__y); }
1.2635 # endif
1.2636
1.2637 @@ -2453,10 +2308,8 @@
1.2638
1.2639
1.2640 // Hash functions should probably be revisited later:
1.2641 -_STLP_TEMPLATE_NULL struct hash<crope>
1.2642 -{
1.2643 - size_t operator()(const crope& __str) const
1.2644 - {
1.2645 +_STLP_TEMPLATE_NULL struct hash<crope> {
1.2646 + size_t operator()(const crope& __str) const {
1.2647 size_t _p_size = __str.size();
1.2648
1.2649 if (0 == _p_size) return 0;
1.2650 @@ -2464,11 +2317,9 @@
1.2651 }
1.2652 };
1.2653
1.2654 -# ifdef _STLP_HAS_WCHAR_T // dwa 8/21/97
1.2655 -_STLP_TEMPLATE_NULL struct hash<wrope>
1.2656 -{
1.2657 - size_t operator()(const wrope& __str) const
1.2658 - {
1.2659 +#if defined (_STLP_HAS_WCHAR_T) // dwa 8/21/97
1.2660 +_STLP_TEMPLATE_NULL struct hash<wrope> {
1.2661 + size_t operator()(const wrope& __str) const {
1.2662 size_t _p_size = __str.size();
1.2663
1.2664 if (0 == _p_size) return 0;
1.2665 @@ -2477,41 +2328,47 @@
1.2666 };
1.2667 #endif
1.2668
1.2669 -#ifndef _STLP_MSVC
1.2670 +#if (!defined (_STLP_MSVC) || (_STLP_MSVC >= 1310))
1.2671 // I couldn't get this to work with VC++
1.2672 template<class _CharT,class _Alloc>
1.2673 -void
1.2674 -_Rope_rotate(_Rope_iterator<_CharT,_Alloc> __first,
1.2675 - _Rope_iterator<_CharT,_Alloc> __middle,
1.2676 - _Rope_iterator<_CharT,_Alloc> __last);
1.2677 +# if defined (__DMC__) && !defined (__PUT_STATIC_DATA_MEMBERS_HERE)
1.2678 +extern
1.2679 +# endif
1.2680 +void _Rope_rotate(_Rope_iterator<_CharT, _Alloc> __first,
1.2681 + _Rope_iterator<_CharT, _Alloc> __middle,
1.2682 + _Rope_iterator<_CharT, _Alloc> __last);
1.2683
1.2684 -#if !defined(__GNUC__)
1.2685 -// Appears to confuse g++
1.2686 -inline void rotate(_Rope_iterator<char,_STLP_DEFAULT_ALLOCATOR(char) > __first,
1.2687 - _Rope_iterator<char,_STLP_DEFAULT_ALLOCATOR(char) > __middle,
1.2688 - _Rope_iterator<char,_STLP_DEFAULT_ALLOCATOR(char) > __last) {
1.2689 - _Rope_rotate(__first, __middle, __last);
1.2690 -}
1.2691 -#endif
1.2692 -
1.2693 +inline void rotate(_Rope_iterator<char, _STLP_DEFAULT_ALLOCATOR(char) > __first,
1.2694 + _Rope_iterator<char, _STLP_DEFAULT_ALLOCATOR(char) > __middle,
1.2695 + _Rope_iterator<char, _STLP_DEFAULT_ALLOCATOR(char) > __last)
1.2696 +{ _Rope_rotate(__first, __middle, __last); }
1.2697 #endif
1.2698
1.2699 template <class _CharT, class _Alloc>
1.2700 -inline _Rope_char_ref_proxy<_CharT, _Alloc>::operator _CharT () const
1.2701 -{
1.2702 +inline _Rope_char_ref_proxy<_CharT, _Alloc>::operator _CharT () const {
1.2703 if (_M_current_valid) {
1.2704 - return _M_current;
1.2705 + return _M_current;
1.2706 } else {
1.2707 return _My_rope::_S_fetch(_M_root->_M_tree_ptr._M_data, _M_pos);
1.2708 }
1.2709 }
1.2710 +
1.2711 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
1.2712 +template <class _CharT, class _Alloc>
1.2713 +struct __move_traits<rope<_CharT, _Alloc> > {
1.2714 + typedef __stlp_movable implemented;
1.2715 + //Completness depends on the allocator:
1.2716 + typedef typename __move_traits<_Alloc>::complete complete;
1.2717 +};
1.2718 +#endif
1.2719 +
1.2720 _STLP_END_NAMESPACE
1.2721
1.2722 -# if !defined (_STLP_LINK_TIME_INSTANTIATION)
1.2723 +#if !defined (_STLP_LINK_TIME_INSTANTIATION)
1.2724 # include <stl/_rope.c>
1.2725 -# endif
1.2726 +#endif
1.2727
1.2728 -# endif /* _STLP_INTERNAL_ROPE_H */
1.2729 +#endif /* _STLP_INTERNAL_ROPE_H */
1.2730
1.2731 // Local Variables:
1.2732 // mode:C++