1 // Locale support (codecvt) -*- C++ -*-
3 // Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 22.2.1.5 Template class codecvt
34 // Written by Benjamin Kosnik <bkoz@cygnus.com>
37 * This is an internal header file, included by other library headers.
38 * You should not attempt to use it directly.
44 #pragma GCC system_header
46 // 22.2.1.5 Template class codecvt
59 // Template class __codecvt_abstract_base
60 // NB: An abstract base class that fills in the public inlines, so
61 // that the specializations don't have to re-copy the public
63 template<typename _InternT
, typename _ExternT
, typename _StateT
>
64 class __codecvt_abstract_base
65 : public locale::facet
, public codecvt_base
69 typedef codecvt_base::result result
;
70 typedef _InternT intern_type
;
71 typedef _ExternT extern_type
;
72 typedef _StateT state_type
;
74 // 22.2.1.5.1 codecvt members
76 out(state_type
& __state
, const intern_type
* __from
,
77 const intern_type
* __from_end
, const intern_type
*& __from_next
,
78 extern_type
* __to
, extern_type
* __to_end
,
79 extern_type
*& __to_next
) const
81 return this->do_out(__state
, __from
, __from_end
, __from_next
,
82 __to
, __to_end
, __to_next
);
86 unshift(state_type
& __state
, extern_type
* __to
, extern_type
* __to_end
,
87 extern_type
*& __to_next
) const
88 { return this->do_unshift(__state
, __to
,__to_end
,__to_next
); }
91 in(state_type
& __state
, const extern_type
* __from
,
92 const extern_type
* __from_end
, const extern_type
*& __from_next
,
93 intern_type
* __to
, intern_type
* __to_end
,
94 intern_type
*& __to_next
) const
96 return this->do_in(__state
, __from
, __from_end
, __from_next
,
97 __to
, __to_end
, __to_next
);
101 encoding() const throw()
102 { return this->do_encoding(); }
105 always_noconv() const throw()
106 { return this->do_always_noconv(); }
109 length(state_type
& __state
, const extern_type
* __from
,
110 const extern_type
* __end
, size_t __max
) const
111 { return this->do_length(__state
, __from
, __end
, __max
); }
114 max_length() const throw()
115 { return this->do_max_length(); }
119 __codecvt_abstract_base(size_t __refs
= 0) : locale::facet(__refs
) { }
122 ~__codecvt_abstract_base() { }
125 do_out(state_type
& __state
, const intern_type
* __from
,
126 const intern_type
* __from_end
, const intern_type
*& __from_next
,
127 extern_type
* __to
, extern_type
* __to_end
,
128 extern_type
*& __to_next
) const = 0;
131 do_unshift(state_type
& __state
, extern_type
* __to
,
132 extern_type
* __to_end
, extern_type
*& __to_next
) const = 0;
135 do_in(state_type
& __state
, const extern_type
* __from
,
136 const extern_type
* __from_end
, const extern_type
*& __from_next
,
137 intern_type
* __to
, intern_type
* __to_end
,
138 intern_type
*& __to_next
) const = 0;
141 do_encoding() const throw() = 0;
144 do_always_noconv() const throw() = 0;
147 do_length(state_type
&, const extern_type
* __from
,
148 const extern_type
* __end
, size_t __max
) const = 0;
151 do_max_length() const throw() = 0;
154 // 22.2.1.5 Template class codecvt
155 // NB: Generic, mostly useless implementation.
156 template<typename _InternT
, typename _ExternT
, typename _StateT
>
158 : public __codecvt_abstract_base
<_InternT
, _ExternT
, _StateT
>
162 typedef codecvt_base::result result
;
163 typedef _InternT intern_type
;
164 typedef _ExternT extern_type
;
165 typedef _StateT state_type
;
168 __c_locale _M_c_locale_codecvt
;
171 static locale::id id
;
174 codecvt(size_t __refs
= 0)
175 : __codecvt_abstract_base
<_InternT
, _ExternT
, _StateT
> (__refs
) { }
178 codecvt(__c_locale __cloc
, size_t __refs
= 0);
185 do_out(state_type
& __state
, const intern_type
* __from
,
186 const intern_type
* __from_end
, const intern_type
*& __from_next
,
187 extern_type
* __to
, extern_type
* __to_end
,
188 extern_type
*& __to_next
) const;
191 do_unshift(state_type
& __state
, extern_type
* __to
,
192 extern_type
* __to_end
, extern_type
*& __to_next
) const;
195 do_in(state_type
& __state
, const extern_type
* __from
,
196 const extern_type
* __from_end
, const extern_type
*& __from_next
,
197 intern_type
* __to
, intern_type
* __to_end
,
198 intern_type
*& __to_next
) const;
201 do_encoding() const throw();
204 do_always_noconv() const throw();
207 do_length(state_type
&, const extern_type
* __from
,
208 const extern_type
* __end
, size_t __max
) const;
211 do_max_length() const throw();
214 template<typename _InternT
, typename _ExternT
, typename _StateT
>
215 locale::id codecvt
<_InternT
, _ExternT
, _StateT
>::id
;
217 // codecvt<char, char, mbstate_t> required specialization
219 class codecvt
<char, char, mbstate_t>
220 : public __codecvt_abstract_base
<char, char, mbstate_t>
224 typedef char intern_type
;
225 typedef char extern_type
;
226 typedef mbstate_t state_type
;
229 __c_locale _M_c_locale_codecvt
;
232 static locale::id id
;
235 codecvt(size_t __refs
= 0);
238 codecvt(__c_locale __cloc
, size_t __refs
= 0);
245 do_out(state_type
& __state
, const intern_type
* __from
,
246 const intern_type
* __from_end
, const intern_type
*& __from_next
,
247 extern_type
* __to
, extern_type
* __to_end
,
248 extern_type
*& __to_next
) const;
251 do_unshift(state_type
& __state
, extern_type
* __to
,
252 extern_type
* __to_end
, extern_type
*& __to_next
) const;
255 do_in(state_type
& __state
, const extern_type
* __from
,
256 const extern_type
* __from_end
, const extern_type
*& __from_next
,
257 intern_type
* __to
, intern_type
* __to_end
,
258 intern_type
*& __to_next
) const;
261 do_encoding() const throw();
264 do_always_noconv() const throw();
267 do_length(state_type
&, const extern_type
* __from
,
268 const extern_type
* __end
, size_t __max
) const;
271 do_max_length() const throw();
274 #ifdef _GLIBCXX_USE_WCHAR_T
275 // codecvt<wchar_t, char, mbstate_t> required specialization
277 class codecvt
<wchar_t, char, mbstate_t>
278 : public __codecvt_abstract_base
<wchar_t, char, mbstate_t>
282 typedef wchar_t intern_type
;
283 typedef char extern_type
;
284 typedef mbstate_t state_type
;
287 __c_locale _M_c_locale_codecvt
;
290 static locale::id id
;
293 codecvt(size_t __refs
= 0);
296 codecvt(__c_locale __cloc
, size_t __refs
= 0);
303 do_out(state_type
& __state
, const intern_type
* __from
,
304 const intern_type
* __from_end
, const intern_type
*& __from_next
,
305 extern_type
* __to
, extern_type
* __to_end
,
306 extern_type
*& __to_next
) const;
309 do_unshift(state_type
& __state
,
310 extern_type
* __to
, extern_type
* __to_end
,
311 extern_type
*& __to_next
) const;
314 do_in(state_type
& __state
,
315 const extern_type
* __from
, const extern_type
* __from_end
,
316 const extern_type
*& __from_next
,
317 intern_type
* __to
, intern_type
* __to_end
,
318 intern_type
*& __to_next
) const;
321 int do_encoding() const throw();
324 bool do_always_noconv() const throw();
327 int do_length(state_type
&, const extern_type
* __from
,
328 const extern_type
* __end
, size_t __max
) const;
331 do_max_length() const throw();
333 #endif //_GLIBCXX_USE_WCHAR_T
335 // 22.2.1.6 Template class codecvt_byname
336 template<typename _InternT
, typename _ExternT
, typename _StateT
>
337 class codecvt_byname
: public codecvt
<_InternT
, _ExternT
, _StateT
>
341 codecvt_byname(const char* __s
, size_t __refs
= 0)
342 : codecvt
<_InternT
, _ExternT
, _StateT
>(__refs
)
344 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
346 _S_destroy_c_locale(this->_M_c_locale_codecvt
);
347 _S_create_c_locale(this->_M_c_locale_codecvt
, __s
);
353 ~codecvt_byname() { }
356 // Include host and configuration specific partial specializations
357 // with additional functionality, if possible.
358 #ifdef _GLIBCXX_USE_WCHAR_T
359 #include <bits/codecvt_specializations.h>