1 // Locale support (codecvt) -*- C++ -*-
3 // Copyright (C) 2000, 2001 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 // Warning: this file is not meant for user inclusion. Use <locale>.
36 // Written by Benjamin Kosnik <bkoz@cygnus.com>
38 #ifndef _CPP_BITS_CODECVT_H
39 #define _CPP_BITS_CODECVT_H 1
41 #pragma GCC system_header
43 // 22.2.1.5 Template class codecvt
56 // Template class __codecvt_abstract_base
57 // NB: An abstract base class that fills in the public inlines, so
58 // that the specializations don't have to re-copy the public
60 template<typename _InternT, typename _ExternT, typename _StateT>
61 class __codecvt_abstract_base
62 : public locale::facet, public codecvt_base
66 typedef codecvt_base::result result;
67 typedef _InternT intern_type;
68 typedef _ExternT extern_type;
69 typedef _StateT state_type;
71 // 22.2.1.5.1 codecvt members
73 out(state_type& __state, const intern_type* __from,
74 const intern_type* __from_end, const intern_type*& __from_next,
75 extern_type* __to, extern_type* __to_end,
76 extern_type*& __to_next) const
78 return this->do_out(__state, __from, __from_end, __from_next,
79 __to, __to_end, __to_next);
83 unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
84 extern_type*& __to_next) const
85 { return this->do_unshift(__state, __to,__to_end,__to_next); }
88 in(state_type& __state, const extern_type* __from,
89 const extern_type* __from_end, const extern_type*& __from_next,
90 intern_type* __to, intern_type* __to_end,
91 intern_type*& __to_next) const
93 return this->do_in(__state, __from, __from_end, __from_next,
94 __to, __to_end, __to_next);
98 encoding() const throw()
99 { return this->do_encoding(); }
102 always_noconv() const throw()
103 { return this->do_always_noconv(); }
106 length(const state_type& __state, const extern_type* __from,
107 const extern_type* __end, size_t __max) const
108 { return this->do_length(__state, __from, __end, __max); }
111 max_length() const throw()
112 { return this->do_max_length(); }
116 __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
119 ~__codecvt_abstract_base() { }
122 do_out(state_type& __state, const intern_type* __from,
123 const intern_type* __from_end, const intern_type*& __from_next,
124 extern_type* __to, extern_type* __to_end,
125 extern_type*& __to_next) const = 0;
128 do_unshift(state_type& __state, extern_type* __to,
129 extern_type* __to_end, extern_type*& __to_next) const = 0;
132 do_in(state_type& __state, const extern_type* __from,
133 const extern_type* __from_end, const extern_type*& __from_next,
134 intern_type* __to, intern_type* __to_end,
135 intern_type*& __to_next) const = 0;
138 do_encoding() const throw() = 0;
141 do_always_noconv() const throw() = 0;
144 do_length(const state_type&, const extern_type* __from,
145 const extern_type* __end, size_t __max) const = 0;
148 do_max_length() const throw() = 0;
151 // 22.2.1.5 Template class codecvt
152 // NB: Generic, mostly useless implementation.
153 template<typename _InternT, typename _ExternT, typename _StateT>
155 : public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
159 typedef codecvt_base::result result;
160 typedef _InternT intern_type;
161 typedef _ExternT extern_type;
162 typedef _StateT state_type;
165 static locale::id id;
168 codecvt(size_t __refs = 0)
169 : __codecvt_abstract_base<_InternT,_ExternT,_StateT> (__refs) { }
176 template<typename _InternT, typename _ExternT, typename _StateT>
177 locale::id codecvt<_InternT, _ExternT, _StateT>::id;
179 // codecvt<char, char, mbstate_t> required specialization
181 class codecvt<char, char, mbstate_t>
182 : public __codecvt_abstract_base<char, char, mbstate_t>
186 typedef char intern_type;
187 typedef char extern_type;
188 typedef mbstate_t state_type;
191 static locale::id id;
194 codecvt(size_t __refs = 0);
201 do_out(state_type& __state, const intern_type* __from,
202 const intern_type* __from_end, const intern_type*& __from_next,
203 extern_type* __to, extern_type* __to_end,
204 extern_type*& __to_next) const;
207 do_unshift(state_type& __state, extern_type* __to,
208 extern_type* __to_end, extern_type*& __to_next) const;
211 do_in(state_type& __state, const extern_type* __from,
212 const extern_type* __from_end, const extern_type*& __from_next,
213 intern_type* __to, intern_type* __to_end,
214 intern_type*& __to_next) const;
217 do_encoding() const throw();
220 do_always_noconv() const throw();
223 do_length(const state_type&, const extern_type* __from,
224 const extern_type* __end, size_t __max) const;
227 do_max_length() const throw();
230 #ifdef _GLIBCPP_USE_WCHAR_T
231 // codecvt<wchar_t, char, mbstate_t> required specialization
233 class codecvt<wchar_t, char, mbstate_t>
234 : public __codecvt_abstract_base<wchar_t, char, mbstate_t>
238 typedef wchar_t intern_type;
239 typedef char extern_type;
240 typedef mbstate_t state_type;
243 static locale::id id;
246 codecvt(size_t __refs = 0);
253 do_out(state_type& __state, const intern_type* __from,
254 const intern_type* __from_end, const intern_type*& __from_next,
255 extern_type* __to, extern_type* __to_end,
256 extern_type*& __to_next) const;
259 do_unshift(state_type& __state,
260 extern_type* __to, extern_type* __to_end,
261 extern_type*& __to_next) const;
264 do_in(state_type& __state,
265 const extern_type* __from, const extern_type* __from_end,
266 const extern_type*& __from_next,
267 intern_type* __to, intern_type* __to_end,
268 intern_type*& __to_next) const;
271 int do_encoding() const throw();
274 bool do_always_noconv() const throw();
277 int do_length(const state_type&, const extern_type* __from,
278 const extern_type* __end, size_t __max) const;
281 do_max_length() const throw();
283 #endif //_GLIBCPP_USE_WCHAR_T
285 // 22.2.1.6 Template class codecvt_byname
286 template<typename _InternT, typename _ExternT, typename _StateT>
287 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
291 codecvt_byname(const char*, size_t __refs = 0)
292 : codecvt<_InternT, _ExternT, _StateT>(__refs) { }
295 ~codecvt_byname() { }
298 // Include host and configuration specific partial specializations
299 // with additional functionality, if possible.
300 #ifdef _GLIBCPP_USE_WCHAR_T
301 #include <bits/codecvt_specializations.h>
304 #endif // _CPP_BITS_CODECVT_H