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