home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / Rw / CODECVT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  12.1 KB  |  360 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.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  12.  * ALL RIGHTS RESERVED
  13.  *
  14.  * The software and information contained herein are proprietary to, and
  15.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  16.  * intends to preserve as trade secrets such software and information.
  17.  * This software is furnished pursuant to a written license agreement and
  18.  * may be used, copied, transmitted, and stored only in accordance with
  19.  * the terms of such license and with the inclusion of the above copyright
  20.  * notice.  This software and information or any other copies thereof may
  21.  * not be provided or otherwise made available to any other person.
  22.  *
  23.  * Notwithstanding any other lease or license that may pertain to, or
  24.  * accompany the delivery of, this computer software and information, the
  25.  * rights of the Government regarding its use, reproduction and disclosure
  26.  * are as set forth in Section 52.227-19 of the FARS Computer
  27.  * Software-Restricted Rights clause.
  28.  * 
  29.  * Use, duplication, or disclosure by the Government is subject to
  30.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  31.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  32.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  33.  * P.O. Box 2328, Corvallis, Oregon 97339.
  34.  *
  35.  * This computer software and information is distributed with "restricted
  36.  * rights."  Use, duplication or disclosure is subject to restrictions as
  37.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  38.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  39.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  40.  * then the "Alternate III" clause applies.
  41.  *
  42.  **************************************************************************/
  43.  
  44. #ifndef __STD_CODECVT__
  45. #define __STD_CODECVT__
  46.  
  47. #ifndef __STD_RWLOCALE__
  48. #include <rw/rwlocale> 
  49. #endif
  50.  
  51. #ifndef __STD_LIMITS
  52. #include <limits>
  53. #endif
  54.  
  55. #ifndef _RWSTD_NO_NAMESPACE
  56. namespace std {
  57. #endif
  58.  
  59. class _RWSTDExport codecvt_base {
  60.  public:
  61.   enum result { ok, partial, error, noconv };
  62. };
  63.  
  64. // ------------------------------------------------------
  65. // Codeset conversion facet -- codecvt<fromT,toT,stateT>.
  66. // ------------------------------------------------------
  67.  
  68. _RWSTD_TEMPLATE
  69. class _RWSTDExport codecvt<char,char,mbstate_t>:
  70.     public locale::facet, public codecvt_base
  71. {
  72.  public:
  73.   typedef char      extern_type;   
  74.   typedef char      intern_type;
  75.   typedef mbstate_t state_type;
  76.  
  77.   _EXPLICIT codecvt (size_t refs=0):
  78.       locale::facet(refs,locale::__rw_ctype_category) { }
  79.  
  80.   result out (mbstate_t& state,
  81.       const char* from, const char* from_end, const char*& from_next,
  82.       char* to, char* to_limit, char*& to_next) const
  83.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  84.  
  85.   result unshift (mbstate_t& state,
  86.       char* to, char* to_limit, char*& to_next) const
  87.     { return do_unshift(state,to,to_limit,to_next); }
  88.  
  89.   result in(mbstate_t& state,
  90.       const char* from, const char* from_end, const char*& from_next,
  91.       char* to, char* to_limit, char*& to_next) const
  92.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  93.  
  94.   int encoding() const _RWSTD_THROW_SPEC_NULL
  95.     { return do_encoding(); }
  96.  
  97.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  98.     { return do_always_noconv(); }
  99.  
  100.   int length (const mbstate_t& state, const char* from, const char* end,
  101.       size_t max) const { return do_length(state,from,end,max); }
  102.  
  103.   int max_length() const _RWSTD_THROW_SPEC_NULL
  104.     { return do_max_length(); }
  105.  
  106. #if !defined(_MSC_VER) || defined(__BORLANDC__)
  107.   static locale::id _RWSTDExport id;
  108. #else
  109.   static locale::id id;
  110. #endif
  111.  
  112.   // Rogue Wave extension:
  113.   typedef string internal_string_type;
  114.   typedef string external_string_type;
  115.   internal_string_type in (const external_string_type &s) const { return s; }
  116.   external_string_type out (const internal_string_type &s) const { return s; }
  117.  
  118.   // Implementation:
  119.   enum { __facet_cat = locale::__rw_ctype_category, __ok_implicit = 1 };
  120.  
  121.  protected:
  122.   virtual ~codecvt();
  123.  
  124.   virtual result do_out(mbstate_t& state,
  125.     const char* from, const char* from_end, const char*& from_next,
  126.           char* to, char* to_limit, char*& to_next) const;
  127.  
  128.   virtual result do_in(mbstate_t& state,
  129.     const char* from, const char* from_end, const char*& from_next,
  130.           char* to, char* to_limit, char*& to_next) const;
  131.  
  132.   virtual result do_unshift(mbstate_t& state,
  133.           char* to, char* to_limit, char*& to_next) const;
  134.  
  135.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  136.  
  137.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  138.  
  139.   virtual int do_length (const mbstate_t&, const char* from, const char* end,
  140.       size_t max) const;
  141.  
  142.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  143.  
  144.  private:
  145.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  146.   locale::id &__get_id (void) const { return id; }
  147.   #endif
  148. };
  149.  
  150. #ifndef _RWSTD_NO_WIDE_CHAR
  151. _RWSTD_TEMPLATE
  152. class _RWSTDExport codecvt<wchar_t,char,mbstate_t>:
  153.     public locale::facet, public codecvt_base
  154. {
  155.  public:
  156.   typedef wchar_t intern_type;
  157.   typedef char    extern_type;
  158.   typedef mbstate_t state_type;
  159.  
  160.   _EXPLICIT codecvt (size_t refs=0):
  161.       locale::facet(refs,locale::__rw_ctype_category) { }
  162.  
  163.   result out (mbstate_t& state,
  164.       const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
  165.       char* to, char* to_limit, char*& to_next) const
  166.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  167.  
  168.   result unshift (mbstate_t& state,
  169.       char* to, char* to_limit, char*& to_next) const
  170.     { return do_unshift(state,to,to_limit,to_next); }
  171.  
  172.   result in (mbstate_t& state,
  173.       const char* from, const char* from_end, const char*& from_next,
  174.       wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const
  175.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  176.  
  177.   int encoding() const _RWSTD_THROW_SPEC_NULL
  178.     { return do_encoding(); }
  179.  
  180.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  181.     { return do_always_noconv(); }
  182.  
  183.   int length (const mbstate_t& state, const char* from, const char* end,
  184.       size_t max) const
  185.     { return do_length(state,from,end,max); }
  186.  
  187.   int max_length() const _RWSTD_THROW_SPEC_NULL
  188.     { return do_max_length(); }
  189.  
  190. #if !defined(_MSC_VER) || defined(__BORLANDC__)
  191.   static locale::id _RWSTDExport id;
  192. #else
  193.   static locale::id id;
  194. #endif
  195.  
  196.   // Rogue Wave extension:
  197.   typedef string external_string_type;
  198.   typedef wstring internal_string_type;
  199.   internal_string_type in (const external_string_type &s) const;
  200.   external_string_type out (const internal_string_type &s) const;
  201.  
  202.   // Implementation:
  203.   enum { __facet_cat = locale::__rw_ctype_category, __ok_implicit = 1 };
  204.  
  205.  protected:
  206.   virtual ~codecvt();
  207.  
  208.   virtual result do_out (mbstate_t& state,
  209.     const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
  210.           char* to, char* to_limit, char*& to_next) const;
  211.  
  212.   virtual result do_in (mbstate_t& state,
  213.     const char* from, const char* from_end, const char*& from_next,
  214.           wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
  215.  
  216.   virtual result do_unshift (mbstate_t& state,
  217.           char* to, char* to_limit, char*& to_next) const;
  218.  
  219.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  220.  
  221.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  222.  
  223.   virtual int do_length (const mbstate_t&, const char* from,
  224.       const char* end, size_t max) const;
  225.  
  226.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  227.  
  228.  private:
  229.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  230.   locale::id &__get_id (void) const { return id; }
  231.   #endif
  232. };
  233.  
  234. #endif // _RWSTD_NO_WIDE_CHAR
  235.  
  236. template <class internT, class externT, class stateT>
  237. class _RWSTDExportTemplate codecvt: public locale::facet, public codecvt_base { // RW_BUG: fix for bts-42913
  238.  public:
  239.   typedef internT intern_type;
  240.   typedef externT extern_type;
  241.   typedef stateT state_type;
  242.  
  243.   _EXPLICIT codecvt (size_t refs=0): locale::facet(refs) { }
  244.  
  245.   result out (stateT& state,
  246.       const internT* from, const internT* from_end, const internT*& from_next,
  247.       externT* to, externT* to_limit, externT*& to_next) const
  248.     { return do_out(state,from,from_end,from_next,to,to_limit,to_next); }
  249.  
  250.   result unshift (stateT& state,
  251.       externT* to, externT* to_limit, externT*& to_next) const
  252.     { return do_unshift(state,to,to_limit,to_next); }
  253.  
  254.   result in (stateT& state,
  255.       const externT* from, const externT* from_end, const externT*& from_next,
  256.       internT* to, internT* to_limit, internT*& to_next) const
  257.     { return do_in(state,from,from_end,from_next,to,to_limit,to_next); }
  258.  
  259.   bool always_noconv() const _RWSTD_THROW_SPEC_NULL
  260.     { return do_always_noconv(); }
  261.  
  262.   int encoding() const _RWSTD_THROW_SPEC_NULL
  263.     { return do_encoding(); }
  264.  
  265.   int length (const stateT& state, const externT* from, const externT* end,
  266.       size_t max) const
  267.     { return do_length(state,from,end,max); }
  268.  
  269.   int max_length() const _RWSTD_THROW_SPEC_NULL
  270.     { return do_max_length(); }
  271.  
  272.   static locale::id id;
  273.  
  274.   // Rogue Wave extension:
  275.   typedef basic_string<externT,char_traits<externT>,allocator<externT> >
  276.       external_string_type;
  277.   typedef basic_string<internT,char_traits<internT>,allocator<internT> >
  278.       internal_string_type;
  279.   internal_string_type in (const external_string_type &s) const;
  280.   external_string_type out (const internal_string_type &s) const;
  281.  
  282.   // Implementation:
  283.   enum { __facet_cat = locale::__rw_ctype_category, __ok_implicit = 1 };
  284.  
  285.  protected:
  286.   virtual ~codecvt();
  287.  
  288.   virtual result do_out (stateT& state,
  289.     const internT* from, const internT* from_end, const internT*& from_next,
  290.           externT* to, externT* to_limit, externT*& to_next) const;
  291.  
  292.   virtual result do_in (stateT& state,
  293.     const externT* from, const externT* from_end, const externT*& from_next,
  294.           internT* to, internT* to_limit, internT*& to_next) const;
  295.  
  296.   virtual result do_unshift (stateT& state,
  297.           externT* to, externT* to_limit, externT*& to_next) const;
  298.  
  299.   virtual int do_encoding() const _RWSTD_THROW_SPEC_NULL;
  300.  
  301.   virtual bool do_always_noconv() const _RWSTD_THROW_SPEC_NULL;
  302.  
  303.   virtual int do_length (const stateT&, const externT* from, const externT* end,
  304.       size_t max) const;
  305.  
  306.   virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  307.  
  308.  private:
  309.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  310.   locale::id &__get_id (void) const { return id; }
  311.   #endif
  312. };
  313.  
  314. template <class internT, class externT, class stateT>
  315. class codecvt_byname: public codecvt<internT,externT,stateT> {
  316.  public:
  317.   
  318.   typedef internT intern_type;
  319.   typedef externT extern_type;
  320.   typedef stateT state_type; 
  321.  
  322.   _EXPLICIT codecvt_byname (const char*, size_t refs=0);
  323.  
  324.  protected:
  325.   virtual ~codecvt_byname();
  326.  
  327.   virtual codecvt_base::result do_out (stateT&, 
  328.           const internT*, const internT*, const internT*&,
  329.           externT*, externT*, externT*&) const;
  330.  
  331.   virtual codecvt_base::result do_in (stateT&,
  332.     const externT*, const externT*, const externT*&,
  333.           internT*, internT*, internT*&) const;
  334.  
  335.   virtual codecvt_base::result do_unshift (stateT&,
  336.           externT*, externT*, externT*&) const;
  337.  
  338.   virtual int do_encoding () const _RWSTD_THROW_SPEC_NULL;
  339.  
  340.   virtual bool do_always_noconv () const _RWSTD_THROW_SPEC_NULL;
  341.  
  342. // Virtual member functions inherited from codecvt<,,>:
  343. // virtual int do_length (const stateT &state, const externT* from,
  344. //     const externT* end, size_t max) const;
  345. // virtual int do_max_length() const _RWSTD_THROW_SPEC_NULL;
  346. };
  347.  
  348. #ifndef _RWSTD_NO_NAMESPACE
  349. }
  350. #endif
  351.  
  352. #ifdef _RWSTD_COMPILE_INSTANTIATE
  353. #include <rw/codecvt.cc>
  354. #endif
  355.  
  356. #endif // __STD_CODECVT__
  357.  
  358. #pragma option pop
  359. #endif /* __CODECVT_H */
  360.