// SGI's rope class -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
/*
* Copyright (c) 1997
#ifndef _ROPE
#define _ROPE 1
-#include <bits/stl_algobase.h>
+#include <algorithm>
+#include <iosfwd>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
-#include <bits/stl_algo.h>
#include <bits/stl_function.h>
#include <bits/stl_numeric.h>
#include <bits/allocator.h>
-#include <ext/hash_fun.h>
+#include <bits/gthr.h>
+#include <tr1/functional>
# ifdef __GC
# define __GC_CONST const
# else
-# include <bits/gthr.h>
# define __GC_CONST // constant except for deallocation
# endif
#include <ext/memory> // For uninitialized_copy_n
-namespace __gnu_cxx
-{
+_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
+
+ namespace __detail
+ {
+ enum { _S_max_rope_depth = 45 };
+ enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
+ } // namespace __detail
+
using std::size_t;
using std::ptrdiff_t;
using std::allocator;
- using std::iterator;
- using std::reverse_iterator;
using std::_Destroy;
+ // See libstdc++/36832.
+ template<typename _ForwardIterator, typename _Allocator>
+ void
+ _Destroy_const(_ForwardIterator __first,
+ _ForwardIterator __last, _Allocator __alloc)
+ {
+ for (; __first != __last; ++__first)
+ __alloc.destroy(&*__first);
+ }
+
+ template<typename _ForwardIterator, typename _Tp>
+ inline void
+ _Destroy_const(_ForwardIterator __first,
+ _ForwardIterator __last, allocator<_Tp>)
+ { _Destroy(__first, __last); }
+
// The _S_eos function is used for those functions that
// convert to/from C-like strings to detect the end of the string.
{ __c = 0; }
// char_producers are logically functions that generate a section of
- // a string. These can be convereted to ropes. The resulting rope
+ // a string. These can be converted to ropes. The resulting rope
// invokes the char_producer on demand. This allows, for example,
// files to be viewed as ropes without reading the entire file.
template <class _CharT>
class char_producer
{
public:
- virtual ~char_producer() {};
+ virtual ~char_producer() { };
virtual void
operator()(size_t __start_pos, size_t __len,
template<class _Sequence, size_t _Buf_sz = 100>
class sequence_buffer
- : public iterator<std::output_iterator_tag, void, void, void, void>
+ : public std::iterator<std::output_iterator_tag, void, void, void, void>
{
public:
typedef typename _Sequence::value_type value_type;
// compile-time would do. Hence this should all be private
// for now.
// The symmetry with char_producer is accidental and temporary.
- virtual ~_Rope_char_consumer() {};
+ virtual ~_Rope_char_consumer() { };
virtual bool
operator()(const _CharT* __buffer, size_t __len) = 0;
get_allocator() const
{ return *static_cast<const _Alloc*>(this); }
+ allocator_type&
+ _M_get_allocator()
+ { return *static_cast<_Alloc*>(this); }
+
+ const allocator_type&
+ _M_get_allocator() const
+ { return *static_cast<const _Alloc*>(this); }
+
_Rope_rep_base(size_t __size, const allocator_type&)
- : _M_size(__size) {}
+ : _M_size(__size) { }
size_t _M_size;
# undef __ROPE_DEFINE_ALLOC
};
- namespace _Rope_constants
- {
- enum { _S_max_rope_depth = 45 };
- enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
- }
-
template<class _CharT, class _Alloc>
struct _Rope_RopeRep
: public _Rope_rep_base<_CharT, _Alloc>
# endif
{
public:
- _Rope_constants::_Tag _M_tag:8;
+ __detail::_Tag _M_tag:8;
bool _M_is_balanced:8;
unsigned char _M_depth;
__GC_CONST _CharT* _M_c_string;
allocator_type;
using _Rope_rep_base<_CharT, _Alloc>::get_allocator;
+ using _Rope_rep_base<_CharT, _Alloc>::_M_get_allocator;
- _Rope_RopeRep(_Rope_constants::_Tag __t, int __d, bool __b, size_t __size,
- allocator_type __a)
+ _Rope_RopeRep(__detail::_Tag __t, int __d, bool __b, size_t __size,
+ const allocator_type& __a)
: _Rope_rep_base<_CharT, _Alloc>(__size, __a),
#ifndef __GC
_Refcount_Base(1),
#endif
#ifdef __GC
void
- _M_incr () {}
+ _M_incr () { }
#endif
static void
_S_free_string(__GC_CONST _CharT*, size_t __len,
- allocator_type __a);
+ allocator_type& __a);
#define __STL_FREE_STRING(__s, __l, __a) _S_free_string(__s, __l, __a);
// Deallocate data section of a leaf.
// This shouldn't be a member function.
__t->_M_free_tree();
}
# else /* __GC */
- void _M_unref_nonnil() {}
- void _M_ref_nonnil() {}
- static void _S_unref(_Rope_RopeRep*) {}
- static void _S_ref(_Rope_RopeRep*) {}
- static void _S_free_if_unref(_Rope_RopeRep*) {}
+ void _M_unref_nonnil() { }
+ void _M_ref_nonnil() { }
+ static void _S_unref(_Rope_RopeRep*) { }
+ static void _S_ref(_Rope_RopeRep*) { }
+ static void _S_free_if_unref(_Rope_RopeRep*) { }
# endif
protected:
_Rope_RopeRep&
return __size_with_eos;
#else
// Allow slop for in-place expansion.
- return ((__size_with_eos + _S_alloc_granularity - 1)
- &~ (_S_alloc_granularity - 1));
+ return ((__size_with_eos + size_t(_S_alloc_granularity) - 1)
+ &~ (size_t(_S_alloc_granularity) - 1));
#endif
}
__GC_CONST _CharT* _M_data; /* Not necessarily 0 terminated. */
allocator_type;
_Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size,
- allocator_type __a)
- : _Rope_RopeRep<_CharT, _Alloc>(_Rope_constants::_S_leaf, 0, true,
+ const allocator_type& __a)
+ : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_leaf, 0, true,
__size, __a), _M_data(__d)
{
if (_S_is_basic_char_type((_CharT *)0))
if (_M_data != this->_M_c_string)
this->_M_free_c_string();
- __STL_FREE_STRING(_M_data, this->_M_size, this->get_allocator());
+ __STL_FREE_STRING(_M_data, this->_M_size, this->_M_get_allocator());
}
#endif
protected:
_Rope_RopeConcatenation(_Rope_RopeRep<_CharT, _Alloc>* __l,
_Rope_RopeRep<_CharT, _Alloc>* __r,
- allocator_type __a)
- : _Rope_RopeRep<_CharT, _Alloc>(_Rope_constants::_S_concat,
+ const allocator_type& __a)
+ : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_concat,
std::max(__l->_M_depth,
__r->_M_depth) + 1,
false,
allocator_type;
_Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size,
- bool __d, allocator_type __a)
- : _Rope_RopeRep<_CharT, _Alloc>(_Rope_constants::_S_function,
- 0, true, __size, __a)
+ bool __d, const allocator_type& __a)
+ : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_function, 0, true, __size, __a)
, _M_fn(__f)
#ifndef __GC
, _M_delete_when_done(__d)
{
switch(_M_base->_M_tag)
{
- case _Rope_constants::_S_function:
- case _Rope_constants::_S_substringfn:
+ case __detail::_S_function:
+ case __detail::_S_substringfn:
{
char_producer<_CharT>* __fn =
((_Rope_RopeFunction<_CharT,_Alloc>*)_M_base)->_M_fn;
(*__fn)(__start_pos + _M_start, __req_len, __buffer);
}
break;
- case _Rope_constants::_S_leaf:
+ case __detail::_S_leaf:
{
__GC_CONST _CharT* __s =
((_Rope_RopeLeaf<_CharT,_Alloc>*)_M_base)->_M_data;
allocator_type;
_Rope_RopeSubstring(_Rope_RopeRep<_CharT, _Alloc>* __b, size_t __s,
- size_t __l, allocator_type __a)
+ size_t __l, const allocator_type& __a)
: _Rope_RopeFunction<_CharT, _Alloc>(this, __l, false, __a),
char_producer<_CharT>(), _M_base(__b), _M_start(__s)
{
#ifndef __GC
_M_base->_M_ref_nonnil();
#endif
- this->_M_tag = _Rope_constants::_S_substringfn;
+ this->_M_tag = __detail::_S_substringfn;
}
virtual ~_Rope_RopeSubstring() throw()
{
~_Rope_self_destruct_ptr()
{ _Rope_RopeRep<_CharT, _Alloc>::_S_unref(_M_ptr); }
#ifdef __EXCEPTIONS
- _Rope_self_destruct_ptr() : _M_ptr(0) {};
+ _Rope_self_destruct_ptr() : _M_ptr(0) { };
#else
- _Rope_self_destruct_ptr() {};
+ _Rope_self_destruct_ptr() { };
#endif
_Rope_self_destruct_ptr(_Rope_RopeRep<_CharT, _Alloc>* __p)
- : _M_ptr(__p) {}
+ : _M_ptr(__p) { }
_Rope_RopeRep<_CharT, _Alloc>&
operator*()
_My_rope* _M_root; // The whole rope.
public:
_Rope_char_ref_proxy(_My_rope* __r, size_t __p)
- : _M_pos(__p), _M_current(), _M_current_valid(false), _M_root(__r) {}
+ : _M_pos(__p), _M_current(), _M_current_valid(false), _M_root(__r) { }
_Rope_char_ref_proxy(const _Rope_char_ref_proxy& __x)
- : _M_pos(__x._M_pos), _M_current(__x._M_current), _M_current_valid(false),
- _M_root(__x._M_root) {}
+ : _M_pos(__x._M_pos), _M_current(__x._M_current),
+ _M_current_valid(false), _M_root(__x._M_root) { }
// Don't preserve cache if the reference can outlive the
// expression. We claim that's not possible without calling
// a copy constructor or generating reference to a proxy
// reference. We declare the latter to have undefined semantics.
_Rope_char_ref_proxy(_My_rope* __r, size_t __p, _CharT __c)
- : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
+ : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) { }
inline operator _CharT () const;
rope<_CharT,_Alloc>* _M_root; // The whole rope.
public:
_Rope_char_ptr_proxy(const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
- : _M_pos(__x._M_pos), _M_root(__x._M_root) {}
+ : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
_Rope_char_ptr_proxy(const _Rope_char_ptr_proxy& __x)
- : _M_pos(__x._M_pos), _M_root(__x._M_root) {}
+ : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
- _Rope_char_ptr_proxy() {}
+ _Rope_char_ptr_proxy() { }
_Rope_char_ptr_proxy(_CharT* __x)
: _M_root(0), _M_pos(0) { }
template<class _CharT, class _Alloc>
class _Rope_iterator_base
- : public iterator<std::random_access_iterator_tag, _CharT>
+ : public std::iterator<std::random_access_iterator_tag, _CharT>
{
friend class rope<_CharT, _Alloc>;
public:
static void _S_setcache_for_incr(_Rope_iterator_base& __x);
// As above, but assumes path
// cache is valid for previous posn.
- _Rope_iterator_base() {}
+ _Rope_iterator_base() { }
_Rope_iterator_base(_RopeRep* __root, size_t __pos)
- : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) {}
+ : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) { }
void _M_incr(size_t __n);
void _M_decr(size_t __n);
: _Rope_iterator_base<_CharT, _Alloc>(const_cast<_RopeRep*>(__root),
__pos)
// Only nonconst iterators modify root ref count
- {}
+ { }
public:
typedef _CharT reference; // Really a value. Returning a reference
// Would be a mess, since it would have
typedef const _CharT* pointer;
public:
- _Rope_const_iterator() {};
+ _Rope_const_iterator() { };
_Rope_const_iterator(const _Rope_const_iterator& __x)
: _Rope_iterator_base<_CharT,_Alloc>(__x) { }
_S_setcache(*this);
return *this->_M_buf_ptr;
}
-
+
+ // Without this const version, Rope iterators do not meet the
+ // requirements of an Input Iterator.
+ reference
+ operator*() const
+ {
+ return *const_cast<_Rope_const_iterator&>(*this);
+ }
+
_Rope_const_iterator&
operator++()
{
protected:
typedef typename _Rope_iterator_base<_CharT, _Alloc>::_RopeRep _RopeRep;
rope<_CharT, _Alloc>* _M_root_rope;
- // root is treated as a cached version of this,
- // and is used to detect changes to the underlying
- // rope.
- // Root is included in the reference count.
- // This is necessary so that we can detect changes reliably.
- // Unfortunately, it requires careful bookkeeping for the
- // nonGC case.
+
+ // root is treated as a cached version of this, and is used to
+ // detect changes to the underlying rope.
+
+ // Root is included in the reference count. This is necessary
+ // so that we can detect changes reliably. Unfortunately, it
+ // requires careful bookkeeping for the nonGC case.
_Rope_iterator(rope<_CharT, _Alloc>* __r, size_t __pos)
: _Rope_iterator_base<_CharT, _Alloc>(__r->_M_tree_ptr, __pos),
_M_root_rope(__r)
typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
typedef _Rope_char_ref_proxy<_CharT, _Alloc>* pointer;
- public:
rope<_CharT, _Alloc>&
container()
{ return *_M_root_rope; }
*this->_M_buf_ptr);
}
+ // See above comment.
+ reference
+ operator*() const
+ {
+ return *const_cast<_Rope_iterator&>(*this);
+ }
+
_Rope_iterator&
operator++()
{
get_allocator() const
{ return *static_cast<const _Alloc*>(this); }
+ allocator_type&
+ _M_get_allocator()
+ { return *static_cast<_Alloc*>(this); }
+
+ const allocator_type&
+ _M_get_allocator() const
+ { return *static_cast<const _Alloc*>(this); }
+
typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
// The one in _Base may not be visible due to template rules.
_Rope_base(_RopeRep* __t, const allocator_type&)
- : _M_tree_ptr(__t) {}
+ : _M_tree_ptr(__t) { }
- _Rope_base(const allocator_type&) {}
+ _Rope_base(const allocator_type&) { }
// The only data member of a rope:
_RopeRep *_M_tree_ptr;
typedef typename _Base::allocator_type allocator_type;
using _Base::_M_tree_ptr;
using _Base::get_allocator;
+ using _Base::_M_get_allocator;
typedef __GC_CONST _CharT* _Cstrptr;
static _CharT _S_empty_c_str[1];
{ _RopeRep::_S_ref(__t); }
#else /* __GC */
- static void _S_unref(_RopeRep*) {}
- static void _S_ref(_RopeRep*) {}
+ static void _S_unref(_RopeRep*) { }
+ static void _S_ref(_RopeRep*) { }
#endif
#ifdef __GC
// Takes ownership of s instead of copying.
static _RopeLeaf*
_S_new_RopeLeaf(__GC_CONST _CharT *__s,
- size_t __size, allocator_type __a)
+ size_t __size, allocator_type& __a)
{
_RopeLeaf* __space = typename _Base::_LAlloc(__a).allocate(1);
return new(__space) _RopeLeaf(__s, __size, __a);
static _RopeConcatenation*
_S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right,
- allocator_type __a)
+ allocator_type& __a)
{
_RopeConcatenation* __space = typename _Base::_CAlloc(__a).allocate(1);
return new(__space) _RopeConcatenation(__left, __right, __a);
static _RopeFunction*
_S_new_RopeFunction(char_producer<_CharT>* __f,
- size_t __size, bool __d, allocator_type __a)
+ size_t __size, bool __d, allocator_type& __a)
{
_RopeFunction* __space = typename _Base::_FAlloc(__a).allocate(1);
return new(__space) _RopeFunction(__f, __size, __d, __a);
static _RopeSubstring*
_S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
- size_t __l, allocator_type __a)
+ size_t __l, allocator_type& __a)
{
_RopeSubstring* __space = typename _Base::_SAlloc(__a).allocate(1);
return new(__space) _RopeSubstring(__b, __s, __l, __a);
static _RopeLeaf*
_S_RopeLeaf_from_unowned_char_ptr(const _CharT *__s,
- size_t __size, allocator_type __a)
+ size_t __size, allocator_type& __a)
#define __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __size, __a) \
_S_RopeLeaf_from_unowned_char_ptr(__s, __size, __a)
{
__uninitialized_copy_n_a(__s, __size, __buf, __a);
_S_cond_store_eos(__buf[__size]);
- try
+ __try
{ return _S_new_RopeLeaf(__buf, __size, __a); }
- catch(...)
+ __catch(...)
{
_RopeRep::__STL_FREE_STRING(__buf, __size, __a);
__throw_exception_again;
_CharT* __buffer);
static const unsigned long
- _S_min_len[_Rope_constants::_S_max_rope_depth + 1];
+ _S_min_len[__detail::_S_max_rope_depth + 1];
static bool
_S_is_balanced(_RopeRep* __r)
// definition.
static _RopeRep* _S_balance(_RopeRep* __r);
- // Add all unbalanced subtrees to the forest of balanceed trees.
+ // Add all unbalanced subtrees to the forest of balanced trees.
// Used only by balance.
static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest);
{ return _S_compare(this->_M_tree_ptr, __y._M_tree_ptr); }
rope(const _CharT* __s, const allocator_type& __a = allocator_type())
- : _Base(__STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s),
- __a), __a)
- { }
+ : _Base(__a)
+ {
+ this->_M_tree_ptr =
+ __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s),
+ _M_get_allocator());
+ }
rope(const _CharT* __s, size_t __len,
const allocator_type& __a = allocator_type())
- : _Base(__STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, __a), __a)
- { }
+ : _Base(__a)
+ {
+ this->_M_tree_ptr =
+ __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, _M_get_allocator());
+ }
// Should perhaps be templatized with respect to the iterator type
// and use Sequence_buffer. (It should perhaps use sequence_buffer
// even now.)
- rope(const _CharT *__s, const _CharT *__e,
+ rope(const _CharT* __s, const _CharT* __e,
const allocator_type& __a = allocator_type())
- : _Base(__STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, __a), __a)
- { }
+ : _Base(__a)
+ {
+ this->_M_tree_ptr =
+ __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, _M_get_allocator());
+ }
rope(const const_iterator& __s, const const_iterator& __e,
const allocator_type& __a = allocator_type())
{
_CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1));
- get_allocator().construct(__buf, __c);
- try
- { this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1, __a); }
- catch(...)
+ _M_get_allocator().construct(__buf, __c);
+ __try
+ {
+ this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1,
+ _M_get_allocator());
+ }
+ __catch(...)
{
- _RopeRep::__STL_FREE_STRING(__buf, 1, __a);
+ _RopeRep::__STL_FREE_STRING(__buf, 1, _M_get_allocator());
__throw_exception_again;
}
}
const allocator_type& __a = allocator_type());
rope(const allocator_type& __a = allocator_type())
- : _Base(0, __a) {}
+ : _Base(0, __a) { }
- // Construct a rope from a function that can compute its members
+ // Construct a rope from a function that can compute its members
rope(char_producer<_CharT> *__fn, size_t __len, bool __delete_fn,
const allocator_type& __a = allocator_type())
: _Base(__a)
pop_back()
{
_RopeRep* __old = this->_M_tree_ptr;
- this->_M_tree_ptr =
- _S_substring(this->_M_tree_ptr,
- 0, this->_M_tree_ptr->_M_size - 1);
+ this->_M_tree_ptr = _S_substring(this->_M_tree_ptr,
+ 0, this->_M_tree_ptr->_M_size - 1);
_S_unref(__old);
}
{
_RopeRep* __old = this->_M_tree_ptr;
_RopeRep* __left =
- __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, this->get_allocator());
- try
+ __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, _M_get_allocator());
+ __try
{
this->_M_tree_ptr = _S_concat(__left, this->_M_tree_ptr);
_S_unref(__old);
_S_unref(__left);
}
- catch(...)
+ __catch(...)
{
_S_unref(__left);
__throw_exception_again;
this->_M_tree_ptr = _S_balance(this->_M_tree_ptr);
_S_unref(__old);
}
-
+
void
copy(_CharT* __buffer) const
{
- _Destroy(__buffer, __buffer + size(), get_allocator());
+ _Destroy_const(__buffer, __buffer + size(), _M_get_allocator());
_S_flatten(this->_M_tree_ptr, __buffer);
}
{
size_t __size = size();
size_t __len = (__pos + __n > __size? __size - __pos : __n);
-
- _Destroy(__buffer, __buffer + __len, get_allocator());
+
+ _Destroy_const(__buffer, __buffer + __len, _M_get_allocator());
_S_flatten(this->_M_tree_ptr, __pos, __len, __buffer);
return __len;
}
// Embedded 0s in the input do not terminate the copy.
const _CharT* c_str() const;
- // As above, but lso use the flattened representation as the
+ // As above, but also use the flattened representation as
// the new rope representation.
const _CharT* replace_with_c_str();
{
if (0 == this->_M_tree_ptr)
return;
- if (_Rope_constants::_S_leaf == this->_M_tree_ptr->_M_tag &&
+ if (__detail::_S_leaf == this->_M_tree_ptr->_M_tag &&
((_RopeLeaf*)this->_M_tree_ptr)->_M_data ==
this->_M_tree_ptr->_M_c_string)
{
size_type
max_size() const
{
- return _S_min_len[_Rope_constants::_S_max_rope_depth - 1] - 1;
- // Guarantees that the result can be sufficirntly
+ return _S_min_len[int(__detail::_S_max_rope_depth) - 1] - 1;
+ // Guarantees that the result can be sufficiently
// balanced. Longer ropes will probably still work,
// but it's harder to make guarantees.
}
- typedef reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
const_reverse_iterator
rbegin() const
template<class _CharT2, class _Alloc2>
friend rope<_CharT2, _Alloc2>
operator+(const rope<_CharT2, _Alloc2>& __left, _CharT2 __right);
- // The symmetric cases are intentionally omitted, since they're presumed
- // to be less common, and we don't handle them as well.
- // The following should really be templatized.
- // The first argument should be an input iterator or
- // forward iterator with value_type _CharT.
+ // The symmetric cases are intentionally omitted, since they're
+ // presumed to be less common, and we don't handle them as well.
+
+ // The following should really be templatized. The first
+ // argument should be an input iterator or forward iterator with
+ // value_type _CharT.
rope&
append(const _CharT* __iter, size_t __n)
{
_Self_destruct_ptr __appendee(_S_substring(__s._M_root,
__s._M_current_pos,
__e._M_current_pos));
- _RopeRep* __result =
- _S_concat(this->_M_tree_ptr, (_RopeRep*)__appendee);
+ _RopeRep* __result = _S_concat(this->_M_tree_ptr,
+ (_RopeRep*)__appendee);
_S_unref(this->_M_tree_ptr);
this->_M_tree_ptr = __result;
return *this;
mutable_end()
{ return(iterator(this, size())); }
- typedef reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
reverse_iterator
mutable_rbegin()
return (*this)[__pos];
}
- void resize(size_type __n, _CharT __c) {}
- void resize(size_type __n) {}
- void reserve(size_type __res_arg = 0) {}
+ void resize(size_type __n, _CharT __c) { }
+ void resize(size_type __n) { }
+ void reserve(size_type __res_arg = 0) { }
size_type
capacity() const
__x._M_current_pos + __n); }
template <class _CharT, class _Alloc>
- inline _Rope_iterator<_CharT,_Alloc>
+ inline _Rope_iterator<_CharT, _Alloc>
operator+(ptrdiff_t __n, const _Rope_iterator<_CharT, _Alloc>& __x)
{ return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
__x._M_current_pos + __n); }
template <class _CharT, class _Alloc>
- inline rope<_CharT,_Alloc>
+ inline rope<_CharT, _Alloc>
operator+(const rope<_CharT, _Alloc>& __left,
const rope<_CharT, _Alloc>& __right)
{
- return rope<_CharT, _Alloc>(rope<_CharT, _Alloc>::
- _S_concat(__left._M_tree_ptr,
- __right._M_tree_ptr));
// Inlining this should make it possible to keep __left and
// __right in registers.
+ typedef rope<_CharT, _Alloc> rope_type;
+ return rope_type(rope_type::_S_concat(__left._M_tree_ptr,
+ __right._M_tree_ptr));
}
template <class _CharT, class _Alloc>
operator+(const rope<_CharT, _Alloc>& __left,
const _CharT* __right)
{
- size_t __rlen = rope<_CharT,_Alloc>::_S_char_ptr_len(__right);
- return rope<_CharT, _Alloc>(rope<_CharT, _Alloc>::
- _S_concat_char_iter(__left._M_tree_ptr,
+ typedef rope<_CharT, _Alloc> rope_type;
+ size_t __rlen = rope_type::_S_char_ptr_len(__right);
+ return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
__right, __rlen));
}
inline rope<_CharT, _Alloc>
operator+(const rope<_CharT, _Alloc>& __left, _CharT __right)
{
- return rope<_CharT, _Alloc>(rope<_CharT, _Alloc>::
- _S_concat_char_iter(__left._M_tree_ptr,
+ typedef rope<_CharT, _Alloc> rope_type;
+ return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
&__right, 1));
}
swap(rope<_CharT, _Alloc>& __x, rope<_CharT, _Alloc>& __y)
{ __x.swap(__y); }
- // Hash functions should probably be revisited later:
+_GLIBCXX_END_NAMESPACE
+
+
+namespace std
+{
+namespace tr1
+{
template<>
- struct hash<crope>
+ struct hash<__gnu_cxx::crope>
{
size_t
- operator()(const crope& __str) const
+ operator()(const __gnu_cxx::crope& __str) const
{
size_t __size = __str.size();
-
if (0 == __size)
return 0;
return 13 * __str[0] + 5 * __str[__size - 1] + __size;
template<>
- struct hash<wrope>
+ struct hash<__gnu_cxx::wrope>
{
size_t
- operator()(const wrope& __str) const
+ operator()(const __gnu_cxx::wrope& __str) const
{
size_t __size = __str.size();
-
if (0 == __size)
return 0;
return 13 * __str[0] + 5 * __str[__size - 1] + __size;
}
};
-
-} // namespace __gnu_cxx
+} // namespace tr1
+} // namespace std
# include <ext/ropeimpl.h>