home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / Rw / CODECVT.CC next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  6.7 KB  |  194 lines

  1. #ifndef __CODECVT_CC
  2. #define __CODECVT_CC
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. /***************************************************************************
  5.  *
  6.  * codecvt.cc - Definitions for the Standard Library code conversion facet
  7.  *
  8.  ***************************************************************************
  9.  *
  10.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  11.  * ALL RIGHTS RESERVED
  12.  *
  13.  * The software and information contained herein are proprietary to, and
  14.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  15.  * intends to preserve as trade secrets such software and information.
  16.  * This software is furnished pursuant to a written license agreement and
  17.  * may be used, copied, transmitted, and stored only in accordance with
  18.  * the terms of such license and with the inclusion of the above copyright
  19.  * notice.  This software and information or any other copies thereof may
  20.  * not be provided or otherwise made available to any other person.
  21.  *
  22.  * Notwithstanding any other lease or license that may pertain to, or
  23.  * accompany the delivery of, this computer software and information, the
  24.  * rights of the Government regarding its use, reproduction and disclosure
  25.  * are as set forth in Section 52.227-19 of the FARS Computer
  26.  * Software-Restricted Rights clause.
  27.  * 
  28.  * Use, duplication, or disclosure by the Government is subject to
  29.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  30.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  31.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  32.  * P.O. Box 2328, Corvallis, Oregon 97339.
  33.  *
  34.  * This computer software and information is distributed with "restricted
  35.  * rights."  Use, duplication or disclosure is subject to restrictions as
  36.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  37.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  38.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  39.  * then the "Alternate III" clause applies.
  40.  *
  41.  **************************************************************************/
  42.  
  43. #ifndef _RWSTD_NO_NAMESPACE
  44. namespace std {
  45. #endif
  46.  
  47. // -------------------------------------------------------
  48. // Facet codecvt<internT,externT,stateT> member templates.
  49. // -------------------------------------------------------
  50.  
  51. #ifndef _RWSTD_NO_TEMPLATE_STATIC_ID
  52. template <class internT,class externT,class stateT>
  53. locale::id codecvt<internT,externT,stateT>::id;
  54. #endif
  55.  
  56. template <class internT,class externT,class stateT>
  57. codecvt<internT,externT,stateT>::~codecvt() {}
  58.  
  59. template <class internT, class externT, class stateT>
  60. codecvt_base::result
  61. codecvt<internT,externT,stateT>::do_out (stateT&,
  62.     const internT*, const internT*, const internT*&,
  63.     externT*, externT*, externT*&) const
  64. {
  65.   return noconv;
  66. }
  67.  
  68. template <class internT, class externT, class stateT>
  69. codecvt_base::result
  70. codecvt<internT,externT,stateT>::do_in (stateT&,
  71.     const externT*, const externT*, const externT*&,
  72.     internT*, internT*, internT*&) const
  73. {
  74.   return noconv;
  75. }
  76.  
  77. template <class internT, class externT, class stateT>
  78. codecvt_base::result
  79. codecvt<internT,externT,stateT>::do_unshift (stateT&,
  80.     externT*, externT*, externT*&) const
  81. {
  82.   return noconv;
  83. }
  84.  
  85. template <class internT,class externT,class stateT>
  86. int codecvt<internT,externT,stateT>::do_encoding()
  87.     const _RWSTD_THROW_SPEC_NULL
  88. {
  89.   return sizeof(internT) == sizeof(externT);
  90. }
  91.  
  92. template <class internT,class externT,class stateT>
  93. bool codecvt<internT,externT,stateT>::do_always_noconv ()
  94.     const _RWSTD_THROW_SPEC_NULL
  95. {
  96.   return true;
  97. }
  98.  
  99. template <class internT,class externT,class stateT>
  100. int codecvt<internT,externT,stateT>::do_length (const stateT&,
  101.     const externT *from, const externT *from_end, size_t max) const
  102. {
  103.   return min (size_t(from_end-from), max);
  104. }
  105.  
  106. template <class internT,class externT,class stateT>
  107. int codecvt<internT,externT,stateT>::do_max_length ()
  108.     const _RWSTD_THROW_SPEC_NULL
  109. {
  110.   return 1;
  111. }
  112.  
  113. template <class internT,class externT,class stateT>
  114. _TYPENAME codecvt<internT,externT,stateT>::internal_string_type
  115. codecvt<internT,externT,stateT>::in (const external_string_type &s) const
  116. {
  117.   // Calculate the number of internT's that will be produced.  (I'm not sure
  118.   // what to use for max in the do_length call; too bad char_traits can't tell
  119.   // me.) (This needs to be revised to use separate in and out versions of
  120.   // do_length once someone comes up with the right syntax.)
  121.   int n=1000; // do_length(stateT(0),s.c_str(),s.c_str()+s.length(),
  122.               // numeric_limits<size_t>::max() / do_max_length());
  123.  
  124.   const externT *unused_from;
  125.   internT *unused_to;
  126.  
  127.   internT *conversion_buffer=new internT[n];
  128.   stateT stt(0);
  129.   n=do_in(stt,s.c_str(),s.c_str()+s.length(),unused_from,
  130.       conversion_buffer,conversion_buffer+n,unused_to);
  131.   internal_string_type result(conversion_buffer,conversion_buffer+n);
  132.   delete[] conversion_buffer;
  133.   return result;
  134. }
  135.  
  136. // --------------------------------------------------------------
  137. // Facet codecvt_byname<internT,externT,stateT> member templates.
  138. // --------------------------------------------------------------
  139.  
  140. template <class internT, class externT, class stateT>
  141. codecvt_byname<internT,externT,stateT>::codecvt_byname
  142.     (const char*, size_t refs):
  143.     codecvt<internT,externT,stateT>(refs)
  144. { }
  145.  
  146. template <class internT, class externT, class stateT>
  147. codecvt_byname<internT,externT, stateT>::~codecvt_byname ()
  148. { }
  149.  
  150. template <class internT, class externT, class stateT>
  151. codecvt_base::result 
  152. codecvt_byname<internT,externT, stateT>::do_out (stateT&,
  153.     const internT*, const internT*, const internT*&,
  154.           externT*, externT*, externT*&) const
  155. {
  156.   return codecvt_base::error;
  157. }
  158.  
  159. template <class internT, class externT, class stateT>
  160. codecvt_base::result
  161. codecvt_byname<internT,externT, stateT>::do_in (stateT&,
  162.     const externT*, const externT*, const externT*&,
  163.           internT*, internT*, internT*&) const
  164. {
  165.   return codecvt_base::error;
  166. }
  167.  
  168. template <class internT, class externT, class stateT>
  169. codecvt_base::result
  170. codecvt_byname<internT,externT,stateT>::do_unshift (stateT&,
  171.           externT*, externT*, externT*&) const
  172. {
  173.   return codecvt_base::error;
  174. }
  175.  
  176. template <class internT, class externT, class stateT>
  177. int codecvt_byname<internT,externT,stateT>::do_encoding () const
  178.     _RWSTD_THROW_SPEC_NULL
  179. {
  180.   return -1;
  181. }
  182.  
  183. template <class internT, class externT, class stateT>
  184. bool codecvt_byname<internT,externT,stateT>::do_always_noconv () const
  185.     _RWSTD_THROW_SPEC_NULL
  186. {
  187.   return false;
  188. }
  189. #ifndef _RWSTD_NO_NAMESPACE
  190. }
  191. #endif
  192. #pragma option pop
  193. #endif /* __CODECVT_CC */
  194.