codecvt.h

Go to the documentation of this file.
00001 // Locale support (codecvt) -*- C++ -*-
00002 
00003 // Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 //
00031 // ISO C++ 14882: 22.2.1.5 Template class codecvt
00032 //
00033 
00034 // Written by Benjamin Kosnik <bkoz@cygnus.com>
00035 
00041 #ifndef _CODECVT_H
00042 #define _CODECVT_H 1
00043 
00044 #pragma GCC system_header
00045 
00046   //  22.2.1.5  Template class codecvt
00048   class codecvt_base
00049   {
00050   public:
00051     enum result
00052     {
00053       ok,
00054       partial,
00055       error,
00056       noconv
00057     };
00058   };
00059 
00060   // Template class __codecvt_abstract_base
00061   // NB: An abstract base class that fills in the public inlines, so
00062   // that the specializations don't have to re-copy the public
00063   // interface.
00073   template<typename _InternT, typename _ExternT, typename _StateT>
00074     class __codecvt_abstract_base
00075     : public locale::facet, public codecvt_base
00076     {
00077     public:
00078       // Types:
00079       typedef codecvt_base::result  result;
00080       typedef _InternT          intern_type;
00081       typedef _ExternT          extern_type;
00082       typedef _StateT           state_type;
00083 
00084       // 22.2.1.5.1 codecvt members
00120       result
00121       out(state_type& __state, const intern_type* __from,
00122       const intern_type* __from_end, const intern_type*& __from_next,
00123       extern_type* __to, extern_type* __to_end,
00124       extern_type*& __to_next) const
00125       {
00126     return this->do_out(__state, __from, __from_end, __from_next,
00127                 __to, __to_end, __to_next);
00128       }
00129 
00159       result
00160       unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
00161           extern_type*& __to_next) const
00162       { return this->do_unshift(__state, __to,__to_end,__to_next); }
00163 
00199       result
00200       in(state_type& __state, const extern_type* __from,
00201      const extern_type* __from_end, const extern_type*& __from_next,
00202      intern_type* __to, intern_type* __to_end,
00203      intern_type*& __to_next) const
00204       {
00205     return this->do_in(__state, __from, __from_end, __from_next,
00206                __to, __to_end, __to_next);
00207       }
00208 
00209       int
00210       encoding() const throw()
00211       { return this->do_encoding(); }
00212 
00213       bool
00214       always_noconv() const throw()
00215       { return this->do_always_noconv(); }
00216 
00217       int
00218       length(state_type& __state, const extern_type* __from,
00219          const extern_type* __end, size_t __max) const
00220       { return this->do_length(__state, __from, __end, __max); }
00221 
00222       int
00223       max_length() const throw()
00224       { return this->do_max_length(); }
00225 
00226     protected:
00227       explicit
00228       __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
00229 
00230       virtual
00231       ~__codecvt_abstract_base() { }
00232 
00240       virtual result
00241       do_out(state_type& __state, const intern_type* __from,
00242          const intern_type* __from_end, const intern_type*& __from_next,
00243          extern_type* __to, extern_type* __to_end,
00244          extern_type*& __to_next) const = 0;
00245 
00246       virtual result
00247       do_unshift(state_type& __state, extern_type* __to,
00248          extern_type* __to_end, extern_type*& __to_next) const = 0;
00249 
00250       virtual result
00251       do_in(state_type& __state, const extern_type* __from,
00252         const extern_type* __from_end, const extern_type*& __from_next,
00253         intern_type* __to, intern_type* __to_end,
00254         intern_type*& __to_next) const = 0;
00255 
00256       virtual int
00257       do_encoding() const throw() = 0;
00258 
00259       virtual bool
00260       do_always_noconv() const throw() = 0;
00261 
00262       virtual int
00263       do_length(state_type&, const extern_type* __from,
00264         const extern_type* __end, size_t __max) const = 0;
00265 
00266       virtual int
00267       do_max_length() const throw() = 0;
00268     };
00269 
00270   // 22.2.1.5 Template class codecvt
00271   // NB: Generic, mostly useless implementation.
00272   template<typename _InternT, typename _ExternT, typename _StateT>
00273     class codecvt
00274     : public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
00275     {
00276     public:
00277       // Types:
00278       typedef codecvt_base::result  result;
00279       typedef _InternT          intern_type;
00280       typedef _ExternT          extern_type;
00281       typedef _StateT           state_type;
00282 
00283     protected:
00284       __c_locale            _M_c_locale_codecvt;
00285 
00286     public:
00287       static locale::id         id;
00288 
00289       explicit
00290       codecvt(size_t __refs = 0)
00291       : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs) { }
00292 
00293       explicit
00294       codecvt(__c_locale __cloc, size_t __refs = 0);
00295 
00296     protected:
00297       virtual
00298       ~codecvt() { }
00299 
00300       virtual result
00301       do_out(state_type& __state, const intern_type* __from,
00302          const intern_type* __from_end, const intern_type*& __from_next,
00303          extern_type* __to, extern_type* __to_end,
00304          extern_type*& __to_next) const;
00305 
00306       virtual result
00307       do_unshift(state_type& __state, extern_type* __to,
00308          extern_type* __to_end, extern_type*& __to_next) const;
00309 
00310       virtual result
00311       do_in(state_type& __state, const extern_type* __from,
00312         const extern_type* __from_end, const extern_type*& __from_next,
00313         intern_type* __to, intern_type* __to_end,
00314         intern_type*& __to_next) const;
00315 
00316       virtual int
00317       do_encoding() const throw();
00318 
00319       virtual bool
00320       do_always_noconv() const throw();
00321 
00322       virtual int
00323       do_length(state_type&, const extern_type* __from,
00324         const extern_type* __end, size_t __max) const;
00325 
00326       virtual int
00327       do_max_length() const throw();
00328     };
00329 
00330   template<typename _InternT, typename _ExternT, typename _StateT>
00331     locale::id codecvt<_InternT, _ExternT, _StateT>::id;
00332 
00333   // codecvt<char, char, mbstate_t> required specialization
00334   template<>
00335     class codecvt<char, char, mbstate_t>
00336     : public __codecvt_abstract_base<char, char, mbstate_t>
00337     {
00338     public:
00339       // Types:
00340       typedef char          intern_type;
00341       typedef char          extern_type;
00342       typedef mbstate_t         state_type;
00343 
00344     protected:
00345       __c_locale            _M_c_locale_codecvt;
00346 
00347     public:
00348       static locale::id id;
00349 
00350       explicit
00351       codecvt(size_t __refs = 0);
00352 
00353       explicit
00354       codecvt(__c_locale __cloc, size_t __refs = 0);
00355 
00356     protected:
00357       virtual
00358       ~codecvt();
00359 
00360       virtual result
00361       do_out(state_type& __state, const intern_type* __from,
00362          const intern_type* __from_end, const intern_type*& __from_next,
00363          extern_type* __to, extern_type* __to_end,
00364          extern_type*& __to_next) const;
00365 
00366       virtual result
00367       do_unshift(state_type& __state, extern_type* __to,
00368          extern_type* __to_end, extern_type*& __to_next) const;
00369 
00370       virtual result
00371       do_in(state_type& __state, const extern_type* __from,
00372         const extern_type* __from_end, const extern_type*& __from_next,
00373         intern_type* __to, intern_type* __to_end,
00374         intern_type*& __to_next) const;
00375 
00376       virtual int
00377       do_encoding() const throw();
00378 
00379       virtual bool
00380       do_always_noconv() const throw();
00381 
00382       virtual int
00383       do_length(state_type&, const extern_type* __from,
00384         const extern_type* __end, size_t __max) const;
00385 
00386       virtual int
00387       do_max_length() const throw();
00388   };
00389 
00390 #ifdef _GLIBCXX_USE_WCHAR_T
00391   // codecvt<wchar_t, char, mbstate_t> required specialization
00392   template<>
00393     class codecvt<wchar_t, char, mbstate_t>
00394     : public __codecvt_abstract_base<wchar_t, char, mbstate_t>
00395     {
00396     public:
00397       // Types:
00398       typedef wchar_t           intern_type;
00399       typedef char          extern_type;
00400       typedef mbstate_t         state_type;
00401 
00402     protected:
00403       __c_locale            _M_c_locale_codecvt;
00404 
00405     public:
00406       static locale::id         id;
00407 
00408       explicit
00409       codecvt(size_t __refs = 0);
00410 
00411       explicit
00412       codecvt(__c_locale __cloc, size_t __refs = 0);
00413 
00414     protected:
00415       virtual
00416       ~codecvt();
00417 
00418       virtual result
00419       do_out(state_type& __state, const intern_type* __from,
00420          const intern_type* __from_end, const intern_type*& __from_next,
00421          extern_type* __to, extern_type* __to_end,
00422          extern_type*& __to_next) const;
00423 
00424       virtual result
00425       do_unshift(state_type& __state,
00426          extern_type* __to, extern_type* __to_end,
00427          extern_type*& __to_next) const;
00428 
00429       virtual result
00430       do_in(state_type& __state,
00431          const extern_type* __from, const extern_type* __from_end,
00432          const extern_type*& __from_next,
00433          intern_type* __to, intern_type* __to_end,
00434          intern_type*& __to_next) const;
00435 
00436       virtual
00437       int do_encoding() const throw();
00438 
00439       virtual
00440       bool do_always_noconv() const throw();
00441 
00442       virtual
00443       int do_length(state_type&, const extern_type* __from,
00444             const extern_type* __end, size_t __max) const;
00445 
00446       virtual int
00447       do_max_length() const throw();
00448     };
00449 #endif //_GLIBCXX_USE_WCHAR_T
00450 
00451   // 22.2.1.6  Template class codecvt_byname
00452   template<typename _InternT, typename _ExternT, typename _StateT>
00453     class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
00454     {
00455     public:
00456       explicit
00457       codecvt_byname(const char* __s, size_t __refs = 0)
00458       : codecvt<_InternT, _ExternT, _StateT>(__refs)
00459       {
00460     if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
00461       {
00462         this->_S_destroy_c_locale(this->_M_c_locale_codecvt);
00463         this->_S_create_c_locale(this->_M_c_locale_codecvt, __s);
00464       }
00465       }
00466 
00467     protected:
00468       virtual
00469       ~codecvt_byname() { }
00470     };
00471 
00472   // Include host and configuration specific partial specializations
00473   // with additional functionality, if possible.
00474 #ifdef _GLIBCXX_USE_WCHAR_T
00475   #include <bits/codecvt_specializations.h>
00476 #endif
00477 
00478 #endif // _CODECVT_H

Generated on Tue Jan 30 17:31:48 2007 for GNU C++ STL by doxygen 1.3.6