1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_time_facets.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,341 @@
1.4 +/*
1.5 + * Copyright (c) 1999
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +// WARNING: This is an internal header file, included by other C++
1.22 +// standard library headers. You should not attempt to use this header
1.23 +// file directly.
1.24 +
1.25 +
1.26 +#ifndef _STLP_INTERNAL_TIME_FACETS_H
1.27 +#define _STLP_INTERNAL_TIME_FACETS_H
1.28 +
1.29 +#ifndef _STLP_INTERNAL_CTIME
1.30 +# include <stl/_ctime.h> // Needed (for struct tm) by time facets
1.31 +#endif
1.32 +
1.33 +#ifndef _STLP_C_LOCALE_H
1.34 +# include <stl/c_locale.h>
1.35 +#endif
1.36 +
1.37 +#ifndef _STLP_IOS_BASE_H
1.38 +# include <stl/_ios_base.h>
1.39 +#endif
1.40 +
1.41 +_STLP_BEGIN_NAMESPACE
1.42 +
1.43 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.44 +
1.45 +// Template functions used by time_get
1.46 +
1.47 +// Matching input against a list of names
1.48 +
1.49 +// Alphabetic input of the names of months and the names
1.50 +// of weekdays requires matching input against a list of names.
1.51 +// We use a simple generic algorithm to accomplish this. This
1.52 +// algorithm is not very efficient, especially for longer lists
1.53 +// of names, but it probably does not matter for the initial
1.54 +// implementation and it may never matter, since we do not expect
1.55 +// this kind of input to be used very often. The algorithm
1.56 +// could be improved fairly simply by creating a new list of
1.57 +// names still in the running at each iteration. A more sophisticated
1.58 +// approach would be to build a trie to do the matching.
1.59 +//
1.60 +// We compare each character of the input to the corresponding
1.61 +// character of each name on the list that has not been eliminated,
1.62 +// either because every character in the name has already been
1.63 +// matched, or because some character has not been matched. We
1.64 +// continue only as long as there are some names that have not been
1.65 +// eliminated.
1.66 +
1.67 +// We do not really need a random access iterator (a forward iterator
1.68 +// would do), but the extra generality makes the notation clumsier,
1.69 +// and we don't really need it.
1.70 +
1.71 +// We can recognize a failed match by the fact that the second
1.72 +// component of the return value will be __name_end.
1.73 +
1.74 +#define _MAXNAMES 64
1.75 +#define _MAX_NAME_LENGTH 64
1.76 +
1.77 +// Both time_get and time_put need a structure of type _Time_Info
1.78 +// to provide names and abbreviated names for months and days,
1.79 +// as well as the am/pm designator. The month and weekday tables
1.80 +// have the all the abbreviated names before all the full names.
1.81 +// The _Time_Info tables are initialized using the non-template
1.82 +// function _Init_timeinfo, which has two overloadings: one
1.83 +// with a single reference parameter for the table to be initialized,
1.84 +// and one with a second _Locale_time * parameter. The first form
1.85 +// is called by the default constructor and the second by a special
1.86 +// constructor invoked from the _byname subclass constructor to
1.87 +// construct the base class.
1.88 +
1.89 +class _STLP_CLASS_DECLSPEC _Time_Info {
1.90 +public:
1.91 + string _M_dayname[14];
1.92 + string _M_monthname[24];
1.93 + string _M_am_pm[2];
1.94 + string _M_time_format;
1.95 + string _M_date_format;
1.96 + string _M_date_time_format;
1.97 + string _M_long_date_format;
1.98 + string _M_long_date_time_format;
1.99 +};
1.100 +
1.101 +void _STLP_CALL _Init_timeinfo(_Time_Info&);
1.102 +void _STLP_CALL _Init_timeinfo(_Time_Info&, _Locale_time*);
1.103 +
1.104 +_STLP_MOVE_TO_STD_NAMESPACE
1.105 +
1.106 +class _STLP_CLASS_DECLSPEC time_base {
1.107 +public:
1.108 + enum dateorder {no_order, dmy, mdy, ymd, ydm};
1.109 +};
1.110 +
1.111 +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
1.112 +template <class _Ch, class _InIt>
1.113 +#else
1.114 +template <class _Ch, class _InIt = istreambuf_iterator<_Ch, char_traits<_Ch> > >
1.115 +#endif
1.116 +class time_get : public locale::facet, public time_base {
1.117 + friend class _Locale_impl;
1.118 +
1.119 +public:
1.120 + typedef _Ch char_type;
1.121 + typedef _InIt iter_type;
1.122 +
1.123 + explicit time_get(size_t __refs = 0) : locale::facet(__refs)
1.124 + { _STLP_PRIV _Init_timeinfo(_M_timeinfo); }
1.125 + dateorder date_order() const { return do_date_order(); }
1.126 + iter_type get_time(iter_type __s, iter_type __end, ios_base& __str,
1.127 + ios_base::iostate& __err, tm* __t) const
1.128 + { return do_get_time(__s, __end, __str, __err, __t); }
1.129 + iter_type get_date(iter_type __s, iter_type __end, ios_base& __str,
1.130 + ios_base::iostate& __err, tm* __t) const
1.131 + { return do_get_date(__s, __end, __str, __err, __t); }
1.132 + iter_type get_weekday(iter_type __s, iter_type __end, ios_base& __str,
1.133 + ios_base::iostate& __err, tm* __t) const
1.134 + { return do_get_weekday(__s, __end, __str, __err, __t); }
1.135 + iter_type get_monthname(iter_type __s, iter_type __end, ios_base& __str,
1.136 + ios_base::iostate& __err, tm* __t) const
1.137 + { return do_get_monthname(__s, __end, __str, __err, __t); }
1.138 + iter_type get_year(iter_type __s, iter_type __end, ios_base& __str,
1.139 + ios_base::iostate& __err, tm* __t) const
1.140 + { return do_get_year(__s, __end, __str, __err, __t); }
1.141 +
1.142 + static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
1.143 +
1.144 +protected:
1.145 + time_get(_Locale_time *, size_t __refs) : locale::facet(__refs) {}
1.146 +
1.147 + ~time_get() {}
1.148 +
1.149 + virtual dateorder do_date_order() const {return no_order;}
1.150 +
1.151 + virtual iter_type do_get_time(iter_type __s, iter_type __end,
1.152 + ios_base&, ios_base::iostate& __err,
1.153 + tm* __t) const;
1.154 +
1.155 + virtual iter_type do_get_date(iter_type __s, iter_type __end,
1.156 + ios_base&, ios_base::iostate& __err,
1.157 + tm* __t) const;
1.158 +
1.159 + virtual iter_type do_get_weekday(iter_type __s, iter_type __end,
1.160 + ios_base&,
1.161 + ios_base::iostate& __err,
1.162 + tm* __t) const;
1.163 + virtual iter_type do_get_monthname(iter_type __s, iter_type __end,
1.164 + ios_base&,
1.165 + ios_base::iostate& __err,
1.166 + tm* __t) const;
1.167 +
1.168 + virtual iter_type do_get_year(iter_type __s, iter_type __end,
1.169 + ios_base&, ios_base::iostate& __err,
1.170 + tm* __t) const;
1.171 +
1.172 + _STLP_PRIV _Time_Info _M_timeinfo;
1.173 +};
1.174 +
1.175 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.176 +
1.177 +time_base::dateorder _STLP_CALL __get_date_order(_Locale_time*);
1.178 +_Locale_time* _STLP_CALL __acquire_time(const char* __name, _Locale_name_hint*);
1.179 +void _STLP_CALL __release_time(_Locale_time* __time);
1.180 +
1.181 +_STLP_MOVE_TO_STD_NAMESPACE
1.182 +
1.183 +template <class _Ch, class _InIt>
1.184 +class time_get_byname;
1.185 +
1.186 +#if defined (__GNUC__) && (__GNUC__ < 3)
1.187 +template <class _Ch, class _InIt>
1.188 +_Locale_name_hint* _Locale_time_extract_hint(time_get_byname<_Ch, _InIt>*);
1.189 +#else
1.190 +_Locale_name_hint* _Locale_time_extract_hint(time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >*);
1.191 +#endif
1.192 +
1.193 +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
1.194 +template <class _Ch, class _InIt>
1.195 +#else
1.196 +template <class _Ch, class _InIt = istreambuf_iterator<_Ch, char_traits<_Ch> > >
1.197 +#endif
1.198 +class time_get_byname : public time_get<_Ch, _InIt> {
1.199 +public:
1.200 + typedef time_base::dateorder dateorder;
1.201 + typedef _InIt iter_type;
1.202 +
1.203 + explicit time_get_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0)
1.204 + : time_get<_Ch, _InIt>((_Locale_time*) 0, __refs),
1.205 + _M_time(_STLP_PRIV __acquire_time(__name, __hint))
1.206 + { _STLP_PRIV _Init_timeinfo(this->_M_timeinfo, this->_M_time); }
1.207 +
1.208 +protected:
1.209 + ~time_get_byname() { _STLP_PRIV __release_time(_M_time); }
1.210 + dateorder do_date_order() const { return _STLP_PRIV __get_date_order(_M_time); }
1.211 +
1.212 +private:
1.213 + _Locale_time* _M_time;
1.214 +
1.215 + typedef time_get_byname<_Ch, _InIt> _Self;
1.216 + //explicitely defined as private to avoid warnings:
1.217 + time_get_byname(_Self const&);
1.218 + _Self& operator = (_Self const&);
1.219 +#if defined (__GNUC__) && (__GNUC__ < 3)
1.220 + friend _Locale_name_hint* _Locale_time_extract_hint<>(_Self*);
1.221 +#else
1.222 + friend _Locale_name_hint* _Locale_time_extract_hint(time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >*);
1.223 +#endif
1.224 +};
1.225 +
1.226 +// time_put facet
1.227 +
1.228 +// For the formats 'x, 'X', and 'c', do_put calls the first form of
1.229 +// put with the pattern obtained from _M_timeinfo._M_date_format or
1.230 +// _M_timeinfo._M_time_format.
1.231 +
1.232 +// Helper function: __ takes a single-character
1.233 +// format. As indicated by the foregoing remark, this will never be
1.234 +// 'x', 'X', or 'c'.
1.235 +
1.236 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.237 +
1.238 +char * _STLP_CALL
1.239 +__write_formatted_time(char *__buf, size_t __buf_size, char __format, char __modifier,
1.240 + const _Time_Info& __table, const tm* __t);
1.241 +
1.242 +template <class _OuIt>
1.243 +inline _OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out_ite,
1.244 + const ios_base& /* __loc */, char)
1.245 +{ return copy(__first, __last, __out_ite); }
1.246 +
1.247 +#if !defined (_STLP_NO_WCHAR_T)
1.248 +template <class _OuIt>
1.249 +_OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out_ite,
1.250 + const ios_base& __s, wchar_t);
1.251 +#endif
1.252 +
1.253 +_STLP_MOVE_TO_STD_NAMESPACE
1.254 +
1.255 +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
1.256 +template <class _Ch, class _OutIt>
1.257 +#else
1.258 +template <class _Ch, class _OutIt = ostreambuf_iterator<_Ch, char_traits<_Ch> > >
1.259 +#endif
1.260 +class time_put : public locale::facet, public time_base {
1.261 + friend class _Locale_impl;
1.262 +public:
1.263 + typedef _Ch char_type;
1.264 + typedef _OutIt iter_type;
1.265 +
1.266 + explicit time_put(size_t __refs = 0) : locale::facet(__refs)
1.267 + { _STLP_PRIV _Init_timeinfo(_M_timeinfo); }
1.268 +
1.269 + _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
1.270 + const tm* __tmb,
1.271 + const _Ch* __pat, const _Ch* __pat_end) const;
1.272 +
1.273 + _OutIt put(iter_type __s, ios_base& __f, _Ch __fill,
1.274 + const tm* __tmb, char __format, char __modifier = 0) const
1.275 + { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
1.276 +
1.277 + static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
1.278 +
1.279 +protected:
1.280 + time_put(_Locale_time* /*__time*/, size_t __refs) : locale::facet(__refs)
1.281 + {} //_STLP_PRIV _Init_timeinfo(_M_timeinfo, __time); }
1.282 +
1.283 + ~time_put() {}
1.284 + virtual iter_type do_put(iter_type __s, ios_base& __f,
1.285 + char_type /* __fill */, const tm* __tmb,
1.286 + char __format, char /* __modifier */) const;
1.287 +
1.288 + _STLP_PRIV _Time_Info _M_timeinfo;
1.289 +};
1.290 +
1.291 +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
1.292 +template <class _Ch, class _OutIt>
1.293 +#else
1.294 +template <class _Ch, class _OutIt = ostreambuf_iterator<_Ch, char_traits<_Ch> > >
1.295 +#endif
1.296 +class time_put_byname : public time_put<_Ch, _OutIt> {
1.297 + friend class _Locale_impl;
1.298 +public:
1.299 + typedef time_base::dateorder dateorder;
1.300 + typedef _OutIt iter_type;
1.301 + typedef _Ch char_type;
1.302 +
1.303 + explicit time_put_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0)
1.304 + : time_put<_Ch, _OutIt>((_Locale_time*) 0, __refs),
1.305 + _M_time(_STLP_PRIV __acquire_time(__name, __hint))
1.306 + { _STLP_PRIV _Init_timeinfo(this->_M_timeinfo, this->_M_time); }
1.307 +
1.308 +protected:
1.309 + ~time_put_byname() { _STLP_PRIV __release_time(_M_time); }
1.310 +
1.311 +private:
1.312 + _Locale_time* _M_time;
1.313 +
1.314 + typedef time_put_byname<_Ch, _OutIt> _Self;
1.315 + //explicitely defined as private to avoid warnings:
1.316 + time_put_byname(_Self const&);
1.317 + _Self& operator = (_Self const&);
1.318 +};
1.319 +
1.320 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
1.321 +_STLP_EXPORT_TEMPLATE_CLASS time_get<char, istreambuf_iterator<char, char_traits<char> > >;
1.322 +_STLP_EXPORT_TEMPLATE_CLASS time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
1.323 +// _STLP_EXPORT_TEMPLATE_CLASS time_get<char, const char*>;
1.324 +// _STLP_EXPORT_TEMPLATE_CLASS time_put<char, char*>;
1.325 +# if !defined (_STLP_NO_WCHAR_T)
1.326 +_STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
1.327 +_STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
1.328 +// _STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, const wchar_t*>;
1.329 +// _STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, wchar_t*>;
1.330 +# endif
1.331 +
1.332 +#endif
1.333 +
1.334 +_STLP_END_NAMESPACE
1.335 +
1.336 +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
1.337 +# include <stl/_time_facets.c>
1.338 +#endif
1.339 +
1.340 +#endif /* _STLP_INTERNAL_TIME_FACETS_H */
1.341 +
1.342 +// Local Variables:
1.343 +// mode:C++
1.344 +// End: