📄 _string.h
字号:
/*
* Copyright (c) 1997-1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
#ifndef _STLP_DBG_STRING_H
#define _STLP_DBG_STRING_H
#ifndef _STLP_DBG_ITERATOR_H
# include <stl/debug/_iterator.h>
#endif
_STLP_BEGIN_NAMESPACE
#define _STLP_NON_DBG_STRING_NAME _STLP_NON_DBG_NAME(str)
#define _STLP_NON_DBG_STRING _STLP_PRIV _STLP_NON_DBG_STRING_NAME <_CharT, _Traits, _Alloc>
#if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
template <class _CharT,class _Traits, class _Alloc>
inline _CharT*
value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_STRING >&)
{ return (_CharT*)0; }
template <class _CharT, class _Traits, class _Alloc>
inline random_access_iterator_tag
iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_STRING >&)
{ return random_access_iterator_tag(); }
#endif
template <class _CharT, class _Traits, class _Alloc>
class basic_string :
#if !defined (__DMC__)
private
#else
public
#endif
_STLP_PRIV __construct_checker<_STLP_NON_DBG_STRING >
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (basic_string)
, public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
#endif
{
protected:
typedef _STLP_NON_DBG_STRING _Base;
typedef basic_string<_CharT, _Traits, _Alloc> _Self;
typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_STRING > _ConstructCheck;
typedef typename _IsPOD<_CharT>::_Type _Char_Is_POD;
public:
__IMPORT_CONTAINER_TYPEDEFS(_Base)
typedef typename _Base::traits_type traits_type;
typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Nonconst_traits<value_type> > > iterator;
typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Const_traits<value_type> > > const_iterator;
_STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
public: // Constructor, destructor, assignment.
typedef typename _Base::_Reserve_t _Reserve_t;
private:
_Base _M_non_dbg_impl;
_STLP_PRIV __owned_list _M_iter_list;
void _Invalidate_all()
{ _M_iter_list._Invalidate_all(); }
void _Compare_Capacity (size_type __old_capacity) {
if (this->capacity() > __old_capacity) {
_Invalidate_all();
}
}
void _Invalidate_iterator(const iterator& __it)
{ _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
void _Invalidate_iterators(const iterator& __f, const iterator& __l)
{ _STLP_PRIV __invalidate_range(&_M_iter_list, __f, __l); }
public:
#include <stl/_string_npos.h>
allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
explicit basic_string(const allocator_type& __a = allocator_type())
: _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
basic_string(_Reserve_t __r, size_t __n,
const allocator_type& __a = allocator_type())
: _M_non_dbg_impl(__r, __n, __a), _M_iter_list(&_M_non_dbg_impl) {}
basic_string(const _Self& __s)
: _ConstructCheck(__s),
_M_non_dbg_impl(__s._M_non_dbg_impl), _M_iter_list(&_M_non_dbg_impl) {}
basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
const allocator_type& __a = allocator_type())
: _M_non_dbg_impl(__s._M_non_dbg_impl, __pos, __n, __a),
_M_iter_list(&_M_non_dbg_impl) {}
basic_string(const _CharT* __s, size_type __n,
const allocator_type& __a = allocator_type())
: _ConstructCheck(__s), _M_non_dbg_impl(__s, __n, __a),
_M_iter_list(&_M_non_dbg_impl) {}
basic_string(const _CharT* __s,
const allocator_type& __a = allocator_type())
: _ConstructCheck(__s),
_M_non_dbg_impl(__s, __a), _M_iter_list(&_M_non_dbg_impl) {}
basic_string(size_type __n, _CharT __c,
const allocator_type& __a = allocator_type())
: _M_non_dbg_impl(__n, __c, __a), _M_iter_list(&_M_non_dbg_impl) {}
basic_string(__move_source<_Self> src)
: _M_non_dbg_impl(__move_source<_Base >(src.get()._M_non_dbg_impl)),
_M_iter_list(&_M_non_dbg_impl) {
#if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
src.get()._M_iter_list._Invalidate_all();
#else
src.get()._M_iter_list._Set_owner(_M_iter_list);
#endif
}
#if !defined (_STLP_MEMBER_TEMPLATES) || defined(__MRC__) || defined(__SC__)
basic_string(const _CharT* __f, const _CharT* __l,
const allocator_type& __a = allocator_type())
: _ConstructCheck(__f, __l),
_M_non_dbg_impl(__f, __l, __a), _M_iter_list(&_M_non_dbg_impl) {
}
basic_string(const_iterator __f, const_iterator __l,
const allocator_type & __a = allocator_type())
: _ConstructCheck(__f, __l),
_M_non_dbg_impl(__f._M_iterator, __l._M_iterator, __a), _M_iter_list(&_M_non_dbg_impl) {
}
#else
template <class _InputIterator>
basic_string(_InputIterator __f, _InputIterator __l,
const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
: _ConstructCheck(__f, __l),
_M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l), __a),
_M_iter_list(&_M_non_dbg_impl) {}
# if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
template <class _InputIterator>
basic_string(_InputIterator __f, _InputIterator __l)
: _ConstructCheck(__f, __l),
_M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__f), _STLP_PRIV _Non_Dbg_iter(__l)),
_M_iter_list(&_M_non_dbg_impl) {}
# endif
#endif
private:
// constructor from non-debug version for substr
basic_string (const _Base& __x)
: _M_non_dbg_impl(__x), _M_iter_list(&_M_non_dbg_impl) {}
public:
_Self& operator=(const _Self& __s) {
if (this != &__s) {
assign(__s);
}
return *this;
}
_Self& operator=(const _CharT* __s) {
_STLP_FIX_LITERAL_BUG(__s)
_STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
return assign(__s);
}
_Self& operator=(_CharT __c) {
return assign(1, __c);
}
// Iterators.
iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
// Size, capacity, etc.
size_type size() const { return _M_non_dbg_impl.size(); }
size_type length() const { return _M_non_dbg_impl.length(); }
size_t max_size() const { return _M_non_dbg_impl.max_size(); }
void resize(size_type __n, _CharT __c) {
if (__n > capacity())
_Invalidate_all();
else if (__n < size())
_Invalidate_iterators(begin() + __n, end());
_M_non_dbg_impl.resize(__n, __c);
}
void resize(size_type __n) { resize(__n, _STLP_DEFAULT_CONSTRUCTED(_CharT)); }
size_type capacity() const { return _M_non_dbg_impl.capacity(); }
void reserve(size_type __s = 0) {
if (__s > capacity()) _Invalidate_all();
_M_non_dbg_impl.reserve(__s);
}
void clear() {
_Invalidate_all();
_M_non_dbg_impl.clear();
}
bool empty() const { return _M_non_dbg_impl.empty(); }
const_reference operator[](size_type __n) const {
_STLP_VERBOSE_ASSERT(__n <= this->size(), _StlMsg_OUT_OF_BOUNDS);
return _M_non_dbg_impl[__n];
}
reference operator[](size_type __n) {
_STLP_VERBOSE_ASSERT(__n < this->size(), _StlMsg_OUT_OF_BOUNDS)
return _M_non_dbg_impl[__n];
}
const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
// Append, operator+=, push_back.
_Self& operator+=(const _Self& __s) { return append(__s); }
_Self& operator+=(const _CharT* __s) {
_STLP_FIX_LITERAL_BUG(__s)
_STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
return append(__s);
}
_Self& operator+=(_CharT __c) { return append(1, __c); }
#if defined (_STLP_MEMBER_TEMPLATES)
template <class _InputIter>
_Self& append(_InputIter __first, _InputIter __last) {
_STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
size_type __old_capacity = capacity();
_M_non_dbg_impl.append(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
_Compare_Capacity(__old_capacity);
return *this;
}
#endif
#if !defined (_STLP_MEMBER_TEMPLATES) || \
!defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
_Self& append(const _CharT* __f, const _CharT* __l) {
_STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
_STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__f, __l))
size_type __old_capacity = capacity();
_M_non_dbg_impl.append(__f, __l);
_Compare_Capacity(__old_capacity);
return *this;
}
_Self& append(const_iterator __f, const_iterator __l) {
_STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__f, __l))
size_type __old_capacity = capacity();
_M_non_dbg_impl.append(__f._M_iterator, __l._M_iterator);
_Compare_Capacity(__old_capacity);
return *this;
}
#endif
_Self& append(const _Self& __s) {
size_type __old_capacity = capacity();
_M_non_dbg_impl.append(__s._M_non_dbg_impl);
_Compare_Capacity(__old_capacity);
return *this;
}
_Self& append(const _Self& __s, size_type __pos, size_type __n) {
size_type __old_capacity = capacity();
_M_non_dbg_impl.append(__s._M_non_dbg_impl, __pos, __n);
_Compare_Capacity(__old_capacity);
return *this;
}
_Self& append(const _CharT* __s, size_type __n) {
_STLP_FIX_LITERAL_BUG(__s)
_STLP_VERBOSE_ASSERT((__s != 0), _StlMsg_INVALID_ARGUMENT)
size_type __old_capacity = capacity();
_M_non_dbg_impl.append(__s, __n);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -