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