ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

char_traits.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1996,1997
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 #ifndef _STLP_CHAR_TRAITS_H
00020 #define _STLP_CHAR_TRAITS_H
00021 
00022 // Define char_traits
00023 
00024 #ifndef _STLP_INTERNAL_CSTDDEF
00025 #  include <stl/_cstddef.h>
00026 #endif
00027 
00028 #ifndef _STLP_INTERNAL_CSTRING
00029 #  include <stl/_cstring.h>
00030 #endif
00031 
00032 #if defined (__unix)
00033 #  include <sys/types.h>         // For off_t
00034 #endif /* __unix */
00035 
00036 #if defined (__BORLANDC__)
00037 #  include <mem.h>
00038 #  include <string.h>
00039 #  include <_stddef.h>
00040 #  include <sys/types.h>
00041 #endif
00042 
00043 #ifndef _STLP_INTERNAL_CONSTRUCT_H
00044 #  include <stl/_construct.h>
00045 #endif
00046 
00047 #ifndef _STLP_INTERNAL_CWCHAR
00048 #  include <stl/_cwchar.h>
00049 #endif
00050 
00051 _STLP_BEGIN_NAMESPACE
00052 
00053 template <class _Tp> class allocator;
00054 
00055 #define _STLP_NULL_CHAR_INIT(_ChT) _STLP_DEFAULT_CONSTRUCTED(_ChT)
00056 
00057 #if defined(_STLP_WCE)
00058 typedef long streamoff;
00059 #elif defined (_STLP_WIN32)
00060 #  if defined (_STLP_LONG_LONG) && !defined (__CYGWIN__)
00061 //The Win32 file io API support 64 bits access so streamoff and streamsize
00062 //has to reflect that. Do not change the stringbuf behavior.
00063 typedef _STLP_LONG_LONG streamoff;
00064 #  else
00065 typedef ptrdiff_t streamoff;
00066 #  endif
00067 #else // __unix
00068 #  ifdef _STLP_USE_DEFAULT_FILE_OFFSET
00069 typedef off_t streamoff;
00070 #  elif defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE) /* || defined(__USE_FILE_OFFSET64) */ \
00071        /* || (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */ /* || defined (__sgi) && defined (_STLP_HAS_NO_NEW_C_HEADERS) */
00072 typedef off64_t streamoff;
00073 #  else
00074 typedef off_t streamoff;
00075 #  endif
00076 #endif /* __unix */
00077 
00078 #if defined (_STLP_WIN32)
00079 typedef streamoff streamsize;
00080 #else
00081 typedef ptrdiff_t streamsize;
00082 #endif
00083 
00084 // Class fpos, which represents a position within a file.  (The C++
00085 // standard calls for it to be defined in <ios>.  This implementation
00086 // moves it to <iosfwd>, which is included by <ios>.)
00087 template <class _StateT> class fpos {
00088 public:                         // From table 88 of the C++ standard.
00089   fpos(streamoff __pos) : _M_pos(__pos), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
00090   fpos() : _M_pos(0), _M_st(_STLP_NULL_CHAR_INIT(_StateT)) {}
00091 
00092   operator streamoff() const { return _M_pos; }
00093 
00094   bool operator==(const fpos& __y) const
00095   { return _M_pos == __y._M_pos; }
00096   bool operator!=(const fpos& __y) const
00097   { return _M_pos != __y._M_pos; }
00098 
00099   fpos& operator+=(streamoff __off) {
00100     _M_pos += __off;
00101     return *this;
00102   }
00103   fpos& operator-=(streamoff __off) {
00104     _M_pos -= __off;
00105     return *this;
00106   }
00107 
00108   fpos operator+(streamoff __off) {
00109     fpos __tmp(*this);
00110     __tmp += __off;
00111     return __tmp;
00112   }
00113   fpos operator-(streamoff __off) {
00114     fpos __tmp(*this);
00115     __tmp -= __off;
00116     return __tmp;
00117   }
00118 
00119 public:                         // Manipulation of the state member.
00120   _StateT state() const { return _M_st; }
00121   void state(_StateT __st) { _M_st = __st; }
00122 private:
00123   streamoff _M_pos;
00124   _StateT _M_st;
00125 };
00126 
00127 typedef fpos<mbstate_t> streampos;
00128 typedef fpos<mbstate_t> wstreampos;
00129 
00130 // Class __char_traits_base.
00131 template <class _CharT, class _IntT>
00132 class __char_traits_base {
00133 public:
00134   typedef _CharT char_type;
00135   typedef _IntT int_type;
00136   typedef streamoff off_type;
00137   typedef streampos pos_type;
00138   typedef mbstate_t state_type;
00139 
00140   static void _STLP_CALL assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
00141   static bool _STLP_CALL eq(const char_type& __c1, const char_type& __c2)
00142   { return __c1 == __c2; }
00143   static bool _STLP_CALL lt(const char_type& __c1, const char_type& __c2)
00144   { return __c1 < __c2; }
00145 
00146   static int _STLP_CALL compare(const char_type* __s1, const char_type* __s2, size_t __n) {
00147     for (size_t __i = 0; __i < __n; ++__i)
00148       if (!eq(__s1[__i], __s2[__i]))
00149         return __s1[__i] < __s2[__i] ? -1 : 1;
00150     return 0;
00151   }
00152 
00153   static size_t _STLP_CALL length(const char_type* __s) {
00154     const char_type _NullChar = _STLP_DEFAULT_CONSTRUCTED(char_type);
00155     size_t __i(0);
00156     for (; !eq(__s[__i], _NullChar); ++__i) {}
00157     return __i;
00158   }
00159 
00160   static const char_type* _STLP_CALL find(const char_type* __s, size_t __n, const char_type& __c) {
00161     for ( ; __n > 0 ; ++__s, --__n)
00162       if (eq(*__s, __c))
00163         return __s;
00164     return 0;
00165   }
00166 
00167   static char_type* _STLP_CALL move(char_type* __s1, const char_type* __s2, size_t _Sz)
00168   { return (_Sz == 0 ? __s1 : (char_type*)memmove(__s1, __s2, _Sz * sizeof(char_type))); }
00169 
00170   static char_type* _STLP_CALL copy(char_type* __s1, const char_type* __s2, size_t __n) {
00171     return (__n == 0 ? __s1 :
00172       (char_type*)memcpy(__s1, __s2, __n * sizeof(char_type)));
00173   }
00174 
00175   static char_type* _STLP_CALL assign(char_type* __s, size_t __n, char_type __c) {
00176     for (size_t __i = 0; __i < __n; ++__i)
00177       __s[__i] = __c;
00178     return __s;
00179   }
00180 
00181   static int_type _STLP_CALL not_eof(const int_type& __c)
00182   { return !eq_int_type(__c, eof()) ? __c : __STATIC_CAST(int_type, 0); }
00183 
00184   static char_type _STLP_CALL to_char_type(const int_type& __c)
00185   { return (char_type)__c; }
00186 
00187   static int_type _STLP_CALL to_int_type(const char_type& __c)
00188   { return (int_type)__c; }
00189 
00190   static bool _STLP_CALL eq_int_type(const int_type& __c1, const int_type& __c2)
00191   { return __c1 == __c2; }
00192 
00193   static int_type _STLP_CALL eof()
00194   { return (int_type)-1; }
00195 };
00196 
00197 // Generic char_traits class.  Note that this class is provided only
00198 //  as a base for explicit specialization; it is unlikely to be useful
00199 //  as is for any particular user-defined type.  In particular, it
00200 //  *will not work* for a non-POD type.
00201 
00202 template <class _CharT>
00203 class char_traits
00204   : public __char_traits_base<_CharT, _CharT> {};
00205 
00206 // Specialization for char.
00207 
00208 _STLP_TEMPLATE_NULL
00209 class _STLP_CLASS_DECLSPEC char_traits<char>
00210   : public __char_traits_base<char, int>,
00211     public __stlport_class<char_traits<char> > {
00212 public:
00213   typedef char char_type;
00214   typedef int int_type;
00215   typedef streamoff off_type;
00216   typedef streampos pos_type;
00217   typedef mbstate_t state_type;
00218 
00219   static char _STLP_CALL to_char_type(const int& __c)
00220   { return (char)(unsigned char)__c; }
00221 
00222   static int _STLP_CALL to_int_type(const char& __c)
00223   { return (unsigned char)__c; }
00224 
00225   static int _STLP_CALL compare(const char* __s1, const char* __s2, size_t __n)
00226   { return memcmp(__s1, __s2, __n); }
00227 
00228   static size_t _STLP_CALL length(const char* __s)
00229   { return strlen(__s); }
00230 
00231   static void _STLP_CALL assign(char& __c1, const char& __c2)
00232   { __c1 = __c2; }
00233 
00234   static char* _STLP_CALL assign(char* __s, size_t __n, char __c) {
00235     memset(__s, __c, __n);
00236     return __s;
00237   }
00238 };
00239 
00240 #if defined (_STLP_HAS_WCHAR_T)
00241 // Specialization for wchar_t.
00242 _STLP_TEMPLATE_NULL
00243 class _STLP_CLASS_DECLSPEC char_traits<wchar_t>
00244   : public __char_traits_base<wchar_t, wint_t> {
00245 #  if !defined (_STLP_NO_NATIVE_WIDE_FUNCTIONS) && !defined (_STLP_WCHAR_HPACC_EXCLUDE)
00246 public:
00247 #    if !defined (__BORLANDC__)
00248   static wchar_t* _STLP_CALL move(wchar_t* __dest, const wchar_t* __src, size_t __n)
00249   { return wmemmove(__dest, __src, __n); }
00250 #    endif
00251 
00252   static wchar_t* _STLP_CALL copy(wchar_t* __dest, const wchar_t* __src, size_t __n)
00253   { return wmemcpy(__dest, __src, __n); }
00254 
00255 #    if !defined (__DMC__) && !defined (__BORLANDC__)
00256   static int _STLP_CALL compare(const wchar_t* __s1, const wchar_t* __s2, size_t __n)
00257   { return wmemcmp(__s1, __s2, __n); }
00258 #    endif
00259 
00260   static wchar_t* _STLP_CALL assign(wchar_t* __s, size_t __n, wchar_t __c)
00261   { return wmemset(__s, __c, __n); }
00262 
00263   static size_t _STLP_CALL length(const wchar_t* __s)
00264   { return wcslen(__s); }
00265 
00266   static void _STLP_CALL assign(wchar_t& __c1, const wchar_t& __c2)
00267   { __c1 = __c2; }
00268 #  endif
00269 };
00270 #endif
00271 
00272 _STLP_END_NAMESPACE
00273 
00274 #endif /* _STLP_CHAR_TRAITS_H */
00275 
00276 // Local Variables:
00277 // mode:C++
00278 // End:

Generated on Sat May 26 2012 04:28:23 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.