3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
23 #ifndef _STLP_INTERNAL_CODECVT_H
24 #define _STLP_INTERNAL_CODECVT_H
26 #ifndef _STLP_C_LOCALE_H
27 # include <stl/c_locale.h>
30 #ifndef _STLP_INTERNAL_LOCALE_H
31 # include <stl/_locale.h>
34 #ifndef _STLP_INTERNAL_ALGOBASE_H
35 # include <stl/_algobase.h>
40 class _STLP_CLASS_DECLSPEC codecvt_base {
42 enum result {ok, partial, error, noconv};
45 template <class _InternT, class _ExternT, class _StateT>
46 class codecvt : public locale::facet, public codecvt_base {
48 typedef _InternT intern_type;
49 typedef _ExternT extern_type;
50 typedef _StateT state_type;
52 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300)
53 /* For the moment VC6 do not support this facet default implementation
54 * because of the static locale::id instance. When VC6 see this definition
55 * it goes crasy with locale::id static instances and all the has_facet tests
56 * unit tests are failing.
60 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
62 result out(state_type& __state,
63 const intern_type* __from,
64 const intern_type* __from_end,
65 const intern_type*& __from_next,
67 extern_type* __to_limit,
68 extern_type*& __to_next) const {
69 return do_out(__state,
70 __from, __from_end, __from_next,
71 __to, __to_limit, __to_next);
74 result unshift(state_type& __state,
76 extern_type* __to_limit,
77 extern_type*& __to_next) const {
78 return do_unshift(__state, __to, __to_limit, __to_next);
81 result in(state_type& __state,
82 const extern_type* __from,
83 const extern_type* __from_end,
84 const extern_type*& __from_next,
86 intern_type* __to_limit,
87 intern_type*& __to_next) const {
89 __from, __from_end, __from_next,
90 __to, __to_limit, __to_next);
93 int encoding() const _STLP_NOTHROW { return do_encoding(); }
95 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
97 int length(const state_type& __state,
98 const extern_type* __from,
99 const extern_type* __end,
100 size_t __max) const {
101 return do_length(__state, __from, __end, __max);
104 int max_length() const _STLP_NOTHROW { return do_max_length(); }
106 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
111 virtual result do_out(state_type&,
112 const intern_type* __from,
114 const intern_type*& __from_next,
117 extern_type*& __to_next) const
118 { __from_next = __from; __to_next = __to; return noconv; }
120 virtual result do_in (state_type&,
121 const extern_type* __from,
123 const extern_type*& __from_next,
126 intern_type*& __to_next) const
127 { __from_next = __from; __to_next = __to; return noconv; }
129 virtual result do_unshift(state_type&,
132 extern_type*& __to_next) const
133 { __to_next = __to; return noconv; }
135 virtual int do_encoding() const _STLP_NOTHROW
138 virtual bool do_always_noconv() const _STLP_NOTHROW
141 virtual int do_length(const state_type&,
142 const extern_type* __from,
143 const extern_type* __end,
145 { return (int)(min) ( __STATIC_CAST(size_t, (__end - __from)), __max); }
147 virtual int do_max_length() const _STLP_NOTHROW
151 codecvt(const codecvt<intern_type, extern_type, state_type>&);
152 codecvt<intern_type, extern_type, state_type>& operator = (const codecvt<intern_type, extern_type, state_type>&);
155 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
156 # if (_STLP_STATIC_TEMPLATE_DATA > 0)
157 # if !defined (__BORLANDC__)
158 template <class _InternT, class _ExternT, class _StateT>
159 locale::id codecvt<_InternT, _ExternT, _StateT>::id;
165 template <class _InternT, class _ExternT, class _StateT>
166 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {};
169 class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t>
170 : public locale::facet, public codecvt_base
172 friend class _Locale_impl;
175 typedef char intern_type;
176 typedef char extern_type;
177 typedef mbstate_t state_type;
179 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
181 result out(mbstate_t& __state,
183 const char* __from_end,
184 const char*& __from_next,
187 char*& __to_next) const {
188 return do_out(__state,
189 __from, __from_end, __from_next,
190 __to, __to_limit, __to_next);
193 result unshift(mbstate_t& __state,
194 char* __to, char* __to_limit, char*& __to_next) const
195 { return do_unshift(__state, __to, __to_limit, __to_next); }
197 result in(state_type& __state,
199 const char* __from_end,
200 const char*& __from_next,
203 char*& __to_next) const {
204 return do_in(__state,
205 __from, __from_end, __from_next,
206 __to, __to_limit, __to_next);
209 int encoding() const _STLP_NOTHROW { return do_encoding(); }
211 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
213 int length(const state_type& __state,
214 const char* __from, const char* __end,
216 { return do_length(__state, __from, __end, __max); }
218 int max_length() const _STLP_NOTHROW { return do_max_length(); }
220 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
225 virtual result do_out(mbstate_t& /* __state */,
227 const char* /* __from_end */,
228 const char*& __from_next,
230 char* /* __to_limit */,
231 char*& __to_next) const;
233 virtual result do_in (mbstate_t& /* __state */ ,
235 const char* /* __from_end */,
236 const char*& __from_next,
238 char* /* __to_end */,
239 char*& __to_next) const;
241 virtual result do_unshift(mbstate_t& /* __state */,
243 char* /* __to_limit */,
244 char*& __to_next) const;
246 virtual int do_encoding() const _STLP_NOTHROW;
247 virtual bool do_always_noconv() const _STLP_NOTHROW;
248 virtual int do_length(const mbstate_t& __state,
252 virtual int do_max_length() const _STLP_NOTHROW;
254 codecvt(const codecvt<char, char, mbstate_t>&);
255 codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&);
258 # ifndef _STLP_NO_WCHAR_T
261 class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t>
262 : public locale::facet, public codecvt_base
264 friend class _Locale_impl;
266 typedef wchar_t intern_type;
267 typedef char extern_type;
268 typedef mbstate_t state_type;
270 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
272 result out(mbstate_t& __state,
273 const wchar_t* __from,
274 const wchar_t* __from_end,
275 const wchar_t*& __from_next,
278 char*& __to_next) const {
279 return do_out(__state,
280 __from, __from_end, __from_next,
281 __to, __to_limit, __to_next);
284 result unshift(mbstate_t& __state,
285 char* __to, char* __to_limit, char*& __to_next) const {
286 return do_unshift(__state, __to, __to_limit, __to_next);
289 result in(mbstate_t& __state,
291 const char* __from_end,
292 const char*& __from_next,
295 wchar_t*& __to_next) const {
296 return do_in(__state,
297 __from, __from_end, __from_next,
298 __to, __to_limit, __to_next);
301 int encoding() const _STLP_NOTHROW { return do_encoding(); }
303 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
305 int length(const mbstate_t& __state,
306 const char* __from, const char* __end,
308 { return do_length(__state, __from, __end, __max); }
310 int max_length() const _STLP_NOTHROW { return do_max_length(); }
312 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
317 virtual result do_out(mbstate_t& __state,
318 const wchar_t* __from,
319 const wchar_t* __from_end,
320 const wchar_t*& __from_next,
323 char*& __to_next) const;
325 virtual result do_in (mbstate_t& __state,
327 const char* __from_end,
328 const char*& __from_next,
331 wchar_t*& __to_next) const;
333 virtual result do_unshift(mbstate_t& __state,
336 char*& __to_next) const;
338 virtual int do_encoding() const _STLP_NOTHROW;
340 virtual bool do_always_noconv() const _STLP_NOTHROW;
342 virtual int do_length(const mbstate_t& __state,
347 virtual int do_max_length() const _STLP_NOTHROW;
350 codecvt(const codecvt<wchar_t, char, mbstate_t>&);
351 codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);
357 class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t>
358 : public codecvt<char, char, mbstate_t> {
360 explicit codecvt_byname(const char* __name, size_t __refs = 0);
363 codecvt_byname(const codecvt_byname<char, char, mbstate_t>&);
364 codecvt_byname<char, char, mbstate_t>& operator =(const codecvt_byname<char, char, mbstate_t>&);
367 # ifndef _STLP_NO_WCHAR_T
369 class _STLP_CLASS_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>
370 : public codecvt<wchar_t, char, mbstate_t>
373 explicit codecvt_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
378 virtual result do_out(mbstate_t& __state,
379 const wchar_t* __from,
380 const wchar_t* __from_end,
381 const wchar_t*& __from_next,
384 char*& __to_next) const;
386 virtual result do_in (mbstate_t& __state,
388 const char* __from_end,
389 const char*& __from_next,
392 wchar_t*& __to_next) const;
394 virtual result do_unshift(mbstate_t& __state,
397 char*& __to_next) const;
399 virtual int do_encoding() const _STLP_NOTHROW;
401 virtual bool do_always_noconv() const _STLP_NOTHROW;
403 virtual int do_length(const mbstate_t& __state,
408 virtual int do_max_length() const _STLP_NOTHROW;
411 _Locale_ctype* _M_ctype;
412 codecvt_byname(const codecvt_byname<wchar_t, char, mbstate_t>&);
413 codecvt_byname<wchar_t, char, mbstate_t>& operator =(const codecvt_byname<wchar_t, char, mbstate_t>&);
420 #endif /* _STLP_INTERNAL_CODECVT_H */