epoc32/include/stdapis/stlportv5/stl/char_traits.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/char_traits.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
/*
williamr@2
     2
 * Copyright (c) 1996,1997
williamr@2
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     4
 *
williamr@2
     5
 * Copyright (c) 1999
williamr@2
     6
 * Boris Fomitchev
williamr@2
     7
 *
williamr@2
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
     9
 * or implied. Any use is at your own risk.
williamr@2
    10
 *
williamr@2
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
    12
 * without fee, provided the above notices are retained on all copies.
williamr@2
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    14
 * provided the above notices are retained, and a notice that the code was
williamr@2
    15
 * modified is included with the above copyright notice.
williamr@2
    16
 *
williamr@2
    17
 */
williamr@2
    18
williamr@2
    19
#ifndef _STLP_CHAR_TRAITS_H
williamr@2
    20
#define _STLP_CHAR_TRAITS_H
williamr@2
    21
williamr@2
    22
// Define char_traits
williamr@2
    23
williamr@2
    24
# if defined (_STLP_OWN_IOSTREAMS) || ! defined (_STLP_USE_NEW_IOSTREAMS)
williamr@2
    25
williamr@2
    26
# if ! defined (_STLP_CSTDDEF)
williamr@2
    27
#  include <cstddef>
williamr@2
    28
# endif
williamr@2
    29
williamr@2
    30
#if ! defined (_STLP_CSTRING)
williamr@2
    31
#  include <cstring>
williamr@2
    32
#endif
williamr@2
    33
williamr@2
    34
#if defined (_STLP_UNIX) && defined (_STLP_HAS_NO_NEW_C_HEADERS)
williamr@2
    35
#include <sys/types.h>          // For off_t
williamr@2
    36
#endif /* __unix */
williamr@2
    37
williamr@2
    38
#ifdef __BORLANDC__
williamr@2
    39
# include <mem.h>
williamr@2
    40
# include <string.h>
williamr@2
    41
# include <_stddef.h>
williamr@2
    42
// class mbstate_t;
williamr@2
    43
#endif
williamr@2
    44
williamr@2
    45
#ifndef __TYPE_TRAITS_H
williamr@2
    46
# include <stl/type_traits.h>
williamr@2
    47
#endif
williamr@2
    48
williamr@2
    49
# if !defined (_STLP_CWCHAR)
williamr@2
    50
#  include <stl/_cwchar.h>
williamr@2
    51
# endif
williamr@2
    52
williamr@2
    53
_STLP_BEGIN_NAMESPACE
williamr@2
    54
williamr@2
    55
# ifdef _STLP_OWN_IOSTREAMS
williamr@2
    56
williamr@2
    57
template <class _Tp> class allocator;
williamr@2
    58
williamr@2
    59
#define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
williamr@2
    60
williamr@2
    61
#if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* IRIX */
williamr@2
    62
typedef off64_t   streamoff;
williamr@2
    63
// #elif defined (__unix) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* Other version of UNIX */
williamr@2
    64
// typedef off_t     streamoff;
williamr@2
    65
#else /* __unix */
williamr@2
    66
// boris : here, it's not ptrdiff_t as some Solaris systems have confusing definitions of these.
williamr@2
    67
typedef long streamoff;
williamr@2
    68
#endif /* _STLP_HAS_NO_NEW_C_HEADERS */
williamr@2
    69
williamr@2
    70
typedef ptrdiff_t streamsize;
williamr@2
    71
williamr@2
    72
// Class fpos, which represents a position within a file.  (The C++
williamr@2
    73
// standard calls for it to be defined in <ios>.  This implementation
williamr@2
    74
// moves it to <iosfwd>, which is included by <ios>.)
williamr@2
    75
template <class _StateT> class fpos
williamr@2
    76
{
williamr@2
    77
public:                         // From table 88 of the C++ standard.
williamr@2
    78
  fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
williamr@2
    79
  fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
williamr@2
    80
williamr@2
    81
  operator streamoff() const { return _M_pos; }
williamr@2
    82
williamr@2
    83
  bool  _STLP_CALL operator==(const fpos<_StateT>& __y) const
williamr@2
    84
    { return _M_pos == __y._M_pos; }
williamr@2
    85
  bool _STLP_CALL operator!=(const fpos<_StateT>& __y) const
williamr@2
    86
    { return _M_pos != __y._M_pos; }
williamr@2
    87
williamr@2
    88
  fpos<_StateT>& operator+=(streamoff __off) {
williamr@2
    89
    _M_pos += __off;
williamr@2
    90
    return *this;
williamr@2
    91
  }
williamr@2
    92
  fpos<_StateT>& operator-=(streamoff __off) {
williamr@2
    93
    _M_pos -= __off;
williamr@2
    94
    return *this;
williamr@2
    95
  }
williamr@2
    96
williamr@2
    97
  fpos<_StateT> operator+(streamoff __off) {
williamr@2
    98
    fpos<_StateT> __tmp(*this);
williamr@2
    99
    __tmp += __off;
williamr@2
   100
    return __tmp;
williamr@2
   101
  }
williamr@2
   102
  fpos<_StateT> operator-(streamoff __off) {
williamr@2
   103
    fpos<_StateT> __tmp(*this);
williamr@2
   104
    __tmp -= __off;
williamr@2
   105
    return __tmp;
williamr@2
   106
  }
williamr@2
   107
williamr@2
   108
public:                         // Manipulation of the state member.
williamr@2
   109
  _StateT state() const { return _M_st; }
williamr@2
   110
  void state(_StateT __st) { _M_st = __st; }
williamr@2
   111
private:
williamr@2
   112
  streamoff _M_pos;
williamr@2
   113
  _StateT _M_st;
williamr@2
   114
};
williamr@2
   115
williamr@2
   116
typedef fpos<mbstate_t> streampos;
williamr@2
   117
typedef fpos<mbstate_t> wstreampos;
williamr@2
   118
# endif
williamr@2
   119
williamr@2
   120
// Class __char_traits_base.
williamr@2
   121
williamr@2
   122
template <class _CharT, class _IntT> class __char_traits_base {
williamr@2
   123
public:
williamr@2
   124
  typedef _CharT char_type;
williamr@2
   125
  typedef _IntT int_type;
williamr@2
   126
#ifdef _STLP_USE_NEW_IOSTREAMS
williamr@2
   127
  typedef streamoff off_type;
williamr@2
   128
  typedef streampos pos_type;
williamr@2
   129
# ifdef _STLP_NO_MBSTATE_T
williamr@2
   130
  typedef char      state_type;
williamr@2
   131
# else
williamr@2
   132
  typedef mbstate_t state_type;
williamr@2
   133
# endif
williamr@2
   134
#endif /* _STLP_USE_NEW_IOSTREAMS */
williamr@2
   135
williamr@2
   136
  static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
williamr@2
   137
  static bool _STLP_CALL eq(const _CharT& __c1, const _CharT& __c2)
williamr@2
   138
    { return __c1 == __c2; }
williamr@2
   139
  static bool _STLP_CALL lt(const _CharT& __c1, const _CharT& __c2)
williamr@2
   140
    { return __c1 < __c2; }
williamr@2
   141
williamr@2
   142
  static int _STLP_CALL compare(const _CharT* __s1, const _CharT* __s2, size_t __n) {
williamr@2
   143
    for (size_t __i = 0; __i < __n; ++__i)
williamr@2
   144
      if (!eq(__s1[__i], __s2[__i]))
williamr@2
   145
        return __s1[__i] < __s2[__i] ? -1 : 1;
williamr@2
   146
    return 0;
williamr@2
   147
  }
williamr@2
   148
williamr@2
   149
  static size_t _STLP_CALL length(const _CharT* __s) {
williamr@2
   150
    const _CharT _NullChar = _STLP_DEFAULT_CONSTRUCTED(_CharT);
williamr@2
   151
    size_t __i;
williamr@2
   152
    for (__i = 0; !eq(__s[__i], _NullChar); ++__i)
williamr@2
   153
      {}
williamr@2
   154
    return __i;
williamr@2
   155
  }
williamr@2
   156
williamr@2
   157
  static const _CharT* _STLP_CALL find(const _CharT* __s, size_t __n, const _CharT& __c) {
williamr@2
   158
    for ( ; __n > 0 ; ++__s, --__n)
williamr@2
   159
      if (eq(*__s, __c))
williamr@2
   160
        return __s;
williamr@2
   161
    return 0;
williamr@2
   162
  }
williamr@2
   163
williamr@2
   164
williamr@2
   165
  static _CharT* _STLP_CALL move(_CharT* __s1, const _CharT* __s2, size_t _Sz) {
williamr@2
   166
    return (_Sz == 0 ? __s1 : (_CharT*)memmove(__s1, __s2, _Sz * sizeof(_CharT)));
williamr@2
   167
  }
williamr@2
   168
williamr@2
   169
  static _CharT* _STLP_CALL copy(_CharT* __s1, const _CharT* __s2, size_t __n) {
williamr@2
   170
    return (__n == 0 ? __s1 :
williamr@2
   171
	    (_CharT*)memcpy(__s1, __s2, __n * sizeof(_CharT)));
williamr@2
   172
    }
williamr@2
   173
williamr@2
   174
  static _CharT* _STLP_CALL assign(_CharT* __s, size_t __n, _CharT __c) {
williamr@2
   175
    for (size_t __i = 0; __i < __n; ++__i)
williamr@2
   176
      __s[__i] = __c;
williamr@2
   177
    return __s;
williamr@2
   178
  }
williamr@2
   179
williamr@2
   180
  static int_type _STLP_CALL not_eof(const int_type& __c) {
williamr@2
   181
    return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0);
williamr@2
   182
  }
williamr@2
   183
williamr@2
   184
  static char_type _STLP_CALL to_char_type(const int_type& __c) {
williamr@2
   185
    return (char_type)__c;
williamr@2
   186
  }
williamr@2
   187
williamr@2
   188
  static int_type _STLP_CALL to_int_type(const char_type& __c) {
williamr@2
   189
    return (int_type)__c;
williamr@2
   190
  }
williamr@2
   191
williamr@2
   192
  static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2) {
williamr@2
   193
    return __c1 == __c2;
williamr@2
   194
  }
williamr@2
   195
williamr@2
   196
  static int_type _STLP_CALL eof() {
williamr@2
   197
    return (int_type)-1;
williamr@2
   198
    //    return __STATIC_CAST(int_type,-1);
williamr@2
   199
  }
williamr@2
   200
};
williamr@2
   201
williamr@2
   202
// Generic char_traits class.  Note that this class is provided only
williamr@2
   203
//  as a base for explicit specialization; it is unlikely to be useful
williamr@2
   204
//  as is for any particular user-defined type.  In particular, it
williamr@2
   205
//  *will not work* for a non-POD type.
williamr@2
   206
williamr@2
   207
template <class _CharT> class char_traits
williamr@2
   208
  : public __char_traits_base<_CharT, _CharT>
williamr@2
   209
{};
williamr@2
   210
williamr@2
   211
// Specialization for char.
williamr@2
   212
williamr@2
   213
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<char>
williamr@2
   214
  : public __char_traits_base<char, int>
williamr@2
   215
{
williamr@2
   216
public:
williamr@2
   217
  typedef char char_type;
williamr@2
   218
  typedef int int_type;
williamr@2
   219
#ifdef _STLP_USE_NEW_IOSTREAMS
williamr@2
   220
  typedef streamoff off_type;
williamr@2
   221
# ifndef _STLP_NO_MBSTATE_T
williamr@2
   222
  typedef streampos pos_type;
williamr@2
   223
  typedef mbstate_t state_type;
williamr@2
   224
# endif
williamr@2
   225
#endif /* _STLP_USE_NEW_IOSTREAMS */
williamr@2
   226
williamr@2
   227
  static char _STLP_CALL to_char_type(const int& __c) {
williamr@2
   228
    return (char)(unsigned char)__c;
williamr@2
   229
  }
williamr@2
   230
williamr@2
   231
  static int _STLP_CALL to_int_type(const char& __c) {
williamr@2
   232
    return (unsigned char)__c;
williamr@2
   233
  }
williamr@2
   234
williamr@2
   235
  static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
williamr@2
   236
    { return memcmp(__s1, __s2, __n); }
williamr@2
   237
williamr@2
   238
  static size_t _STLP_CALL length(const char* __s) { return strlen(__s); }
williamr@2
   239
williamr@2
   240
  static void _STLP_CALL assign(char& __c1, const char& __c2) { __c1 = __c2; }
williamr@2
   241
williamr@2
   242
  static char* _STLP_CALL assign(char* __s, size_t __n, char __c)
williamr@2
   243
    { memset(__s, __c, __n); return __s; }
williamr@2
   244
};
williamr@2
   245
williamr@2
   246
# if defined (_STLP_HAS_WCHAR_T)
williamr@2
   247
// Specialization for wchar_t.
williamr@2
   248
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
williamr@2
   249
  : public __char_traits_base<wchar_t, wint_t>
williamr@2
   250
{};
williamr@2
   251
# endif
williamr@2
   252
williamr@2
   253
_STLP_END_NAMESPACE
williamr@2
   254
williamr@2
   255
# else /* OWN_IOSTREAMS */
williamr@2
   256
williamr@2
   257
#  include <wrap_std/iosfwd>
williamr@2
   258
williamr@2
   259
# endif /* OWN_IOSTREAMS */
williamr@2
   260
williamr@2
   261
#endif /* _STLP_CHAR_TRAITS_H */
williamr@2
   262
williamr@2
   263
// Local Variables:
williamr@2
   264
// mode:C++
williamr@2
   265
// End:
williamr@2
   266