epoc32/include/tools/stlport/stl/char_traits.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) 1996,1997
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
williamr@4
    19
#ifndef _STLP_CHAR_TRAITS_H
williamr@4
    20
#define _STLP_CHAR_TRAITS_H
williamr@4
    21
williamr@4
    22
// Define char_traits
williamr@4
    23
williamr@4
    24
#ifndef _STLP_INTERNAL_CSTDDEF
williamr@4
    25
#  include <stl/_cstddef.h>
williamr@4
    26
#endif
williamr@4
    27
williamr@4
    28
#ifndef _STLP_INTERNAL_CSTRING
williamr@4
    29
#  include <stl/_cstring.h>
williamr@4
    30
#endif
williamr@4
    31
williamr@4
    32
#if defined (__unix) || defined (N_PLAT_NLM)
williamr@4
    33
#  include <sys/types.h>         // For off_t
williamr@4
    34
#endif /* __unix */
williamr@4
    35
williamr@4
    36
#ifdef __BORLANDC__
williamr@4
    37
#  include _STLP_NATIVE_C_HEADER(mem.h)
williamr@4
    38
#  include _STLP_NATIVE_C_HEADER(string.h)
williamr@4
    39
#  include _STLP_NATIVE_C_HEADER(_stddef.h)
williamr@4
    40
#endif
williamr@4
    41
williamr@4
    42
#ifndef _STLP_INTERNAL_CONSTRUCT_H
williamr@4
    43
#  include <stl/_construct.h>
williamr@4
    44
#endif
williamr@4
    45
williamr@4
    46
#ifndef _STLP_INTERNAL_CWCHAR
williamr@4
    47
#  include <stl/_cwchar.h>
williamr@4
    48
#endif
williamr@4
    49
williamr@4
    50
_STLP_BEGIN_NAMESPACE
williamr@4
    51
williamr@4
    52
template <class _Tp> class allocator;
williamr@4
    53
williamr@4
    54
#define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
williamr@4
    55
williamr@4
    56
#if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* IRIX */
williamr@4
    57
typedef off64_t streamoff;
williamr@4
    58
#elif defined(_STLP_WCE)
williamr@4
    59
typedef long streamoff;
williamr@4
    60
#elif defined (_STLP_WIN32)
williamr@4
    61
#  if defined (_STLP_LONG_LONG) && !defined (__CYGWIN__)
williamr@4
    62
//The Win32 file io API support 64 bits access so streamoff and streamsize
williamr@4
    63
//has to reflect that. Do not change the stringbuf behavior.
williamr@4
    64
typedef _STLP_LONG_LONG streamoff;
williamr@4
    65
#  else
williamr@4
    66
typedef ptrdiff_t streamoff;
williamr@4
    67
#  endif
williamr@4
    68
#else // __unix
williamr@4
    69
typedef off_t streamoff;
williamr@4
    70
#endif /* _STLP_HAS_NO_NEW_C_HEADERS */
williamr@4
    71
williamr@4
    72
#if defined (_STLP_WIN32)
williamr@4
    73
typedef streamoff streamsize;
williamr@4
    74
#else
williamr@4
    75
typedef ptrdiff_t streamsize;
williamr@4
    76
#endif
williamr@4
    77
williamr@4
    78
// Class fpos, which represents a position within a file.  (The C++
williamr@4
    79
// standard calls for it to be defined in <ios>.  This implementation
williamr@4
    80
// moves it to <iosfwd>, which is included by <ios>.)
williamr@4
    81
template <class _StateT> class fpos {
williamr@4
    82
public:                         // From table 88 of the C++ standard.
williamr@4
    83
  fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
williamr@4
    84
  fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
williamr@4
    85
williamr@4
    86
  operator streamoff() const { return _M_pos; }
williamr@4
    87
williamr@4
    88
  bool operator==(const fpos& __y) const
williamr@4
    89
  { return _M_pos == __y._M_pos; }
williamr@4
    90
  bool operator!=(const fpos& __y) const
williamr@4
    91
  { return _M_pos != __y._M_pos; }
williamr@4
    92
williamr@4
    93
  fpos& operator+=(streamoff __off) {
williamr@4
    94
    _M_pos += __off;
williamr@4
    95
    return *this;
williamr@4
    96
  }
williamr@4
    97
  fpos& operator-=(streamoff __off) {
williamr@4
    98
    _M_pos -= __off;
williamr@4
    99
    return *this;
williamr@4
   100
  }
williamr@4
   101
williamr@4
   102
  fpos operator+(streamoff __off) {
williamr@4
   103
    fpos __tmp(*this);
williamr@4
   104
    __tmp += __off;
williamr@4
   105
    return __tmp;
williamr@4
   106
  }
williamr@4
   107
  fpos operator-(streamoff __off) {
williamr@4
   108
    fpos __tmp(*this);
williamr@4
   109
    __tmp -= __off;
williamr@4
   110
    return __tmp;
williamr@4
   111
  }
williamr@4
   112
williamr@4
   113
public:                         // Manipulation of the state member.
williamr@4
   114
  _StateT state() const { return _M_st; }
williamr@4
   115
  void state(_StateT __st) { _M_st = __st; }
williamr@4
   116
private:
williamr@4
   117
  streamoff _M_pos;
williamr@4
   118
  _StateT _M_st;
williamr@4
   119
};
williamr@4
   120
williamr@4
   121
#if !defined (_STLP_NO_MBSTATE_T)
williamr@4
   122
typedef fpos<mbstate_t> streampos;
williamr@4
   123
typedef fpos<mbstate_t> wstreampos;
williamr@4
   124
#endif
williamr@4
   125
williamr@4
   126
// Class __char_traits_base.
williamr@4
   127
template <class _CharT, class _IntT>
williamr@4
   128
class __char_traits_base {
williamr@4
   129
public:
williamr@4
   130
  typedef _CharT char_type;
williamr@4
   131
  typedef _IntT int_type;
williamr@4
   132
  typedef streamoff off_type;
williamr@4
   133
  typedef streampos pos_type;
williamr@4
   134
#if defined (_STLP_NO_MBSTATE_T)
williamr@4
   135
  typedef char      state_type;
williamr@4
   136
#else
williamr@4
   137
  typedef mbstate_t state_type;
williamr@4
   138
#endif
williamr@4
   139
williamr@4
   140
  static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
williamr@4
   141
  static bool _STLP_CALL eq(const char_type& __c1, const char_type& __c2)
williamr@4
   142
  { return __c1 == __c2; }
williamr@4
   143
  static bool _STLP_CALL lt(const char_type& __c1, const char_type& __c2)
williamr@4
   144
  { return __c1 < __c2; }
williamr@4
   145
williamr@4
   146
  static int _STLP_CALL compare(const char_type* __s1, const char_type* __s2, size_t __n) {
williamr@4
   147
    for (size_t __i = 0; __i < __n; ++__i)
williamr@4
   148
      if (!eq(__s1[__i], __s2[__i]))
williamr@4
   149
        return __s1[__i] < __s2[__i] ? -1 : 1;
williamr@4
   150
    return 0;
williamr@4
   151
  }
williamr@4
   152
williamr@4
   153
  static size_t _STLP_CALL length(const char_type* __s) {
williamr@4
   154
    const char_type _NullChar = _STLP_DEFAULT_CONSTRUCTED(char_type);
williamr@4
   155
    size_t __i(0);
williamr@4
   156
    for (; !eq(__s[__i], _NullChar); ++__i) {}
williamr@4
   157
    return __i;
williamr@4
   158
  }
williamr@4
   159
williamr@4
   160
  static const char_type* _STLP_CALL find(const char_type* __s, size_t __n, const char_type& __c) {
williamr@4
   161
    for ( ; __n > 0 ; ++__s, --__n)
williamr@4
   162
      if (eq(*__s, __c))
williamr@4
   163
        return __s;
williamr@4
   164
    return 0;
williamr@4
   165
  }
williamr@4
   166
williamr@4
   167
  static char_type* _STLP_CALL move(char_type* __s1, const char_type* __s2, size_t _Sz)
williamr@4
   168
  { return (_Sz == 0 ? __s1 : (char_type*)memmove(__s1, __s2, _Sz * sizeof(char_type))); }
williamr@4
   169
williamr@4
   170
  static char_type* _STLP_CALL copy(char_type* __s1, const char_type* __s2, size_t __n) {
williamr@4
   171
    return (__n == 0 ? __s1 :
williamr@4
   172
      (char_type*)memcpy(__s1, __s2, __n * sizeof(char_type)));
williamr@4
   173
  }
williamr@4
   174
williamr@4
   175
  static char_type* _STLP_CALL assign(char_type* __s, size_t __n, char_type __c) {
williamr@4
   176
    for (size_t __i = 0; __i < __n; ++__i)
williamr@4
   177
      __s[__i] = __c;
williamr@4
   178
    return __s;
williamr@4
   179
  }
williamr@4
   180
williamr@4
   181
  static int_type _STLP_CALL not_eof(const int_type& __c)
williamr@4
   182
  { return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0); }
williamr@4
   183
williamr@4
   184
  static char_type _STLP_CALL to_char_type(const int_type& __c)
williamr@4
   185
  { return (char_type)__c; }
williamr@4
   186
williamr@4
   187
  static int_type _STLP_CALL to_int_type(const char_type& __c)
williamr@4
   188
  { return (int_type)__c; }
williamr@4
   189
williamr@4
   190
  static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2)
williamr@4
   191
  { return __c1 == __c2; }
williamr@4
   192
williamr@4
   193
  static int_type _STLP_CALL eof()
williamr@4
   194
  { return (int_type)-1; }
williamr@4
   195
};
williamr@4
   196
williamr@4
   197
// Generic char_traits class.  Note that this class is provided only
williamr@4
   198
//  as a base for explicit specialization; it is unlikely to be useful
williamr@4
   199
//  as is for any particular user-defined type.  In particular, it
williamr@4
   200
//  *will not work* for a non-POD type.
williamr@4
   201
williamr@4
   202
template <class _CharT>
williamr@4
   203
class char_traits
williamr@4
   204
  : public __char_traits_base<_CharT, _CharT> {};
williamr@4
   205
williamr@4
   206
// Specialization for char.
williamr@4
   207
williamr@4
   208
_STLP_TEMPLATE_NULL
williamr@4
   209
class _STLP_CLASS_DECLSPEC char_traits<char>
williamr@4
   210
  : public __char_traits_base<char, int> {
williamr@4
   211
public:
williamr@4
   212
  typedef char char_type;
williamr@4
   213
  typedef int int_type;
williamr@4
   214
  typedef streamoff off_type;
williamr@4
   215
#if !defined (_STLP_NO_MBSTATE_T)
williamr@4
   216
  typedef streampos pos_type;
williamr@4
   217
  typedef mbstate_t state_type;
williamr@4
   218
#endif
williamr@4
   219
williamr@4
   220
  static char _STLP_CALL to_char_type(const int& __c)
williamr@4
   221
  { return (char)(unsigned char)__c; }
williamr@4
   222
williamr@4
   223
  static int _STLP_CALL to_int_type(const char& __c)
williamr@4
   224
  { return (unsigned char)__c; }
williamr@4
   225
williamr@4
   226
  static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
williamr@4
   227
  { return memcmp(__s1, __s2, __n); }
williamr@4
   228
williamr@4
   229
  static size_t _STLP_CALL length(const char* __s)
williamr@4
   230
  { return strlen(__s); }
williamr@4
   231
williamr@4
   232
  static void _STLP_CALL assign(char& __c1, const char& __c2)
williamr@4
   233
  { __c1 = __c2; }
williamr@4
   234
williamr@4
   235
  static char* _STLP_CALL assign(char* __s, size_t __n, char __c) {
williamr@4
   236
    memset(__s, __c, __n);
williamr@4
   237
    return __s;
williamr@4
   238
  }
williamr@4
   239
};
williamr@4
   240
williamr@4
   241
#if defined (_STLP_HAS_WCHAR_T)
williamr@4
   242
// Specialization for wchar_t.
williamr@4
   243
_STLP_TEMPLATE_NULL
williamr@4
   244
class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
williamr@4
   245
  : public __char_traits_base<wchar_t, wint_t> {
williamr@4
   246
#  if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && !defined (_STLP_WCHAR_HPACC_EXCLUDE)
williamr@4
   247
public:
williamr@4
   248
#    if !defined (N_PLAT_NLM)
williamr@4
   249
#      if !defined (__BORLANDC__)
williamr@4
   250
  static wchar_t* _STLP_CALL move(wchar_t* __dest, const wchar_t* __src, size_t __n)
williamr@4
   251
  { return wmemmove(__dest, __src, __n); }
williamr@4
   252
#      endif
williamr@4
   253
williamr@4
   254
  static wchar_t* _STLP_CALL copy(wchar_t* __dest, const wchar_t* __src, size_t __n)
williamr@4
   255
  { return wmemcpy(__dest, __src, __n); }
williamr@4
   256
williamr@4
   257
#      if !defined (__DMC__) && !defined (__BORLANDC__)
williamr@4
   258
  static int _STLP_CALL compare(const wchar_t* __s1, const wchar_t* __s2, size_t __n)
williamr@4
   259
  { return wmemcmp(__s1, __s2, __n); }
williamr@4
   260
#      endif
williamr@4
   261
williamr@4
   262
  static wchar_t* _STLP_CALL assign(wchar_t* __s, size_t __n, wchar_t __c)
williamr@4
   263
  { return wmemset(__s, __c, __n); }
williamr@4
   264
#    endif
williamr@4
   265
williamr@4
   266
  static size_t _STLP_CALL length(const wchar_t* __s)
williamr@4
   267
  { return wcslen(__s); }
williamr@4
   268
williamr@4
   269
  static void _STLP_CALL assign(wchar_t& __c1, const wchar_t& __c2)
williamr@4
   270
  { __c1 = __c2; }
williamr@4
   271
#  endif
williamr@4
   272
};
williamr@4
   273
#endif
williamr@4
   274
williamr@4
   275
_STLP_END_NAMESPACE
williamr@4
   276
williamr@4
   277
#endif /* _STLP_CHAR_TRAITS_H */
williamr@4
   278
williamr@4
   279
// Local Variables:
williamr@4
   280
// mode:C++
williamr@4
   281
// End: