_time_facets.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers. You should not attempt to use this header
  20. // file directly.
  21. #ifndef _STLP_INTERNAL_TIME_FACETS_H
  22. #define _STLP_INTERNAL_TIME_FACETS_H
  23. #ifndef _STLP_INTERNAL_CTIME
  24. # include <stl/_ctime.h> // Needed (for struct tm) by time facets
  25. #endif
  26. #ifndef _STLP_C_LOCALE_H
  27. # include <stl/c_locale.h>
  28. #endif
  29. #ifndef _STLP_IOS_BASE_H
  30. # include <stl/_ios_base.h>
  31. #endif
  32. #ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
  33. # include <stl/_iostream_string.h>
  34. #endif
  35. #ifndef _STLP_FACETS_FWD_H
  36. # include <stl/_facets_fwd.h>
  37. #endif
  38. _STLP_BEGIN_NAMESPACE
  39. _STLP_MOVE_TO_PRIV_NAMESPACE
  40. // Template functions used by time_get
  41. /* Both time_get and time_put need a structure of type _Time_Info
  42. * to provide names and abbreviated names for months and days,
  43. * as well as the am/pm designator. The month and weekday tables
  44. * have the all the abbreviated names before all the full names.
  45. * The _Time_Info tables are initialized using the non-template
  46. * time_base class, which has a default constructor and two protected.
  47. * The default one initialize _Time_Info with "C" time info. The
  48. * protected initialize _time_Info using a _Locale_time instance
  49. * or using a name( in fact the name is used to build a _Locale_time
  50. * instance that is then used for initialization). */
  51. class _STLP_CLASS_DECLSPEC _Time_Info_Base {
  52. public:
  53. string _M_time_format;
  54. string _M_date_format;
  55. string _M_date_time_format;
  56. string _M_long_date_format;
  57. string _M_long_date_time_format;
  58. };
  59. class _STLP_CLASS_DECLSPEC _Time_Info : public _Time_Info_Base {
  60. public:
  61. string _M_dayname[14];
  62. string _M_monthname[24];
  63. string _M_am_pm[2];
  64. };
  65. #ifndef _STLP_NO_WCHAR_T
  66. class _STLP_CLASS_DECLSPEC _WTime_Info : public _Time_Info_Base {
  67. public:
  68. wstring _M_dayname[14];
  69. wstring _M_monthname[24];
  70. wstring _M_am_pm[2];
  71. };
  72. #endif
  73. _STLP_MOVE_TO_STD_NAMESPACE
  74. class _STLP_CLASS_DECLSPEC time_base {
  75. public:
  76. enum dateorder {no_order, dmy, mdy, ymd, ydm};
  77. };
  78. _STLP_MOVE_TO_PRIV_NAMESPACE
  79. template <class _Ch>
  80. class time_init;
  81. _STLP_TEMPLATE_NULL
  82. class _STLP_CLASS_DECLSPEC time_init<char> {
  83. protected:
  84. time_init();
  85. time_init(const char *name);
  86. time_init(_Locale_time*);
  87. #if defined (__BORLANDC__)
  88. static
  89. #endif
  90. _Time_Info _M_timeinfo;
  91. time_base::dateorder _M_dateorder;
  92. };
  93. #ifndef _STLP_NO_WCHAR_T
  94. _STLP_TEMPLATE_NULL
  95. class _STLP_CLASS_DECLSPEC time_init<wchar_t> {
  96. protected:
  97. time_init();
  98. time_init(const char *name);
  99. time_init(_Locale_time*);
  100. #if defined (__BORLANDC__)
  101. static
  102. #endif
  103. _WTime_Info _M_timeinfo;
  104. time_base::dateorder _M_dateorder;
  105. };
  106. #endif
  107. _STLP_MOVE_TO_STD_NAMESPACE
  108. template <class _Ch, class _InIt>
  109. class time_get : public locale::facet, public time_base, public _STLP_PRIV time_init<_Ch> {
  110. public:
  111. typedef _Ch char_type;
  112. typedef _InIt iter_type;
  113. explicit time_get(size_t __refs = 0) : locale::facet(__refs)
  114. {}
  115. dateorder date_order() const { return do_date_order(); }
  116. iter_type get_time(iter_type __s, iter_type __end, ios_base& __str,
  117. ios_base::iostate& __err, tm* __t) const
  118. { return do_get_time(__s, __end, __str, __err, __t); }
  119. iter_type get_date(iter_type __s, iter_type __end, ios_base& __str,
  120. ios_base::iostate& __err, tm* __t) const
  121. { return do_get_date(__s, __end, __str, __err, __t); }
  122. iter_type get_weekday(iter_type __s, iter_type __end, ios_base& __str,
  123. ios_base::iostate& __err, tm* __t) const
  124. { return do_get_weekday(__s, __end, __str, __err, __t); }
  125. iter_type get_monthname(iter_type __s, iter_type __end, ios_base& __str,
  126. ios_base::iostate& __err, tm* __t) const
  127. { return do_get_monthname(__s, __end, __str, __err, __t); }
  128. iter_type get_year(iter_type __s, iter_type __end, ios_base& __str,
  129. ios_base::iostate& __err, tm* __t) const
  130. { return do_get_year(__s, __end, __str, __err, __t); }
  131. static locale::id id;
  132. protected:
  133. time_get(const char* __name, size_t __refs)
  134. : locale::facet(__refs), _STLP_PRIV time_init<_Ch>(__name)
  135. {}
  136. time_get(_Locale_time *__time)
  137. : _STLP_PRIV time_init<_Ch>(__time)
  138. {}
  139. ~time_get() {}
  140. virtual dateorder do_date_order() const { return this->_M_dateorder; }
  141. virtual iter_type do_get_time(iter_type __s, iter_type __end,
  142. ios_base&, ios_base::iostate& __err,
  143. tm* __t) const;
  144. virtual iter_type do_get_date(iter_type __s, iter_type __end,
  145. ios_base&, ios_base::iostate& __err,
  146. tm* __t) const;
  147. virtual iter_type do_get_weekday(iter_type __s, iter_type __end,
  148. ios_base&,
  149. ios_base::iostate& __err,
  150. tm* __t) const;
  151. virtual iter_type do_get_monthname(iter_type __s, iter_type __end,
  152. ios_base&,
  153. ios_base::iostate& __err,
  154. tm* __t) const;
  155. virtual iter_type do_get_year(iter_type __s, iter_type __end,
  156. ios_base&, ios_base::iostate& __err,
  157. tm* __t) const;
  158. };
  159. #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
  160. template <class _Ch, class _InIt>
  161. #else
  162. template <class _Ch, class _InIt = istreambuf_iterator<_Ch, char_traits<_Ch> > >
  163. #endif
  164. class time_get_byname : public time_get<_Ch, _InIt> {
  165. friend class _Locale_impl;
  166. public:
  167. typedef time_base::dateorder dateorder;
  168. typedef _InIt iter_type;
  169. explicit time_get_byname(const char* __name, size_t __refs = 0)
  170. : time_get<_Ch, _InIt>(__name, __refs) {}
  171. protected:
  172. ~time_get_byname() {}
  173. dateorder do_date_order() const { return this->_M_dateorder; }
  174. private:
  175. time_get_byname(_Locale_time *__time)
  176. : time_get<_Ch, _InIt>(__time)
  177. {}
  178. typedef time_get_byname<_Ch, _InIt> _Self;
  179. //explicitely defined as private to avoid warnings:
  180. time_get_byname(_Self const&);
  181. _Self& operator = (_Self const&);
  182. };
  183. // time_put facet
  184. // For the formats 'x, 'X', and 'c', do_put calls the first form of
  185. // put with the pattern obtained from _M_timeinfo._M_date_format or
  186. // _M_timeinfo._M_time_format.
  187. // Helper function: __ takes a single-character
  188. // format. As indicated by the foregoing remark, this will never be
  189. // 'x', 'X', or 'c'.
  190. _STLP_MOVE_TO_PRIV_NAMESPACE
  191. _STLP_DECLSPEC void _STLP_CALL
  192. __write_formatted_time(__iostring&, const ctype<char>& __ct,
  193. char __format, char __modifier,
  194. const _Time_Info& __table, const tm* __t);
  195. #ifndef _STLP_NO_WCHAR_T
  196. _STLP_DECLSPEC void _STLP_CALL
  197. __write_formatted_time(__iowstring&, const ctype<wchar_t>& __ct,
  198. char __format, char __modifier,
  199. const _WTime_Info& __table, const tm* __t);
  200. #endif
  201. _STLP_MOVE_TO_STD_NAMESPACE
  202. template <class _Ch, class _OutIt>
  203. class time_put : public locale::facet, public time_base, public _STLP_PRIV time_init<_Ch> {
  204. public:
  205. typedef _Ch char_type;
  206. typedef _OutIt iter_type;
  207. explicit time_put(size_t __refs = 0) : locale::facet(__refs)
  208. {}
  209. _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
  210. const tm* __tmb,
  211. const _Ch* __pat, const _Ch* __pat_end) const;
  212. _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
  213. const tm* __tmb, char __format, char __modifier = 0) const
  214. { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
  215. static locale::id id;
  216. protected:
  217. time_put(const char* __name, size_t __refs)
  218. : locale::facet(__refs), _STLP_PRIV time_init<_Ch>(__name)
  219. {}
  220. time_put(_Locale_time *__time)
  221. : _STLP_PRIV time_init<_Ch>(__time)
  222. {}
  223. ~time_put() {}
  224. virtual iter_type do_put(iter_type __s, ios_base& __f,
  225. char_type /* __fill */, const tm* __tmb,
  226. char __format, char /* __modifier */) const;
  227. };
  228. #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
  229. template <class _Ch, class _OutIt>
  230. #else
  231. template <class _Ch, class _OutIt = ostreambuf_iterator<_Ch, char_traits<_Ch> > >
  232. #endif
  233. class time_put_byname : public time_put<_Ch, _OutIt> {
  234. friend class _Locale_impl;
  235. public:
  236. typedef time_base::dateorder dateorder;
  237. typedef _OutIt iter_type;
  238. typedef _Ch char_type;
  239. explicit time_put_byname(const char * __name, size_t __refs = 0)
  240. : time_put<_Ch, _OutIt>(__name, __refs)
  241. {}
  242. protected:
  243. ~time_put_byname() {}
  244. private:
  245. time_put_byname(_Locale_time *__time)
  246. : time_put<_Ch, _OutIt>(__time)
  247. {}
  248. typedef time_put_byname<_Ch, _OutIt> _Self;
  249. //explicitely defined as private to avoid warnings:
  250. time_put_byname(_Self const&);
  251. _Self& operator = (_Self const&);
  252. };
  253. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  254. _STLP_EXPORT_TEMPLATE_CLASS time_get<char, istreambuf_iterator<char, char_traits<char> > >;
  255. _STLP_EXPORT_TEMPLATE_CLASS time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
  256. # if !defined (_STLP_NO_WCHAR_T)
  257. _STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  258. _STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  259. # endif
  260. #endif
  261. _STLP_END_NAMESPACE
  262. #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
  263. # include <stl/_time_facets.c>
  264. #endif
  265. #endif /* _STLP_INTERNAL_TIME_FACETS_H */
  266. // Local Variables:
  267. // mode:C++
  268. // End: