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