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