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