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.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
22 #ifndef _STLP_INTERNAL_COLLATE_H
23 #define _STLP_INTERNAL_COLLATE_H
25 #ifndef _STLP_C_LOCALE_H
26 # include <stl/c_locale.h>
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 # include <stl/_locale.h>
33 #ifndef _STLP_INTERNAL_STRING_H
34 # include <stl/_string.h>
39 template <class _CharT> class collate {};
40 template <class _CharT> class collate_byname {};
43 class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
45 friend class _Locale_impl;
48 typedef char char_type;
49 typedef string string_type;
51 explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
53 int compare(const char* __low1, const char* __high1,
54 const char* __low2, const char* __high2) const {
55 return do_compare( __low1, __high1, __low2, __high2);
58 string_type transform(const char* __low, const char* __high) const {
59 return do_transform(__low, __high);
62 long hash(const char* __low, const char* __high) const
63 { return do_hash(__low, __high); }
65 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
70 virtual int do_compare(const char*, const char*,
71 const char*, const char*) const;
72 virtual string_type do_transform(const char*, const char*) const;
73 virtual long do_hash(const char*, const char*) const;
75 collate(const collate<char>&);
76 collate<char>& operator =(const collate<char>&);
79 # ifndef _STLP_NO_WCHAR_T
82 class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
84 friend class _Locale_impl;
87 typedef wchar_t char_type;
88 typedef wstring string_type;
90 explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
92 int compare(const wchar_t* __low1, const wchar_t* __high1,
93 const wchar_t* __low2, const wchar_t* __high2) const {
94 return do_compare( __low1, __high1, __low2, __high2);
97 string_type transform(const wchar_t* __low, const wchar_t* __high) const {
98 return do_transform(__low, __high);
101 long hash(const wchar_t* __low, const wchar_t* __high) const
102 { return do_hash(__low, __high); }
104 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
109 virtual int do_compare(const wchar_t*, const wchar_t*,
110 const wchar_t*, const wchar_t*) const;
111 virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
112 virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
114 collate(const collate<wchar_t>&);
115 collate<wchar_t>& operator = (const collate<wchar_t>&);
118 # endif /* NO_WCHAR_T */
121 class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
124 explicit collate_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
129 virtual int do_compare(const char*, const char*,
130 const char*, const char*) const;
131 virtual string_type do_transform(const char*, const char*) const;
134 _Locale_collate* _M_collate;
135 collate_byname(const collate_byname<char>&);
136 collate_byname<char>& operator =(const collate_byname<char>&);
137 friend _Locale_name_hint* _Locale_extract_hint(collate_byname<char>*);
140 # ifndef _STLP_NO_WCHAR_T
143 class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
146 explicit collate_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
151 virtual int do_compare(const wchar_t*, const wchar_t*,
152 const wchar_t*, const wchar_t*) const;
153 virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
156 _Locale_collate* _M_collate;
157 collate_byname(const collate_byname<wchar_t>&);
158 collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
161 # endif /* NO_WCHAR_T */
163 #if defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
164 # define locale _STLP_NO_MEM_T_NAME(loc)
167 template <class _CharT, class _Traits, class _Alloc>
169 __locale_do_operator_call (const locale* __that,
170 const basic_string<_CharT, _Traits, _Alloc>& __x,
171 const basic_string<_CharT, _Traits, _Alloc>& __y)
173 collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::id);
175 __that->_M_throw_runtime_error();
176 return __f->compare(__x.data(), __x.data() + __x.size(),
177 __y.data(), __y.data() + __y.size()) < 0;
179 #if defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
185 #endif /* _STLP_INTERNAL_COLLATE_H */