Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_codecvt.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_LOC_CODECVT_H_INCLUDED
33#define _RWSTD_LOC_CODECVT_H_INCLUDED
34
35
36#include <rw/_defs.h>
37#include <loc/_facet.h>
38#include <rw/_mbstate.h> // for _RWSTD_MBSTATE_T
39
40
42
43struct __rw_ctype_t;
44
45} // namespace __rw
46
48
49// 22.2.1.5 - Template class codecvt
50
51struct codecvt_base
52{
53 enum result { ok, partial, error, noconv };
54};
55
56
58template <class _InternT, class _ExternT, class _StateT>
59class codecvt;
60
61
62#ifndef _RWSTD_NO_EXT_CODECVT_PRIMARY
63
65template <class _InternT, class _ExternT, class _StateT>
66class codecvt: public _RW::__rw_facet,
67 public codecvt_base
68{
69public:
70 typedef _InternT intern_type;
71 typedef _ExternT extern_type;
72 typedef _StateT state_type;
73
74protected:
75
76 // extension: where reasonable, the default behavior of the primary
77 // template is the same as that of codecvt<char, char, mbstate_t> if
78 // sizeof (intern_type) == sizeof (extern_type) to allow iostream
79 // instantiations on signed char or unsigned char to have somewhat
80 // meaningful behavior
81
82 virtual result
83 do_out (state_type&,
84 const intern_type*, const intern_type*, const intern_type*&,
85 extern_type*, extern_type*, extern_type*&) const {
86 return sizeof (intern_type) == sizeof (extern_type) ? noconv : error;
87 }
88
89 virtual result
90 do_in (state_type&,
91 const extern_type*, const extern_type*, const extern_type*&,
92 intern_type*, intern_type*, intern_type*&) const {
93 return sizeof (intern_type) == sizeof (extern_type) ? noconv : error;
94 }
95
96 virtual result
97 do_unshift (state_type&, extern_type*, extern_type*, extern_type*&) const {
98 return sizeof (intern_type) == sizeof (extern_type) ? noconv : error;
99 }
100
101 virtual int do_encoding () const _THROWS (()) {
102 return -1; // unknown, possibly state dependent
103 }
104
105 virtual bool do_always_noconv () const _THROWS (()) {
106 return sizeof (intern_type) == sizeof (extern_type);
107 }
108
109 virtual int do_max_length () const _THROWS (()) {
110 return _RWSTD_INT_MAX;
111 }
112
113 virtual int
114 do_length (state_type&,
115 const extern_type*, const extern_type*, _RWSTD_SIZE_T) const {
116 return _RWSTD_INT_MAX;
117 }
118
119public:
120
121 explicit codecvt (_RWSTD_SIZE_T __ref = 0): _RW::__rw_facet (__ref) { }
122
123 virtual ~codecvt () _RWSTD_ATTRIBUTE_NOTHROW;
124
125 // 22,2,1,5,1, p1
126 result out (state_type& __state,
127 const intern_type* __from, const intern_type* __from_end,
128 const intern_type*& __from_next,
129 extern_type* __to, extern_type* __to_limit,
130 extern_type*& __to_next) const {
131 return do_out(__state,__from,__from_end,__from_next,
132 __to,__to_limit,__to_next);
133 }
134
135 // 22,2,1,5,1, p2
136 result unshift (state_type& __state, extern_type* __to,
137 extern_type* __to_limit, extern_type*& __to_next) const {
138 return do_unshift (__state,__to,__to_limit,__to_next);
139 }
140
141 // 22,2,1,5,1, p3
142 result in (state_type& __state, const extern_type* __from,
143 const extern_type* __from_end, const extern_type*& __from_next,
144 intern_type* __to, intern_type* __to_limit,
145 intern_type*& __to_next) const {
146 return do_in (__state,__from,__from_end,__from_next,
147 __to,__to_limit,__to_next);
148 }
149
150 // 22,2,1,5,1, p5
151 bool always_noconv () const _THROWS (()) {
152 return do_always_noconv();
153 }
154
155 // 22,2,1,5,1, p4
156 int encoding () const _THROWS (()) {
157 return do_encoding();
158 }
159
160 // 22,2,1,5,1, p6, lwg issue 75
161 int length (state_type& __state, const extern_type* __from,
162 const extern_type* __end, _RWSTD_SIZE_T __maxlen) const {
163 return do_length (__state, __from, __end, __maxlen);
164 }
165
166 // 22,2,1,5,1, p7
167 int max_length() const _THROWS (()) {
168 return do_max_length();
169 }
170
171 static _RW::__rw_facet_id id;
172
173};
174
175#endif // _RWSTD_NO_EXT_CODECVT_PRIMARY
176
177
178// 22.2.1.5, p3 - performs no conversion
179
181class _RWSTD_EXPORT codecvt<char, char, _RWSTD_MBSTATE_T>
182 : public _RW::__rw_facet,
183 public codecvt_base
184{
185public:
186
187 typedef char extern_type;
188 typedef char intern_type;
189 typedef _RWSTD_MBSTATE_T state_type;
190
191 explicit codecvt (_RWSTD_SIZE_T = 0);
192
193 virtual ~codecvt () _RWSTD_ATTRIBUTE_NOTHROW;
194
195 result out (state_type &__state,
196 const intern_type *__from, const intern_type* __from_end,
197 const intern_type *&__from_next,
198 extern_type* __to, extern_type* __to_limit,
199 extern_type *&__to_next) const {
200 return do_out (__state, __from, __from_end, __from_next,
201 __to, __to_limit, __to_next);
202 }
203
204 result unshift (state_type &__state,
205 extern_type *__to, extern_type *__to_limit,
206 extern_type*& __to_next) const {
207 return do_unshift (__state, __to, __to_limit, __to_next);
208 }
209
210 result in (state_type &__state,
211 const extern_type *__from, const extern_type *__from_end,
212 const extern_type *&__from_next,
213 intern_type *__to, intern_type *__to_limit,
214 intern_type *&__to_next) const {
215 return do_in (__state, __from, __from_end, __from_next,
216 __to, __to_limit, __to_next);
217 }
218
219 int encoding () const _THROWS (()) {
220 return do_encoding ();
221 }
222
223 bool always_noconv () const _THROWS (());
224
225 // signature follows lwg issue 75
226 int length (state_type &__state, const extern_type *__from,
227 const extern_type *__end, _RWSTD_SIZE_T __maxlen) const {
228 return do_length (__state, __from, __end, __maxlen);
229 }
230
231 int max_length () const _THROWS (()) {
232 return do_max_length ();
233 }
234
235 static _RW::__rw_facet_id id;
236
237protected:
238
239 virtual result
240 do_out (state_type&,
241 const intern_type*, const intern_type*, const intern_type*&,
242 extern_type*, extern_type*, extern_type*&) const;
243
244 virtual result
245 do_in (state_type&,
246 const extern_type*, const extern_type*, const extern_type*&,
247 intern_type*, intern_type*, intern_type*&) const;
248
249 // 22.2.1.5.2, p5 - stores no characters
250 virtual result
251 do_unshift (state_type&,
252 extern_type*, extern_type*, extern_type*&) const;
253
254 virtual int do_encoding () const _THROWS (());
255
256 virtual bool do_always_noconv () const _THROWS (());
257
258 // signature follows lwg issue 75
259 virtual int
260 do_length (state_type&,
261 const extern_type*, const extern_type*, _RWSTD_SIZE_T) const;
262
263 virtual int do_max_length () const _THROWS (());
264
265private:
266
267 int _C_always_noconv; // cached value
268};
269
270
271inline bool
272codecvt<char, char, _RWSTD_MBSTATE_T>::
273always_noconv () const _THROWS (())
274{
275 // optimize away repeated calls to the virtual function
276 if (_C_always_noconv < 0) {
277
278 // typedef works around an HP aCC x.38 bug (PR #25832)
279 typedef codecvt<char, char, _RWSTD_MBSTATE_T> _CodeCvt;
280
281 _CodeCvt *__self = _RWSTD_CONST_CAST (_CodeCvt*, this);
282
283 __self->_C_always_noconv = do_always_noconv ();
284 }
285
286 return 1 == _C_always_noconv;
287}
288
289
290#ifndef _RWSTD_NO_WCHAR_T
291
292// 22.2.1.5, p3 - converts between wide and narrow characters
293// of the native character set (i.e., widens and narrows)
294
296class _RWSTD_EXPORT codecvt<wchar_t, char, _RWSTD_MBSTATE_T>
297 : public _RW::__rw_facet,
298 public codecvt_base
299{
300public:
301
302 typedef wchar_t intern_type;
303 typedef char extern_type;
304 typedef _RWSTD_MBSTATE_T state_type;
305
306protected:
307
308 virtual result
309 do_out (state_type&, const intern_type*, const intern_type*,
310 const intern_type*&,
311 extern_type*, extern_type*, extern_type*&) const;
312
313 virtual result
314 do_in (state_type&,
315 const extern_type*, const extern_type*, const extern_type*&,
316 intern_type*, intern_type*, intern_type*&) const;
317
318 // 22.2.1.5.2, p5 - stores no characters
319 virtual result
320 do_unshift (state_type&, extern_type*, extern_type*, extern_type*&) const;
321
322 virtual bool do_always_noconv () const _THROWS (());
323
324 virtual int do_encoding () const _THROWS (());
325
326 // signature follows lwg issue 75
327 virtual int
328 do_length (state_type&,
329 const extern_type*, const extern_type*, _RWSTD_SIZE_T) const;
330
331 virtual int do_max_length () const _THROWS (());
332
333public:
334
335 explicit codecvt (_RWSTD_SIZE_T = 0);
336
337 virtual ~codecvt () _RWSTD_ATTRIBUTE_NOTHROW;
338
339 result out (state_type& __state,
340 const intern_type *__from, const intern_type *__from_end,
341 const intern_type *&__from_next,
342 extern_type *__to, extern_type* __to_limit,
343 extern_type *& __to_next) const {
344 return do_out (__state, __from, __from_end, __from_next, __to,
345 __to_limit, __to_next);
346 }
347
348 result unshift (state_type &__state,
349 extern_type *__to, extern_type *__to_limit,
350 extern_type *&__to_next) const {
351 return do_unshift (__state, __to, __to_limit, __to_next);
352 }
353
354 result in (state_type& __state,
355 const extern_type *__from, const extern_type *__from_end,
356 const extern_type *&__from_next,
357 intern_type *__to, intern_type *__to_limit,
358 intern_type *&__to_next) const {
359 return do_in (__state, __from, __from_end, __from_next,
360 __to, __to_limit, __to_next);
361 }
362
363 int encoding () const _THROWS (()) {
364 return do_encoding();
365 }
366
367 bool always_noconv () const _THROWS (()) {
368 return do_always_noconv ();
369 }
370
371 // signature follows lwg issue 75
372 int length (state_type &__state,
373 const extern_type *__from, const extern_type *__end,
374 _RWSTD_SIZE_T __maxlen) const {
375 return do_length (__state, __from, __end, __maxlen);
376 }
377
378 int max_length () const _THROWS (()) {
379 return do_max_length ();
380 }
381
382 static _RW::__rw_facet_id id;
383};
384
385
386#endif // _RWSTD_NO_WCHAR_T
387
388
389// 22.2.1.6
390template <class _InternT, class _ExternT, class _StateT>
391class codecvt_byname: public codecvt<_InternT, _ExternT, _StateT>
392{
393 char _C_namebuf [32];
394
395public:
396
397 typedef _InternT intern_type;
398 typedef _ExternT extern_type;
399 typedef _StateT state_type;
400
401 explicit codecvt_byname (const char *__name, _RWSTD_SIZE_T __ref = 0)
402 : codecvt <_InternT, _ExternT, _StateT> (__ref) {
403 this->_C_set_name (__name, _C_namebuf, sizeof _C_namebuf);
404 }
405
406 virtual ~codecvt_byname () _RWSTD_ATTRIBUTE_NOTHROW;
407};
408
409
411class _RWSTD_EXPORT codecvt_byname<char, char, _RWSTD_MBSTATE_T>
412 : public codecvt<char, char, _RWSTD_MBSTATE_T>
413{
414 char _C_namebuf [32];
415
416public:
417
418 explicit codecvt_byname (const char*, _RWSTD_SIZE_T = 0);
419
420 virtual ~codecvt_byname () _RWSTD_ATTRIBUTE_NOTHROW;
421};
422
423
424
425#ifndef _RWSTD_NO_WCHAR_T
426
428class _RWSTD_EXPORT codecvt_byname<wchar_t, char, _RWSTD_MBSTATE_T>
429 : public codecvt<wchar_t, char, _RWSTD_MBSTATE_T>
430{
431 char _C_namebuf [32];
432
433 unsigned _C_flags;
434
435public:
436
437 explicit codecvt_byname (const char*, _RWSTD_SIZE_T = 0);
438
439 virtual ~codecvt_byname () _RWSTD_ATTRIBUTE_NOTHROW;
440
441protected:
442
443 virtual codecvt_base::result
444 do_out (state_type&,
445 const intern_type*, const intern_type*, const intern_type*&,
446 extern_type*, extern_type*, extern_type*&) const;
447
448 virtual codecvt_base::result
449 do_in (state_type&,
450 const extern_type*, const extern_type*, const extern_type*&,
451 intern_type*, intern_type*, intern_type*&) const;
452
453
454 virtual codecvt_base::result
455 do_unshift (state_type&,
456 extern_type*, extern_type*, extern_type*&) const;
457
458 virtual int do_encoding () const _THROWS (());
459
460 // signature follows lwg issue 75
461 virtual int
462 do_length (state_type&, const extern_type*, const extern_type*,
463 _RWSTD_SIZE_T) const;
464
465 virtual int do_max_length () const _THROWS (());
466};
467
468
469#endif // _RWSTD_NO_WCHAR_T
470
471
472} // namespace std
473
474
475#if _RWSTD_DEFINE_TEMPLATE (_CODECVT)
476# include <loc/_codecvt.cc>
477#endif // _RWSTD_DEFINE_TEMPLATE (_CODECVT)
478
479
480#endif // _RWSTD_LOC_CODECVT_H_INCLUDED
volatile int result
@ do_always_noconv
@ do_encoding
@ do_max_length
const int out
const int in
#define _RWSTD_SPECIALIZED_CLASS
#define _THROWS()
unsigned short wchar_t
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ATTRIBUTE_NOTHROW
Definition _defs.h:1179
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
#define _RWSTD_MBSTATE_T
Definition _mbstate.h:199
Definition json.h:5363