/home/ntakagi/work/STLport-5.1.5/stlport/stl/_codecvt.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 // WARNING: This is an internal header file, included by other C++ 00019 // standard library headers. You should not attempt to use this header 00020 // file directly. 00021 00022 00023 #ifndef _STLP_INTERNAL_CODECVT_H 00024 #define _STLP_INTERNAL_CODECVT_H 00025 00026 #ifndef _STLP_C_LOCALE_H 00027 # include <stl/c_locale.h> 00028 #endif 00029 00030 #ifndef _STLP_INTERNAL_LOCALE_H 00031 # include <stl/_locale.h> 00032 #endif 00033 00034 #ifndef _STLP_INTERNAL_ALGOBASE_H 00035 # include <stl/_algobase.h> 00036 #endif 00037 00038 _STLP_BEGIN_NAMESPACE 00039 00040 class _STLP_CLASS_DECLSPEC codecvt_base { 00041 public: 00042 enum result {ok, partial, error, noconv}; 00043 }; 00044 00045 template <class _InternT, class _ExternT, class _StateT> 00046 class codecvt : public locale::facet, public codecvt_base { 00047 public: 00048 typedef _InternT intern_type; 00049 typedef _ExternT extern_type; 00050 typedef _StateT state_type; 00051 00052 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) 00053 /* For the moment VC6 do not support this facet default implementation 00054 * because of the static locale::id instance. When VC6 see this definition 00055 * it goes crasy with locale::id static instances and all the has_facet tests 00056 * unit tests are failing. 00057 */ 00058 }; 00059 #else 00060 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 00061 00062 result out(state_type& __state, 00063 const intern_type* __from, 00064 const intern_type* __from_end, 00065 const intern_type*& __from_next, 00066 extern_type* __to, 00067 extern_type* __to_limit, 00068 extern_type*& __to_next) const { 00069 return do_out(__state, 00070 __from, __from_end, __from_next, 00071 __to, __to_limit, __to_next); 00072 } 00073 00074 result unshift(state_type& __state, 00075 extern_type* __to, 00076 extern_type* __to_limit, 00077 extern_type*& __to_next) const { 00078 return do_unshift(__state, __to, __to_limit, __to_next); 00079 } 00080 00081 result in(state_type& __state, 00082 const extern_type* __from, 00083 const extern_type* __from_end, 00084 const extern_type*& __from_next, 00085 intern_type* __to, 00086 intern_type* __to_limit, 00087 intern_type*& __to_next) const { 00088 return do_in(__state, 00089 __from, __from_end, __from_next, 00090 __to, __to_limit, __to_next); 00091 } 00092 00093 int encoding() const _STLP_NOTHROW { return do_encoding(); } 00094 00095 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); } 00096 00097 int length(const state_type& __state, 00098 const extern_type* __from, 00099 const extern_type* __end, 00100 size_t __max) const { 00101 return do_length(__state, __from, __end, __max); 00102 } 00103 00104 int max_length() const _STLP_NOTHROW { return do_max_length(); } 00105 00106 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id; 00107 00108 protected: 00109 ~codecvt() {} 00110 00111 virtual result do_out(state_type&, 00112 const intern_type* __from, 00113 const intern_type*, 00114 const intern_type*& __from_next, 00115 extern_type* __to, 00116 extern_type*, 00117 extern_type*& __to_next) const 00118 { __from_next = __from; __to_next = __to; return noconv; } 00119 00120 virtual result do_in (state_type&, 00121 const extern_type* __from, 00122 const extern_type*, 00123 const extern_type*& __from_next, 00124 intern_type* __to, 00125 intern_type*, 00126 intern_type*& __to_next) const 00127 { __from_next = __from; __to_next = __to; return noconv; } 00128 00129 virtual result do_unshift(state_type&, 00130 extern_type* __to, 00131 extern_type*, 00132 extern_type*& __to_next) const 00133 { __to_next = __to; return noconv; } 00134 00135 virtual int do_encoding() const _STLP_NOTHROW 00136 { return 1; } 00137 00138 virtual bool do_always_noconv() const _STLP_NOTHROW 00139 { return true; } 00140 00141 virtual int do_length(const state_type&, 00142 const extern_type* __from, 00143 const extern_type* __end, 00144 size_t __max) const 00145 { return (int)(min) ( __STATIC_CAST(size_t, (__end - __from)), __max); } 00146 00147 virtual int do_max_length() const _STLP_NOTHROW 00148 { return 1; } 00149 00150 private: 00151 codecvt(const codecvt<intern_type, extern_type, state_type>&); 00152 codecvt<intern_type, extern_type, state_type>& operator = (const codecvt<intern_type, extern_type, state_type>&); 00153 }; 00154 00155 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) 00156 # if (_STLP_STATIC_TEMPLATE_DATA > 0) 00157 # if !defined (__BORLANDC__) 00158 template <class _InternT, class _ExternT, class _StateT> 00159 locale::id codecvt<_InternT, _ExternT, _StateT>::id; 00160 # endif 00161 # endif 00162 # endif 00163 #endif 00164 00165 template <class _InternT, class _ExternT, class _StateT> 00166 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {}; 00167 00168 _STLP_TEMPLATE_NULL 00169 class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t> 00170 : public locale::facet, public codecvt_base 00171 { 00172 friend class _Locale_impl; 00173 00174 public: 00175 typedef char intern_type; 00176 typedef char extern_type; 00177 typedef mbstate_t state_type; 00178 00179 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 00180 00181 result out(mbstate_t& __state, 00182 const char* __from, 00183 const char* __from_end, 00184 const char*& __from_next, 00185 char* __to, 00186 char* __to_limit, 00187 char*& __to_next) const { 00188 return do_out(__state, 00189 __from, __from_end, __from_next, 00190 __to, __to_limit, __to_next); 00191 } 00192 00193 result unshift(mbstate_t& __state, 00194 char* __to, char* __to_limit, char*& __to_next) const 00195 { return do_unshift(__state, __to, __to_limit, __to_next); } 00196 00197 result in(state_type& __state, 00198 const char* __from, 00199 const char* __from_end, 00200 const char*& __from_next, 00201 char* __to, 00202 char* __to_limit, 00203 char*& __to_next) const { 00204 return do_in(__state, 00205 __from, __from_end, __from_next, 00206 __to, __to_limit, __to_next); 00207 } 00208 00209 int encoding() const _STLP_NOTHROW { return do_encoding(); } 00210 00211 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); } 00212 00213 int length(const state_type& __state, 00214 const char* __from, const char* __end, 00215 size_t __max) const 00216 { return do_length(__state, __from, __end, __max); } 00217 00218 int max_length() const _STLP_NOTHROW { return do_max_length(); } 00219 00220 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id; 00221 00222 protected: 00223 ~codecvt(); 00224 00225 virtual result do_out(mbstate_t& /* __state */, 00226 const char* __from, 00227 const char* /* __from_end */, 00228 const char*& __from_next, 00229 char* __to, 00230 char* /* __to_limit */, 00231 char*& __to_next) const; 00232 00233 virtual result do_in (mbstate_t& /* __state */ , 00234 const char* __from, 00235 const char* /* __from_end */, 00236 const char*& __from_next, 00237 char* __to, 00238 char* /* __to_end */, 00239 char*& __to_next) const; 00240 00241 virtual result do_unshift(mbstate_t& /* __state */, 00242 char* __to, 00243 char* /* __to_limit */, 00244 char*& __to_next) const; 00245 00246 virtual int do_encoding() const _STLP_NOTHROW; 00247 virtual bool do_always_noconv() const _STLP_NOTHROW; 00248 virtual int do_length(const mbstate_t& __state, 00249 const char* __from, 00250 const char* __end, 00251 size_t __max) const; 00252 virtual int do_max_length() const _STLP_NOTHROW; 00253 private: 00254 codecvt(const codecvt<char, char, mbstate_t>&); 00255 codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&); 00256 }; 00257 00258 # ifndef _STLP_NO_WCHAR_T 00259 00260 _STLP_TEMPLATE_NULL 00261 class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t> 00262 : public locale::facet, public codecvt_base 00263 { 00264 friend class _Locale_impl; 00265 public: 00266 typedef wchar_t intern_type; 00267 typedef char extern_type; 00268 typedef mbstate_t state_type; 00269 00270 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 00271 00272 result out(mbstate_t& __state, 00273 const wchar_t* __from, 00274 const wchar_t* __from_end, 00275 const wchar_t*& __from_next, 00276 char* __to, 00277 char* __to_limit, 00278 char*& __to_next) const { 00279 return do_out(__state, 00280 __from, __from_end, __from_next, 00281 __to, __to_limit, __to_next); 00282 } 00283 00284 result unshift(mbstate_t& __state, 00285 char* __to, char* __to_limit, char*& __to_next) const { 00286 return do_unshift(__state, __to, __to_limit, __to_next); 00287 } 00288 00289 result in(mbstate_t& __state, 00290 const char* __from, 00291 const char* __from_end, 00292 const char*& __from_next, 00293 wchar_t* __to, 00294 wchar_t* __to_limit, 00295 wchar_t*& __to_next) const { 00296 return do_in(__state, 00297 __from, __from_end, __from_next, 00298 __to, __to_limit, __to_next); 00299 } 00300 00301 int encoding() const _STLP_NOTHROW { return do_encoding(); } 00302 00303 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); } 00304 00305 int length(const mbstate_t& __state, 00306 const char* __from, const char* __end, 00307 size_t __max) const 00308 { return do_length(__state, __from, __end, __max); } 00309 00310 int max_length() const _STLP_NOTHROW { return do_max_length(); } 00311 00312 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id; 00313 00314 protected: 00315 ~codecvt(); 00316 00317 virtual result do_out(mbstate_t& __state, 00318 const wchar_t* __from, 00319 const wchar_t* __from_end, 00320 const wchar_t*& __from_next, 00321 char* __to, 00322 char* __to_limit, 00323 char*& __to_next) const; 00324 00325 virtual result do_in (mbstate_t& __state, 00326 const char* __from, 00327 const char* __from_end, 00328 const char*& __from_next, 00329 wchar_t* __to, 00330 wchar_t* __to_limit, 00331 wchar_t*& __to_next) const; 00332 00333 virtual result do_unshift(mbstate_t& __state, 00334 char* __to, 00335 char* __to_limit, 00336 char*& __to_next) const; 00337 00338 virtual int do_encoding() const _STLP_NOTHROW; 00339 00340 virtual bool do_always_noconv() const _STLP_NOTHROW; 00341 00342 virtual int do_length(const mbstate_t& __state, 00343 const char* __from, 00344 const char* __end, 00345 size_t __max) const; 00346 00347 virtual int do_max_length() const _STLP_NOTHROW; 00348 00349 private: 00350 codecvt(const codecvt<wchar_t, char, mbstate_t>&); 00351 codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&); 00352 }; 00353 00354 # endif 00355 00356 _STLP_TEMPLATE_NULL 00357 class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t> 00358 : public codecvt<char, char, mbstate_t> { 00359 public: 00360 explicit codecvt_byname(const char* __name, size_t __refs = 0); 00361 ~codecvt_byname(); 00362 private: 00363 codecvt_byname(const codecvt_byname<char, char, mbstate_t>&); 00364 codecvt_byname<char, char, mbstate_t>& operator =(const codecvt_byname<char, char, mbstate_t>&); 00365 }; 00366 00367 # ifndef _STLP_NO_WCHAR_T 00368 _STLP_TEMPLATE_NULL 00369 class _STLP_CLASS_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t> 00370 : public codecvt<wchar_t, char, mbstate_t> 00371 { 00372 public: 00373 explicit codecvt_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0); 00374 00375 protected: 00376 ~codecvt_byname(); 00377 00378 virtual result do_out(mbstate_t& __state, 00379 const wchar_t* __from, 00380 const wchar_t* __from_end, 00381 const wchar_t*& __from_next, 00382 char* __to, 00383 char* __to_limit, 00384 char*& __to_next) const; 00385 00386 virtual result do_in (mbstate_t& __state, 00387 const char* __from, 00388 const char* __from_end, 00389 const char*& __from_next, 00390 wchar_t* __to, 00391 wchar_t* __to_limit, 00392 wchar_t*& __to_next) const; 00393 00394 virtual result do_unshift(mbstate_t& __state, 00395 char* __to, 00396 char* __to_limit, 00397 char*& __to_next) const; 00398 00399 virtual int do_encoding() const _STLP_NOTHROW; 00400 00401 virtual bool do_always_noconv() const _STLP_NOTHROW; 00402 00403 virtual int do_length(const mbstate_t& __state, 00404 const char* __from, 00405 const char* __end, 00406 size_t __max) const; 00407 00408 virtual int do_max_length() const _STLP_NOTHROW; 00409 00410 private: 00411 _Locale_ctype* _M_ctype; 00412 codecvt_byname(const codecvt_byname<wchar_t, char, mbstate_t>&); 00413 codecvt_byname<wchar_t, char, mbstate_t>& operator =(const codecvt_byname<wchar_t, char, mbstate_t>&); 00414 }; 00415 00416 # endif 00417 00418 _STLP_END_NAMESPACE 00419 00420 #endif /* _STLP_INTERNAL_CODECVT_H */ 00421 00422 // Local Variables: 00423 // mode:C++ 00424 // End: 00425
Generated on Mon Mar 10 15:32:20 2008 by ![]() |