[CMAKE]
[reactos.git] / lib / 3rdparty / stlport / stlport / stl / _time_facets.h
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
22
23 #ifndef _STLP_INTERNAL_TIME_FACETS_H
24 #define _STLP_INTERNAL_TIME_FACETS_H
25
26 #ifndef _STLP_INTERNAL_CTIME
27 # include <stl/_ctime.h> // Needed (for struct tm) by time facets
28 #endif
29
30 #ifndef _STLP_C_LOCALE_H
31 # include <stl/c_locale.h>
32 #endif
33
34 #ifndef _STLP_IOS_BASE_H
35 # include <stl/_ios_base.h>
36 #endif
37
38 #ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
39 # include <stl/_iostream_string.h>
40 #endif
41
42 #ifndef _STLP_FACETS_FWD_H
43 # include <stl/_facets_fwd.h>
44 #endif
45
46 _STLP_BEGIN_NAMESPACE
47
48 _STLP_MOVE_TO_PRIV_NAMESPACE
49
50 // Template functions used by time_get
51
52 /* Both time_get and time_put need a structure of type _Time_Info
53 * to provide names and abbreviated names for months and days,
54 * as well as the am/pm designator. The month and weekday tables
55 * have the all the abbreviated names before all the full names.
56 * The _Time_Info tables are initialized using the non-template
57 * time_base class, which has a default constructor and two protected.
58 * The default one initialize _Time_Info with "C" time info. The
59 * protected initialize _time_Info using a _Locale_time instance
60 * or using a name( in fact the name is used to build a _Locale_time
61 * instance that is then used for initialization). */
62
63 class _STLP_CLASS_DECLSPEC _Time_Info_Base {
64 public:
65 string _M_time_format;
66 string _M_date_format;
67 string _M_date_time_format;
68 string _M_long_date_format;
69 string _M_long_date_time_format;
70 };
71
72 class _STLP_CLASS_DECLSPEC _Time_Info : public _Time_Info_Base {
73 public:
74 string _M_dayname[14];
75 string _M_monthname[24];
76 string _M_am_pm[2];
77 };
78
79 #ifndef _STLP_NO_WCHAR_T
80 class _STLP_CLASS_DECLSPEC _WTime_Info : public _Time_Info_Base {
81 public:
82 wstring _M_dayname[14];
83 wstring _M_monthname[24];
84 wstring _M_am_pm[2];
85 };
86 #endif
87
88 _STLP_MOVE_TO_STD_NAMESPACE
89
90 class _STLP_CLASS_DECLSPEC time_base {
91 public:
92 enum dateorder {no_order, dmy, mdy, ymd, ydm};
93 };
94
95 _STLP_MOVE_TO_PRIV_NAMESPACE
96
97 template <class _Ch>
98 class time_init;
99
100 _STLP_TEMPLATE_NULL
101 class _STLP_CLASS_DECLSPEC time_init<char> {
102 protected:
103 time_init();
104 time_init(const char *name);
105 time_init(_Locale_time*);
106 #if defined (__BORLANDC__)
107 static
108 #endif
109 _Time_Info _M_timeinfo;
110 time_base::dateorder _M_dateorder;
111 };
112
113 #ifndef _STLP_NO_WCHAR_T
114 _STLP_TEMPLATE_NULL
115 class _STLP_CLASS_DECLSPEC time_init<wchar_t> {
116 protected:
117 time_init();
118 time_init(const char *name);
119 time_init(_Locale_time*);
120 #if defined (__BORLANDC__)
121 static
122 #endif
123 _WTime_Info _M_timeinfo;
124 time_base::dateorder _M_dateorder;
125 };
126 #endif
127
128 _STLP_MOVE_TO_STD_NAMESPACE
129
130 template <class _Ch, class _InIt>
131 class time_get : public locale::facet, public time_base, public _STLP_PRIV time_init<_Ch> {
132 public:
133 typedef _Ch char_type;
134 typedef _InIt iter_type;
135
136 explicit time_get(size_t __refs = 0) : locale::facet(__refs)
137 {}
138
139 dateorder date_order() const { return do_date_order(); }
140 iter_type get_time(iter_type __s, iter_type __end, ios_base& __str,
141 ios_base::iostate& __err, tm* __t) const
142 { return do_get_time(__s, __end, __str, __err, __t); }
143 iter_type get_date(iter_type __s, iter_type __end, ios_base& __str,
144 ios_base::iostate& __err, tm* __t) const
145 { return do_get_date(__s, __end, __str, __err, __t); }
146 iter_type get_weekday(iter_type __s, iter_type __end, ios_base& __str,
147 ios_base::iostate& __err, tm* __t) const
148 { return do_get_weekday(__s, __end, __str, __err, __t); }
149 iter_type get_monthname(iter_type __s, iter_type __end, ios_base& __str,
150 ios_base::iostate& __err, tm* __t) const
151 { return do_get_monthname(__s, __end, __str, __err, __t); }
152 iter_type get_year(iter_type __s, iter_type __end, ios_base& __str,
153 ios_base::iostate& __err, tm* __t) const
154 { return do_get_year(__s, __end, __str, __err, __t); }
155
156 static locale::id id;
157
158 protected:
159 time_get(const char* __name, size_t __refs)
160 : locale::facet(__refs), _STLP_PRIV time_init<_Ch>(__name)
161 {}
162 time_get(_Locale_time *__time)
163 : _STLP_PRIV time_init<_Ch>(__time)
164 {}
165
166 ~time_get() {}
167
168 virtual dateorder do_date_order() const { return this->_M_dateorder; }
169
170 virtual iter_type do_get_time(iter_type __s, iter_type __end,
171 ios_base&, ios_base::iostate& __err,
172 tm* __t) const;
173
174 virtual iter_type do_get_date(iter_type __s, iter_type __end,
175 ios_base&, ios_base::iostate& __err,
176 tm* __t) const;
177
178 virtual iter_type do_get_weekday(iter_type __s, iter_type __end,
179 ios_base&,
180 ios_base::iostate& __err,
181 tm* __t) const;
182 virtual iter_type do_get_monthname(iter_type __s, iter_type __end,
183 ios_base&,
184 ios_base::iostate& __err,
185 tm* __t) const;
186
187 virtual iter_type do_get_year(iter_type __s, iter_type __end,
188 ios_base&, ios_base::iostate& __err,
189 tm* __t) const;
190 };
191
192 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
193 template <class _Ch, class _InIt>
194 #else
195 template <class _Ch, class _InIt = istreambuf_iterator<_Ch, char_traits<_Ch> > >
196 #endif
197 class time_get_byname : public time_get<_Ch, _InIt> {
198 friend class _Locale_impl;
199 public:
200 typedef time_base::dateorder dateorder;
201 typedef _InIt iter_type;
202
203 explicit time_get_byname(const char* __name, size_t __refs = 0)
204 : time_get<_Ch, _InIt>(__name, __refs) {}
205
206 protected:
207 ~time_get_byname() {}
208 dateorder do_date_order() const { return this->_M_dateorder; }
209
210 private:
211 time_get_byname(_Locale_time *__time)
212 : time_get<_Ch, _InIt>(__time)
213 {}
214
215 typedef time_get_byname<_Ch, _InIt> _Self;
216 //explicitely defined as private to avoid warnings:
217 time_get_byname(_Self const&);
218 _Self& operator = (_Self const&);
219 };
220
221 // time_put facet
222
223 // For the formats 'x, 'X', and 'c', do_put calls the first form of
224 // put with the pattern obtained from _M_timeinfo._M_date_format or
225 // _M_timeinfo._M_time_format.
226
227 // Helper function: __ takes a single-character
228 // format. As indicated by the foregoing remark, this will never be
229 // 'x', 'X', or 'c'.
230
231 _STLP_MOVE_TO_PRIV_NAMESPACE
232
233 _STLP_DECLSPEC void _STLP_CALL
234 __write_formatted_time(__iostring&, const ctype<char>& __ct,
235 char __format, char __modifier,
236 const _Time_Info& __table, const tm* __t);
237
238 #ifndef _STLP_NO_WCHAR_T
239 _STLP_DECLSPEC void _STLP_CALL
240 __write_formatted_time(__iowstring&, const ctype<wchar_t>& __ct,
241 char __format, char __modifier,
242 const _WTime_Info& __table, const tm* __t);
243 #endif
244
245 _STLP_MOVE_TO_STD_NAMESPACE
246
247 template <class _Ch, class _OutIt>
248 class time_put : public locale::facet, public time_base, public _STLP_PRIV time_init<_Ch> {
249 public:
250 typedef _Ch char_type;
251 typedef _OutIt iter_type;
252
253 explicit time_put(size_t __refs = 0) : locale::facet(__refs)
254 {}
255
256 _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
257 const tm* __tmb,
258 const _Ch* __pat, const _Ch* __pat_end) const;
259
260 _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
261 const tm* __tmb, char __format, char __modifier = 0) const
262 { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
263
264 static locale::id id;
265
266 protected:
267 time_put(const char* __name, size_t __refs)
268 : locale::facet(__refs), _STLP_PRIV time_init<_Ch>(__name)
269 {}
270 time_put(_Locale_time *__time)
271 : _STLP_PRIV time_init<_Ch>(__time)
272 {}
273 ~time_put() {}
274 virtual iter_type do_put(iter_type __s, ios_base& __f,
275 char_type /* __fill */, const tm* __tmb,
276 char __format, char /* __modifier */) const;
277 };
278
279 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
280 template <class _Ch, class _OutIt>
281 #else
282 template <class _Ch, class _OutIt = ostreambuf_iterator<_Ch, char_traits<_Ch> > >
283 #endif
284 class time_put_byname : public time_put<_Ch, _OutIt> {
285 friend class _Locale_impl;
286 public:
287 typedef time_base::dateorder dateorder;
288 typedef _OutIt iter_type;
289 typedef _Ch char_type;
290
291 explicit time_put_byname(const char * __name, size_t __refs = 0)
292 : time_put<_Ch, _OutIt>(__name, __refs)
293 {}
294
295 protected:
296 ~time_put_byname() {}
297
298 private:
299 time_put_byname(_Locale_time *__time)
300 : time_put<_Ch, _OutIt>(__time)
301 {}
302
303 typedef time_put_byname<_Ch, _OutIt> _Self;
304 //explicitely defined as private to avoid warnings:
305 time_put_byname(_Self const&);
306 _Self& operator = (_Self const&);
307 };
308
309 #if defined (_STLP_USE_TEMPLATE_EXPORT)
310 _STLP_EXPORT_TEMPLATE_CLASS time_get<char, istreambuf_iterator<char, char_traits<char> > >;
311 _STLP_EXPORT_TEMPLATE_CLASS time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
312 # if !defined (_STLP_NO_WCHAR_T)
313 _STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
314 _STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
315 # endif
316
317 #endif
318
319 _STLP_END_NAMESPACE
320
321 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
322 # include <stl/_time_facets.c>
323 #endif
324
325 #endif /* _STLP_INTERNAL_TIME_FACETS_H */
326
327 // Local Variables:
328 // mode:C++
329 // End: