Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _LOCALE_CLASSES_TCC
00035 #define _LOCALE_CLASSES_TCC 1
00036
00037 #pragma GCC system_header
00038
00039 namespace std _GLIBCXX_VISIBILITY(default)
00040 {
00041 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00042
00043 template<typename _Facet>
00044 locale::
00045 locale(const locale& __other, _Facet* __f)
00046 {
00047 _M_impl = new _Impl(*__other._M_impl, 1);
00048
00049 __try
00050 { _M_impl->_M_install_facet(&_Facet::id, __f); }
00051 __catch(...)
00052 {
00053 _M_impl->_M_remove_reference();
00054 __throw_exception_again;
00055 }
00056 delete [] _M_impl->_M_names[0];
00057 _M_impl->_M_names[0] = 0;
00058 }
00059
00060 template<typename _Facet>
00061 locale
00062 locale::
00063 combine(const locale& __other) const
00064 {
00065 _Impl* __tmp = new _Impl(*_M_impl, 1);
00066 __try
00067 {
00068 __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
00069 }
00070 __catch(...)
00071 {
00072 __tmp->_M_remove_reference();
00073 __throw_exception_again;
00074 }
00075 return locale(__tmp);
00076 }
00077
00078 template<typename _CharT, typename _Traits, typename _Alloc>
00079 bool
00080 locale::
00081 operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
00082 const basic_string<_CharT, _Traits, _Alloc>& __s2) const
00083 {
00084 typedef std::collate<_CharT> __collate_type;
00085 const __collate_type& __collate = use_facet<__collate_type>(*this);
00086 return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
00087 __s2.data(), __s2.data() + __s2.length()) < 0);
00088 }
00089
00090
00091 template<typename _Facet>
00092 bool
00093 has_facet(const locale& __loc) throw()
00094 {
00095 const size_t __i = _Facet::id._M_id();
00096 const locale::facet** __facets = __loc._M_impl->_M_facets;
00097 return (__i < __loc._M_impl->_M_facets_size
00098 #ifdef __GXX_RTTI
00099 && dynamic_cast<const _Facet*>(__facets[__i]));
00100 #else
00101 && static_cast<const _Facet*>(__facets[__i]));
00102 #endif
00103 }
00104
00105 template<typename _Facet>
00106 const _Facet&
00107 use_facet(const locale& __loc)
00108 {
00109 const size_t __i = _Facet::id._M_id();
00110 const locale::facet** __facets = __loc._M_impl->_M_facets;
00111 if (__i >= __loc._M_impl->_M_facets_size || !__facets[__i])
00112 __throw_bad_cast();
00113 #ifdef __GXX_RTTI
00114 return dynamic_cast<const _Facet&>(*__facets[__i]);
00115 #else
00116 return static_cast<const _Facet&>(*__facets[__i]);
00117 #endif
00118 }
00119
00120
00121
00122 template<typename _CharT>
00123 int
00124 collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const throw ()
00125 { return 0; }
00126
00127
00128 template<typename _CharT>
00129 size_t
00130 collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const throw ()
00131 { return 0; }
00132
00133 template<typename _CharT>
00134 int
00135 collate<_CharT>::
00136 do_compare(const _CharT* __lo1, const _CharT* __hi1,
00137 const _CharT* __lo2, const _CharT* __hi2) const
00138 {
00139
00140
00141 const string_type __one(__lo1, __hi1);
00142 const string_type __two(__lo2, __hi2);
00143
00144 const _CharT* __p = __one.c_str();
00145 const _CharT* __pend = __one.data() + __one.length();
00146 const _CharT* __q = __two.c_str();
00147 const _CharT* __qend = __two.data() + __two.length();
00148
00149
00150
00151
00152 for (;;)
00153 {
00154 const int __res = _M_compare(__p, __q);
00155 if (__res)
00156 return __res;
00157
00158 __p += char_traits<_CharT>::length(__p);
00159 __q += char_traits<_CharT>::length(__q);
00160 if (__p == __pend && __q == __qend)
00161 return 0;
00162 else if (__p == __pend)
00163 return -1;
00164 else if (__q == __qend)
00165 return 1;
00166
00167 __p++;
00168 __q++;
00169 }
00170 }
00171
00172 template<typename _CharT>
00173 typename collate<_CharT>::string_type
00174 collate<_CharT>::
00175 do_transform(const _CharT* __lo, const _CharT* __hi) const
00176 {
00177 string_type __ret;
00178
00179
00180 const string_type __str(__lo, __hi);
00181
00182 const _CharT* __p = __str.c_str();
00183 const _CharT* __pend = __str.data() + __str.length();
00184
00185 size_t __len = (__hi - __lo) * 2;
00186
00187 _CharT* __c = new _CharT[__len];
00188
00189 __try
00190 {
00191
00192
00193
00194 for (;;)
00195 {
00196
00197 size_t __res = _M_transform(__c, __p, __len);
00198
00199
00200 if (__res >= __len)
00201 {
00202 __len = __res + 1;
00203 delete [] __c, __c = 0;
00204 __c = new _CharT[__len];
00205 __res = _M_transform(__c, __p, __len);
00206 }
00207
00208 __ret.append(__c, __res);
00209 __p += char_traits<_CharT>::length(__p);
00210 if (__p == __pend)
00211 break;
00212
00213 __p++;
00214 __ret.push_back(_CharT());
00215 }
00216 }
00217 __catch(...)
00218 {
00219 delete [] __c;
00220 __throw_exception_again;
00221 }
00222
00223 delete [] __c;
00224
00225 return __ret;
00226 }
00227
00228 template<typename _CharT>
00229 long
00230 collate<_CharT>::
00231 do_hash(const _CharT* __lo, const _CharT* __hi) const
00232 {
00233 unsigned long __val = 0;
00234 for (; __lo < __hi; ++__lo)
00235 __val =
00236 *__lo + ((__val << 7)
00237 | (__val >> (__gnu_cxx::__numeric_traits<unsigned long>::
00238 __digits - 7)));
00239 return static_cast<long>(__val);
00240 }
00241
00242
00243
00244
00245 #if _GLIBCXX_EXTERN_TEMPLATE
00246 extern template class collate<char>;
00247 extern template class collate_byname<char>;
00248
00249 extern template
00250 const collate<char>&
00251 use_facet<collate<char> >(const locale&);
00252
00253 extern template
00254 bool
00255 has_facet<collate<char> >(const locale&);
00256
00257 #ifdef _GLIBCXX_USE_WCHAR_T
00258 extern template class collate<wchar_t>;
00259 extern template class collate_byname<wchar_t>;
00260
00261 extern template
00262 const collate<wchar_t>&
00263 use_facet<collate<wchar_t> >(const locale&);
00264
00265 extern template
00266 bool
00267 has_facet<collate<wchar_t> >(const locale&);
00268 #endif
00269 #endif
00270
00271 _GLIBCXX_END_NAMESPACE_VERSION
00272 }
00273
00274 #endif