williamr@2: /* williamr@2: * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. williamr@2: * williamr@2: * Copyright (c) 1999 williamr@2: * Silicon Graphics Computer Systems, Inc. williamr@2: * williamr@2: * Copyright (c) 1999 williamr@2: * Boris Fomitchev williamr@2: * williamr@2: * This material is provided "as is", with absolutely no warranty expressed williamr@2: * or implied. Any use is at your own risk. williamr@2: * williamr@2: * Permission to use or copy this software for any purpose is hereby granted williamr@2: * without fee, provided the above notices are retained on all copies. williamr@2: * Permission to modify the code and to distribute modified code is granted, williamr@2: * provided the above notices are retained, and a notice that the code was williamr@2: * modified is included with the above copyright notice. williamr@2: * williamr@2: */ williamr@2: // WARNING: This is an internal header file, included by other C++ williamr@2: // standard library headers. You should not attempt to use this header williamr@2: // file directly. williamr@2: williamr@2: williamr@2: #ifndef _STLP_INTERNAL_TIME_FACETS_H williamr@2: #define _STLP_INTERNAL_TIME_FACETS_H williamr@2: williamr@2: #ifndef _STLP_CTIME williamr@2: # include // Needed (for struct tm) by time facets williamr@2: #endif williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: _STLP_BEGIN_NAMESPACE williamr@2: williamr@2: // Template functions used by time_get williamr@2: williamr@2: // Matching input against a list of names williamr@2: williamr@2: // Alphabetic input of the names of months and the names williamr@2: // of weekdays requires matching input against a list of names. williamr@2: // We use a simple generic algorithm to accomplish this. This williamr@2: // algorithm is not very efficient, especially for longer lists williamr@2: // of names, but it probably does not matter for the initial williamr@2: // implementation and it may never matter, since we do not expect williamr@2: // this kind of input to be used very often. The algorithm williamr@2: // could be improved fairly simply by creating a new list of williamr@2: // names still in the running at each iteration. A more sophisticated williamr@2: // approach would be to build a trie to do the matching. williamr@2: // williamr@2: // We compare each character of the input to the corresponding williamr@2: // character of each name on the list that has not been eliminated, williamr@2: // either because every character in the name has already been williamr@2: // matched, or because some character has not been matched. We williamr@2: // continue only as long as there are some names that have not been williamr@2: // eliminated. williamr@2: williamr@2: // We do not really need a random access iterator (a forward iterator williamr@2: // would do), but the extra generality makes the notation clumsier, williamr@2: // and we don't really need it. williamr@2: williamr@2: // We can recognize a failed match by the fact that the second williamr@2: // component of the return value will be __name_end. williamr@2: williamr@2: #define _MAXNAMES 64 williamr@2: #define _MAX_NAME_LENGTH 64 williamr@2: williamr@2: // Both time_get and time_put need a structure of type _Time_Info williamr@2: // to provide names and abbreviated names for months and days, williamr@2: // as well as the am/pm designator. The month and weekday tables williamr@2: // have the all the abbreviated names before all the full names. williamr@2: // The _Time_Info tables are initialized using the non-template williamr@2: // function _Init_timeinfo, which has two overloadings: one williamr@2: // with a single reference parameter for the table to be initialized, williamr@2: // and one with a second _Locale_time * parameter. The first form williamr@2: // is called by the default constructor and the second by a special williamr@2: // constructor invoked from the _byname subclass constructor to williamr@2: // construct the base class. williamr@2: williamr@2: class _STLP_CLASS_DECLSPEC _Time_Info { williamr@2: public: williamr@2: string _M_dayname[14]; williamr@2: string _M_monthname[24]; williamr@2: string _M_am_pm[2]; williamr@2: string _M_time_format; williamr@2: string _M_date_format; williamr@2: string _M_date_time_format; williamr@2: string _M_long_date_format; williamr@2: string _M_long_date_time_format; williamr@2: }; williamr@2: williamr@2: _STLP_DECLSPEC void _STLP_CALL _Init_timeinfo(_Time_Info&); williamr@2: _STLP_DECLSPEC void _STLP_CALL _Init_timeinfo(_Time_Info&, _Locale_time*); williamr@2: williamr@2: class _STLP_CLASS_DECLSPEC time_base { williamr@2: public: williamr@2: enum dateorder {no_order, dmy, mdy, ymd, ydm}; williamr@2: }; williamr@2: williamr@2: williamr@2: template ) > williamr@2: class time_get : public locale::facet, public time_base williamr@2: { williamr@2: friend class _Locale; williamr@2: williamr@2: public: williamr@2: typedef _Ch char_type; williamr@2: typedef _InIt iter_type; williamr@2: williamr@2: explicit time_get(size_t __refs = 0) : _BaseFacet(__refs) { williamr@2: _Init_timeinfo(_M_timeinfo); williamr@2: } williamr@2: dateorder date_order() const { return do_date_order(); } williamr@2: iter_type get_time(iter_type __s, iter_type __end, ios_base& __str, williamr@2: ios_base::iostate& __err, tm* __t) const williamr@2: { return do_get_time(__s, __end, __str, __err, __t); } williamr@2: iter_type get_date(iter_type __s, iter_type __end, ios_base& __str, williamr@2: ios_base::iostate& __err, tm* __t) const williamr@2: { return do_get_date(__s, __end, __str, __err, __t); } williamr@2: iter_type get_weekday(iter_type __s, iter_type __end, ios_base& __str, williamr@2: ios_base::iostate& __err, tm* __t) const williamr@2: { return do_get_weekday(__s, __end, __str, __err, __t); } williamr@2: iter_type get_monthname(iter_type __s, iter_type __end, ios_base& __str, williamr@2: ios_base::iostate& __err, tm* __t) const williamr@2: { return do_get_monthname(__s, __end, __str, __err, __t); } williamr@2: iter_type get_year(iter_type __s, iter_type __end, ios_base& __str, williamr@2: ios_base::iostate& __err, tm* __t) const williamr@2: { return do_get_year(__s, __end, __str, __err, __t); } williamr@2: williamr@2: #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(istreambuf_iterator >*); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(const wchar_t**); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(istreambuf_iterator >*); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(const char**); williamr@2: #else williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id id; williamr@2: #endif williamr@2: williamr@2: protected: williamr@2: _Time_Info _M_timeinfo; williamr@2: williamr@2: time_get(_Locale_time *, size_t __refs) : _BaseFacet(__refs) {} williamr@2: williamr@2: ~time_get() {} williamr@2: williamr@2: virtual dateorder do_date_order() const {return no_order;} williamr@2: williamr@2: virtual iter_type do_get_time(iter_type __s, iter_type __end, williamr@2: ios_base&, ios_base::iostate& __err, williamr@2: tm* __t) const; williamr@2: williamr@2: virtual iter_type do_get_date(iter_type __s, iter_type __end, williamr@2: ios_base&, ios_base::iostate& __err, williamr@2: tm* __t) const; williamr@2: williamr@2: virtual iter_type do_get_weekday(iter_type __s, iter_type __end, williamr@2: ios_base&, williamr@2: ios_base::iostate& __err, williamr@2: tm* __t) const; williamr@2: virtual iter_type do_get_monthname(iter_type __s, iter_type __end, williamr@2: ios_base&, williamr@2: ios_base::iostate& __err, williamr@2: tm* __t) const; williamr@2: williamr@2: virtual iter_type do_get_year(iter_type __s, iter_type __end, williamr@2: ios_base&, ios_base::iostate& __err, williamr@2: tm* __t) const; williamr@2: }; williamr@2: williamr@2: time_base::dateorder _STLP_CALL williamr@2: _STLP_DECLSPEC __get_date_order(_Locale_time*); williamr@2: _Locale_time* _STLP_CALL __acquire_time(const char* __name); williamr@2: void _STLP_CALL __release_time(_Locale_time* __time); williamr@2: williamr@2: template ) > williamr@2: class time_get_byname : public time_get<_Ch, _InIt> williamr@2: { williamr@2: public: williamr@2: typedef time_base::dateorder dateorder; williamr@2: typedef _InIt iter_type; williamr@2: williamr@2: explicit time_get_byname(const char* __name, size_t __refs = 0) williamr@2: : time_get<_Ch, _InIt>((_Locale_time*) 0, __refs), williamr@2: _M_time(__acquire_time(__name)) williamr@2: { _Init_timeinfo(this->_M_timeinfo, this->_M_time); } williamr@2: williamr@2: protected: williamr@2: ~time_get_byname() { __release_time(_M_time); } williamr@2: dateorder do_date_order() const { return __get_date_order(_M_time); } williamr@2: private: williamr@2: _Locale_time* _M_time; williamr@2: }; williamr@2: williamr@2: // time_put facet williamr@2: williamr@2: // For the formats 'x, 'X', and 'c', do_put calls the first form of williamr@2: // put with the pattern obtained from _M_timeinfo._M_date_format or williamr@2: // _M_timeinfo._M_time_format. williamr@2: williamr@2: // Helper function: __ takes a single-character williamr@2: // format. As indicated by the foregoing remark, this will never be williamr@2: // 'x', 'X', or 'c'. williamr@2: williamr@2: _STLP_DECLSPEC char * _STLP_CALL williamr@2: __write_formatted_time(char * __buf, char __format, char __modifier, williamr@2: const _Time_Info& __table, const tm* __t); williamr@2: williamr@2: template williamr@2: inline _OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out, williamr@2: const ios_base& /* __loc */, char) { williamr@2: return copy(__first, __last, __out); williamr@2: } williamr@2: williamr@2: # ifndef _STLP_NO_WCHAR_T williamr@2: template williamr@2: _OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out, williamr@2: const ios_base& __s, wchar_t); williamr@2: # endif williamr@2: williamr@2: template ) > williamr@2: class time_put : public locale::facet, public time_base williamr@2: { williamr@2: friend class _Locale; williamr@2: public: williamr@2: typedef _Ch char_type; williamr@2: typedef _OutputIter iter_type; williamr@2: williamr@2: explicit time_put(size_t __refs = 0) : _BaseFacet(__refs) { williamr@2: _Init_timeinfo(_M_timeinfo); williamr@2: } williamr@2: williamr@2: _OutputIter put(iter_type __s, ios_base& __f, _Ch __fill, williamr@2: const tm* __tmb, williamr@2: const _Ch* __pat, const _Ch* __pat_end) const; williamr@2: williamr@2: _OutputIter put(iter_type __s, ios_base& __f, _Ch __fill, williamr@2: const tm* __tmb, char __format, char __modifier = 0) const { williamr@2: return do_put(__s, __f, __fill, __tmb, __format, __modifier); williamr@2: } williamr@2: williamr@2: #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(ostreambuf_iterator >*); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(wchar_t**); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(ostreambuf_iterator >*); williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(char**); williamr@2: #else williamr@2: _STLP_STATIC_MEMBER_DECLSPEC static locale::id id; williamr@2: #endif williamr@2: williamr@2: protected: williamr@2: _Time_Info _M_timeinfo; williamr@2: williamr@2: time_put(_Locale_time* /*__time*/, size_t __refs) : _BaseFacet(__refs) { williamr@2: // _Init_timeinfo(_M_timeinfo, __time); williamr@2: } williamr@2: williamr@2: ~time_put() {} williamr@2: virtual iter_type do_put(iter_type __s, ios_base& __f, williamr@2: char_type /* __fill */, const tm* __tmb, williamr@2: char __format, char /* __modifier */) const; williamr@2: }; williamr@2: williamr@2: template ) > williamr@2: class time_put_byname : public time_put<_Ch, _InIt> williamr@2: { williamr@2: friend class _Locale; williamr@2: public: williamr@2: typedef time_base::dateorder dateorder; williamr@2: typedef _InIt iter_type; williamr@2: typedef _Ch char_type; williamr@2: williamr@2: explicit time_put_byname(const char * __name, size_t __refs = 0) williamr@2: : time_put<_Ch, _InIt>((_Locale_time*) 0, __refs), williamr@2: _M_time(__acquire_time(__name)) williamr@2: { _Init_timeinfo(this->_M_timeinfo, this->_M_time); } williamr@2: williamr@2: protected: williamr@2: ~time_put_byname() { __release_time(_M_time); } williamr@2: williamr@2: private: williamr@2: _Locale_time* _M_time; williamr@2: }; williamr@2: williamr@2: # ifdef _STLP_USE_TEMPLATE_EXPORT williamr@2: _STLP_EXPORT_TEMPLATE_CLASS time_get > >; williamr@2: _STLP_EXPORT_TEMPLATE_CLASS time_put > >; williamr@2: // _STLP_EXPORT_TEMPLATE_CLASS time_get; williamr@2: // _STLP_EXPORT_TEMPLATE_CLASS time_put; williamr@2: # ifndef _STLP_NO_WCHAR_T williamr@2: _STLP_EXPORT_TEMPLATE_CLASS time_get > >; williamr@2: _STLP_EXPORT_TEMPLATE_CLASS time_put > >; williamr@2: // _STLP_EXPORT_TEMPLATE_CLASS time_get; williamr@2: // _STLP_EXPORT_TEMPLATE_CLASS time_put; williamr@2: # endif /* INSTANTIATE_WIDE_STREAMS */ williamr@2: williamr@2: # endif williamr@2: williamr@2: # if defined (__BORLANDC__) && defined (_RTLDLL) williamr@2: inline void _Stl_loc_init_time_facets() { williamr@2: williamr@2: #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) williamr@2: time_get > >::GetFacetLocaleId()._M_index = 16; williamr@2: time_get::GetFacetLocaleId()._M_index = 17; williamr@2: time_put > >::GetFacetLocaleId()._M_index = 18; williamr@2: time_put::GetFacetLocaleId()._M_index = 19; williamr@2: #else williamr@2: time_get > >::GetFacetLocaleId()._M_index = 16; williamr@2: time_get::id._M_index = 17; williamr@2: time_put > >::GetFacetLocaleId()._M_index = 18; williamr@2: time_put::id._M_index = 19; williamr@2: #endif williamr@2: williamr@2: # ifndef _STLP_NO_WCHAR_T williamr@2: #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) williamr@2: time_get > >::GetFacetLocaleId()._M_index = 35; williamr@2: time_get::GetFacetLocaleId()._M_index = 36; williamr@2: time_put > >::GetFacetLocaleId()._M_index = 37; williamr@2: time_put::GetFacetLocaleId()._M_index = 38; williamr@2: #else williamr@2: time_get > >::id._M_index = 35; williamr@2: time_get::id._M_index = 36; williamr@2: time_put > >::id._M_index = 37; williamr@2: time_put::id._M_index = 38; williamr@2: #endif //__SYMBIAN32__ williamr@2: # endif //!_STLP_NO_WCHAR_T williamr@2: williamr@2: } williamr@2: # endif williamr@2: williamr@2: _STLP_END_NAMESPACE williamr@2: williamr@2: #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) williamr@2: # include williamr@2: # endif williamr@2: williamr@2: #endif /* _STLP_INTERNAL_TIME_FACETS_H */ williamr@2: williamr@2: // Local Variables: williamr@2: // mode:C++ williamr@2: // End: williamr@2: williamr@2: