home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _codecvt.h < prev    next >
C/C++ Source or Header  |  2001-03-27  |  10KB  |  304 lines

  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. # ifndef _STLP_INTERNAL_LOCALE_H
  30. #  include <stl/_locale.h>
  31. # endif
  32.  
  33. _STLP_BEGIN_NAMESPACE
  34.  
  35. class _STLP_CLASS_DECLSPEC codecvt_base {
  36. public:
  37.   enum result {ok, partial, error, noconv};
  38. };
  39.  
  40. template <class _InternT, class _ExternT, class _StateT>
  41. class codecvt {};
  42.  
  43. template <class _InternT, class _ExternT, class _StateT>
  44. class codecvt_byname {};
  45.  
  46. _STLP_TEMPLATE_NULL
  47. class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t>
  48.   : public locale::facet, public codecvt_base 
  49. {
  50.   friend class _Locale;
  51. public:
  52.   typedef char       intern_type;
  53.   typedef char       extern_type;
  54.   typedef mbstate_t  state_type;
  55.  
  56.   explicit codecvt(size_t __refs = 0) : _BaseFacet(__refs) {}
  57.  
  58.   result out(mbstate_t    __state,
  59.              const char*  __from,
  60.              const char*  __from_end,
  61.              const char*& __from_next,
  62.              char*        __to,
  63.              char*        __to_limit, 
  64.              char*&       __to_next) const {
  65.     return do_out(__state, 
  66.                   __from, __from_end, __from_next,
  67.                   __to,   __to_limit, __to_next);
  68.   }
  69.  
  70.   result unshift(mbstate_t& __state,
  71.                  char* __to, char* __to_limit, char*& __to_next) const
  72.     { return do_unshift(__state, __to, __to_limit, __to_next); }
  73.     
  74.   result in(mbstate_t&   __state,
  75.             const char*  __from,
  76.             const char*  __from_end,  
  77.             const char*& __from_next,
  78.             char*        __to, 
  79.             char*        __to_limit, 
  80.             char*&       __to_next) const {
  81.     return do_in(__state,
  82.                  __from, __from_end, __from_next,
  83.                  __to,   __to_limit, __to_next);
  84.   }
  85.  
  86.   int encoding() const _STLP_NOTHROW { return do_encoding(); }
  87.  
  88.   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
  89.  
  90.   int length(const mbstate_t& __state,
  91.              const char* __from, const char* __end,
  92.              size_t __max) const
  93.     { return do_length(__state, __from, __end, __max); }
  94.   
  95.   int max_length() const _STLP_NOTHROW { return do_max_length(); }
  96.  
  97.   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
  98.  
  99. protected:
  100.   ~codecvt();
  101.  
  102.   virtual result do_out(mbstate_t&   /* __state */,
  103.                         const char*  __from,
  104.                         const char*  /* __from_end */,
  105.                         const char*& __from_next,
  106.                         char*        __to,
  107.                         char*        /* __to_limit */,
  108.                         char*&       __to_next) const;
  109.  
  110.   virtual result do_in (mbstate_t&   /* __state */ , 
  111.                         const char*  __from,
  112.                         const char*  /* __from_end */,
  113.                         const char*& __from_next,
  114.                         char*        __to,
  115.                         char*        /* __to_end */,
  116.                         char*&       __to_next) const;
  117.  
  118.   virtual result do_unshift(mbstate_t& /* __state */,
  119.                             char*      __to,
  120.                             char*      /* __to_limit */,
  121.                             char*&     __to_next) const;
  122.  
  123.   virtual int do_encoding() const _STLP_NOTHROW;
  124.   virtual bool do_always_noconv() const _STLP_NOTHROW;
  125.   virtual int do_length(const mbstate_t&         __state,
  126.                         const  char* __from, 
  127.                         const  char* __end,
  128.                         size_t __max) const;
  129.   virtual int do_max_length() const _STLP_NOTHROW;
  130. private:
  131.   codecvt(const codecvt<char, char, mbstate_t>&);
  132.   codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&); 
  133. };
  134.  
  135. # ifndef _STLP_NO_WCHAR_T
  136.  
  137. _STLP_TEMPLATE_NULL
  138. class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t>
  139.   : public locale::facet, public codecvt_base
  140. {
  141.   friend class _Locale;
  142. public:
  143.   typedef wchar_t    intern_type;
  144.   typedef char       extern_type;
  145.   typedef mbstate_t  state_type;
  146.  
  147.   explicit codecvt(size_t __refs = 0) : _BaseFacet(__refs) {}
  148.  
  149.   result out(mbstate_t       __state,
  150.              const wchar_t*  __from,
  151.              const wchar_t*  __from_end,
  152.              const wchar_t*& __from_next,
  153.              char*           __to,
  154.              char*           __to_limit,
  155.              char*&          __to_next) const {
  156.     return do_out(__state,
  157.                   __from, __from_end, __from_next, 
  158.                   __to,   __to_limit, __to_next);
  159.   }
  160.  
  161.   result unshift(mbstate_t& __state,
  162.                  char*  __to, char*  __to_limit, char*& __to_next) const {
  163.     return do_unshift(__state, __to, __to_limit, __to_next);
  164.   }
  165.     
  166.   result in(mbstate_t    __state,
  167.             const char*  __from,
  168.             const char*  __from_end,  
  169.             const char*& __from_next,
  170.             wchar_t*     __to, 
  171.             wchar_t*     __to_limit, 
  172.             wchar_t*&    __to_next) const {
  173.     return do_in(__state, 
  174.                  __from, __from_end, __from_next,
  175.                  __to,  __to_limit, __to_next);
  176.   }
  177.  
  178.   int encoding() const _STLP_NOTHROW { return do_encoding(); }
  179.  
  180.   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
  181.  
  182.   int length(const mbstate_t&        __state,
  183.              const char* __from,
  184.              const char* __end,
  185.              size_t             __max) const
  186.     { return do_length(__state, __from, __end, __max); }
  187.   
  188.   int max_length() const _STLP_NOTHROW { return do_max_length(); }
  189.  
  190.   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
  191.  
  192. protected:
  193.   ~codecvt();
  194.  
  195.   virtual result do_out(mbstate_t&         __state,
  196.                         const wchar_t*  __from,
  197.                         const wchar_t*  __from_end,
  198.                         const wchar_t*& __from_next,
  199.                         char*        __to,
  200.                         char*        __to_limit,
  201.                         char*&       __to_next) const;
  202.  
  203.   virtual result do_in (mbstate_t&         __state,
  204.                         const char*  __from,
  205.                         const char*  __from_end,
  206.                         const char*& __from_next,
  207.                         wchar_t*        __to,
  208.                         wchar_t*        __to_limit,
  209.                         wchar_t*&       __to_next) const;
  210.  
  211.   virtual result do_unshift(mbstate_t&   __state,
  212.                             char*  __to, 
  213.                             char*  __to_limit,
  214.                             char*& __to_next) const;
  215.  
  216.   virtual int do_encoding() const _STLP_NOTHROW;
  217.  
  218.   virtual bool do_always_noconv() const _STLP_NOTHROW;
  219.   
  220.   virtual int do_length(const mbstate_t& __state,
  221.                         const  char* __from, 
  222.                         const  char* __end,
  223.                         size_t __max) const;
  224.  
  225.   virtual int do_max_length() const _STLP_NOTHROW;
  226.  
  227. private:
  228.   codecvt(const codecvt<wchar_t, char, mbstate_t>&);
  229.   codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);  
  230. };
  231.  
  232. # endif
  233.  
  234. _STLP_TEMPLATE_NULL
  235. class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t>
  236.   : public codecvt<char, char, mbstate_t> {
  237. public:
  238.   explicit codecvt_byname(const char* __name, size_t __refs = 0);
  239.   ~codecvt_byname();
  240. private:
  241.   codecvt_byname(const codecvt_byname<char, char, mbstate_t>&);
  242.   codecvt_byname<char, char, mbstate_t>& operator =(const codecvt_byname<char, char, mbstate_t>&);  
  243. };
  244.  
  245. # ifndef _STLP_NO_WCHAR_T
  246. _STLP_TEMPLATE_NULL
  247. class codecvt_byname<wchar_t, char, mbstate_t>
  248.   : public codecvt<wchar_t, char, mbstate_t> 
  249. {
  250. public:
  251.   explicit codecvt_byname(const char * __name, size_t __refs = 0);    
  252.  
  253. protected:
  254.   ~codecvt_byname();
  255.  
  256.   virtual result do_out(mbstate_t&         __state,
  257.                         const wchar_t*  __from,
  258.                         const wchar_t*  __from_end,
  259.                         const wchar_t*& __from_next,
  260.                         char*        __to,
  261.                         char*        __to_limit,
  262.                         char*&       __to_next) const;
  263.  
  264.   virtual result do_in (mbstate_t&         __state,
  265.                         const char*  __from,
  266.                         const char*  __from_end,
  267.                         const char*& __from_next,
  268.                         wchar_t*        __to,
  269.                         wchar_t*        __to_limit,
  270.                         wchar_t*&       __to_next) const;
  271.  
  272.   virtual result do_unshift(mbstate_t&   __state,
  273.                             char*  __to, 
  274.                             char*  __to_limit,
  275.                             char*& __to_next) const;
  276.  
  277.   virtual int do_encoding() const _STLP_NOTHROW;
  278.  
  279.   virtual bool do_always_noconv() const _STLP_NOTHROW;
  280.   
  281.   virtual int do_length(const mbstate_t&         __state,
  282.                         const  char* __from, 
  283.                         const  char* __end,
  284.                         size_t __max) const;
  285.  
  286.   virtual int do_max_length() const _STLP_NOTHROW;
  287.  
  288. private:
  289.   _Locale_ctype* _M_ctype;
  290.   codecvt_byname(const codecvt_byname<wchar_t, char, mbstate_t>&);
  291.   codecvt_byname<wchar_t, char, mbstate_t>& operator =(const codecvt_byname<wchar_t, char, mbstate_t>&);  
  292. };
  293.  
  294. # endif
  295.  
  296. _STLP_END_NAMESPACE
  297.  
  298. #endif /* _STLP_INTERNAL_CODECVT_H */
  299.  
  300. // Local Variables:
  301. // mode:C++
  302. // End:
  303.  
  304.