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