2
* Copyright (c) 1996,1997
3
* Silicon Graphics Computer Systems, Inc.
8
* This material is provided "as is", with absolutely no warranty expressed
9
* or implied. Any use is at your own risk.
11
* Permission to use or copy this software for any purpose is hereby granted
12
* without fee, provided the above notices are retained on all copies.
13
* Permission to modify the code and to distribute modified code is granted,
14
* provided the above notices are retained, and a notice that the code was
15
* modified is included with the above copyright notice.
19
#ifndef _STLP_CHAR_TRAITS_H
20
#define _STLP_CHAR_TRAITS_H
24
# if defined (_STLP_OWN_IOSTREAMS) || ! defined (_STLP_USE_NEW_IOSTREAMS)
26
# if ! defined (_STLP_CSTDDEF)
30
#if ! defined (_STLP_CSTRING)
34
#if defined (_STLP_UNIX) && defined (_STLP_HAS_NO_NEW_C_HEADERS)
35
#include <sys/types.h> // For off_t
45
#ifndef __TYPE_TRAITS_H
46
# include <stl/type_traits.h>
49
# if !defined (_STLP_CWCHAR)
50
# include <stl/_cwchar.h>
55
# ifdef _STLP_OWN_IOSTREAMS
57
template <class _Tp> class allocator;
59
#define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
61
#if defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* IRIX */
62
typedef off64_t streamoff;
63
// #elif defined (__unix) && defined (_STLP_HAS_NO_NEW_C_HEADERS) /* Other version of UNIX */
64
// typedef off_t streamoff;
66
// boris : here, it's not ptrdiff_t as some Solaris systems have confusing definitions of these.
67
typedef long streamoff;
68
#endif /* _STLP_HAS_NO_NEW_C_HEADERS */
70
typedef ptrdiff_t streamsize;
72
// Class fpos, which represents a position within a file. (The C++
73
// standard calls for it to be defined in <ios>. This implementation
74
// moves it to <iosfwd>, which is included by <ios>.)
75
template <class _StateT> class fpos
77
public: // From table 88 of the C++ standard.
78
fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
79
fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
81
operator streamoff() const { return _M_pos; }
83
bool _STLP_CALL operator==(const fpos<_StateT>& __y) const
84
{ return _M_pos == __y._M_pos; }
85
bool _STLP_CALL operator!=(const fpos<_StateT>& __y) const
86
{ return _M_pos != __y._M_pos; }
88
fpos<_StateT>& operator+=(streamoff __off) {
92
fpos<_StateT>& operator-=(streamoff __off) {
97
fpos<_StateT> operator+(streamoff __off) {
98
fpos<_StateT> __tmp(*this);
102
fpos<_StateT> operator-(streamoff __off) {
103
fpos<_StateT> __tmp(*this);
108
public: // Manipulation of the state member.
109
_StateT state() const { return _M_st; }
110
void state(_StateT __st) { _M_st = __st; }
116
typedef fpos<mbstate_t> streampos;
117
typedef fpos<mbstate_t> wstreampos;
120
// Class __char_traits_base.
122
template <class _CharT, class _IntT> class __char_traits_base {
124
typedef _CharT char_type;
125
typedef _IntT int_type;
126
#ifdef _STLP_USE_NEW_IOSTREAMS
127
typedef streamoff off_type;
128
typedef streampos pos_type;
129
# ifdef _STLP_NO_MBSTATE_T
130
typedef char state_type;
132
typedef mbstate_t state_type;
134
#endif /* _STLP_USE_NEW_IOSTREAMS */
136
static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
137
static bool _STLP_CALL eq(const _CharT& __c1, const _CharT& __c2)
138
{ return __c1 == __c2; }
139
static bool _STLP_CALL lt(const _CharT& __c1, const _CharT& __c2)
140
{ return __c1 < __c2; }
142
static int _STLP_CALL compare(const _CharT* __s1, const _CharT* __s2, size_t __n) {
143
for (size_t __i = 0; __i < __n; ++__i)
144
if (!eq(__s1[__i], __s2[__i]))
145
return __s1[__i] < __s2[__i] ? -1 : 1;
149
static size_t _STLP_CALL length(const _CharT* __s) {
150
const _CharT _NullChar = _STLP_DEFAULT_CONSTRUCTED(_CharT);
152
for (__i = 0; !eq(__s[__i], _NullChar); ++__i)
157
static const _CharT* _STLP_CALL find(const _CharT* __s, size_t __n, const _CharT& __c) {
158
for ( ; __n > 0 ; ++__s, --__n)
165
static _CharT* _STLP_CALL move(_CharT* __s1, const _CharT* __s2, size_t _Sz) {
166
return (_Sz == 0 ? __s1 : (_CharT*)memmove(__s1, __s2, _Sz * sizeof(_CharT)));
169
static _CharT* _STLP_CALL copy(_CharT* __s1, const _CharT* __s2, size_t __n) {
170
return (__n == 0 ? __s1 :
171
(_CharT*)memcpy(__s1, __s2, __n * sizeof(_CharT)));
174
static _CharT* _STLP_CALL assign(_CharT* __s, size_t __n, _CharT __c) {
175
for (size_t __i = 0; __i < __n; ++__i)
180
static int_type _STLP_CALL not_eof(const int_type& __c) {
181
return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0);
184
static char_type _STLP_CALL to_char_type(const int_type& __c) {
185
return (char_type)__c;
188
static int_type _STLP_CALL to_int_type(const char_type& __c) {
189
return (int_type)__c;
192
static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2) {
196
static int_type _STLP_CALL eof() {
198
// return __STATIC_CAST(int_type,-1);
202
// Generic char_traits class. Note that this class is provided only
203
// as a base for explicit specialization; it is unlikely to be useful
204
// as is for any particular user-defined type. In particular, it
205
// *will not work* for a non-POD type.
207
template <class _CharT> class char_traits
208
: public __char_traits_base<_CharT, _CharT>
211
// Specialization for char.
213
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<char>
214
: public __char_traits_base<char, int>
217
typedef char char_type;
218
typedef int int_type;
219
#ifdef _STLP_USE_NEW_IOSTREAMS
220
typedef streamoff off_type;
221
# ifndef _STLP_NO_MBSTATE_T
222
typedef streampos pos_type;
223
typedef mbstate_t state_type;
225
#endif /* _STLP_USE_NEW_IOSTREAMS */
227
static char _STLP_CALL to_char_type(const int& __c) {
228
return (char)(unsigned char)__c;
231
static int _STLP_CALL to_int_type(const char& __c) {
232
return (unsigned char)__c;
235
static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
236
{ return memcmp(__s1, __s2, __n); }
238
static size_t _STLP_CALL length(const char* __s) { return strlen(__s); }
240
static void _STLP_CALL assign(char& __c1, const char& __c2) { __c1 = __c2; }
242
static char* _STLP_CALL assign(char* __s, size_t __n, char __c)
243
{ memset(__s, __c, __n); return __s; }
246
# if defined (_STLP_HAS_WCHAR_T)
247
// Specialization for wchar_t.
248
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
249
: public __char_traits_base<wchar_t, wint_t>
255
# else /* OWN_IOSTREAMS */
257
# include <wrap_std/iosfwd>
259
# endif /* OWN_IOSTREAMS */
261
#endif /* _STLP_CHAR_TRAITS_H */