home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / cwin / c.exe / $INSTDIR / include / c++ / bits / codecvt.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-15  |  9.9 KB  |  337 lines

  1. // Locale support (codecvt) -*- C++ -*-
  2.  
  3. // Copyright (C) 2000, 2001 Free Software Foundation, Inc.
  4. //
  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)
  9. // any later version.
  10.  
  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.
  15.  
  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,
  19. // USA.
  20.  
  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.
  29.  
  30. //
  31. // ISO C++ 14882: 22.2.1.5 Template class codecvt
  32. //
  33.  
  34. // Written by Benjamin Kosnik <bkoz@cygnus.com>
  35.  
  36. /** @file codecvt.h
  37.  *  This is an internal header file, included by other library headers.
  38.  *  You should not attempt to use it directly.
  39.  */
  40.  
  41. #ifndef _CPP_BITS_CODECVT_H
  42. #define _CPP_BITS_CODECVT_H    1
  43.  
  44. #pragma GCC system_header
  45.  
  46.   //  22.2.1.5  Template class codecvt
  47.   class codecvt_base
  48.   {
  49.   public:
  50.     enum result
  51.     {
  52.       ok,
  53.       partial,
  54.       error,
  55.       noconv
  56.     };
  57.   };
  58.  
  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
  62.   // interface.
  63.   template<typename _InternT, typename _ExternT, typename _StateT>
  64.     class __codecvt_abstract_base 
  65.     : public locale::facet, public codecvt_base
  66.     {
  67.     public:
  68.       // Types:
  69.       typedef codecvt_base::result            result;
  70.       typedef _InternT                     intern_type;
  71.       typedef _ExternT                     extern_type;
  72.       typedef _StateT                      state_type;
  73.       
  74.       // 22.2.1.5.1 codecvt members
  75.       result
  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
  80.       { 
  81.     return this->do_out(__state, __from, __from_end, __from_next, 
  82.                 __to, __to_end, __to_next); 
  83.       }
  84.  
  85.       result
  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); }
  89.  
  90.       result
  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
  95.       { 
  96.     return this->do_in(__state, __from, __from_end, __from_next,
  97.                __to, __to_end, __to_next); 
  98.       }
  99.  
  100.       int 
  101.       encoding() const throw()
  102.       { return this->do_encoding(); }
  103.  
  104.       bool 
  105.       always_noconv() const throw()
  106.       { return this->do_always_noconv(); }
  107.  
  108.       int
  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); }
  112.  
  113.       int 
  114.       max_length() const throw()
  115.       { return this->do_max_length(); }
  116.  
  117.     protected:
  118.       explicit 
  119.       __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
  120.  
  121.       virtual 
  122.       ~__codecvt_abstract_base() { }
  123.  
  124.       virtual result
  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;
  129.  
  130.       virtual result
  131.       do_unshift(state_type& __state, extern_type* __to, 
  132.          extern_type* __to_end, extern_type*& __to_next) const = 0;
  133.       
  134.       virtual result
  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;
  139.       
  140.       virtual int 
  141.       do_encoding() const throw() = 0;
  142.  
  143.       virtual bool 
  144.       do_always_noconv() const throw() = 0;
  145.  
  146.       virtual int 
  147.       do_length(const state_type&, const extern_type* __from, 
  148.         const extern_type* __end, size_t __max) const = 0;
  149.  
  150.       virtual int 
  151.       do_max_length() const throw() = 0;
  152.     };
  153.  
  154.   // 22.2.1.5 Template class codecvt
  155.   // NB: Generic, mostly useless implementation.
  156.   template<typename _InternT, typename _ExternT, typename _StateT>
  157.     class codecvt 
  158.     : public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
  159.     {
  160.     public:      
  161.       // Types:
  162.       typedef codecvt_base::result            result;
  163.       typedef _InternT intern_type;
  164.       typedef _ExternT extern_type;
  165.       typedef _StateT  state_type;
  166.  
  167.       // Data Members:
  168.       static locale::id id;
  169.  
  170.       explicit 
  171.       codecvt(size_t __refs = 0) 
  172.       : __codecvt_abstract_base<_InternT,_ExternT,_StateT> (__refs) { }
  173.  
  174.     protected:
  175.       virtual 
  176.       ~codecvt() { }
  177.  
  178.       virtual result
  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;
  183.  
  184.       virtual result
  185.       do_unshift(state_type& __state, extern_type* __to, 
  186.          extern_type* __to_end, extern_type*& __to_next) const;
  187.       
  188.       virtual result
  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;
  193.       
  194.       virtual int 
  195.       do_encoding() const throw();
  196.  
  197.       virtual bool 
  198.       do_always_noconv() const throw();
  199.  
  200.       virtual int 
  201.       do_length(const state_type&, const extern_type* __from, 
  202.         const extern_type* __end, size_t __max) const;
  203.  
  204.       virtual int 
  205.       do_max_length() const throw();
  206.     };
  207.  
  208.   template<typename _InternT, typename _ExternT, typename _StateT>
  209.     locale::id codecvt<_InternT, _ExternT, _StateT>::id;
  210.  
  211.   // codecvt<char, char, mbstate_t> required specialization
  212.   template<>
  213.     class codecvt<char, char, mbstate_t> 
  214.     : public __codecvt_abstract_base<char, char, mbstate_t>
  215.     {
  216.     public:      
  217.       // Types:
  218.       typedef char     intern_type;
  219.       typedef char     extern_type;
  220.       typedef mbstate_t state_type;
  221.  
  222.       // Data Members:
  223.       static locale::id id;
  224.  
  225.       explicit 
  226.       codecvt(size_t __refs = 0);
  227.  
  228.     protected:
  229.       virtual 
  230.       ~codecvt();
  231.  
  232.       virtual result
  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;
  237.  
  238.       virtual result
  239.       do_unshift(state_type& __state, extern_type* __to, 
  240.          extern_type* __to_end, extern_type*& __to_next) const;
  241.  
  242.       virtual result
  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;
  247.  
  248.       virtual int 
  249.       do_encoding() const throw();
  250.  
  251.       virtual bool 
  252.       do_always_noconv() const throw();
  253.  
  254.       virtual int 
  255.       do_length(const state_type&, const extern_type* __from, 
  256.         const extern_type* __end, size_t __max) const;
  257.  
  258.       virtual int 
  259.       do_max_length() const throw();
  260.   };
  261.  
  262. #ifdef _GLIBCPP_USE_WCHAR_T
  263.   // codecvt<wchar_t, char, mbstate_t> required specialization
  264.   template<>
  265.     class codecvt<wchar_t, char, mbstate_t> 
  266.     : public __codecvt_abstract_base<wchar_t, char, mbstate_t>
  267.     {
  268.     public:
  269.       // Types:
  270.       typedef wchar_t     intern_type;
  271.       typedef char     extern_type;
  272.       typedef mbstate_t state_type;
  273.  
  274.       // Data Members:
  275.       static locale::id id;
  276.  
  277.       explicit 
  278.       codecvt(size_t __refs = 0);
  279.  
  280.     protected:
  281.       virtual 
  282.       ~codecvt();
  283.  
  284.       virtual result
  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;
  289.  
  290.       virtual result
  291.       do_unshift(state_type& __state,
  292.          extern_type* __to, extern_type* __to_end,
  293.          extern_type*& __to_next) const;
  294.  
  295.       virtual result
  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;
  301.  
  302.       virtual 
  303.       int do_encoding() const throw();
  304.  
  305.       virtual 
  306.       bool do_always_noconv() const throw();
  307.  
  308.       virtual 
  309.       int do_length(const state_type&, const extern_type* __from,
  310.             const extern_type* __end, size_t __max) const;
  311.  
  312.       virtual int 
  313.       do_max_length() const throw();
  314.     };
  315. #endif //_GLIBCPP_USE_WCHAR_T
  316.  
  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>
  320.     {
  321.     public:
  322.       explicit 
  323.       codecvt_byname(const char*, size_t __refs = 0) 
  324.       : codecvt<_InternT, _ExternT, _StateT>(__refs) { }
  325.     protected:
  326.       virtual 
  327.       ~codecvt_byname() { }
  328.     };
  329.  
  330.   // Include host and configuration specific partial specializations
  331.   // with additional functionality, if possible.
  332. #ifdef _GLIBCPP_USE_WCHAR_T
  333.   #include <bits/codecvt_specializations.h>
  334. #endif
  335.  
  336. #endif // _CPP_BITS_CODECVT_H
  337.