epoc32/include/tools/stlport/stl/char_traits.h
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/char_traits.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,281 @@
     1.4 +/*
     1.5 + * Copyright (c) 1996,1997
     1.6 + * Silicon Graphics Computer Systems, Inc.
     1.7 + *
     1.8 + * Copyright (c) 1999
     1.9 + * Boris Fomitchev
    1.10 + *
    1.11 + * This material is provided "as is", with absolutely no warranty expressed
    1.12 + * or implied. Any use is at your own risk.
    1.13 + *
    1.14 + * Permission to use or copy this software for any purpose is hereby granted
    1.15 + * without fee, provided the above notices are retained on all copies.
    1.16 + * Permission to modify the code and to distribute modified code is granted,
    1.17 + * provided the above notices are retained, and a notice that the code was
    1.18 + * modified is included with the above copyright notice.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef _STLP_CHAR_TRAITS_H
    1.23 +#define _STLP_CHAR_TRAITS_H
    1.24 +
    1.25 +// Define char_traits
    1.26 +
    1.27 +#ifndef _STLP_INTERNAL_CSTDDEF
    1.28 +#  include <stl/_cstddef.h>
    1.29 +#endif
    1.30 +
    1.31 +#ifndef _STLP_INTERNAL_CSTRING
    1.32 +#  include <stl/_cstring.h>
    1.33 +#endif
    1.34 +
    1.35 +#if defined (__unix) || defined (N_PLAT_NLM)
    1.36 +#  include <sys/types.h>         // For off_t
    1.37 +#endif /* __unix */
    1.38 +
    1.39 +#ifdef __BORLANDC__
    1.40 +#  include _STLP_NATIVE_C_HEADER(mem.h)
    1.41 +#  include _STLP_NATIVE_C_HEADER(string.h)
    1.42 +#  include _STLP_NATIVE_C_HEADER(_stddef.h)
    1.43 +#endif
    1.44 +
    1.45 +#ifndef _STLP_INTERNAL_CONSTRUCT_H
    1.46 +#  include <stl/_construct.h>
    1.47 +#endif
    1.48 +
    1.49 +#ifndef _STLP_INTERNAL_CWCHAR
    1.50 +#  include <stl/_cwchar.h>
    1.51 +#endif
    1.52 +
    1.53 +_STLP_BEGIN_NAMESPACE
    1.54 +
    1.55 +template <class _Tp> class allocator;
    1.56 +
    1.57 +#define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
    1.58 +
    1.59 +#if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* IRIX */
    1.60 +typedef off64_t streamoff;
    1.61 +#elif defined(_STLP_WCE)
    1.62 +typedef long streamoff;
    1.63 +#elif defined (_STLP_WIN32)
    1.64 +#  if defined (_STLP_LONG_LONG) && !defined (__CYGWIN__)
    1.65 +//The Win32 file io API support 64 bits access so streamoff and streamsize
    1.66 +//has to reflect that. Do not change the stringbuf behavior.
    1.67 +typedef _STLP_LONG_LONG streamoff;
    1.68 +#  else
    1.69 +typedef ptrdiff_t streamoff;
    1.70 +#  endif
    1.71 +#else // __unix
    1.72 +typedef off_t streamoff;
    1.73 +#endif /* _STLP_HAS_NO_NEW_C_HEADERS */
    1.74 +
    1.75 +#if defined (_STLP_WIN32)
    1.76 +typedef streamoff streamsize;
    1.77 +#else
    1.78 +typedef ptrdiff_t streamsize;
    1.79 +#endif
    1.80 +
    1.81 +// Class fpos, which represents a position within a file.  (The C++
    1.82 +// standard calls for it to be defined in <ios>.  This implementation
    1.83 +// moves it to <iosfwd>, which is included by <ios>.)
    1.84 +template <class _StateT> class fpos {
    1.85 +public:                         // From table 88 of the C++ standard.
    1.86 +  fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
    1.87 +  fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
    1.88 +
    1.89 +  operator streamoff() const { return _M_pos; }
    1.90 +
    1.91 +  bool operator==(const fpos& __y) const
    1.92 +  { return _M_pos == __y._M_pos; }
    1.93 +  bool operator!=(const fpos& __y) const
    1.94 +  { return _M_pos != __y._M_pos; }
    1.95 +
    1.96 +  fpos& operator+=(streamoff __off) {
    1.97 +    _M_pos += __off;
    1.98 +    return *this;
    1.99 +  }
   1.100 +  fpos& operator-=(streamoff __off) {
   1.101 +    _M_pos -= __off;
   1.102 +    return *this;
   1.103 +  }
   1.104 +
   1.105 +  fpos operator+(streamoff __off) {
   1.106 +    fpos __tmp(*this);
   1.107 +    __tmp += __off;
   1.108 +    return __tmp;
   1.109 +  }
   1.110 +  fpos operator-(streamoff __off) {
   1.111 +    fpos __tmp(*this);
   1.112 +    __tmp -= __off;
   1.113 +    return __tmp;
   1.114 +  }
   1.115 +
   1.116 +public:                         // Manipulation of the state member.
   1.117 +  _StateT state() const { return _M_st; }
   1.118 +  void state(_StateT __st) { _M_st = __st; }
   1.119 +private:
   1.120 +  streamoff _M_pos;
   1.121 +  _StateT _M_st;
   1.122 +};
   1.123 +
   1.124 +#if !defined (_STLP_NO_MBSTATE_T)
   1.125 +typedef fpos<mbstate_t> streampos;
   1.126 +typedef fpos<mbstate_t> wstreampos;
   1.127 +#endif
   1.128 +
   1.129 +// Class __char_traits_base.
   1.130 +template <class _CharT, class _IntT>
   1.131 +class __char_traits_base {
   1.132 +public:
   1.133 +  typedef _CharT char_type;
   1.134 +  typedef _IntT int_type;
   1.135 +  typedef streamoff off_type;
   1.136 +  typedef streampos pos_type;
   1.137 +#if defined (_STLP_NO_MBSTATE_T)
   1.138 +  typedef char      state_type;
   1.139 +#else
   1.140 +  typedef mbstate_t state_type;
   1.141 +#endif
   1.142 +
   1.143 +  static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
   1.144 +  static bool _STLP_CALL eq(const char_type& __c1, const char_type& __c2)
   1.145 +  { return __c1 == __c2; }
   1.146 +  static bool _STLP_CALL lt(const char_type& __c1, const char_type& __c2)
   1.147 +  { return __c1 < __c2; }
   1.148 +
   1.149 +  static int _STLP_CALL compare(const char_type* __s1, const char_type* __s2, size_t __n) {
   1.150 +    for (size_t __i = 0; __i < __n; ++__i)
   1.151 +      if (!eq(__s1[__i], __s2[__i]))
   1.152 +        return __s1[__i] < __s2[__i] ? -1 : 1;
   1.153 +    return 0;
   1.154 +  }
   1.155 +
   1.156 +  static size_t _STLP_CALL length(const char_type* __s) {
   1.157 +    const char_type _NullChar = _STLP_DEFAULT_CONSTRUCTED(char_type);
   1.158 +    size_t __i(0);
   1.159 +    for (; !eq(__s[__i], _NullChar); ++__i) {}
   1.160 +    return __i;
   1.161 +  }
   1.162 +
   1.163 +  static const char_type* _STLP_CALL find(const char_type* __s, size_t __n, const char_type& __c) {
   1.164 +    for ( ; __n > 0 ; ++__s, --__n)
   1.165 +      if (eq(*__s, __c))
   1.166 +        return __s;
   1.167 +    return 0;
   1.168 +  }
   1.169 +
   1.170 +  static char_type* _STLP_CALL move(char_type* __s1, const char_type* __s2, size_t _Sz)
   1.171 +  { return (_Sz == 0 ? __s1 : (char_type*)memmove(__s1, __s2, _Sz * sizeof(char_type))); }
   1.172 +
   1.173 +  static char_type* _STLP_CALL copy(char_type* __s1, const char_type* __s2, size_t __n) {
   1.174 +    return (__n == 0 ? __s1 :
   1.175 +      (char_type*)memcpy(__s1, __s2, __n * sizeof(char_type)));
   1.176 +  }
   1.177 +
   1.178 +  static char_type* _STLP_CALL assign(char_type* __s, size_t __n, char_type __c) {
   1.179 +    for (size_t __i = 0; __i < __n; ++__i)
   1.180 +      __s[__i] = __c;
   1.181 +    return __s;
   1.182 +  }
   1.183 +
   1.184 +  static int_type _STLP_CALL not_eof(const int_type& __c)
   1.185 +  { return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0); }
   1.186 +
   1.187 +  static char_type _STLP_CALL to_char_type(const int_type& __c)
   1.188 +  { return (char_type)__c; }
   1.189 +
   1.190 +  static int_type _STLP_CALL to_int_type(const char_type& __c)
   1.191 +  { return (int_type)__c; }
   1.192 +
   1.193 +  static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2)
   1.194 +  { return __c1 == __c2; }
   1.195 +
   1.196 +  static int_type _STLP_CALL eof()
   1.197 +  { return (int_type)-1; }
   1.198 +};
   1.199 +
   1.200 +// Generic char_traits class.  Note that this class is provided only
   1.201 +//  as a base for explicit specialization; it is unlikely to be useful
   1.202 +//  as is for any particular user-defined type.  In particular, it
   1.203 +//  *will not work* for a non-POD type.
   1.204 +
   1.205 +template <class _CharT>
   1.206 +class char_traits
   1.207 +  : public __char_traits_base<_CharT, _CharT> {};
   1.208 +
   1.209 +// Specialization for char.
   1.210 +
   1.211 +_STLP_TEMPLATE_NULL
   1.212 +class _STLP_CLASS_DECLSPEC char_traits<char>
   1.213 +  : public __char_traits_base<char, int> {
   1.214 +public:
   1.215 +  typedef char char_type;
   1.216 +  typedef int int_type;
   1.217 +  typedef streamoff off_type;
   1.218 +#if !defined (_STLP_NO_MBSTATE_T)
   1.219 +  typedef streampos pos_type;
   1.220 +  typedef mbstate_t state_type;
   1.221 +#endif
   1.222 +
   1.223 +  static char _STLP_CALL to_char_type(const int& __c)
   1.224 +  { return (char)(unsigned char)__c; }
   1.225 +
   1.226 +  static int _STLP_CALL to_int_type(const char& __c)
   1.227 +  { return (unsigned char)__c; }
   1.228 +
   1.229 +  static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
   1.230 +  { return memcmp(__s1, __s2, __n); }
   1.231 +
   1.232 +  static size_t _STLP_CALL length(const char* __s)
   1.233 +  { return strlen(__s); }
   1.234 +
   1.235 +  static void _STLP_CALL assign(char& __c1, const char& __c2)
   1.236 +  { __c1 = __c2; }
   1.237 +
   1.238 +  static char* _STLP_CALL assign(char* __s, size_t __n, char __c) {
   1.239 +    memset(__s, __c, __n);
   1.240 +    return __s;
   1.241 +  }
   1.242 +};
   1.243 +
   1.244 +#if defined (_STLP_HAS_WCHAR_T)
   1.245 +// Specialization for wchar_t.
   1.246 +_STLP_TEMPLATE_NULL
   1.247 +class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
   1.248 +  : public __char_traits_base<wchar_t, wint_t> {
   1.249 +#  if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && !defined (_STLP_WCHAR_HPACC_EXCLUDE)
   1.250 +public:
   1.251 +#    if !defined (N_PLAT_NLM)
   1.252 +#      if !defined (__BORLANDC__)
   1.253 +  static wchar_t* _STLP_CALL move(wchar_t* __dest, const wchar_t* __src, size_t __n)
   1.254 +  { return wmemmove(__dest, __src, __n); }
   1.255 +#      endif
   1.256 +
   1.257 +  static wchar_t* _STLP_CALL copy(wchar_t* __dest, const wchar_t* __src, size_t __n)
   1.258 +  { return wmemcpy(__dest, __src, __n); }
   1.259 +
   1.260 +#      if !defined (__DMC__) && !defined (__BORLANDC__)
   1.261 +  static int _STLP_CALL compare(const wchar_t* __s1, const wchar_t* __s2, size_t __n)
   1.262 +  { return wmemcmp(__s1, __s2, __n); }
   1.263 +#      endif
   1.264 +
   1.265 +  static wchar_t* _STLP_CALL assign(wchar_t* __s, size_t __n, wchar_t __c)
   1.266 +  { return wmemset(__s, __c, __n); }
   1.267 +#    endif
   1.268 +
   1.269 +  static size_t _STLP_CALL length(const wchar_t* __s)
   1.270 +  { return wcslen(__s); }
   1.271 +
   1.272 +  static void _STLP_CALL assign(wchar_t& __c1, const wchar_t& __c2)
   1.273 +  { __c1 = __c2; }
   1.274 +#  endif
   1.275 +};
   1.276 +#endif
   1.277 +
   1.278 +_STLP_END_NAMESPACE
   1.279 +
   1.280 +#endif /* _STLP_CHAR_TRAITS_H */
   1.281 +
   1.282 +// Local Variables:
   1.283 +// mode:C++
   1.284 +// End: