epoc32/include/stdapis/stlport/stl/_time_facets.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
williamr@4
     3
 *
williamr@4
     4
 * Copyright (c) 1999
williamr@4
     5
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     6
 *
williamr@4
     7
 * Copyright (c) 1999 
williamr@4
     8
 * Boris Fomitchev
williamr@4
     9
 *
williamr@4
    10
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
    11
 * or implied. Any use is at your own risk.
williamr@4
    12
 *
williamr@4
    13
 * Permission to use or copy this software for any purpose is hereby granted 
williamr@4
    14
 * without fee, provided the above notices are retained on all copies.
williamr@4
    15
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    16
 * provided the above notices are retained, and a notice that the code was
williamr@4
    17
 * modified is included with the above copyright notice.
williamr@4
    18
 *
williamr@4
    19
 */ 
williamr@4
    20
// WARNING: This is an internal header file, included by other C++
williamr@4
    21
// standard library headers.  You should not attempt to use this header
williamr@4
    22
// file directly.
williamr@4
    23
williamr@4
    24
williamr@4
    25
#ifndef _STLP_INTERNAL_TIME_FACETS_H
williamr@4
    26
#define _STLP_INTERNAL_TIME_FACETS_H
williamr@4
    27
williamr@4
    28
#ifndef _STLP_CTIME
williamr@4
    29
# include <ctime>                // Needed (for struct tm) by time facets
williamr@4
    30
#endif
williamr@4
    31
williamr@4
    32
#include <stl/c_locale.h>
williamr@4
    33
#include <stl/_ios_base.h>
williamr@4
    34
williamr@4
    35
_STLP_BEGIN_NAMESPACE
williamr@4
    36
williamr@4
    37
// Template functions used by time_get
williamr@4
    38
williamr@4
    39
// Matching input against a list of names
williamr@4
    40
williamr@4
    41
// Alphabetic input of the names of months and the names
williamr@4
    42
// of weekdays requires matching input against a list of names.
williamr@4
    43
// We use a simple generic algorithm to accomplish this.  This
williamr@4
    44
// algorithm is not very efficient, especially for longer lists
williamr@4
    45
// of names, but it probably does not matter for the initial
williamr@4
    46
// implementation and it may never matter, since we do not expect
williamr@4
    47
// this kind of input to be used very often.  The algorithm
williamr@4
    48
// could be improved fairly simply by creating a new list of
williamr@4
    49
// names still in the running at each iteration.  A more sophisticated
williamr@4
    50
// approach would be to build a trie to do the matching.
williamr@4
    51
//
williamr@4
    52
// We compare each character of the input to the corresponding
williamr@4
    53
// character of each name on the list that has not been eliminated,
williamr@4
    54
// either because every character in the name has already been
williamr@4
    55
// matched, or because some character has not been matched.  We
williamr@4
    56
// continue only as long as there are some names that have not been
williamr@4
    57
// eliminated.
williamr@4
    58
williamr@4
    59
// We do not really need a random access iterator (a forward iterator
williamr@4
    60
// would do), but the extra generality makes the notation clumsier,
williamr@4
    61
// and we don't really need it.
williamr@4
    62
williamr@4
    63
// We can recognize a failed match by the fact that the second
williamr@4
    64
// component of the return value will be __name_end.
williamr@4
    65
williamr@4
    66
#define _MAXNAMES        64
williamr@4
    67
#define _MAX_NAME_LENGTH 64
williamr@4
    68
williamr@4
    69
// Both time_get and time_put need a structure of type _Time_Info
williamr@4
    70
// to provide names and abbreviated names for months and days,
williamr@4
    71
// as well as the am/pm designator.  The month and weekday tables
williamr@4
    72
// have the all the abbreviated names before all the full names.
williamr@4
    73
// The _Time_Info tables are initialized using the non-template
williamr@4
    74
// function _Init_timeinfo, which has two overloadings:  one
williamr@4
    75
// with a single reference parameter for the table to be initialized,
williamr@4
    76
// and one with a second _Locale_time * parameter.  The first form
williamr@4
    77
// is called by the default constructor and the second by a special
williamr@4
    78
// constructor invoked from the _byname subclass constructor to
williamr@4
    79
// construct the base class.
williamr@4
    80
williamr@4
    81
class _STLP_CLASS_DECLSPEC _Time_Info {
williamr@4
    82
public:
williamr@4
    83
  string _M_dayname[14];
williamr@4
    84
  string _M_monthname[24];
williamr@4
    85
  string _M_am_pm[2];
williamr@4
    86
  string _M_time_format;
williamr@4
    87
  string _M_date_format;
williamr@4
    88
  string _M_date_time_format;
williamr@4
    89
  string _M_long_date_format;
williamr@4
    90
  string _M_long_date_time_format;
williamr@4
    91
};
williamr@4
    92
williamr@4
    93
_STLP_DECLSPEC void _STLP_CALL _Init_timeinfo(_Time_Info&);
williamr@4
    94
_STLP_DECLSPEC void _STLP_CALL _Init_timeinfo(_Time_Info&, _Locale_time*);
williamr@4
    95
williamr@4
    96
class _STLP_CLASS_DECLSPEC time_base {
williamr@4
    97
public:
williamr@4
    98
  enum dateorder {no_order, dmy, mdy, ymd, ydm};
williamr@4
    99
};
williamr@4
   100
williamr@4
   101
williamr@4
   102
template <class _Ch, __DFL_TMPL_PARAM( _InIt , istreambuf_iterator<_Ch>) >
williamr@4
   103
class time_get : public locale::facet, public time_base 
williamr@4
   104
{
williamr@4
   105
  friend class _Locale;
williamr@4
   106
williamr@4
   107
public:
williamr@4
   108
  typedef _Ch   char_type;
williamr@4
   109
  typedef _InIt iter_type;
williamr@4
   110
williamr@4
   111
  explicit  time_get(size_t __refs = 0)   : _BaseFacet(__refs) {
williamr@4
   112
      _Init_timeinfo(_M_timeinfo);
williamr@4
   113
  }
williamr@4
   114
  dateorder date_order() const { return do_date_order(); }
williamr@4
   115
  iter_type get_time(iter_type __s, iter_type  __end, ios_base&  __str,
williamr@4
   116
                     ios_base::iostate&  __err, tm* __t) const
williamr@4
   117
    { return do_get_time(__s,  __end,  __str,  __err, __t); }
williamr@4
   118
  iter_type get_date(iter_type __s, iter_type  __end, ios_base&  __str,
williamr@4
   119
                     ios_base::iostate&  __err, tm* __t) const
williamr@4
   120
    { return do_get_date(__s,  __end,  __str,  __err, __t); }
williamr@4
   121
  iter_type get_weekday(iter_type __s, iter_type  __end, ios_base&  __str,
williamr@4
   122
                        ios_base::iostate&  __err, tm* __t) const
williamr@4
   123
    { return do_get_weekday(__s,  __end,  __str,  __err, __t); }
williamr@4
   124
  iter_type get_monthname(iter_type __s, iter_type  __end, ios_base&  __str,
williamr@4
   125
                          ios_base::iostate&  __err, tm* __t) const
williamr@4
   126
    { return do_get_monthname(__s,  __end,  __str,  __err, __t); }
williamr@4
   127
  iter_type get_year(iter_type __s, iter_type  __end, ios_base&  __str,
williamr@4
   128
                     ios_base::iostate&  __err, tm* __t) const
williamr@4
   129
    { return do_get_year(__s,  __end,  __str,  __err, __t); }
williamr@4
   130
williamr@4
   131
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
williamr@4
   132
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId();
williamr@4
   133
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(istreambuf_iterator<wchar_t, char_traits<wchar_t> >*);
williamr@4
   134
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(const wchar_t**);
williamr@4
   135
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(istreambuf_iterator<char, char_traits<char> >*);
williamr@4
   136
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(const char**);
williamr@4
   137
#else
williamr@4
   138
 	_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
williamr@4
   139
#endif
williamr@4
   140
williamr@4
   141
protected:
williamr@4
   142
  _Time_Info _M_timeinfo;
williamr@4
   143
williamr@4
   144
  time_get(_Locale_time *, size_t __refs) : _BaseFacet(__refs) {}
williamr@4
   145
williamr@4
   146
  ~time_get() {}
williamr@4
   147
williamr@4
   148
  virtual dateorder do_date_order() const {return no_order;}
williamr@4
   149
    
williamr@4
   150
  virtual iter_type do_get_time(iter_type __s, iter_type  __end,
williamr@4
   151
                                ios_base&, ios_base::iostate&  __err,
williamr@4
   152
                                tm* __t) const;
williamr@4
   153
    
williamr@4
   154
  virtual iter_type do_get_date(iter_type __s, iter_type  __end,
williamr@4
   155
                                ios_base&, ios_base::iostate& __err,
williamr@4
   156
                                tm* __t) const;
williamr@4
   157
williamr@4
   158
  virtual iter_type do_get_weekday(iter_type __s, iter_type  __end,
williamr@4
   159
                                   ios_base&,
williamr@4
   160
                                   ios_base::iostate& __err,
williamr@4
   161
                                   tm* __t) const;
williamr@4
   162
  virtual iter_type do_get_monthname(iter_type __s, iter_type  __end,
williamr@4
   163
                                     ios_base&,
williamr@4
   164
                                     ios_base::iostate& __err,
williamr@4
   165
                                     tm* __t) const;
williamr@4
   166
  
williamr@4
   167
  virtual iter_type do_get_year(iter_type __s, iter_type  __end,
williamr@4
   168
                                ios_base&, ios_base::iostate& __err,
williamr@4
   169
                                tm* __t) const;
williamr@4
   170
};
williamr@4
   171
williamr@4
   172
time_base::dateorder _STLP_CALL
williamr@4
   173
_STLP_DECLSPEC __get_date_order(_Locale_time*);
williamr@4
   174
_Locale_time* _STLP_CALL __acquire_time(const char* __name);
williamr@4
   175
void          _STLP_CALL __release_time(_Locale_time* __time);
williamr@4
   176
williamr@4
   177
template <class _Ch, __DFL_TMPL_PARAM( _InIt , istreambuf_iterator<_Ch>) >
williamr@4
   178
class time_get_byname : public time_get<_Ch, _InIt> 
williamr@4
   179
{
williamr@4
   180
public:
williamr@4
   181
  typedef  time_base::dateorder dateorder;
williamr@4
   182
  typedef _InIt                 iter_type;
williamr@4
   183
williamr@4
   184
  explicit   time_get_byname(const char* __name, size_t __refs = 0)
williamr@4
   185
    : time_get<_Ch, _InIt>((_Locale_time*) 0, __refs),
williamr@4
   186
      _M_time(__acquire_time(__name))
williamr@4
   187
    { _Init_timeinfo(this->_M_timeinfo, this->_M_time); }
williamr@4
   188
williamr@4
   189
protected:
williamr@4
   190
  ~time_get_byname() { __release_time(_M_time); }
williamr@4
   191
  dateorder do_date_order() const { return __get_date_order(_M_time); }
williamr@4
   192
private:
williamr@4
   193
  _Locale_time* _M_time;
williamr@4
   194
};
williamr@4
   195
williamr@4
   196
// time_put facet
williamr@4
   197
williamr@4
   198
// For the formats 'x, 'X', and 'c', do_put calls the first form of
williamr@4
   199
// put with the pattern obtained from _M_timeinfo._M_date_format or
williamr@4
   200
// _M_timeinfo._M_time_format.
williamr@4
   201
williamr@4
   202
// Helper function:  __  takes a single-character
williamr@4
   203
// format.  As indicated by the foregoing remark, this will never be
williamr@4
   204
// 'x', 'X', or 'c'.
williamr@4
   205
williamr@4
   206
_STLP_DECLSPEC char * _STLP_CALL
williamr@4
   207
__write_formatted_time(char * __buf, char __format, char __modifier,
williamr@4
   208
                       const _Time_Info& __table, const tm* __t);
williamr@4
   209
williamr@4
   210
template <class _OuIt>
williamr@4
   211
inline _OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out,
williamr@4
   212
                                   const ios_base& /* __loc */, char) {
williamr@4
   213
    return copy(__first, __last, __out);
williamr@4
   214
}
williamr@4
   215
williamr@4
   216
# ifndef _STLP_NO_WCHAR_T
williamr@4
   217
template <class _OuIt>
williamr@4
   218
_OuIt _STLP_CALL __put_time(char * __first, char * __last, _OuIt __out,
williamr@4
   219
                            const ios_base& __s, wchar_t);
williamr@4
   220
# endif
williamr@4
   221
williamr@4
   222
template<class _Ch, __DFL_TMPL_PARAM( _OutputIter , ostreambuf_iterator<_Ch> ) >
williamr@4
   223
class time_put : public locale::facet, public time_base
williamr@4
   224
{
williamr@4
   225
  friend class _Locale;
williamr@4
   226
public:
williamr@4
   227
  typedef _Ch      char_type;
williamr@4
   228
  typedef _OutputIter iter_type;
williamr@4
   229
williamr@4
   230
  explicit   time_put(size_t __refs = 0) : _BaseFacet(__refs) {
williamr@4
   231
    _Init_timeinfo(_M_timeinfo);
williamr@4
   232
  }
williamr@4
   233
williamr@4
   234
  _OutputIter put(iter_type __s, ios_base& __f, _Ch __fill,
williamr@4
   235
		  const tm* __tmb,
williamr@4
   236
		  const _Ch* __pat, const _Ch* __pat_end) const;
williamr@4
   237
  
williamr@4
   238
  _OutputIter put(iter_type __s, ios_base& __f, _Ch  __fill,
williamr@4
   239
		  const tm* __tmb, char __format, char __modifier = 0) const { 
williamr@4
   240
    return do_put(__s, __f,  __fill, __tmb, __format, __modifier); 
williamr@4
   241
  }
williamr@4
   242
  
williamr@4
   243
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
williamr@4
   244
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId();
williamr@4
   245
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(ostreambuf_iterator<wchar_t, char_traits<wchar_t> >*);
williamr@4
   246
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(wchar_t**);
williamr@4
   247
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(ostreambuf_iterator<char, char_traits<char> >*);
williamr@4
   248
    _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId(char**);
williamr@4
   249
#else
williamr@4
   250
   	_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
williamr@4
   251
#endif
williamr@4
   252
  
williamr@4
   253
protected:
williamr@4
   254
  _Time_Info _M_timeinfo;
williamr@4
   255
williamr@4
   256
  time_put(_Locale_time* /*__time*/, size_t __refs) : _BaseFacet(__refs) {
williamr@4
   257
    //    _Init_timeinfo(_M_timeinfo, __time);
williamr@4
   258
  }
williamr@4
   259
williamr@4
   260
  ~time_put() {}
williamr@4
   261
  virtual iter_type do_put(iter_type __s, ios_base& __f,
williamr@4
   262
                           char_type  /* __fill */, const tm* __tmb,
williamr@4
   263
                           char __format, char /* __modifier */) const;
williamr@4
   264
};
williamr@4
   265
williamr@4
   266
template <class _Ch, __DFL_TMPL_PARAM( _InIt , ostreambuf_iterator<_Ch> ) >
williamr@4
   267
class time_put_byname : public time_put<_Ch, _InIt> 
williamr@4
   268
{
williamr@4
   269
  friend class _Locale;
williamr@4
   270
public:
williamr@4
   271
  typedef time_base::dateorder dateorder;
williamr@4
   272
  typedef _InIt iter_type;
williamr@4
   273
  typedef _Ch   char_type;
williamr@4
   274
williamr@4
   275
  explicit    time_put_byname(const char * __name, size_t __refs = 0)
williamr@4
   276
    : time_put<_Ch, _InIt>((_Locale_time*) 0, __refs),
williamr@4
   277
    _M_time(__acquire_time(__name))
williamr@4
   278
  { _Init_timeinfo(this->_M_timeinfo, this->_M_time); }
williamr@4
   279
  
williamr@4
   280
protected:
williamr@4
   281
  ~time_put_byname() { __release_time(_M_time); }
williamr@4
   282
williamr@4
   283
private:
williamr@4
   284
  _Locale_time* _M_time;
williamr@4
   285
};
williamr@4
   286
williamr@4
   287
# ifdef _STLP_USE_TEMPLATE_EXPORT
williamr@4
   288
_STLP_EXPORT_TEMPLATE_CLASS time_get<char, istreambuf_iterator<char, char_traits<char> > >;
williamr@4
   289
_STLP_EXPORT_TEMPLATE_CLASS time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
williamr@4
   290
// _STLP_EXPORT_TEMPLATE_CLASS time_get<char, const char*>;
williamr@4
   291
// _STLP_EXPORT_TEMPLATE_CLASS time_put<char, char*>;
williamr@4
   292
#  ifndef _STLP_NO_WCHAR_T
williamr@4
   293
_STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
williamr@4
   294
_STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
williamr@4
   295
// _STLP_EXPORT_TEMPLATE_CLASS time_get<wchar_t, const wchar_t*>;
williamr@4
   296
// _STLP_EXPORT_TEMPLATE_CLASS time_put<wchar_t, wchar_t*>;
williamr@4
   297
#  endif /* INSTANTIATE_WIDE_STREAMS */
williamr@4
   298
williamr@4
   299
# endif
williamr@4
   300
williamr@4
   301
# if defined (__BORLANDC__) && defined (_RTLDLL)
williamr@4
   302
inline void _Stl_loc_init_time_facets() {
williamr@4
   303
  
williamr@4
   304
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
williamr@4
   305
  time_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()._M_index                      = 16;
williamr@4
   306
  time_get<char, const char*>::GetFacetLocaleId()._M_index         = 17;
williamr@4
   307
  time_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()._M_index                      = 18;
williamr@4
   308
  time_put<char, char*>::GetFacetLocaleId()._M_index               = 19;
williamr@4
   309
#else
williamr@4
   310
  time_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()._M_index                      = 16;
williamr@4
   311
  time_get<char, const char*>::id._M_index         = 17;
williamr@4
   312
  time_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()._M_index                      = 18;
williamr@4
   313
  time_put<char, char*>::id._M_index               = 19;
williamr@4
   314
#endif
williamr@4
   315
williamr@4
   316
# ifndef _STLP_NO_WCHAR_T
williamr@4
   317
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
williamr@4
   318
  time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()._M_index                   = 35;
williamr@4
   319
  time_get<wchar_t, const wchar_t*>::GetFacetLocaleId()._M_index   = 36;
williamr@4
   320
  time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()._M_index                   = 37;
williamr@4
   321
  time_put<wchar_t, wchar_t*>::GetFacetLocaleId()._M_index         = 38;
williamr@4
   322
#else
williamr@4
   323
  time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index                   = 35;
williamr@4
   324
  time_get<wchar_t, const wchar_t*>::id._M_index   = 36;
williamr@4
   325
  time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index                   = 37;
williamr@4
   326
  time_put<wchar_t, wchar_t*>::id._M_index         = 38;
williamr@4
   327
#endif //__SYMBIAN32__
williamr@4
   328
# endif //!_STLP_NO_WCHAR_T
williamr@4
   329
  
williamr@4
   330
}
williamr@4
   331
# endif
williamr@4
   332
williamr@4
   333
_STLP_END_NAMESPACE
williamr@4
   334
williamr@4
   335
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4
   336
#  include <stl/_time_facets.c>
williamr@4
   337
# endif
williamr@4
   338
williamr@4
   339
#endif /* _STLP_INTERNAL_TIME_FACETS_H */
williamr@4
   340
williamr@4
   341
// Local Variables:
williamr@4
   342
// mode:C++
williamr@4
   343
// End:
williamr@4
   344
williamr@4
   345