ReactOS  0.4.12-dev-90-g2e2e63e
char_traits.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1996,1997
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
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.
16  *
17  */
18 
19 #ifndef _STLP_CHAR_TRAITS_H
20 #define _STLP_CHAR_TRAITS_H
21 
22 // Define char_traits
23 
24 #ifndef _STLP_INTERNAL_CSTDDEF
25 # include <stl/_cstddef.h>
26 #endif
27 
28 #ifndef _STLP_INTERNAL_CSTRING
29 # include <stl/_cstring.h>
30 #endif
31 
32 #if defined (__unix)
33 # include <sys/types.h> // For off_t
34 #endif /* __unix */
35 
36 #if defined (__BORLANDC__)
37 # include <mem.h>
38 # include <string.h>
39 # include <_stddef.h>
40 # include <sys/types.h>
41 #endif
42 
43 #ifndef _STLP_INTERNAL_CONSTRUCT_H
44 # include <stl/_construct.h>
45 #endif
46 
47 #ifndef _STLP_INTERNAL_CWCHAR
48 # include <stl/_cwchar.h>
49 #endif
50 
52 
53 template <class _Tp> class allocator;
54 
55 #define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
56 
57 #if defined(_STLP_WCE)
58 typedef long streamoff;
59 #elif defined (_STLP_WIN32)
60 # if defined (_STLP_LONG_LONG) && !defined (__CYGWIN__)
61 //The Win32 file io API support 64 bits access so streamoff and streamsize
62 //has to reflect that. Do not change the stringbuf behavior.
64 # else
65 typedef ptrdiff_t streamoff;
66 # endif
67 #else // __unix
68 # ifdef _STLP_USE_DEFAULT_FILE_OFFSET
69 typedef off_t streamoff;
70 # elif defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE) /* || defined(__USE_FILE_OFFSET64) */ \
71  /* || (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */ /* || defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) */
72 typedef off64_t streamoff;
73 # else
74 typedef off_t streamoff;
75 # endif
76 #endif /* __unix */
77 
78 #if defined (_STLP_WIN32)
79 typedef streamoff streamsize;
80 #else
82 #endif
83 
84 // Class fpos, which represents a position within a file. (The C++
85 // standard calls for it to be defined in <ios>. This implementation
86 // moves it to <iosfwd>, which is included by <ios>.)
87 template <class _StateT> class fpos {
88 public: // From table 88 of the C++ standard.
89  fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
90  fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
91 
92  operator streamoff() const { return _M_pos; }
93 
94  bool operator==(const fpos& __y) const
95  { return _M_pos == __y._M_pos; }
96  bool operator!=(const fpos& __y) const
97  { return _M_pos != __y._M_pos; }
98 
100  _M_pos += __off;
101  return *this;
102  }
104  _M_pos -= __off;
105  return *this;
106  }
107 
109  fpos __tmp(*this);
110  __tmp += __off;
111  return __tmp;
112  }
114  fpos __tmp(*this);
115  __tmp -= __off;
116  return __tmp;
117  }
118 
119 public: // Manipulation of the state member.
120  _StateT state() const { return _M_st; }
121  void state(_StateT __st) { _M_st = __st; }
122 private:
124  _StateT _M_st;
125 };
126 
129 
130 // Class __char_traits_base.
131 template <class _CharT, class _IntT>
133 public:
134  typedef _CharT char_type;
135  typedef _IntT int_type;
139 
140  static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
141  static bool _STLP_CALL eq(const char_type& __c1, const char_type& __c2)
142  { return __c1 == __c2; }
143  static bool _STLP_CALL lt(const char_type& __c1, const char_type& __c2)
144  { return __c1 < __c2; }
145 
146  static int _STLP_CALL compare(const char_type* __s1, const char_type* __s2, size_t __n) {
147  for (size_t __i = 0; __i < __n; ++__i)
148  if (!eq(__s1[__i], __s2[__i]))
149  return __s1[__i] < __s2[__i] ? -1 : 1;
150  return 0;
151  }
152 
153  static size_t _STLP_CALL length(const char_type* __s) {
154  const char_type _NullChar = _STLP_DEFAULT_CONSTRUCTED(char_type);
155  size_t __i(0);
156  for (; !eq(__s[__i], _NullChar); ++__i) {}
157  return __i;
158  }
159 
160  static const char_type* _STLP_CALL find(const char_type* __s, size_t __n, const char_type& __c) {
161  for ( ; __n > 0 ; ++__s, --__n)
162  if (eq(*__s, __c))
163  return __s;
164  return 0;
165  }
166 
167  static char_type* _STLP_CALL move(char_type* __s1, const char_type* __s2, size_t _Sz)
168  { return (_Sz == 0 ? __s1 : (char_type*)memmove(__s1, __s2, _Sz * sizeof(char_type))); }
169 
170  static char_type* _STLP_CALL copy(char_type* __s1, const char_type* __s2, size_t __n) {
171  return (__n == 0 ? __s1 :
172  (char_type*)memcpy(__s1, __s2, __n * sizeof(char_type)));
173  }
174 
175  static char_type* _STLP_CALL assign(char_type* __s, size_t __n, char_type __c) {
176  for (size_t __i = 0; __i < __n; ++__i)
177  __s[__i] = __c;
178  return __s;
179  }
180 
181  static int_type _STLP_CALL not_eof(const int_type& __c)
182  { return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0); }
183 
184  static char_type _STLP_CALL to_char_type(const int_type& __c)
185  { return (char_type)__c; }
186 
187  static int_type _STLP_CALL to_int_type(const char_type& __c)
188  { return (int_type)__c; }
189 
190  static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2)
191  { return __c1 == __c2; }
192 
193  static int_type _STLP_CALL eof()
194  { return (int_type)-1; }
195 };
196 
197 // Generic char_traits class. Note that this class is provided only
198 // as a base for explicit specialization; it is unlikely to be useful
199 // as is for any particular user-defined type. In particular, it
200 // *will not work* for a non-POD type.
201 
202 template <class _CharT>
204  : public __char_traits_base<_CharT, _CharT> {};
205 
206 // Specialization for char.
207 
210  : public __char_traits_base<char, int>,
211  public __stlport_class<char_traits<char> > {
212 public:
213  typedef char char_type;
214  typedef int int_type;
218 
219  static char _STLP_CALL to_char_type(const int& __c)
220  { return (char)(unsigned char)__c; }
221 
222  static int _STLP_CALL to_int_type(const char& __c)
223  { return (unsigned char)__c; }
224 
225  static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
226  { return memcmp(__s1, __s2, __n); }
227 
228  static size_t _STLP_CALL length(const char* __s)
229  { return strlen(__s); }
230 
231  static void _STLP_CALL assign(char& __c1, const char& __c2)
232  { __c1 = __c2; }
233 
234  static char* _STLP_CALL assign(char* __s, size_t __n, char __c) {
235  memset(__s, __c, __n);
236  return __s;
237  }
238 };
239 
240 #if defined (_STLP_HAS_WCHAR_T)
241 // Specialization for wchar_t.
243 class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
244  : public __char_traits_base<wchar_t, wint_t> {
245 # if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && !defined (_STLP_WCHAR_HPACC_EXCLUDE)
246 public:
247 # if !defined (__BORLANDC__)
248  static wchar_t* _STLP_CALL move(wchar_t* __dest, const wchar_t* __src, size_t __n)
249  { return wmemmove(__dest, __src, __n); }
250 # endif
251 
252  static wchar_t* _STLP_CALL copy(wchar_t* __dest, const wchar_t* __src, size_t __n)
253  { return wmemcpy(__dest, __src, __n); }
254 
255 # if !defined (__DMC__) && !defined (__BORLANDC__)
256  static int _STLP_CALL compare(const wchar_t* __s1, const wchar_t* __s2, size_t __n)
257  { return wmemcmp(__s1, __s2, __n); }
258 # endif
259 
260  static wchar_t* _STLP_CALL assign(wchar_t* __s, size_t __n, wchar_t __c)
261  { return wmemset(__s, __c, __n); }
262 
263  static size_t _STLP_CALL length(const wchar_t* __s)
264  { return wcslen(__s); }
265 
266  static void _STLP_CALL assign(wchar_t& __c1, const wchar_t& __c2)
267  { __c1 = __c2; }
268 # endif
269 };
270 #endif
271 
273 
274 #endif /* _STLP_CHAR_TRAITS_H */
275 
276 // Local Variables:
277 // mode:C++
278 // End:
static int_type _STLP_CALL eof()
Definition: char_traits.h:193
off_t streamoff
Definition: char_traits.h:74
static int_type _STLP_CALL not_eof(const int_type &__c)
Definition: char_traits.h:181
void state(_StateT __st)
Definition: char_traits.h:121
bool operator!=(const fpos &__y) const
Definition: char_traits.h:96
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
fpos< mbstate_t > wstreampos
Definition: char_traits.h:128
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
return __n
Definition: _algo.h:75
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static bool _STLP_CALL eq(const char_type &__c1, const char_type &__c2)
Definition: char_traits.h:141
_StateT _M_st
Definition: char_traits.h:124
static char_type *_STLP_CALL move(char_type *__s1, const char_type *__s2, size_t _Sz)
Definition: char_traits.h:167
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
__kernel_off_t off_t
Definition: linux.h:201
mbstate_t state_type
Definition: char_traits.h:217
fpos()
Definition: char_traits.h:90
static bool _STLP_CALL lt(const char_type &__c1, const char_type &__c2)
Definition: char_traits.h:143
#define eq(received, expected, label, type)
Definition: locale.c:144
static int _STLP_CALL to_int_type(const char &__c)
Definition: char_traits.h:222
#define __c
Definition: schilyio.h:209
static void _STLP_CALL assign(char_type &__c1, const char_type &__c2)
Definition: char_traits.h:140
mbstate_t state_type
Definition: char_traits.h:138
static void _STLP_CALL assign(char &__c1, const char &__c2)
Definition: char_traits.h:231
static char_type *_STLP_CALL copy(char_type *__s1, const char_type *__s2, size_t __n)
Definition: char_traits.h:170
static char *_STLP_CALL assign(char *__s, size_t __n, char __c)
Definition: char_traits.h:234
#define _STLP_DEFAULT_CONSTRUCTED(_TTp)
Definition: _construct.h:265
unsigned char
Definition: typeof.h:27
#define _STLP_LONG_LONG
Definition: _apcc.h:12
__MINGW_EXTENSION typedef long long off64_t
Definition: stdio.h:92
_StateT state() const
Definition: char_traits.h:120
static char_type _STLP_CALL to_char_type(const int_type &__c)
Definition: char_traits.h:184
fpos & operator-=(streamoff __off)
Definition: char_traits.h:103
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static size_t _STLP_CALL length(const char_type *__s)
Definition: char_traits.h:153
wchar_t *__cdecl wmemset(_Out_writes_all_(_N) wchar_t *_S, _In_ wchar_t _C, _In_ size_t _N)
Definition: wchar.h:2593
streamoff _M_pos
Definition: char_traits.h:123
static int _STLP_CALL compare(const char_type *__s1, const char_type *__s2, size_t __n)
Definition: char_traits.h:146
streamoff off_type
Definition: char_traits.h:136
static size_t _STLP_CALL length(const char *__s)
Definition: char_traits.h:228
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
bool operator==(const fpos &__y) const
Definition: char_traits.h:94
fpos(streamoff __pos)
Definition: char_traits.h:89
#define _STLP_CLASS_DECLSPEC
Definition: features.h:983
#define _STLP_TEMPLATE_NULL
Definition: features.h:652
static int_type _STLP_CALL to_int_type(const char_type &__c)
Definition: char_traits.h:187
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
#define _STLP_NULL_CHAR_INIT(_ChT)
Definition: char_traits.h:55
streampos pos_type
Definition: char_traits.h:137
static bool _STLP_CALL eq_int_type(const int_type &__c1, const int_type &__c2)
Definition: char_traits.h:190
#define _STLP_END_NAMESPACE
Definition: features.h:503
fpos operator-(streamoff __off)
Definition: char_traits.h:113
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
int __cdecl wmemcmp(_In_reads_(_N) const wchar_t *_S1, _In_reads_(_N) const wchar_t *_S2, _In_ size_t _N)
Definition: wchar.h:2551
static const char_type *_STLP_CALL find(const char_type *__s, size_t __n, const char_type &__c)
Definition: char_traits.h:160
static int _STLP_CALL compare(const char *__s1, const char *__s2, size_t __n)
Definition: char_traits.h:225
#define compare
ptrdiff_t streamsize
Definition: char_traits.h:81
fpos< mbstate_t > streampos
Definition: char_traits.h:127
fpos & operator+=(streamoff __off)
Definition: char_traits.h:99
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
fpos operator+(streamoff __off)
Definition: char_traits.h:108
#define memset(x, y, z)
Definition: compat.h:39
#define _STLP_CALL
Definition: _bc.h:131
static char_type *_STLP_CALL assign(char_type *__s, size_t __n, char_type __c)
Definition: char_traits.h:175
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
wchar_t *__cdecl wmemmove(_Out_writes_all_opt_(_N) wchar_t *_S1, _In_reads_opt_(_N) const wchar_t *_S2, _In_ size_t _N)
Definition: wchar.h:2582
static char _STLP_CALL to_char_type(const int &__c)
Definition: char_traits.h:219