home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / numeral.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  17.0 KB  |  486 lines

  1. #ifndef __NUMERAL_H
  2. #define __NUMERAL_H
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * numeral - Declarations for the Standard Library numeric facets
  8.  *
  9.  *
  10.  ***************************************************************************
  11.  *
  12.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  13.  * ALL RIGHTS RESERVED *
  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_NUMERAL__
  45. #define __STD_NUMERAL__ 1
  46.  
  47. #ifndef __STD_RWLOCALE__
  48. #include "rw/rwlocale.h"
  49. #endif
  50.  
  51. #ifndef __STD_IOSBASE__
  52. #include "rw/iosbase.h"
  53. #endif
  54.  
  55. #ifndef __STD_LIMITS
  56. #include <limits>
  57. #endif
  58.  
  59.  
  60.  
  61. #ifndef _RWSTD_NO_NAMESPACE
  62. namespace __rwstd {
  63. #endif
  64.  
  65. // ------------------------------------------------------
  66. // Implementation class template -- numpunct_init<charT>.
  67. // ------------------------------------------------------
  68.  
  69. // Structure used to initialize a rwstd::numpunct_data.
  70.  
  71. template <class charT>
  72. class _RWSTDExportTemplate numpunct_init {
  73.  public:
  74.   bool del_;                    // Kill the bearer of this message
  75.   charT dp_, ts_;               // Decimal point and thousands separator
  76.   const char *gr_;              // Digit grouping rule
  77.   const charT *tn_, *fn_;       // Strings for boolean true and false
  78. };
  79.  
  80. // --------------------------------------
  81. // Implementation class -- numpunct_base.
  82. // --------------------------------------
  83.  
  84. // Contains parts of numpunct<charT> that don't depend on the charT template
  85. // parameter.
  86.  
  87. class _RWSTDExport numpunct_base {
  88.  public:
  89.   static numpunct_init<char> *get_named_init_ (const char*);
  90. };
  91.  
  92. // ------------------------------------------------------
  93. // Implementation class template -- numpunct_data<charT>.
  94. // ------------------------------------------------------
  95.  
  96. // numpunct<charT> derives from this (via rwstd::numpunct_impl) to get its
  97. // private data members.
  98.  
  99. template <class charT>
  100. class _RWSTDExportTemplate numpunct_data :
  101.     public numpunct_base,
  102.     public punct_data<charT>
  103. {
  104.   friend class _STD::numpunct<charT>;
  105.   friend class keyword_cracker<charT>;
  106.  
  107.   typedef basic_string<charT,char_traits<charT>,allocator<charT> > string_type;
  108.  
  109.   string_type tn_, fn_;
  110.  
  111.   keyword_def<charT> tf_defs_[2];
  112.   keyword_map<charT> tf_map_;
  113.  
  114.  protected:
  115.   numpunct_data (const numpunct_init<charT>*);
  116.   numpunct_init<charT> *get_init_by_name_ (const char*);
  117.   void rw_init (void);
  118. };
  119.  
  120. template <class charT>
  121. inline numpunct_data<charT>::numpunct_data
  122.     (const numpunct_init<charT> *init)
  123. {
  124.   if (!init) {
  125.     this->dp_=charT('.');
  126.     this->ts_=charT(',');
  127.   } else {
  128.     this->dp_=init->dp_;
  129.     this->ts_=init->ts_;
  130.     this->gr_=init->gr_;
  131.     tn_=init->tn_;
  132.     fn_=init->fn_;
  133.  
  134.     if (init->del_)
  135.       delete[] (char*) init;
  136.   }
  137. }
  138.  
  139. template <class charT>
  140. numpunct_init<charT>*
  141. fixup_numpunct_init
  142.     (numpunct_init<char>*,charT*);
  143.  
  144. _RWSTD_TEMPLATE
  145. inline numpunct_init<char>* 
  146. fixup_numpunct_init(numpunct_init<char> *init,char*)
  147. {  return init; }
  148.  
  149. // ------------------------------------------------------
  150. // Implementation class template -- numpunct_impl<charT>.
  151. // ------------------------------------------------------
  152.  
  153. // numpunct<charT> derives from this to obtain the part of its behavior that
  154. // must be specialized for char and wchar_t.  This lets us avoid specializing
  155. // the whole numpunct<charT> template.  Currently the only specialized behavior
  156. // is the initialization of private data members in the constructor.
  157.  
  158. template <class charT>
  159. class _RWSTDExportTemplate numpunct_impl :
  160.     public numpunct_data<charT>
  161. {
  162.  protected:
  163.   numpunct_impl (const numpunct_init<charT>*);
  164.   static const numpunct_init<charT> *get_ivals_ ()
  165.     { return NULL; }
  166. };
  167.  
  168. _RWSTD_TEMPLATE
  169. class _RWSTDExport numpunct_impl<char>:                  // Specialization
  170.     public numpunct_data<char>
  171. {
  172.   static numpunct_init<char> ivals_;        // Vendor-supplied
  173.  protected:
  174.   numpunct_impl
  175.       (const numpunct_init<char> *init):
  176.        numpunct_data<char>(init) { }
  177.   static const numpunct_init<char> *get_ivals_ ()
  178.     { return &ivals_; }
  179. };
  180.  
  181. #ifndef _RWSTD_NO_WIDE_CHAR
  182. _RWSTD_TEMPLATE
  183. class _RWSTDExport numpunct_impl<wchar_t>:               // Specialization
  184.     public numpunct_data<wchar_t>
  185. {
  186.   static numpunct_init<wchar_t> ivals_;     // Vendor-supplied
  187.  protected:
  188.   numpunct_impl
  189.       (const numpunct_init<wchar_t> *init):
  190.        numpunct_data<wchar_t>(init) { }
  191.   static const numpunct_init<wchar_t> *get_ivals_ ()
  192.     { return &ivals_; }
  193. };
  194. #endif // _RWSTD_NO_WIDE_CHAR
  195.  
  196.  
  197. #ifndef _RWSTD_NO_NAMESPACE
  198. } namespace std {
  199. #endif
  200.  
  201. // ---------------------------------------------------------------
  202. // Standard numeric parsing facet -- num_get<charT,InputIterator>.
  203. // ---------------------------------------------------------------
  204.  
  205. template <class charT, class InputIterator>
  206. class  num_get: public locale::facet
  207. {
  208.  public:
  209.   typedef charT char_type;
  210.   typedef InputIterator iter_type;
  211.  
  212.   _EXPLICIT num_get (size_t refs=0): locale::facet(refs,locale::numeric) { }
  213.  
  214. #ifndef _RWSTD_NO_BOOL
  215.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  216.                  bool& v) const            { return do_get(i,e,f,err,v); }
  217. #endif
  218.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  219.                  long& v) const            { return do_get(i,e,f,err,v); }
  220.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  221.                  unsigned short& v) const  { return do_get(i,e,f,err,v); }
  222.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  223.                  unsigned int& v) const    { return do_get(i,e,f,err,v); }
  224.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  225.                  unsigned long& v) const   { return do_get(i,e,f,err,v); }
  226.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  227.                  float& v) const           { return do_get(i,e,f,err,v); }
  228.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  229.                  double& v) const          { return do_get(i,e,f,err,v); }
  230.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  231.                  long double& v) const     { return do_get(i,e,f,err,v); }
  232.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  233.                  void*& p) const           { return do_get(i,e,f,err,p); }
  234.  
  235.   static locale::id _RWSTDExport id;
  236.  
  237.   // Extension for compilers that have an extra-long integer type:
  238. #ifdef _RWSTD_LONG_LONG
  239.   iter_type get (iter_type i, iter_type e, ios_base &f, ios_base::iostate &err,
  240.                  _RWSTD_LONG_LONG& v) const { return do_get(i,e,f,err,v); }
  241. #endif
  242.  
  243.   // Implementation:
  244.   enum { facet_cat_ = locale::numeric, ok_implicit_ = 1 };
  245.  
  246.  protected:
  247.   virtual ~num_get();
  248.  
  249. #ifndef _RWSTD_NO_BOOL
  250.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  251.                             ios_base::iostate& err, bool& v) const;
  252. #endif
  253.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  254.                             ios_base::iostate& err, long& v) const;
  255.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  256.                             ios_base::iostate& err, unsigned short& v) const;
  257.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  258.                             ios_base::iostate& err, unsigned int& v) const;
  259.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  260.                             ios_base::iostate& err, unsigned long& v) const;
  261.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  262.                             ios_base::iostate& err, float& v) const;
  263.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  264.                             ios_base::iostate& err, double& v) const;
  265.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  266.                             ios_base::iostate& err, long double& v) const;
  267.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  268.                             ios_base::iostate& err, void*& p) const;
  269.  
  270. #ifdef _RWSTD_LONG_LONG
  271.   virtual iter_type do_get (iter_type, iter_type, ios_base&,
  272.                             ios_base::iostate& err, _RWSTD_LONG_LONG& v) const;
  273. #endif
  274.  
  275.   // Implementation:
  276.  
  277.  private:
  278.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  279.   locale::id &get_id (void) const { return id; }
  280.   #endif
  281. };
  282.  
  283. // -------------------------------------------------------------------
  284. // Standard numeric formatting facet -- num_put<charT,OutputIterator>.
  285. // -------------------------------------------------------------------
  286.  
  287. template <class charT, class OutputIterator>
  288. class  num_put: public locale::facet {
  289.  public:
  290.   typedef charT char_type;
  291.   typedef OutputIterator iter_type;
  292.  
  293.   _EXPLICIT num_put (size_t refs=0): locale::facet(refs,locale::numeric) { }
  294.  
  295. #ifndef _RWSTD_NO_BOOL
  296.   iter_type put (iter_type s, ios_base& f, char_type fill, bool v)
  297.                  const { return do_put(s,f,fill,v); }
  298. #endif
  299.   iter_type put (iter_type s, ios_base& f, char_type fill, long v)
  300.                  const { return do_put(s,f,fill,v); }
  301.   iter_type put (iter_type s, ios_base& f, char_type fill, unsigned long v)
  302.                  const { return do_put(s,f,fill,v); }
  303.   iter_type put (iter_type s, ios_base& f, char_type fill, double v)
  304.                  const { return do_put(s,f,fill,v); }
  305.   iter_type put (iter_type s, ios_base& f, char_type fill, long double v)
  306.                  const { return do_put(s,f,fill,v); }
  307.   iter_type put (iter_type s, ios_base& f, char_type fill, void* p)
  308.                  const { return do_put(s,f,fill,p); }
  309.  
  310.   // Rogue Wave extensions.
  311.   iter_type put (iter_type s, ios_base& f, char_type fill, short v)
  312.                  const { return do_put(s,f,fill,v); }
  313.   iter_type put (iter_type s, ios_base& f, char_type fill, unsigned short v)
  314.                  const { return do_put(s,f,fill,v); }
  315.   iter_type put (iter_type s, ios_base& f, char_type fill, int v)
  316.                  const { return do_put(s,f,fill,v); }
  317.   iter_type put (iter_type s, ios_base& f, char_type fill, unsigned int v)
  318.                  const { return do_put(s,f,fill,v); }
  319.  
  320. #ifdef _RWSTD_LONG_LONG
  321.   iter_type put (iter_type s, ios_base& f, char_type fill, _RWSTD_LONG_LONG v)
  322.                  const { return do_put(s,f,fill,v); }
  323. #endif
  324.  
  325.   static locale::id _RWSTDExport id;
  326.  
  327.   // Implementation:
  328.   enum { facet_cat_ = locale::numeric, ok_implicit_ = 1 };
  329.  
  330.  protected:
  331.   virtual ~num_put();
  332.  
  333. #ifndef _RWSTD_NO_BOOL
  334.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  335.                             bool v) const;
  336. #endif
  337.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  338.                             long v) const;
  339.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  340.                             unsigned long v) const;
  341.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  342.                             double v) const;
  343.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  344.                             long double v) const;
  345.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  346.                             void* p) const;
  347.  
  348.   // Rogue Wave extensions.
  349.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  350.                             short v) const;
  351.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  352.                             unsigned short v) const;
  353.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  354.                             int v) const;
  355.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  356.                             unsigned int v) const;
  357.  
  358. #ifdef _RWSTD_LONG_LONG
  359.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  360.                             _RWSTD_LONG_LONG v) const;
  361. #endif
  362.  
  363.   // Implementation.
  364.  
  365.  private:
  366.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  367.   locale::id &get_id (void) const { return id; }
  368.   #endif
  369. };
  370.  
  371. // ------------------------------------------------------
  372. // Standard numeric punctuation facet -- numpunct<charT>.
  373. // ------------------------------------------------------
  374.  
  375. template <class charT>
  376. class  numpunct: public locale::facet,
  377.     public __RWSTD::numpunct_impl<charT>
  378. {
  379.  public:
  380.   typedef charT char_type;
  381.   typedef basic_string<charT,char_traits<charT>,allocator<charT> >
  382.     string_type;
  383.  
  384.   // The second parameter (i) to the constructor is implementation specific.
  385.   // For portable code, always let it default as shown.
  386.   _EXPLICIT numpunct (size_t refs=0,
  387.       const __RWSTD::numpunct_init<charT> *i =
  388.       __RWSTD::numpunct_impl<charT>::get_ivals_());
  389.  
  390.   char_type   decimal_point() const { return do_decimal_point(); }
  391.   char_type   thousands_sep() const { return do_thousands_sep(); }
  392.   string      grouping()      const { return do_grouping(); }
  393.   string_type truename()      const { return do_truename(); }
  394.   string_type falsename()     const { return do_falsename(); }
  395.  
  396.   static locale::id id;
  397.  
  398.   // Implementation:
  399.   enum { facet_cat_ = locale::numeric, ok_implicit_ = 1 };
  400.  
  401.  protected:
  402.   virtual ~numpunct();
  403.  
  404.   virtual char_type   do_decimal_point() const;
  405.   virtual char_type   do_thousands_sep() const;
  406.   virtual string      do_grouping()      const;
  407.   virtual string_type do_truename()      const;
  408.   virtual string_type do_falsename()     const;
  409.  
  410.   // Implementation:
  411.  
  412.  private:
  413.   void rw_init (void);
  414.  
  415.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  416.   locale::id &get_id (void) const { return id; }
  417.   #endif
  418.  
  419. #if 0 //def HPPA_WA
  420. public:
  421. #endif
  422.   static const __RWSTD::numpunct_init<charT> *get_ivals_ ()
  423.     { return __RWSTD::numpunct_impl<charT>::get_ivals_(); }
  424. };
  425.  
  426. template <class charT>
  427. inline numpunct<charT>::numpunct
  428.     (size_t refs,const __RWSTD::numpunct_init<charT> *init):
  429.      locale::facet(refs,locale::numeric),
  430.      __RWSTD::numpunct_impl<charT>(init)
  431. { }
  432.  
  433. // -------------------------------------------------
  434. // Standard derived facet -- numpunct_byname<charT>.
  435. // -------------------------------------------------
  436.  
  437. template <class charT>
  438. class _RWSTDExportTemplate numpunct_byname: public numpunct<charT> {
  439.  public:
  440.   _EXPLICIT numpunct_byname (const char*, size_t refs=0);
  441.  
  442.  protected:
  443.   virtual ~numpunct_byname();
  444.  
  445. // Virtual member functions inherited from numpunct<charT>:
  446. // virtual char_type   do_decimal_point() const;
  447. // virtual char_type   do_thousands_sep() const;
  448. // virtual string      do_grouping() const;
  449. // virtual string_type do_truename() const;
  450. // virtual string_type do_falsename() const;
  451. };
  452.  
  453. #ifndef _RWSTD_NO_NAMESPACE
  454. } namespace __rwstd {
  455. #endif
  456.  
  457. #ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC
  458. template <class charT>
  459. inline numpunct<charT>* _RWSTDExport create_named_facet
  460.     (numpunct<charT>*,const char *name,size_t refs)
  461. { return new numpunct_byname<charT>(name,refs); }
  462. #else
  463. inline _STD::numpunct<char>* _RWSTDExport create_named_facet
  464.     (_STD::numpunct<char>*,const char *name,size_t refs)
  465. { return new numpunct_byname<char>(name,refs); }
  466. #ifndef _RWSTD_NO_WIDE_CHAR
  467. inline _STD::numpunct<wchar_t>* _RWSTDExport create_named_facet
  468.     (_STD::numpunct<wchar_t>*,const char *name,size_t refs)
  469. { return new numpunct_byname<wchar_t>(name,refs); }
  470. #endif
  471. #endif
  472.  
  473. #ifndef _RWSTD_NO_NAMESPACE
  474. }
  475. #endif
  476.  
  477. #ifdef _RWSTD_COMPILE_INSTANTIATE
  478. #include <rw/numeral.cc>
  479. #endif
  480.  
  481.  
  482. #endif // __STD_NUMERAL__
  483.  
  484. #pragma option pop
  485. #endif /* __NUMERAL_H */
  486.