home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / Rw / codecvt.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  11.6 KB  |  348 lines

  1. #ifndef __CODECVT_H
  2. #define __CODECVT_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * codecvt - Declarations for the Standard Library code conversion facet
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  12.  *
  13.  * This computer software is owned by Rogue Wave Software, Inc. and is
  14.  * protected by U.S. copyright laws and other laws and by international
  15.  * treaties.  This computer software is furnished by Rogue Wave Software,
  16.  * Inc. pursuant to a written license agreement and may be used, copied,
  17.  * transmitted, and stored only in accordance with the terms of such
  18.  * license and with the inclusion of the above copyright notice.  This
  19.  * computer software or any other copies thereof may not be provided or
  20.  * otherwise made available to any other person.
  21.  *
  22.  * U.S. Government Restricted Rights.  This computer software is provided
  23.  * with Restricted Rights.  Use, duplication, or disclosure by the
  24.  * Government is subject to restrictions as set forth in subparagraph (c)
  25.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  26.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  27.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  28.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  29.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  30.  *
  31.  **************************************************************************/
  32.  
  33. #ifndef __STD_CODECVT__
  34. #define __STD_CODECVT__
  35.  
  36. #ifndef __STD_RWLOCALE__
  37. #include <rw/rwlocale> 
  38. #endif
  39.  
  40. #ifndef __STD_LIMITS
  41. #include <limits>
  42. #endif
  43.  
  44. #ifndef _RWSTD_NO_NAMESPACE
  45. namespace std {
  46. #endif
  47.  
  48. class _RWSTDExport codecvt_base {
  49.  public:
  50.   enum result { ok, partial, error, noconv };
  51. };
  52.  
  53. // ------------------------------------------------------
  54. // Codeset conversion facet -- codecvt<fromT,toT,stateT>.
  55. // ------------------------------------------------------
  56.  
  57. _RWSTD_TEMPLATE
  58. class _RWSTDExport codecvt<char,char,mbstate_t>:
  59.     public locale::facet, public codecvt_base
  60. {
  61.  public:
  62.   typedef char      extern_type;   
  63.   typedef char      intern_type;
  64.   typedef mbstate_t state_type;
  65.  
  66.   _EXPLICIT codecvt (size_t refs=0):
  67.       locale::facet(refs,locale::__rw_ctype_category) { }
  68.  
  69.   result out (mbstate_t& state,
  70.       const char* from, const char* from_end, const char*& from_next,
  71.       char* to, char* to_limit, char*& to_next) const
  72.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  73.  
  74.   result unshift (mbstate_t& state,
  75.       char* to, char* to_limit, char*& to_next) const
  76.     { return do_unshift(state,to,to_limit,to_next); }
  77.  
  78.   result in(mbstate_t& state,
  79.       const char* from, const char* from_end, const char*& from_next,
  80.       char* to, char* to_limit, char*& to_next) const
  81.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  82.  
  83.   int encoding() const _RWSTD_THROW_SPEC_NULL
  84.     { return do_encoding(); }
  85.  
  86.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  87.     { return do_always_noconv(); }
  88.  
  89.   int length (const mbstate_t& state, const char* from, const char* end,
  90.       size_t max) const { return do_length(state,from,end,max); }
  91.  
  92.   int max_length() const _RWSTD_THROW_SPEC_NULL
  93.     { return do_max_length(); }
  94.  
  95. #if !defined(_MSC_VER) || defined(__BORLANDC__)
  96.   static locale::id _RWSTDExport id;
  97. #else
  98.   static locale::id id;
  99. #endif
  100.  
  101.   // Rogue Wave extension:
  102.   typedef string internal_string_type;
  103.   typedef string external_string_type;
  104.   internal_string_type in (const external_string_type &s) const { return s; }
  105.   external_string_type out (const internal_string_type &s) const { return s; }
  106.  
  107.   // Implementation:
  108.   enum { __facet_cat = locale::__rw_ctype_category, __ok_implicit = 1 };
  109.  
  110.  protected:
  111.   virtual ~codecvt();
  112.  
  113.   virtual result do_out(mbstate_t& state,
  114.     const char* from, const char* from_end, const char*& from_next,
  115.           char* to, char* to_limit, char*& to_next) const;
  116.  
  117.   virtual result do_in(mbstate_t& state,
  118.     const char* from, const char* from_end, const char*& from_next,
  119.           char* to, char* to_limit, char*& to_next) const;
  120.  
  121.   virtual result do_unshift(mbstate_t& state,
  122.           char* to, char* to_limit, char*& to_next) const;
  123.  
  124.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  125.  
  126.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  127.  
  128.   virtual int do_length (const mbstate_t&, const char* from, const char* end,
  129.       size_t max) const;
  130.  
  131.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  132.  
  133.  private:
  134.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  135.   locale::id &__get_id (void) const { return id; }
  136.   #endif
  137. };
  138.  
  139. #ifndef _RWSTD_NO_WIDE_CHAR
  140. _RWSTD_TEMPLATE
  141. class _RWSTDExport codecvt<wchar_t,char,mbstate_t>:
  142.     public locale::facet, public codecvt_base
  143. {
  144.  public:
  145.   typedef wchar_t intern_type;
  146.   typedef char    extern_type;
  147.   typedef mbstate_t state_type;
  148.  
  149.   _EXPLICIT codecvt (size_t refs=0):
  150.       locale::facet(refs,locale::__rw_ctype_category) { }
  151.  
  152.   result out (mbstate_t& state,
  153.       const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
  154.       char* to, char* to_limit, char*& to_next) const
  155.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  156.  
  157.   result unshift (mbstate_t& state,
  158.       char* to, char* to_limit, char*& to_next) const
  159.     { return do_unshift(state,to,to_limit,to_next); }
  160.  
  161.   result in (mbstate_t& state,
  162.       const char* from, const char* from_end, const char*& from_next,
  163.       wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const
  164.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  165.  
  166.   int encoding() const _RWSTD_THROW_SPEC_NULL
  167.     { return do_encoding(); }
  168.  
  169.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  170.     { return do_always_noconv(); }
  171.  
  172.   int length (const mbstate_t& state, const char* from, const char* end,
  173.       size_t max) const
  174.     { return do_length(state,from,end,max); }
  175.  
  176.   int max_length() const _RWSTD_THROW_SPEC_NULL
  177.     { return do_max_length(); }
  178.  
  179. #if !defined(_MSC_VER) || defined(__BORLANDC__)
  180.   static locale::id _RWSTDExport id;
  181. #else
  182.   static locale::id id;
  183. #endif
  184.  
  185.   // Rogue Wave extension:
  186.   typedef string external_string_type;
  187.   typedef wstring internal_string_type;
  188.   internal_string_type in (const external_string_type &s) const;
  189.   external_string_type out (const internal_string_type &s) const;
  190.  
  191.   // Implementation:
  192.   enum { __facet_cat = locale::__rw_ctype_category, __ok_implicit = 1 };
  193.  
  194.  protected:
  195.   virtual ~codecvt();
  196.  
  197.   virtual result do_out (mbstate_t& state,
  198.     const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
  199.           char* to, char* to_limit, char*& to_next) const;
  200.  
  201.   virtual result do_in (mbstate_t& state,
  202.     const char* from, const char* from_end, const char*& from_next,
  203.           wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
  204.  
  205.   virtual result do_unshift (mbstate_t& state,
  206.           char* to, char* to_limit, char*& to_next) const;
  207.  
  208.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  209.  
  210.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  211.  
  212.   virtual int do_length (const mbstate_t&, const char* from,
  213.       const char* end, size_t max) const;
  214.  
  215.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  216.  
  217.  private:
  218.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  219.   locale::id &__get_id (void) const { return id; }
  220.   #endif
  221. };
  222.  
  223. #endif // _RWSTD_NO_WIDE_CHAR
  224.  
  225. template <class internT, class externT, class stateT>
  226. class _RWSTDExportTemplate codecvt: public locale::facet, public codecvt_base {
  227.  public:
  228.   typedef internT intern_type;
  229.   typedef externT extern_type;
  230.   typedef stateT state_type;
  231.  
  232.   _EXPLICIT codecvt (size_t refs=0): locale::facet(refs) { }
  233.  
  234.   result out (stateT& state,
  235.       const internT* from, const internT* from_end, const internT*& from_next,
  236.       externT* to, externT* to_limit, externT*& to_next) const
  237.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  238.  
  239.   result unshift (stateT& state,
  240.       externT* to, externT* to_limit, externT*& to_next) const
  241.     { return do_unshift(state,to,to_limit,to_next); }
  242.  
  243.   result in (stateT& state,
  244.       const externT* from, const externT* from_end, const externT*& from_next,
  245.       internT* to, internT* to_limit, internT*& to_next) const
  246.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  247.  
  248.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  249.     { return do_always_noconv(); }
  250.  
  251.   int encoding() const _RWSTD_THROW_SPEC_NULL
  252.     { return do_encoding(); }
  253.  
  254.   int length (const stateT& state, const externT* from, const externT* end,
  255.       size_t max) const
  256.     { return do_length(state,from,end,max); }
  257.  
  258.   int max_length() const _RWSTD_THROW_SPEC_NULL
  259.     { return do_max_length(); }
  260.  
  261.   static locale::id id;
  262.  
  263.   // Rogue Wave extension:
  264.   typedef basic_string<externT,char_traits<externT>,allocator<externT> >
  265.       external_string_type;
  266.   typedef basic_string<internT,char_traits<internT>,allocator<internT> >
  267.       internal_string_type;
  268.   internal_string_type in (const external_string_type &s) const;
  269.   external_string_type out (const internal_string_type &s) const;
  270.  
  271.   // Implementation:
  272.   enum { __facet_cat = locale::__rw_ctype_category, __ok_implicit = 1 };
  273.  
  274.  protected:
  275.   virtual ~codecvt();
  276.  
  277.   virtual result do_out (stateT& state,
  278.     const internT* from, const internT* from_end, const internT*& from_next,
  279.           externT* to, externT* to_limit, externT*& to_next) const;
  280.  
  281.   virtual result do_in (stateT& state,
  282.     const externT* from, const externT* from_end, const externT*& from_next,
  283.           internT* to, internT* to_limit, internT*& to_next) const;
  284.  
  285.   virtual result do_unshift (stateT& state,
  286.           externT* to, externT* to_limit, externT*& to_next) const;
  287.  
  288.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  289.  
  290.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  291.  
  292.   virtual int do_length (const stateT&, const externT* from, const externT* end,
  293.       size_t max) const;
  294.  
  295.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  296.  
  297.  private:
  298.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  299.   locale::id &__get_id (void) const { return id; }
  300.   #endif
  301. };
  302.  
  303. template <class internT, class externT, class stateT>
  304. class codecvt_byname: public codecvt<internT,externT,stateT> {
  305.  public:
  306.   
  307.   typedef internT intern_type;
  308.   typedef externT extern_type;
  309.   typedef stateT state_type; 
  310.  
  311.   _EXPLICIT codecvt_byname (const char*, size_t refs=0);
  312.  
  313.  protected:
  314.   virtual ~codecvt_byname();
  315.  
  316.   virtual codecvt_base::result do_out (stateT&, 
  317.           const internT*, const internT*, const internT*&,
  318.           externT*, externT*, externT*&) const;
  319.  
  320.   virtual codecvt_base::result do_in (stateT&,
  321.     const externT*, const externT*, const externT*&,
  322.           internT*, internT*, internT*&) const;
  323.  
  324.   virtual codecvt_base::result do_unshift (stateT&,
  325.           externT*, externT*, externT*&) const;
  326.  
  327.   virtual int do_encoding () const _RWSTD_THROW_SPEC_NULL;
  328.  
  329.   virtual bool do_always_noconv () const _RWSTD_THROW_SPEC_NULL;
  330.  
  331. // Virtual member functions inherited from codecvt<,,>:
  332. // virtual int do_length (const stateT &state, const externT* from,
  333. //     const externT* end, size_t max) const;
  334. // virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  335. };
  336.  
  337. #ifndef _RWSTD_NO_NAMESPACE
  338. }
  339. #endif
  340.  
  341. #ifdef _RWSTD_COMPILE_INSTANTIATE
  342. #include <rw/codecvt.cc>
  343. #endif
  344.  
  345. #endif // __STD_CODECVT__
  346. #pragma option pop
  347. #endif /* __CODECVT_H */
  348.