epoc32/include/stdapis/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/stdapis/stlport/stl/char_traits.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,266 @@
     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 +# if defined (_STLP_OWN_IOSTREAMS) || ! defined (_STLP_USE_NEW_IOSTREAMS)
    1.28 +
    1.29 +# if ! defined (_STLP_CSTDDEF)
    1.30 +#  include <cstddef>
    1.31 +# endif
    1.32 +
    1.33 +#if ! defined (_STLP_CSTRING)
    1.34 +#  include <cstring>
    1.35 +#endif
    1.36 +
    1.37 +#if defined (_STLP_UNIX) && defined (_STLP_HAS_NO_NEW_C_HEADERS)
    1.38 +#include <sys/types.h>          // For off_t
    1.39 +#endif /* __unix */
    1.40 +
    1.41 +#ifdef __BORLANDC__
    1.42 +# include <mem.h>
    1.43 +# include <string.h>
    1.44 +# include <_stddef.h>
    1.45 +// class mbstate_t;
    1.46 +#endif
    1.47 +
    1.48 +#ifndef __TYPE_TRAITS_H
    1.49 +# include <stl/type_traits.h>
    1.50 +#endif
    1.51 +
    1.52 +# if !defined (_STLP_CWCHAR)
    1.53 +#  include <stl/_cwchar.h>
    1.54 +# endif
    1.55 +
    1.56 +_STLP_BEGIN_NAMESPACE
    1.57 +
    1.58 +# ifdef _STLP_OWN_IOSTREAMS
    1.59 +
    1.60 +template <class _Tp> class allocator;
    1.61 +
    1.62 +#define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
    1.63 +
    1.64 +#if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* IRIX */
    1.65 +typedef off64_t   streamoff;
    1.66 +// #elif defined (__unix) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* Other version of UNIX */
    1.67 +// typedef off_t     streamoff;
    1.68 +#else /* __unix */
    1.69 +// boris : here, it's not ptrdiff_t as some Solaris systems have confusing definitions of these.
    1.70 +typedef long streamoff;
    1.71 +#endif /* _STLP_HAS_NO_NEW_C_HEADERS */
    1.72 +
    1.73 +typedef ptrdiff_t streamsize;
    1.74 +
    1.75 +// Class fpos, which represents a position within a file.  (The C++
    1.76 +// standard calls for it to be defined in <ios>.  This implementation
    1.77 +// moves it to <iosfwd>, which is included by <ios>.)
    1.78 +template <class _StateT> class fpos
    1.79 +{
    1.80 +public:                         // From table 88 of the C++ standard.
    1.81 +  fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
    1.82 +  fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
    1.83 +
    1.84 +  operator streamoff() const { return _M_pos; }
    1.85 +
    1.86 +  bool  _STLP_CALL operator==(const fpos<_StateT>& __y) const
    1.87 +    { return _M_pos == __y._M_pos; }
    1.88 +  bool _STLP_CALL operator!=(const fpos<_StateT>& __y) const
    1.89 +    { return _M_pos != __y._M_pos; }
    1.90 +
    1.91 +  fpos<_StateT>& operator+=(streamoff __off) {
    1.92 +    _M_pos += __off;
    1.93 +    return *this;
    1.94 +  }
    1.95 +  fpos<_StateT>& operator-=(streamoff __off) {
    1.96 +    _M_pos -= __off;
    1.97 +    return *this;
    1.98 +  }
    1.99 +
   1.100 +  fpos<_StateT> operator+(streamoff __off) {
   1.101 +    fpos<_StateT> __tmp(*this);
   1.102 +    __tmp += __off;
   1.103 +    return __tmp;
   1.104 +  }
   1.105 +  fpos<_StateT> operator-(streamoff __off) {
   1.106 +    fpos<_StateT> __tmp(*this);
   1.107 +    __tmp -= __off;
   1.108 +    return __tmp;
   1.109 +  }
   1.110 +
   1.111 +public:                         // Manipulation of the state member.
   1.112 +  _StateT state() const { return _M_st; }
   1.113 +  void state(_StateT __st) { _M_st = __st; }
   1.114 +private:
   1.115 +  streamoff _M_pos;
   1.116 +  _StateT _M_st;
   1.117 +};
   1.118 +
   1.119 +typedef fpos<mbstate_t> streampos;
   1.120 +typedef fpos<mbstate_t> wstreampos;
   1.121 +# endif
   1.122 +
   1.123 +// Class __char_traits_base.
   1.124 +
   1.125 +template <class _CharT, class _IntT> class __char_traits_base {
   1.126 +public:
   1.127 +  typedef _CharT char_type;
   1.128 +  typedef _IntT int_type;
   1.129 +#ifdef _STLP_USE_NEW_IOSTREAMS
   1.130 +  typedef streamoff off_type;
   1.131 +  typedef streampos pos_type;
   1.132 +# ifdef _STLP_NO_MBSTATE_T
   1.133 +  typedef char      state_type;
   1.134 +# else
   1.135 +  typedef mbstate_t state_type;
   1.136 +# endif
   1.137 +#endif /* _STLP_USE_NEW_IOSTREAMS */
   1.138 +
   1.139 +  static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
   1.140 +  static bool _STLP_CALL eq(const _CharT& __c1, const _CharT& __c2)
   1.141 +    { return __c1 == __c2; }
   1.142 +  static bool _STLP_CALL lt(const _CharT& __c1, const _CharT& __c2)
   1.143 +    { return __c1 < __c2; }
   1.144 +
   1.145 +  static int _STLP_CALL compare(const _CharT* __s1, const _CharT* __s2, size_t __n) {
   1.146 +    for (size_t __i = 0; __i < __n; ++__i)
   1.147 +      if (!eq(__s1[__i], __s2[__i]))
   1.148 +        return __s1[__i] < __s2[__i] ? -1 : 1;
   1.149 +    return 0;
   1.150 +  }
   1.151 +
   1.152 +  static size_t _STLP_CALL length(const _CharT* __s) {
   1.153 +    const _CharT _NullChar = _STLP_DEFAULT_CONSTRUCTED(_CharT);
   1.154 +    size_t __i;
   1.155 +    for (__i = 0; !eq(__s[__i], _NullChar); ++__i)
   1.156 +      {}
   1.157 +    return __i;
   1.158 +  }
   1.159 +
   1.160 +  static const _CharT* _STLP_CALL find(const _CharT* __s, size_t __n, const _CharT& __c) {
   1.161 +    for ( ; __n > 0 ; ++__s, --__n)
   1.162 +      if (eq(*__s, __c))
   1.163 +        return __s;
   1.164 +    return 0;
   1.165 +  }
   1.166 +
   1.167 +
   1.168 +  static _CharT* _STLP_CALL move(_CharT* __s1, const _CharT* __s2, size_t _Sz) {
   1.169 +    return (_Sz == 0 ? __s1 : (_CharT*)memmove(__s1, __s2, _Sz * sizeof(_CharT)));
   1.170 +  }
   1.171 +
   1.172 +  static _CharT* _STLP_CALL copy(_CharT* __s1, const _CharT* __s2, size_t __n) {
   1.173 +    return (__n == 0 ? __s1 :
   1.174 +	    (_CharT*)memcpy(__s1, __s2, __n * sizeof(_CharT)));
   1.175 +    }
   1.176 +
   1.177 +  static _CharT* _STLP_CALL assign(_CharT* __s, size_t __n, _CharT __c) {
   1.178 +    for (size_t __i = 0; __i < __n; ++__i)
   1.179 +      __s[__i] = __c;
   1.180 +    return __s;
   1.181 +  }
   1.182 +
   1.183 +  static int_type _STLP_CALL not_eof(const int_type& __c) {
   1.184 +    return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0);
   1.185 +  }
   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 +
   1.191 +  static int_type _STLP_CALL to_int_type(const char_type& __c) {
   1.192 +    return (int_type)__c;
   1.193 +  }
   1.194 +
   1.195 +  static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2) {
   1.196 +    return __c1 == __c2;
   1.197 +  }
   1.198 +
   1.199 +  static int_type _STLP_CALL eof() {
   1.200 +    return (int_type)-1;
   1.201 +    //    return __STATIC_CAST(int_type,-1);
   1.202 +  }
   1.203 +};
   1.204 +
   1.205 +// Generic char_traits class.  Note that this class is provided only
   1.206 +//  as a base for explicit specialization; it is unlikely to be useful
   1.207 +//  as is for any particular user-defined type.  In particular, it
   1.208 +//  *will not work* for a non-POD type.
   1.209 +
   1.210 +template <class _CharT> class char_traits
   1.211 +  : public __char_traits_base<_CharT, _CharT>
   1.212 +{};
   1.213 +
   1.214 +// Specialization for char.
   1.215 +
   1.216 +_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<char>
   1.217 +  : public __char_traits_base<char, int>
   1.218 +{
   1.219 +public:
   1.220 +  typedef char char_type;
   1.221 +  typedef int int_type;
   1.222 +#ifdef _STLP_USE_NEW_IOSTREAMS
   1.223 +  typedef streamoff off_type;
   1.224 +# ifndef _STLP_NO_MBSTATE_T
   1.225 +  typedef streampos pos_type;
   1.226 +  typedef mbstate_t state_type;
   1.227 +# endif
   1.228 +#endif /* _STLP_USE_NEW_IOSTREAMS */
   1.229 +
   1.230 +  static char _STLP_CALL to_char_type(const int& __c) {
   1.231 +    return (char)(unsigned char)__c;
   1.232 +  }
   1.233 +
   1.234 +  static int _STLP_CALL to_int_type(const char& __c) {
   1.235 +    return (unsigned char)__c;
   1.236 +  }
   1.237 +
   1.238 +  static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
   1.239 +    { return memcmp(__s1, __s2, __n); }
   1.240 +
   1.241 +  static size_t _STLP_CALL length(const char* __s) { return strlen(__s); }
   1.242 +
   1.243 +  static void _STLP_CALL assign(char& __c1, const char& __c2) { __c1 = __c2; }
   1.244 +
   1.245 +  static char* _STLP_CALL assign(char* __s, size_t __n, char __c)
   1.246 +    { memset(__s, __c, __n); return __s; }
   1.247 +};
   1.248 +
   1.249 +# if defined (_STLP_HAS_WCHAR_T)
   1.250 +// Specialization for wchar_t.
   1.251 +_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
   1.252 +  : public __char_traits_base<wchar_t, wint_t>
   1.253 +{};
   1.254 +# endif
   1.255 +
   1.256 +_STLP_END_NAMESPACE
   1.257 +
   1.258 +# else /* OWN_IOSTREAMS */
   1.259 +
   1.260 +#  include <wrap_std/iosfwd>
   1.261 +
   1.262 +# endif /* OWN_IOSTREAMS */
   1.263 +
   1.264 +#endif /* _STLP_CHAR_TRAITS_H */
   1.265 +
   1.266 +// Local Variables:
   1.267 +// mode:C++
   1.268 +// End:
   1.269 +