/home/ntakagi/work/STLport-5.1.5/stlport/stl/debug/_string_sum_methods.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2003 00003 * Francois Dumont 00004 * 00005 * This material is provided "as is", with absolutely no warranty expressed 00006 * or implied. Any use is at your own risk. 00007 * 00008 * Permission to use or copy this software for any purpose is hereby granted 00009 * without fee, provided the above notices are retained on all copies. 00010 * Permission to modify the code and to distribute modified code is granted, 00011 * provided the above notices are retained, and a notice that the code was 00012 * modified is included with the above copyright notice. 00013 * 00014 */ 00015 00016 /* 00017 * All the necessary methods used for template expressions with basic_string 00018 * This file do not have to be macro guarded as it is only used in the _string.h 00019 * file and it is a part of the basic_string definition. 00020 */ 00021 00022 template <class _Left, class _Right, class _StorageDir> 00023 basic_string(_STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc, _Left, _Right, _StorageDir> const& __s) 00024 : _M_non_dbg_impl(_Reserve_t(), __s.size(), __s.get_allocator()), 00025 _M_iter_list(&_M_non_dbg_impl) 00026 { _M_append_sum(__s, _M_non_dbg_impl); } 00027 00028 template <class _Left, class _Right, class _StorageDir> 00029 basic_string(_STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc, _Left, _Right, _StorageDir> const& __s, 00030 size_type __pos, size_type __n = npos, 00031 const allocator_type& __a = allocator_type()) 00032 : _M_non_dbg_impl(_Reserve_t(), (__pos <= __s.size()) ? ((min) (__n, __s.size() - __pos)) : 0, __a), 00033 _M_iter_list(&_M_non_dbg_impl) { 00034 size_type __size = __s.size(); 00035 if (__pos > __size) 00036 //This call will generate the necessary out of range exception: 00037 _M_non_dbg_impl.at(0); 00038 else 00039 _M_append_sum_pos(__s, __pos, (min) (__n, __size - __pos), _M_non_dbg_impl); 00040 } 00041 00042 private: 00043 _Base& _M_append_fast(_STLP_PRIV __char_wrapper<_CharT> __c, _Base &__str) 00044 { return __str += __c.getValue(); } 00045 _Base& _M_append_fast(_CharT const* __s, size_type __s_size, _Base &__str) 00046 { return __str.append(__s, __s_size); } 00047 _Base& _M_append_fast(_STLP_PRIV __cstr_wrapper<_CharT> const& __s, _Base &__str) 00048 { return _M_append_fast(__s.c_str(), __s.size(), __str); } 00049 _Base& _M_append_fast(_STLP_PRIV __bstr_wrapper<_CharT, _Traits, _Alloc> __s, _Base &__str) 00050 { return _M_append_fast(__s.b_str(), __str); } 00051 _Base& _M_append_fast(_Self const& __s, _Base &__str) 00052 { return _M_append_fast(__s.data(), __s.size(), __str); } 00053 _Base& _M_append_fast(_STLP_PRIV __sum_storage_elem<_CharT, _Traits, _Alloc> const&, _Base &__str) 00054 { return __str; } 00055 template <class _Left, class _Right, class _StorageDir> 00056 _Base& _M_append_fast(_STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc, _Left, _Right, _StorageDir> const& __s, _Base &__str) 00057 { return _M_append_fast(__s.getRhs(), _M_append_fast(__s.getLhs(), __str)); } 00058 00059 _Base& _M_append_fast_pos(_STLP_PRIV __char_wrapper<_CharT> __c, _Base &__str, size_type /*__pos*/, size_type __n) { 00060 if (__n == 0) 00061 return __str; 00062 return __str += __c.getValue(); 00063 } 00064 _Base& _M_append_fast_pos(_CharT const* __s, size_type __s_size, _Base &__str, 00065 size_type __pos, size_type __n) 00066 { return __str.append(__s + __pos, __s + __pos + (min)(__n, __s_size - __pos)); } 00067 _Base& _M_append_fast_pos(_STLP_PRIV __cstr_wrapper<_CharT> const& __s, _Base &__str, 00068 size_type __pos, size_type __n) 00069 { return _M_append_fast_pos(__s.c_str(), __s.size(), __str, __pos, __n); } 00070 _Base& _M_append_fast_pos(_STLP_PRIV __bstr_wrapper<_CharT, _Traits, _Alloc> __s, _Base &__str, 00071 size_type __pos, size_type __n) 00072 { return _M_append_fast_pos(__s.b_str(), __str, __pos, __n); } 00073 _Base& _M_append_fast_pos(_Self const& __s, _Base &__str, size_type __pos, size_type __n) 00074 { return _M_append_fast_pos(__s.data(), __s.size(), __str, __pos, __n); } 00075 _Base& _M_append_fast_pos(_STLP_PRIV __sum_storage_elem<_CharT, _Traits, _Alloc> const&, _Base &__str, 00076 size_type /*__pos*/, size_type /*__n*/) 00077 { return __str; } 00078 00079 template <class _Left, class _Right, class _StorageDir> 00080 _Base& _M_append_fast_pos(_STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc, _Left, _Right, _StorageDir> const& __s, 00081 _Base &__str, size_type __pos, size_type __n) { 00082 if (__n == 0) { 00083 return __str; 00084 } 00085 size_type __lhs_size = __s.getLhs().size(); 00086 if (__pos < __lhs_size) { 00087 if (__n < (__lhs_size - __pos)) { 00088 return _M_append_fast_pos(__s.getLhs(), __str, __pos, __n); 00089 } else { 00090 return _M_append_fast_pos(__s.getRhs(), _M_append_fast_pos(__s.getLhs(), __str, __pos, __n), 00091 0, __n - (__lhs_size - __pos)); 00092 } 00093 } else { 00094 return _M_append_fast_pos(__s.getRhs(), __str, __pos - __lhs_size, __n); 00095 } 00096 } 00097 00098 template <class _Left, class _Right, class _StorageDir> 00099 _Self& _M_append_sum (_STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc, _Left, _Right, _StorageDir> const& __s, 00100 _Base &__impl) { 00101 _M_append_fast(__s, __impl); 00102 return *this; 00103 } 00104 00105 template <class _Left, class _Right, class _StorageDir> 00106 _Self& _M_append_sum_pos (_STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc, _Left, _Right, _StorageDir> const& __s, 00107 size_type __pos, size_type __n, _Base &__impl) { 00108 _M_non_dbg_impl.reserve(_M_non_dbg_impl.size() + (min) (__s.size() - __pos, __n)); 00109 _M_append_fast_pos(__s, __impl, __pos, __n); 00110 return *this; 00111 }
Generated on Mon Mar 10 15:32:41 2008 by ![]() |