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

  1. #ifndef __BOR_RW__TIME_H
  2. #define __BOR_RW__TIME_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * time - Declarations for the Standard Library time facets
  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_TIME__
  45. #define __STD_TIME__
  46.  
  47. #ifndef __STD_RWLOCALE__
  48. #include <rw/rwlocale> 
  49. #endif
  50.  
  51. #ifndef __STD_RW_LOCNUMRW__
  52. #include <rw/numbrw>
  53. #endif
  54.  
  55. #ifndef __STD_RW_LOCHELP__
  56. #include <rw/lochelp>
  57. #endif
  58.  
  59. #ifndef _RWSTD_NO_NAMESPACE
  60. namespace std {
  61. #endif
  62.  
  63. struct _RWSTDExport time_base {
  64.    enum dateorder { no_order, dmy, mdy, ymd, ydm };
  65. };
  66.  
  67. #ifndef _RWSTD_NO_NAMESPACE
  68. } namespace __rwstd {
  69. #endif
  70.  
  71. #if !defined (_RWSTD_NO_NEW_HEADER) && !defined (_RWSTD_NO_NAMESPACE)
  72.   using std::tm;
  73. #endif
  74.  
  75. // ------------------------------------------------------------------
  76. // Implementation class template -- time_reader<charT,InputIterator>.
  77. // ------------------------------------------------------------------
  78.  
  79. template <class charT,class InputIterator>
  80. class _RWSTDExportTemplate time_reader :
  81.     public digit_reader<charT,InputIterator>
  82. {
  83.  public:
  84.   typedef _TYPENAME timepunct<charT>::string_type string_type;
  85.   const timepunct<charT> &__timp;
  86.  
  87.   time_reader (InputIterator& in,InputIterator& end,
  88.       _RW_STD::ios_base& io, const timepunct<charT>& timepunct);
  89.  
  90.   bool get_time_pattern (const string_type& pattern,tm *time);
  91.  
  92.   static const timepunct<charT>& __idiocy (_RW_STD::ios_base& io) {
  93.     const _RW_STD::locale loc=io.getloc();
  94. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  95.     return _RW_STD::use_facet<timepunct<charT> >(loc);
  96. #else
  97.     return _RW_STD::use_facet(loc,(timepunct<charT>*)0);
  98. #endif //  _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  99.  
  100.   }
  101. };
  102.  
  103. #ifndef _RWSTD_NO_NAMESPACE
  104. } namespace std {
  105. #endif
  106.  
  107. // ----------------------------------------------------------------------
  108. // Standard time and date parsing facet -- time_get<charT,InputIterator>.
  109. // ----------------------------------------------------------------------
  110.  
  111. template <class charT,class InputIterator>
  112. class _RWSTDExportTemplate time_get: public locale::facet, public time_base {  // RW_BUG: fix for bts-42913
  113.  public:
  114.   typedef charT char_type;
  115.   typedef InputIterator iter_type;
  116.  
  117.   _EXPLICIT time_get (size_t refs=0): locale::facet(refs,locale::time)
  118.   { ; }
  119.  
  120.   dateorder date_order() const { return do_date_order(); }
  121.   iter_type get_time (iter_type start, iter_type end, ios_base& format,
  122.       ios_base::iostate &err, tm* time) const
  123.         { return do_get_time (start,end,format,err,time); }
  124.  
  125.   iter_type get_date (iter_type start, iter_type end, ios_base& format,
  126.       ios_base::iostate &err, tm* time) const
  127.         { return do_get_date(start,end,format,err,time); }
  128.  
  129.   iter_type get_weekday (iter_type start, iter_type end, ios_base& format,
  130.       ios_base::iostate &err, tm* time) const
  131.         { return do_get_weekday(start,end,format,err,time); }
  132.  
  133.   iter_type get_monthname (iter_type start, iter_type end, ios_base& format,
  134.       ios_base::iostate &err, tm* time) const
  135.         { return do_get_monthname(start,end,format,err,time); }
  136.  
  137.   iter_type get_year (iter_type start, iter_type end, ios_base& format,
  138.       ios_base::iostate &err, tm* time) const
  139.         { return do_get_year(start,end,format,err,time); }
  140.  
  141.   static locale::id id;
  142.  
  143.   // Implementation:
  144.   enum { __facet_cat = locale::time, __ok_implicit = 1 };
  145.  
  146.  protected:
  147.   virtual ~time_get();
  148.  
  149.   virtual dateorder do_date_order()  const;
  150.  
  151.   virtual iter_type do_get_time
  152.             (iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const;
  153.   virtual iter_type do_get_date
  154.             (iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const;
  155.   virtual iter_type do_get_weekday
  156.             (iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const;
  157.   virtual iter_type do_get_monthname
  158.             (iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const;
  159.   virtual iter_type do_get_year
  160.             (iter_type, iter_type, ios_base&, ios_base::iostate&, tm*) const;
  161.  
  162.   // Implementation:
  163.  
  164.  protected:
  165.   const __RWSTD::timepunct<charT>* __timp;
  166.   string __name;
  167.  
  168.  private:
  169.   void __init_facet (const locale* loc)
  170.   { 
  171.     __RWSTD::use_Clib_locale clocale(__name.c_str(),LC_TIME);    
  172.   #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  173.     __timp = &use_facet<__RWSTD::timepunct<charT> >(*loc);
  174.   #else
  175.     __timp = &use_facet(*loc,(__RWSTD::timepunct<charT>*)0);
  176.   #endif
  177.   }
  178.  
  179.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  180.   locale::id &__get_id (void) const { return id; }
  181.   #endif
  182. };
  183.  
  184. // --------------------------------------------------------------------------
  185. // Standard time and date formatting facet -- time_put<charT,OutputIterator>.
  186. // --------------------------------------------------------------------------
  187.  
  188. template <class charT,class OutputIterator>
  189. class _RWSTDExportTemplate time_put: public locale::facet { // RW_BUG: fix for bts-42913
  190.  public:
  191.   typedef charT char_type;
  192.   typedef OutputIterator iter_type;
  193.  
  194.   _EXPLICIT time_put (size_t refs=0) : locale::facet(refs,locale::time)
  195.   { ; }
  196.  
  197.   iter_type put (iter_type start, ios_base& format, char_type fill,
  198.       const tm* time, const char_type *pattern, const char_type *pat_end) const;
  199.  
  200.   iter_type put (iter_type start, ios_base& format, char_type fill,
  201.       const tm* time, char fmt, char modifier = 0) const
  202.         { return do_put(start,format,fill,time,fmt,modifier); }
  203.  
  204.   static locale::id id;
  205.  
  206.   // Implementation:
  207.   enum { __facet_cat = locale::time, __ok_implicit = 1 };
  208.  
  209.  protected:
  210.   virtual ~time_put();
  211.  
  212.   virtual iter_type do_put (iter_type, ios_base&, char_type fill,
  213.            const tm* time, char fmt, char modifier) const;
  214.  
  215.  protected:
  216.   const __RWSTD::timepunct<charT>* __timp;
  217.   string __name;
  218.  
  219.  private:
  220.   void __init_facet (const locale* loc)
  221.   { 
  222.     __RWSTD::use_Clib_locale clocale(__name.c_str(),LC_TIME);    
  223.   #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  224.     __timp = &use_facet<__RWSTD::timepunct<charT> >(*loc);
  225.   #else
  226.     __timp = &use_facet(*loc,(__RWSTD::timepunct<charT>*)0);
  227.   #endif
  228.   }
  229.   #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  230.   locale::id &__get_id (void) const { return id; }
  231.   #endif
  232. };
  233.  
  234. // -------------------------------------------------
  235. // Standard derived facet -- time_get_byname<charT>.
  236. // -------------------------------------------------
  237.  
  238. template <class charT, class InputIterator>
  239. class  time_get_byname: public time_get<charT,InputIterator> {
  240.  public:
  241.   _EXPLICIT time_get_byname (const char*, size_t refs=0);
  242.  
  243.  protected:
  244.   virtual ~time_get_byname();
  245.  
  246. // Virtual member functions inherited from time_get<charT,InputIterator>:
  247. // virtual dateorder do_date_order()  const;
  248. // virtual iter_type do_get_time (iter_type i, iter_type e, ios_base&,
  249. //                                ios_base::iostate &err, tm* t) const;
  250. // virtual iter_type do_get_date (iter_type i, iter_type e, ios_base&,
  251. //                                ios_base::iostate &err, tm* t) const;
  252. // virtual iter_type do_get_weekday (iter_type i, iter_type e, ios_base&,
  253. //                                ios_base::iostate &err, tm* t) const;
  254. // virtual iter_type do_get_monthname (iter_type i, iter_type e, ios_base&,
  255. //                                ios_base::iostate &err, tm* t) const;
  256. // virtual iter_type do_get_year (iter_type i, iter_type e, ios_base&,
  257. //                                ios_base::iostate &err, tm* t) const;
  258. };
  259.  
  260. // -------------------------------------------------
  261. // Standard derived facet -- time_put_byname<charT>.
  262. // -------------------------------------------------
  263.  
  264. template <class charT, class OutputIterator>
  265. class  time_put_byname: public time_put<charT,OutputIterator> {
  266.  public:
  267.   _EXPLICIT time_put_byname (const char*, size_t refs=0); 
  268.  
  269.  protected:
  270.   virtual ~time_put_byname();
  271.  
  272. // Virtual member functions inherited from time_put<charT,OutputIterator>:
  273. // virtual iter_type do_put (iter_type s, ios_base&, char_type fill,
  274. //                           const tm* t, char format, char modifier) const;
  275. };
  276. #ifndef _RWSTD_NO_NAMESPACE
  277. } namespace __rwstd {
  278. #endif
  279.  
  280. #ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC
  281.  
  282. template <class charT, class InputIterator>
  283. inline _RW_STD::time_get<charT,InputIterator>* create_named_facet
  284.     (_RW_STD::time_get<charT,InputIterator>*,const char *name,size_t refs)
  285. { return new _RW_STD::time_get_byname<charT,InputIterator>(name,refs); }
  286.  
  287. template <class charT, class OutputIterator>
  288. inline _RW_STD::time_put<charT,OutputIterator>* create_named_facet
  289.     (_RW_STD::time_put<charT,OutputIterator>*,const char *name,size_t refs)
  290. { return new _RW_STD::time_put_byname<charT,OutputIterator>(name,refs); }
  291. #else
  292. _RWSTD_TEMPLATE 
  293. inline _RW_STD::time_get<char,_RW_STD::istreambuf_iterator<char,_RW_STD::char_traits<char> > >* create_named_facet
  294.     (_RW_STD::time_get<char,_RW_STD::istreambuf_iterator<char,_RW_STD::char_traits<char> > >*,const char *name,size_t refs)
  295. { return new _RW_STD::time_get_byname<char,_RW_STD::istreambuf_iterator<char,_RW_STD::char_traits<char> > >(name,refs); }
  296.  
  297. inline _RW_STD::time_put<char,_RW_STD::ostreambuf_iterator<char,_RW_STD::char_traits<char> > >* create_named_facet
  298.     (_RW_STD::time_put<char,_RW_STD::ostreambuf_iterator<char,_RW_STD::char_traits<char> > >*,const char *name,size_t refs)
  299. { return new _RW_STD::time_put_byname<char,_RW_STD::ostreambuf_iterator<char,_RW_STD::char_traits<char> > >(name,refs); }
  300.  
  301. #ifndef _RWSTD_NO_WIDE_CHAR
  302. _RWSTD_TEMPLATE
  303. inline _RW_STD::time_get<wchar_t,_RW_STD::istreambuf_iterator<wchar_t,_RW_STD::char_traits<wchar_t> > >* create_named_facet
  304.     (_RW_STD::time_get<wchar_t,_RW_STD::istreambuf_iterator<wchar_t,_RW_STD::char_traits<wchar_t> > >*,const char *name,size_t refs)
  305. { return new _RW_STD::time_get_byname<wchar_t,_RW_STD::istreambuf_iterator<wchar_t,_RW_STD::char_traits<wchar_t> > >(name,refs); }
  306.  
  307. inline _RW_STD::time_put<wchar_t,_RW_STD::ostreambuf_iterator<wchar_t,_RW_STD::char_traits<wchar_t> > >* create_named_facet
  308.     (_RW_STD::time_put<wchar_t,_RW_STD::ostreambuf_iterator<wchar_t,_RW_STD::char_traits<wchar_t> > >*,const char *name,size_t refs)
  309. { return new _RW_STD::time_put_byname<wchar_t,_RW_STD::ostreambuf_iterator<wchar_t,_RW_STD::char_traits<wchar_t> > >(name,refs); }
  310.  
  311. #endif // _RWSTD_NO_WIDE_CHAR
  312. #endif // _RWSTD_NO_FUNC_PARTIAL_SPEC
  313. #ifndef _RWSTD_NO_NAMESPACE
  314. } // namespace __rwstd
  315. #endif
  316.  
  317. #ifdef _RWSTD_COMPILE_INSTANTIATE
  318. #include <rw/time.cc>
  319. #endif
  320. #endif // __STD_TIME__
  321. #pragma option pop
  322. #endif /* __BOR_RW__TIME_H */
  323.