_string_workaround.h

来自「symbian 上的stl_port进过编译的。」· C头文件 代码 · 共 734 行 · 第 1/2 页

H
734
字号
/* * Copyright (c) 2004 * Francois Dumont * * 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. * *///Included from _string.h, no need for macro guarding._STLP_BEGIN_NAMESPACE#if defined (_STLP_DEBUG)#  define basic_string _STLP_NON_DBG_NAME(str)_STLP_MOVE_TO_PRIV_NAMESPACE#endif#define _STLP_NO_MEM_T_STRING_BASE _STLP_PRIV _STLP_NO_MEM_T_NAME(str)<_CharT, _Traits, _Alloc>template <class _CharT, class _Traits, class _Alloc>class basic_string : public _STLP_NO_MEM_T_STRING_BASE#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && \    !defined (basic_string)                   , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >#endif{protected:                        // Protected members inherited from base.  typedef basic_string<_CharT, _Traits, _Alloc> _Self;  typedef _STLP_NO_MEM_T_STRING_BASE _Base;  typedef typename _Base::_Char_Is_POD _Char_Is_POD;public:  __IMPORT_WITH_REVERSE_ITERATORS(_Base)  typedef typename _Base::_Iterator_category _Iterator_category;  typedef typename _Base::traits_type traits_type;  typedef typename _Base::_Reserve_t _Reserve_t;public:                         // Constructor, destructor, assignment.  explicit basic_string(const allocator_type& __a = allocator_type())    : _STLP_NO_MEM_T_STRING_BASE(__a) {}  basic_string(_Reserve_t __r, size_t __n,               const allocator_type& __a = allocator_type())    : _STLP_NO_MEM_T_STRING_BASE(__r, __n, __a) {}  basic_string(const _Self& __s)    : _STLP_NO_MEM_T_STRING_BASE(__s) {}  basic_string(const _Self& __s, size_type __pos, size_type __n = npos,               const allocator_type& __a = allocator_type())    : _STLP_NO_MEM_T_STRING_BASE(__s, __pos, __n, __a) {}  basic_string(const _CharT* __s, size_type __n,               const allocator_type& __a = allocator_type())    : _STLP_NO_MEM_T_STRING_BASE(__s, __n, __a) {}  basic_string(const _CharT* __s,               const allocator_type& __a = allocator_type())    : _STLP_NO_MEM_T_STRING_BASE(__s, __a) {}  basic_string(size_type __n, _CharT __c,               const allocator_type& __a = allocator_type())    : _STLP_NO_MEM_T_STRING_BASE(__n, __c, __a) {}  basic_string(__move_source<_Self> src)    : _STLP_NO_MEM_T_STRING_BASE(__move_source<_Base>(src.get())) {}  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.#if !(defined(__MRC__) || (defined(__SC__) && !defined(__DMC__))) //*ty 04/30/2001 - mpw compilers choke on this ctor  template <class _InputIterator>  basic_string(_InputIterator __f, _InputIterator __l,               const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)    : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), __a) {    typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;    _M_initialize_dispatch(__f, __l, _Integral());  }#  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)  template <class _InputIterator>  basic_string(_InputIterator __f, _InputIterator __l)    : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), allocator_type()) {    typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;    _M_initialize_dispatch(__f, __l, _Integral());  }#  endif#endif /* !__MRC__ || (__SC__ && !__DMC__) */  _Self& operator=(const _Self& __s) {    _Base::operator=(__s);    return *this;  }  _Self& operator=(const _CharT* __s) {    _Base::operator=(__s);    return *this;  }  _Self& operator=(_CharT __c) {    _Base::operator=(__c);    return *this;  }private:  template <class _InputIter>  void _M_range_initialize(_InputIter __f, _InputIter __l,                           const input_iterator_tag &__tag) {    this->_M_allocate_block();    this->_M_construct_null(this->_M_Finish());    _STLP_TRY {      _M_appendT(__f, __l, __tag);    }    _STLP_UNWIND(this->_M_destroy_range())  }  template <class _ForwardIter>  void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,                           const forward_iterator_tag &) {    difference_type __n = distance(__f, __l);    this->_M_allocate_block(__n + 1);#if defined (_STLP_USE_SHORT_STRING_OPTIM)    if (this->_M_using_static_buf()) {      _M_copyT(__f, __l, this->_M_Start());      this->_M_finish = this->_M_Start() + __n;    }    else#endif /* _STLP_USE_SHORT_STRING_OPTIM */    this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());    this->_M_terminate_string();  }  template <class _InputIter>  void _M_range_initializeT(_InputIter __f, _InputIter __l) {    _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));  }  template <class _Integer>  void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {    this->_M_allocate_block(__n + 1);#if defined (_STLP_USE_SHORT_STRING_OPTIM)    if (this->_M_using_static_buf()) {      _Traits::assign(this->_M_Start(), __n, __x);      this->_M_finish = this->_M_Start() + __n;    }    else#endif /* _STLP_USE_SHORT_STRING_OPTIM */    this->_M_finish = uninitialized_fill_n(this->_M_Start(), __n, __x);    this->_M_terminate_string();  }  template <class _InputIter>  void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {    _M_range_initializeT(__f, __l);  }public:                         // Append, operator+=, push_back.  _Self& operator+=(const _Self& __s) {    _Base::operator+=(__s);    return *this;  }  _Self& operator+=(const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    _Base::operator+=(__s);    return *this;  }  _Self& operator+=(_CharT __c) {    _Base::operator+=(__c);    return *this;  }  _Self& append(const _Self& __s) {    _Base::append(__s);    return *this;  }  _Self& append(const _Self& __s,                size_type __pos, size_type __n) {    _Base::append(__s, __pos, __n);    return *this;  }  _Self& append(const _CharT* __s, size_type __n) {    _STLP_FIX_LITERAL_BUG(__s)    _Base::append(__s, __n);    return *this;  }  _Self& append(const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    _Base::append(__s);    return *this;  }  _Self& append(size_type __n, _CharT __c) {    _Base::append(__n, __c);    return *this;  }  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.  template <class _InputIter>  _Self& append(_InputIter __first, _InputIter __last) {    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;    return _M_append_dispatch(__first, __last, _Integral());  }#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)  //See equivalent assign method remark.  _Self& append(const _CharT* __f, const _CharT* __l) {    _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)    _Base::append(__f, __l);    return *this;  }#endifprivate:                        // Helper functions for append.  template <class _InputIter>  _Self& _M_appendT(_InputIter __first, _InputIter __last,                   const input_iterator_tag &) {    for ( ; __first != __last ; ++__first)      _Base::push_back(*__first);    return *this;  }  template <class _ForwardIter>  _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last,                    const forward_iterator_tag &)  {    if (__first != __last) {      const size_type __old_size = this->size();      difference_type __n = distance(__first, __last);      if (__STATIC_CAST(size_type,__n) > max_size() || __old_size > max_size() - __STATIC_CAST(size_type,__n))        this->_M_throw_length_error();      if (__old_size + __n > capacity()) {        const size_type __len = __old_size +          (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;        pointer __new_start = this->_M_end_of_storage.allocate(__len);        pointer __new_finish = __new_start;        _STLP_TRY {          __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start);          __new_finish = uninitialized_copy(__first, __last, __new_finish);          _M_construct_null(__new_finish);        }        _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),          this->_M_end_of_storage.deallocate(__new_start,__len)))          this->_M_destroy_range();        this->_M_deallocate_block();        this->_M_reset(__new_start, __new_finish, __new_start + __len);      }      else {        _ForwardIter __f1 = __first;        ++__f1;#if defined (_STLP_USE_SHORT_STRING_OPTIM)        if (this->_M_using_static_buf())          _M_copyT(__f1, __last, this->_M_Finish() + 1);        else#endif /* _STLP_USE_SHORT_STRING_OPTIM */          uninitialized_copy(__f1, __last, this->_M_Finish() + 1);        _STLP_TRY {          this->_M_construct_null(this->_M_Finish() + __n);        }        _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_Finish() + 1, this->_M_Finish() + __n))        _Traits::assign(*this->_M_finish, *__first);        this->_M_finish += __n;      }    }    return *this;  }  template <class _Integer>  _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/) {    return append((size_type) __n, (_CharT) __x);  }  template <class _InputIter>  _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/) {    return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));  }public:                         // Assign  _Self& assign(const _Self& __s) {    _Base::assign(__s);    return *this;  }  _Self& assign(const _Self& __s,                size_type __pos, size_type __n) {    _Base::assign(__s, __pos, __n);    return *this;  }  _Self& assign(const _CharT* __s, size_type __n) {    _STLP_FIX_LITERAL_BUG(__s)    _Base::assign(__s, __n);    return *this;  }  _Self& assign(const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    _Base::assign(__s);    return *this;  }  _Self& assign(size_type __n, _CharT __c) {    _Base::assign(__n, __c);    return *this;  }private:                        // Helper functions for assign.  template <class _Integer>  _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {    return assign((size_type) __n, (_CharT) __x);  }  template <class _InputIter>  _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/)  {    pointer __cur = this->_M_Start();    while (__f != __l && __cur != this->_M_Finish()) {      _Traits::assign(*__cur, *__f);      ++__f;      ++__cur;    }    if (__f == __l)      _Base::erase(__cur, this->_M_Finish());    else      _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));    return *this;  }public:  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.  template <class _InputIter>  _Self& assign(_InputIter __first, _InputIter __last) {    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;    return _M_assign_dispatch(__first, __last, _Integral());  }#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)  /* This method is not part of the standard and is a specialization of the   * template method assign. It is only granted for convenience to call assign   * with mixed parameters iterator and const_iterator.   */  _Self& assign(const _CharT* __f, const _CharT* __l) {    _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)    _Base::assign(__f, __l);    return *this;  }#endifpublic:                         // Insert  _Self& insert(size_type __pos, const _Self& __s) {    _Base::insert(__pos, __s);    return *this;  }  _Self& insert(size_type __pos, const _Self& __s,                size_type __beg, size_type __n) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?