3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
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.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
23 #ifndef _STLP_INTERNAL_TIME_FACETS_H
24 #define _STLP_INTERNAL_TIME_FACETS_H
26 #ifndef _STLP_INTERNAL_CTIME
27 # include <stl/_ctime.h> // Needed (for struct tm) by time facets
30 #ifndef _STLP_C_LOCALE_H
31 # include <stl/c_locale.h>
34 #ifndef _STLP_IOS_BASE_H
35 # include <stl/_ios_base.h>
38 #ifndef _STLP_INTERNAL_IOSTREAM_STRING_H
39 # include <stl/_iostream_string.h>
42 #ifndef _STLP_FACETS_FWD_H
43 # include <stl/_facets_fwd.h>
48 _STLP_MOVE_TO_PRIV_NAMESPACE
50 // Template functions used by time_get
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). */
63 class _STLP_CLASS_DECLSPEC _Time_Info_Base
{
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
;
72 class _STLP_CLASS_DECLSPEC _Time_Info
: public _Time_Info_Base
{
74 string _M_dayname
[14];
75 string _M_monthname
[24];
79 #ifndef _STLP_NO_WCHAR_T
80 class _STLP_CLASS_DECLSPEC _WTime_Info
: public _Time_Info_Base
{
82 wstring _M_dayname
[14];
83 wstring _M_monthname
[24];
88 _STLP_MOVE_TO_STD_NAMESPACE
90 class _STLP_CLASS_DECLSPEC time_base
{
92 enum dateorder
{no_order
, dmy
, mdy
, ymd
, ydm
};
95 _STLP_MOVE_TO_PRIV_NAMESPACE
101 class _STLP_CLASS_DECLSPEC time_init
<char> {
104 time_init(const char *name
);
105 time_init(_Locale_time
*);
106 #if defined (__BORLANDC__)
109 _Time_Info _M_timeinfo
;
110 time_base::dateorder _M_dateorder
;
113 #ifndef _STLP_NO_WCHAR_T
115 class _STLP_CLASS_DECLSPEC time_init
<wchar_t> {
118 time_init(const char *name
);
119 time_init(_Locale_time
*);
120 #if defined (__BORLANDC__)
123 _WTime_Info _M_timeinfo
;
124 time_base::dateorder _M_dateorder
;
128 _STLP_MOVE_TO_STD_NAMESPACE
130 template <class _Ch
, class _InIt
>
131 class time_get
: public locale::facet
, public time_base
, public _STLP_PRIV time_init
<_Ch
> {
133 typedef _Ch char_type
;
134 typedef _InIt iter_type
;
136 explicit time_get(size_t __refs
= 0) : locale::facet(__refs
)
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
); }
156 static locale::id id
;
159 time_get(const char* __name
, size_t __refs
)
160 : locale::facet(__refs
), _STLP_PRIV time_init
<_Ch
>(__name
)
162 time_get(_Locale_time
*__time
)
163 : _STLP_PRIV time_init
<_Ch
>(__time
)
168 virtual dateorder
do_date_order() const { return this->_M_dateorder
; }
170 virtual iter_type
do_get_time(iter_type __s
, iter_type __end
,
171 ios_base
&, ios_base::iostate
& __err
,
174 virtual iter_type
do_get_date(iter_type __s
, iter_type __end
,
175 ios_base
&, ios_base::iostate
& __err
,
178 virtual iter_type
do_get_weekday(iter_type __s
, iter_type __end
,
180 ios_base::iostate
& __err
,
182 virtual iter_type
do_get_monthname(iter_type __s
, iter_type __end
,
184 ios_base::iostate
& __err
,
187 virtual iter_type
do_get_year(iter_type __s
, iter_type __end
,
188 ios_base
&, ios_base::iostate
& __err
,
192 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
193 template <class _Ch
, class _InIt
>
195 template <class _Ch
, class _InIt
= istreambuf_iterator
<_Ch
, char_traits
<_Ch
> > >
197 class time_get_byname
: public time_get
<_Ch
, _InIt
> {
198 friend class _Locale_impl
;
200 typedef time_base::dateorder dateorder
;
201 typedef _InIt iter_type
;
203 explicit time_get_byname(const char* __name
, size_t __refs
= 0)
204 : time_get
<_Ch
, _InIt
>(__name
, __refs
) {}
207 ~time_get_byname() {}
208 dateorder
do_date_order() const { return this->_M_dateorder
; }
211 time_get_byname(_Locale_time
*__time
)
212 : time_get
<_Ch
, _InIt
>(__time
)
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&);
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.
227 // Helper function: __ takes a single-character
228 // format. As indicated by the foregoing remark, this will never be
231 _STLP_MOVE_TO_PRIV_NAMESPACE
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
);
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
);
245 _STLP_MOVE_TO_STD_NAMESPACE
247 template <class _Ch
, class _OutIt
>
248 class time_put
: public locale::facet
, public time_base
, public _STLP_PRIV time_init
<_Ch
> {
250 typedef _Ch char_type
;
251 typedef _OutIt iter_type
;
253 explicit time_put(size_t __refs
= 0) : locale::facet(__refs
)
256 _OutIt
put(iter_type __s
, ios_base
& __f
, _Ch __fill
,
258 const _Ch
* __pat
, const _Ch
* __pat_end
) const;
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
); }
264 static locale::id id
;
267 time_put(const char* __name
, size_t __refs
)
268 : locale::facet(__refs
), _STLP_PRIV time_init
<_Ch
>(__name
)
270 time_put(_Locale_time
*__time
)
271 : _STLP_PRIV time_init
<_Ch
>(__time
)
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;
279 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
280 template <class _Ch
, class _OutIt
>
282 template <class _Ch
, class _OutIt
= ostreambuf_iterator
<_Ch
, char_traits
<_Ch
> > >
284 class time_put_byname
: public time_put
<_Ch
, _OutIt
> {
285 friend class _Locale_impl
;
287 typedef time_base::dateorder dateorder
;
288 typedef _OutIt iter_type
;
289 typedef _Ch char_type
;
291 explicit time_put_byname(const char * __name
, size_t __refs
= 0)
292 : time_put
<_Ch
, _OutIt
>(__name
, __refs
)
296 ~time_put_byname() {}
299 time_put_byname(_Locale_time
*__time
)
300 : time_put
<_Ch
, _OutIt
>(__time
)
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&);
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> > >;
321 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
322 # include <stl/_time_facets.c>
325 #endif /* _STLP_INTERNAL_TIME_FACETS_H */