]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_codecvt.h
Add STLport 5.1.4
[polintos/scott/priv.git] / include / c++ / stl / stl / _codecvt.h
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
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.
16  *
17  */
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers.  You should not attempt to use this header
20 // file directly.
21
22
23 #ifndef _STLP_INTERNAL_CODECVT_H
24 #define _STLP_INTERNAL_CODECVT_H
25
26 #ifndef _STLP_C_LOCALE_H
27 #  include <stl/c_locale.h>
28 #endif
29
30 #ifndef _STLP_INTERNAL_LOCALE_H
31 #  include <stl/_locale.h>
32 #endif
33
34 #ifndef _STLP_INTERNAL_ALGOBASE_H
35 #  include <stl/_algobase.h>
36 #endif
37
38 _STLP_BEGIN_NAMESPACE
39
40 class _STLP_CLASS_DECLSPEC codecvt_base {
41 public:
42   enum result {ok, partial, error, noconv};
43 };
44
45 template <class _InternT, class _ExternT, class _StateT>
46 class codecvt : public locale::facet, public codecvt_base {
47 public:
48   typedef _InternT intern_type;
49   typedef _ExternT extern_type;
50   typedef _StateT state_type;
51
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.
57    */
58 };
59 #else
60   explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
61
62   result out(state_type&          __state,
63              const intern_type*   __from,
64              const intern_type*   __from_end,
65              const intern_type*&  __from_next,
66              extern_type*         __to,
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);
72   }
73
74   result unshift(state_type&    __state,
75                  extern_type*   __to,
76                  extern_type*   __to_limit,
77                  extern_type*&  __to_next) const {
78     return do_unshift(__state, __to, __to_limit, __to_next);
79   }
80
81   result in(state_type&         __state,
82             const extern_type*  __from,
83             const extern_type*  __from_end,
84             const extern_type*& __from_next,
85             intern_type*        __to,
86             intern_type*        __to_limit,
87             intern_type*&       __to_next) const {
88     return do_in(__state,
89                  __from, __from_end, __from_next,
90                  __to,  __to_limit, __to_next);
91   }
92
93   int encoding() const _STLP_NOTHROW { return do_encoding(); }
94
95   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
96
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);
102   }
103
104   int max_length() const _STLP_NOTHROW { return do_max_length(); }
105
106   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
107
108 protected:
109   ~codecvt() {}
110
111   virtual result do_out(state_type&,
112                         const intern_type*  __from,
113                         const intern_type*,
114                         const intern_type*& __from_next,
115                         extern_type*        __to,
116                         extern_type*,
117                         extern_type*&       __to_next) const
118   { __from_next = __from; __to_next   = __to; return noconv; }
119
120   virtual result do_in (state_type&,
121                         const extern_type*  __from,
122                         const extern_type*,
123                         const extern_type*& __from_next,
124                         intern_type*        __to,
125                         intern_type*,
126                         intern_type*&       __to_next) const
127   { __from_next = __from; __to_next = __to; return noconv; }
128
129   virtual result do_unshift(state_type&,
130                             extern_type* __to,
131                             extern_type*,
132                             extern_type*& __to_next) const
133   { __to_next = __to; return noconv; }
134
135   virtual int do_encoding() const _STLP_NOTHROW
136   { return 1; }
137
138   virtual bool do_always_noconv() const _STLP_NOTHROW
139   { return true; }
140
141   virtual int do_length(const state_type&,
142                         const extern_type* __from,
143                         const extern_type* __end,
144                         size_t __max) const
145   { return (int)(min) ( __STATIC_CAST(size_t, (__end - __from)), __max); }
146
147   virtual int do_max_length() const _STLP_NOTHROW
148   { return 1; }
149
150 private:
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>&);
153 };
154
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;
160 #      endif
161 #    endif
162 #  endif
163 #endif
164
165 template <class _InternT, class _ExternT, class _StateT>
166 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {};
167
168 _STLP_TEMPLATE_NULL
169 class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t>
170   : public locale::facet, public codecvt_base
171 {
172   friend class _Locale_impl;
173
174 public:
175   typedef char       intern_type;
176   typedef char       extern_type;
177   typedef mbstate_t  state_type;
178
179   explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
180
181   result out(mbstate_t&   __state,
182              const char*  __from,
183              const char*  __from_end,
184              const char*& __from_next,
185              char*        __to,
186              char*        __to_limit,
187              char*&       __to_next) const {
188     return do_out(__state,
189                   __from, __from_end, __from_next,
190                   __to,   __to_limit, __to_next);
191   }
192
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); }
196
197   result in(state_type&   __state,
198             const char*  __from,
199             const char*  __from_end,
200             const char*& __from_next,
201             char*        __to,
202             char*        __to_limit,
203             char*&       __to_next) const {
204     return do_in(__state,
205                  __from, __from_end, __from_next,
206                  __to,   __to_limit, __to_next);
207   }
208
209   int encoding() const _STLP_NOTHROW { return do_encoding(); }
210
211   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
212
213   int length(const state_type& __state,
214              const char* __from, const char* __end,
215              size_t __max) const
216     { return do_length(__state, __from, __end, __max); }
217
218   int max_length() const _STLP_NOTHROW { return do_max_length(); }
219
220   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
221
222 protected:
223   ~codecvt();
224
225   virtual result do_out(mbstate_t&   /* __state */,
226                         const char*  __from,
227                         const char*  /* __from_end */,
228                         const char*& __from_next,
229                         char*        __to,
230                         char*        /* __to_limit */,
231                         char*&       __to_next) const;
232
233   virtual result do_in (mbstate_t&   /* __state */ ,
234                         const char*  __from,
235                         const char*  /* __from_end */,
236                         const char*& __from_next,
237                         char*        __to,
238                         char*        /* __to_end */,
239                         char*&       __to_next) const;
240
241   virtual result do_unshift(mbstate_t& /* __state */,
242                             char*      __to,
243                             char*      /* __to_limit */,
244                             char*&     __to_next) const;
245
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,
249                         const  char* __from,
250                         const  char* __end,
251                         size_t __max) const;
252   virtual int do_max_length() const _STLP_NOTHROW;
253 private:
254   codecvt(const codecvt<char, char, mbstate_t>&);
255   codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&);
256 };
257
258 # ifndef _STLP_NO_WCHAR_T
259
260 _STLP_TEMPLATE_NULL
261 class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t>
262   : public locale::facet, public codecvt_base
263 {
264   friend class _Locale_impl;
265 public:
266   typedef wchar_t    intern_type;
267   typedef char       extern_type;
268   typedef mbstate_t  state_type;
269
270   explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
271
272   result out(mbstate_t&      __state,
273              const wchar_t*  __from,
274              const wchar_t*  __from_end,
275              const wchar_t*& __from_next,
276              char*           __to,
277              char*           __to_limit,
278              char*&          __to_next) const {
279     return do_out(__state,
280                   __from, __from_end, __from_next,
281                   __to,   __to_limit, __to_next);
282   }
283
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);
287   }
288
289   result in(mbstate_t&   __state,
290             const char*  __from,
291             const char*  __from_end,
292             const char*& __from_next,
293             wchar_t*     __to,
294             wchar_t*     __to_limit,
295             wchar_t*&    __to_next) const {
296     return do_in(__state,
297                  __from, __from_end, __from_next,
298                  __to,   __to_limit, __to_next);
299   }
300
301   int encoding() const _STLP_NOTHROW { return do_encoding(); }
302
303   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
304
305   int length(const mbstate_t& __state,
306              const char* __from, const char* __end,
307              size_t __max) const
308     { return do_length(__state, __from, __end, __max); }
309
310   int max_length() const _STLP_NOTHROW { return do_max_length(); }
311
312   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
313
314 protected:
315   ~codecvt();
316
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,
321                         char*        __to,
322                         char*        __to_limit,
323                         char*&       __to_next) const;
324
325   virtual result do_in (mbstate_t&         __state,
326                         const char*  __from,
327                         const char*  __from_end,
328                         const char*& __from_next,
329                         wchar_t*        __to,
330                         wchar_t*        __to_limit,
331                         wchar_t*&       __to_next) const;
332
333   virtual result do_unshift(mbstate_t&   __state,
334                             char*  __to,
335                             char*  __to_limit,
336                             char*& __to_next) const;
337
338   virtual int do_encoding() const _STLP_NOTHROW;
339
340   virtual bool do_always_noconv() const _STLP_NOTHROW;
341
342   virtual int do_length(const mbstate_t& __state,
343                         const  char* __from,
344                         const  char* __end,
345                         size_t __max) const;
346
347   virtual int do_max_length() const _STLP_NOTHROW;
348
349 private:
350   codecvt(const codecvt<wchar_t, char, mbstate_t>&);
351   codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);
352 };
353
354 # endif
355
356 _STLP_TEMPLATE_NULL
357 class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t>
358   : public codecvt<char, char, mbstate_t> {
359 public:
360   explicit codecvt_byname(const char* __name, size_t __refs = 0);
361   ~codecvt_byname();
362 private:
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>&);
365 };
366
367 # ifndef _STLP_NO_WCHAR_T
368 _STLP_TEMPLATE_NULL
369 class _STLP_CLASS_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>
370   : public codecvt<wchar_t, char, mbstate_t>
371 {
372 public:
373   explicit codecvt_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
374
375 protected:
376   ~codecvt_byname();
377
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,
382                         char*        __to,
383                         char*        __to_limit,
384                         char*&       __to_next) const;
385
386   virtual result do_in (mbstate_t&         __state,
387                         const char*  __from,
388                         const char*  __from_end,
389                         const char*& __from_next,
390                         wchar_t*        __to,
391                         wchar_t*        __to_limit,
392                         wchar_t*&       __to_next) const;
393
394   virtual result do_unshift(mbstate_t&   __state,
395                             char*  __to,
396                             char*  __to_limit,
397                             char*& __to_next) const;
398
399   virtual int do_encoding() const _STLP_NOTHROW;
400
401   virtual bool do_always_noconv() const _STLP_NOTHROW;
402
403   virtual int do_length(const mbstate_t&         __state,
404                         const  char* __from,
405                         const  char* __end,
406                         size_t __max) const;
407
408   virtual int do_max_length() const _STLP_NOTHROW;
409
410 private:
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>&);
414 };
415
416 # endif
417
418 _STLP_END_NAMESPACE
419
420 #endif /* _STLP_INTERNAL_CODECVT_H */
421
422 // Local Variables:
423 // mode:C++
424 // End:
425