⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _string.tcc

📁 symbian上STL模板库的实现
💻 TCC
📖 第 1 页 / 共 2 页
字号:
/* * * * Copyright (c) 1994 * Hewlett-Packard Company * * Copyright (c) 1996,1997 * Silicon Graphics Computer Systems, Inc. * * Copyright (c) 1997 * Moscow Center for SPARC Technology * * 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_STRING_C#define _STLP_STRING_C#ifndef _STLP_STRING_H# include <bits/STLPort/_string.h>#endif# ifdef _STLP_DEBUG#  define basic_string _Nondebug_string# endif# if defined (_STLP_USE_OWN_NAMESPACE) || !defined (_STLP_USE_NATIVE_STRING)# if defined (_STLP_NESTED_TYPE_PARAM_BUG)#  define __size_type__ size_t#  define size_type size_t#  define iterator   _CharT*# else#  define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type# endif_STLP_BEGIN_NAMESPACE// ------------------------------------------------------------// Non-inline declarations.// Change the string's capacity so that it is large enough to hold//  at least __res_arg elements, plus the terminating _CharT().  Note that,//  if __res_arg < capacity(), this member function may actually decrease//  the string's capacity.template <class _CharT, class _Traits, class _Alloc> void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {    if (__res_arg >= capacity())    {              if (__res_arg > max_size())            this->_M_throw_length_error();        size_type __n = __res_arg + 1;        pointer __new_start = this->_M_end_of_storage.allocate(__n);        pointer __new_finish = __new_start;        _STLP_TRY {            __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);            _M_construct_null(__new_finish);        }        _STLP_UNWIND((_STLP_STD::_Destroy(__new_start, __new_finish),                     this->_M_end_of_storage.deallocate(__new_start, __n)));        _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);        this->_M_deallocate_block();        this->_M_start = __new_start;        this->_M_finish = __new_finish;        this->_M_end_of_storage._M_data = __new_start + __n;    }}    template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) {        if (__n > max_size() || size() > max_size() - __n)            this->_M_throw_length_error();        if (size() + __n > capacity())            reserve(size() + (max)(size(), __n));        if (__n > 0) {            uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);            _STLP_TRY {                _M_construct_null(this->_M_finish + __n);            }            _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));            _Traits::assign(*end(), __c);            this->_M_finish += __n;        }        return *this;    }#ifndef _STLP_MEMBER_TEMPLATEStemplate <class _CharT, class _Traits, class _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>::append(const _CharT* __first,        const _CharT* __last){    if (__first != __last) {        const size_type __old_size = size();        ptrdiff_t __n = __last - __first;        if ((size_type)__n > max_size() || __old_size > max_size() - __n)            this->_M_throw_length_error();        if (__old_size + __n > capacity()) {            const size_type __len = __old_size + (max)(__old_size, (size_t) __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(__new_start,__new_finish),                        this->_M_end_of_storage.deallocate(__new_start,__len)));            _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);            this->_M_deallocate_block();            this->_M_start = __new_start;            this->_M_finish = __new_finish;            this->_M_end_of_storage._M_data = __new_start + __len;         }        else {            const _CharT* __f1 = __first;            ++__f1;            uninitialized_copy(__f1, __last, this->_M_finish + 1);            _STLP_TRY {                _M_construct_null(this->_M_finish + __n);            }            _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));            _Traits::assign(*end(), *__first);            this->_M_finish += __n;        }    }    return *this;  }#endif /* _STLP_MEMBER_TEMPLATES */template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {    if (__n <= size()) {        _Traits::assign(this->_M_start, __n, __c);        erase(begin() + __n, end());    }    else {        _Traits::assign(this->_M_start, size(), __c);        append(__n - size(), __c);    }    return *this;}    template <class _CharT, class _Traits, class _Alloc> _CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,        _CharT __c){    pointer __new_pos = __p;    if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {        _M_construct_null(this->_M_finish + 1);        _Traits::move(__p + 1, __p, this->_M_finish - __p);        _Traits::assign(*__p, __c);        ++this->_M_finish;    }    else {        const size_type __old_len = size();        const size_type __len = __old_len +            (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;        pointer __new_start = this->_M_end_of_storage.allocate(__len);        pointer __new_finish = __new_start;        _STLP_TRY {            __new_pos = uninitialized_copy(this->_M_start, __p, __new_start);            _Construct(__new_pos, __c);            __new_finish = __new_pos + 1;            __new_finish = uninitialized_copy(__p, this->_M_finish, __new_finish);            _M_construct_null(__new_finish);        }        _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),                     this->_M_end_of_storage.deallocate(__new_start,__len)));        _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);        this->_M_deallocate_block();        this->_M_start = __new_start;        this->_M_finish = __new_finish;        this->_M_end_of_storage._M_data = __new_start + __len;    }    return __new_pos;}template <class _CharT, class _Traits, class _Alloc> void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,        size_t __n, _CharT __c){    if (__n != 0) {        if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {            const size_type __elems_after = this->_M_finish - __position;            pointer __old_finish = this->_M_finish;            if (__elems_after >= __n) {                uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,                        this->_M_finish + 1);                this->_M_finish += __n;                _Traits::move(__position + __n,                        __position, (__elems_after - __n) + 1);                _Traits::assign(__position, __n, __c);            }            else {                uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);                this->_M_finish += __n - __elems_after;                _STLP_TRY {                    uninitialized_copy(__position, __old_finish + 1, this->_M_finish);                    this->_M_finish += __elems_after;                }                _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),                             this->_M_finish = __old_finish));                _Traits::assign(__position, __elems_after + 1, __c);            }        }        else {            const size_type __old_size = size();                    const size_type __len = __old_size + (max)(__old_size, __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, __position, __new_start);                __new_finish = uninitialized_fill_n(__new_finish, __n, __c);                __new_finish = uninitialized_copy(__position, this->_M_finish,                        __new_finish);                _M_construct_null(__new_finish);            }            _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),                        this->_M_end_of_storage.deallocate(__new_start,__len)));            _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);            this->_M_deallocate_block();            this->_M_start = __new_start;            this->_M_finish = __new_finish;            this->_M_end_of_storage._M_data = __new_start + __len;            }    }}#ifndef _STLP_MEMBER_TEMPLATES    template <class _CharT, class _Traits, class _Alloc> void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,        const _CharT* __first,         const _CharT* __last){    if (__first != __last) {        const ptrdiff_t __n = __last - __first;        if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {            const ptrdiff_t __elems_after = this->_M_finish - __position;            pointer __old_finish = this->_M_finish;            if (__elems_after >= __n) {                uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,                        this->_M_finish + 1);                this->_M_finish += __n;                _Traits::move(__position + __n,                        __position, (__elems_after - __n) + 1);                _M_copy(__first, __last, __position);            }            else {                const _CharT* __mid = __first;                advance(__mid, __elems_after + 1);                uninitialized_copy(__mid, __last, this->_M_finish + 1);                this->_M_finish += __n - __elems_after;                _STLP_TRY {                    uninitialized_copy(__position, __old_finish + 1, this->_M_finish);                    this->_M_finish += __elems_after;                }                _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),                             this->_M_finish = __old_finish));                _M_copy(__first, __mid, __position);            }        }        else {            size_type __old_size = size();                    size_type __len                = __old_size + (max)(__old_size, __STATIC_CAST(const 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, __position, __new_start);                __new_finish = uninitialized_copy(__first, __last, __new_finish);                __new_finish                    = uninitialized_copy(__position, this->_M_finish, __new_finish);                _M_construct_null(__new_finish);            }            _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),                        this->_M_end_of_storage.deallocate(__new_start,__len)));

⌨️ 快捷键说明

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