/project/jni/stlport/stlport/stl/_time_facets.h

https://github.com/aichunyu/FFPlayer · C Header · 341 lines · 203 code · 67 blank · 71 comment · 4 complexity · a2e0f65a52e4f105291ffdfce9dbaf30 MD5 · raw file

  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. _STLP_BEGIN_NAMESPACE
  33. _STLP_MOVE_TO_PRIV_NAMESPACE
  34. // Template functions used by time_get
  35. // Matching input against a list of names
  36. // Alphabetic input of the names of months and the names
  37. // of weekdays requires matching input against a list of names.
  38. // We use a simple generic algorithm to accomplish this. This
  39. // algorithm is not very efficient, especially for longer lists
  40. // of names, but it probably does not matter for the initial
  41. // implementation and it may never matter, since we do not expect
  42. // this kind of input to be used very often. The algorithm
  43. // could be improved fairly simply by creating a new list of
  44. // names still in the running at each iteration. A more sophisticated
  45. // approach would be to build a trie to do the matching.
  46. //
  47. // We compare each character of the input to the corresponding
  48. // character of each name on the list that has not been eliminated,
  49. // either because every character in the name has already been
  50. // matched, or because some character has not been matched. We
  51. // continue only as long as there are some names that have not been
  52. // eliminated.
  53. // We do not really need a random access iterator (a forward iterator
  54. // would do), but the extra generality makes the notation clumsier,
  55. // and we don't really need it.
  56. // We can recognize a failed match by the fact that the second
  57. // component of the return value will be __name_end.
  58. #define _MAXNAMES 64
  59. #define _MAX_NAME_LENGTH 64
  60. // Both time_get and time_put need a structure of type _Time_Info
  61. // to provide names and abbreviated names for months and days,
  62. // as well as the am/pm designator. The month and weekday tables
  63. // have the all the abbreviated names before all the full names.
  64. // The _Time_Info tables are initialized using the non-template
  65. // function _Init_timeinfo, which has two overloadings: one
  66. // with a single reference parameter for the table to be initialized,
  67. // and one with a second _Locale_time * parameter. The first form
  68. // is called by the default constructor and the second by a special
  69. // constructor invoked from the _byname subclass constructor to
  70. // construct the base class.
  71. class _STLP_CLASS_DECLSPEC _Time_Info {
  72. public:
  73. string _M_dayname[14];
  74. string _M_monthname[24];
  75. string _M_am_pm[2];
  76. string _M_time_format;
  77. string _M_date_format;
  78. string _M_date_time_format;
  79. string _M_long_date_format;
  80. string _M_long_date_time_format;
  81. };
  82. void _STLP_CALL _Init_timeinfo(_Time_Info&);
  83. void _STLP_CALL _Init_timeinfo(_Time_Info&, _Locale_time*);
  84. _STLP_MOVE_TO_STD_NAMESPACE
  85. class _STLP_CLASS_DECLSPEC time_base {
  86. public:
  87. enum dateorder {no_order, dmy, mdy, ymd, ydm};
  88. };
  89. #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
  90. template <class _Ch, class _InIt>
  91. #else
  92. template <class _Ch, class _InIt = istreambuf_iterator<_Ch, char_traits<_Ch> > >
  93. #endif
  94. class time_get : public locale::facet, public time_base {
  95. friend class _Locale_impl;
  96. public:
  97. typedef _Ch char_type;
  98. typedef _InIt iter_type;
  99. explicit time_get(size_t __refs = 0) : locale::facet(__refs)
  100. { _STLP_PRIV _Init_timeinfo(_M_timeinfo); }
  101. dateorder date_order() const { return do_date_order(); }
  102. iter_type get_time(iter_type __s, iter_type __end, ios_base& __str,
  103. ios_base::iostate& __err, tm* __t) const
  104. { return do_get_time(__s, __end, __str, __err, __t); }
  105. iter_type get_date(iter_type __s, iter_type __end, ios_base& __str,
  106. ios_base::iostate& __err, tm* __t) const
  107. { return do_get_date(__s, __end, __str, __err, __t); }
  108. iter_type get_weekday(iter_type __s, iter_type __end, ios_base& __str,
  109. ios_base::iostate& __err, tm* __t) const
  110. { return do_get_weekday(__s, __end, __str, __err, __t); }
  111. iter_type get_monthname(iter_type __s, iter_type __end, ios_base& __str,
  112. ios_base::iostate& __err, tm* __t) const
  113. { return do_get_monthname(__s, __end, __str, __err, __t); }
  114. iter_type get_year(iter_type __s, iter_type __end, ios_base& __str,
  115. ios_base::iostate& __err, tm* __t) const
  116. { return do_get_year(__s, __end, __str, __err, __t); }
  117. static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
  118. protected:
  119. time_get(_Locale_time *, size_t __refs) : locale::facet(__refs) {}
  120. ~time_get() {}
  121. virtual dateorder do_date_order() const {return no_order;}
  122. virtual iter_type do_get_time(iter_type __s, iter_type __end,
  123. ios_base&, ios_base::iostate& __err,
  124. tm* __t) const;
  125. virtual iter_type do_get_date(iter_type __s, iter_type __end,
  126. ios_base&, ios_base::iostate& __err,
  127. tm* __t) const;
  128. virtual iter_type do_get_weekday(iter_type __s, iter_type __end,
  129. ios_base&,
  130. ios_base::iostate& __err,
  131. tm* __t) const;
  132. virtual iter_type do_get_monthname(iter_type __s, iter_type __end,
  133. ios_base&,
  134. ios_base::iostate& __err,
  135. tm* __t) const;
  136. virtual iter_type do_get_year(iter_type __s, iter_type __end,
  137. ios_base&, ios_base::iostate& __err,
  138. tm* __t) const;
  139. _STLP_PRIV _Time_Info _M_timeinfo;
  140. };
  141. _STLP_MOVE_TO_PRIV_NAMESPACE
  142. time_base::dateorder _STLP_CALL __get_date_order(_Locale_time*);
  143. _Locale_time* _STLP_CALL __acquire_time(const char* __name, _Locale_name_hint*);
  144. void _STLP_CALL __release_time(_Locale_time* __time);
  145. _STLP_MOVE_TO_STD_NAMESPACE
  146. template <class _Ch, class _InIt>
  147. class time_get_byname;
  148. #if defined (__GNUC__) && (__GNUC__ < 3)
  149. template <class _Ch, class _InIt>
  150. _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<_Ch, _InIt>*);
  151. #else
  152. _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >*);
  153. #endif
  154. #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
  155. template <class _Ch, class _InIt>
  156. #else
  157. template <class _Ch, class _InIt = istreambuf_iterator<_Ch, char_traits<_Ch> > >
  158. #endif
  159. class time_get_byname : public time_get<_Ch, _InIt> {
  160. public:
  161. typedef time_base::dateorder dateorder;
  162. typedef _InIt iter_type;
  163. explicit time_get_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0)
  164. : time_get<_Ch, _InIt>((_Locale_time*) 0, __refs),
  165. _M_time(_STLP_PRIV __acquire_time(__name, __hint))
  166. { _STLP_PRIV _Init_timeinfo(this->_M_timeinfo, this->_M_time); }
  167. protected:
  168. ~time_get_byname() { _STLP_PRIV __release_time(_M_time); }
  169. dateorder do_date_order() const { return _STLP_PRIV __get_date_order(_M_time); }
  170. private:
  171. _Locale_time* _M_time;
  172. typedef time_get_byname<_Ch, _InIt> _Self;
  173. //explicitely defined as private to avoid warnings:
  174. time_get_byname(_Self const&);
  175. _Self& operator = (_Self const&);
  176. #if defined (__GNUC__) && (__GNUC__ < 3)
  177. friend _Locale_name_hint* _Locale_time_extract_hint<>(_Self*);
  178. #else
  179. friend _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >*);
  180. #endif
  181. };
  182. // time_put facet
  183. // For the formats 'x, 'X', and 'c', do_put calls the first form of
  184. // put with the pattern obtained from _M_timeinfo._M_date_format or
  185. // _M_timeinfo._M_time_format.
  186. // Helper function: __ takes a single-character
  187. // format. As indicated by the foregoing remark, this will never be
  188. // 'x', 'X', or 'c'.
  189. _STLP_MOVE_TO_PRIV_NAMESPACE
  190. char * _STLP_CALL
  191. __write_formatted_time(char *__buf, size_t __buf_size, char __format, char __modifier,
  192. const _Time_Info& __table, const tm* __t);
  193. template <class _OuIt>
  194. inline _OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out_ite,
  195. const ios_base& /* __loc */, char)
  196. { return copy(__first, __last, __out_ite); }
  197. #if !defined (_STLP_NO_WCHAR_T)
  198. template <class _OuIt>
  199. _OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out_ite,
  200. const ios_base& __s, wchar_t);
  201. #endif
  202. _STLP_MOVE_TO_STD_NAMESPACE
  203. #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
  204. template <class _Ch, class _OutIt>
  205. #else
  206. template <class _Ch, class _OutIt = ostreambuf_iterator<_Ch, char_traits<_Ch> > >
  207. #endif
  208. class time_put : public locale::facet, public time_base {
  209. friend class _Locale_impl;
  210. public:
  211. typedef _Ch char_type;
  212. typedef _OutIt iter_type;
  213. explicit time_put(size_t __refs = 0) : locale::facet(__refs)
  214. { _STLP_PRIV _Init_timeinfo(_M_timeinfo); }
  215. _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
  216. const tm* __tmb,
  217. const _Ch* __pat, const _Ch* __pat_end) const;
  218. _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
  219. const tm* __tmb, char __format, char __modifier = 0) const
  220. { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
  221. static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
  222. protected:
  223. time_put(_Locale_time* /*__time*/, size_t __refs) : locale::facet(__refs)
  224. {} //_STLP_PRIV _Init_timeinfo(_M_timeinfo, __time); }
  225. ~time_put() {}
  226. virtual iter_type do_put(iter_type __s, ios_base& __f,
  227. char_type /* __fill */, const tm* __tmb,
  228. char __format, char /* __modifier */) const;
  229. _STLP_PRIV _Time_Info _M_timeinfo;
  230. };
  231. #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
  232. template <class _Ch, class _OutIt>
  233. #else
  234. template <class _Ch, class _OutIt = ostreambuf_iterator<_Ch, char_traits<_Ch> > >
  235. #endif
  236. class time_put_byname : public time_put<_Ch, _OutIt> {
  237. friend class _Locale_impl;
  238. public:
  239. typedef time_base::dateorder dateorder;
  240. typedef _OutIt iter_type;
  241. typedef _Ch char_type;
  242. explicit time_put_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0)
  243. : time_put<_Ch, _OutIt>((_Locale_time*) 0, __refs),
  244. _M_time(_STLP_PRIV __acquire_time(__name, __hint))
  245. { _STLP_PRIV _Init_timeinfo(this->_M_timeinfo, this->_M_time); }
  246. protected:
  247. ~time_put_byname() { _STLP_PRIV __release_time(_M_time); }
  248. private:
  249. _Locale_time* _M_time;
  250. typedef time_put_byname<_Ch, _OutIt> _Self;
  251. //explicitely defined as private to avoid warnings:
  252. time_put_byname(_Self const&);
  253. _Self& operator = (_Self const&);
  254. };
  255. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  256. _STLP_EXPORT_TEMPLATE_CLASS time_get<char, istreambuf_iterator<char, char_traits<char> > >;
  257. _STLP_EXPORT_TEMPLATE_CLASS time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
  258. // _STLP_EXPORT_TEMPLATE_CLASS time_get<char, const char*>;
  259. // _STLP_EXPORT_TEMPLATE_CLASS time_put<char, char*>;
  260. # if !defined (_STLP_NO_WCHAR_T)
  261. _STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  262. _STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  263. // _STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, const wchar_t*>;
  264. // _STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, wchar_t*>;
  265. # endif
  266. #endif
  267. _STLP_END_NAMESPACE
  268. #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
  269. # include <stl/_time_facets.c>
  270. #endif
  271. #endif /* _STLP_INTERNAL_TIME_FACETS_H */
  272. // Local Variables:
  273. // mode:C++
  274. // End: