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.
41 #ifndef _CPP_BITS_CODECVT_H
42 #define _CPP_BITS_CODECVT_H 1
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(const 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(const 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 static locale::id id;
171 codecvt(size_t __refs = 0)
172 : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs) { }
179 do_out(state_type& __state, const intern_type* __from,
180 const intern_type* __from_end, const intern_type*& __from_next,
181 extern_type* __to, extern_type* __to_end,
182 extern_type*& __to_next) const;
185 do_unshift(state_type& __state, extern_type* __to,
186 extern_type* __to_end, extern_type*& __to_next) const;
189 do_in(state_type& __state, const extern_type* __from,
190 const extern_type* __from_end, const extern_type*& __from_next,
191 intern_type* __to, intern_type* __to_end,
192 intern_type*& __to_next) const;
195 do_encoding() const throw();
198 do_always_noconv() const throw();
201 do_length(const state_type&, const extern_type* __from,
202 const extern_type* __end, size_t __max) const;
205 do_max_length() const throw();
208 template<typename _InternT, typename _ExternT, typename _StateT>
209 locale::id codecvt<_InternT, _ExternT, _StateT>::id;
211 // codecvt<char, char, mbstate_t> required specialization
213 class codecvt<char, char, mbstate_t>
214 : public __codecvt_abstract_base<char, char, mbstate_t>
218 typedef char intern_type;
219 typedef char extern_type;
220 typedef mbstate_t state_type;
223 static locale::id id;
226 codecvt(size_t __refs = 0);
233 do_out(state_type& __state, const intern_type* __from,
234 const intern_type* __from_end, const intern_type*& __from_next,
235 extern_type* __to, extern_type* __to_end,
236 extern_type*& __to_next) const;
239 do_unshift(state_type& __state, extern_type* __to,
240 extern_type* __to_end, extern_type*& __to_next) const;
243 do_in(state_type& __state, const extern_type* __from,
244 const extern_type* __from_end, const extern_type*& __from_next,
245 intern_type* __to, intern_type* __to_end,
246 intern_type*& __to_next) const;
249 do_encoding() const throw();
252 do_always_noconv() const throw();
255 do_length(const state_type&, const extern_type* __from,
256 const extern_type* __end, size_t __max) const;
259 do_max_length() const throw();
262 #ifdef _GLIBCPP_USE_WCHAR_T
263 // codecvt<wchar_t, char, mbstate_t> required specialization
265 class codecvt<wchar_t, char, mbstate_t>
266 : public __codecvt_abstract_base<wchar_t, char, mbstate_t>
270 typedef wchar_t intern_type;
271 typedef char extern_type;
272 typedef mbstate_t state_type;
275 static locale::id id;
278 codecvt(size_t __refs = 0);
285 do_out(state_type& __state, const intern_type* __from,
286 const intern_type* __from_end, const intern_type*& __from_next,
287 extern_type* __to, extern_type* __to_end,
288 extern_type*& __to_next) const;
291 do_unshift(state_type& __state,
292 extern_type* __to, extern_type* __to_end,
293 extern_type*& __to_next) const;
296 do_in(state_type& __state,
297 const extern_type* __from, const extern_type* __from_end,
298 const extern_type*& __from_next,
299 intern_type* __to, intern_type* __to_end,
300 intern_type*& __to_next) const;
303 int do_encoding() const throw();
306 bool do_always_noconv() const throw();
309 int do_length(const state_type&, const extern_type* __from,
310 const extern_type* __end, size_t __max) const;
313 do_max_length() const throw();
315 #endif //_GLIBCPP_USE_WCHAR_T
317 // 22.2.1.6 Template class codecvt_byname
318 template<typename _InternT, typename _ExternT, typename _StateT>
319 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
323 codecvt_byname(const char*, size_t __refs = 0)
324 : codecvt<_InternT, _ExternT, _StateT>(__refs) { }
328 ~codecvt_byname() { }
331 // Include host and configuration specific partial specializations
332 // with additional functionality, if possible.
333 #ifdef _GLIBCPP_USE_WCHAR_T
334 #include <bits/codecvt_specializations.h>
337 #endif // _CPP_BITS_CODECVT_H