2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 // WARNING: This is an internal header file, included by other C++
21 // standard library headers. You should not attempt to use this header
24 #ifndef _STLP_INTERNAL_COLLATE_H
25 #define _STLP_INTERNAL_COLLATE_H
27 #ifndef _STLP_C_LOCALE_H
28 # include <stl/c_locale.h>
31 #ifndef _STLP_INTERNAL_LOCALE_H
32 # include <stl/_locale.h>
35 #ifndef _STLP_STRING_H
36 # include <stl/_string.h>
42 template <class _CharT> class collate {};
43 template <class _CharT> class collate_byname {};
47 class collate<char> : public locale::facet
49 class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
54 typedef char char_type;
55 typedef string string_type;
57 explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
59 int compare(const char* __low1, const char* __high1,
60 const char* __low2, const char* __high2) const {
61 return do_compare( __low1, __high1, __low2, __high2);
64 string_type transform(const char* __low, const char* __high) const {
65 return do_transform(__low, __high);
68 long hash(const char* __low, const char* __high) const
69 { return do_hash(__low, __high); }
71 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
72 _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId();
74 _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
78 _STLP_DECLSPEC ~collate();
80 _STLP_DECLSPEC virtual int do_compare(const char*, const char*,
81 const char*, const char*) const;
82 _STLP_DECLSPEC virtual string_type do_transform(const char*, const char*) const;
83 _STLP_DECLSPEC virtual long do_hash(const char*, const char*) const;
85 collate(const collate<char>&);
86 collate<char>& operator =(const collate<char>&);
89 # ifndef _STLP_NO_WCHAR_T
93 class collate<wchar_t> : public locale::facet
95 class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
100 typedef wchar_t char_type;
101 typedef wstring string_type;
103 explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
105 int compare(const wchar_t* __low1, const wchar_t* __high1,
106 const wchar_t* __low2, const wchar_t* __high2) const {
107 return do_compare( __low1, __high1, __low2, __high2);
110 string_type transform(const wchar_t* __low, const wchar_t* __high) const {
111 return do_transform(__low, __high);
114 long hash(const wchar_t* __low, const wchar_t* __high) const
115 { return do_hash(__low, __high); }
117 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
118 _STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId();
120 _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
124 _STLP_DECLSPEC ~collate();
126 _STLP_DECLSPEC virtual int do_compare(const wchar_t*, const wchar_t*,
127 const wchar_t*, const wchar_t*) const;
128 _STLP_DECLSPEC virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
129 _STLP_DECLSPEC virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
131 collate(const collate<wchar_t>&);
132 collate<wchar_t>& operator = (const collate<wchar_t>&);
135 # endif /* NO_WCHAR_T */
138 class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
141 explicit _STLP_DECLSPEC collate_byname(const char* __name, size_t __refs = 0);
144 _STLP_DECLSPEC ~collate_byname();
146 _STLP_DECLSPEC virtual int do_compare(const char*, const char*,
147 const char*, const char*) const;
148 _STLP_DECLSPEC virtual string_type do_transform(const char*, const char*) const;
151 _Locale_collate* _M_collate;
152 collate_byname(const collate_byname<char>&);
153 collate_byname<char>& operator =(const collate_byname<char>&);
156 # ifndef _STLP_NO_WCHAR_T
159 class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
162 explicit _STLP_DECLSPEC collate_byname(const char * __name, size_t __refs = 0);
165 _STLP_DECLSPEC ~collate_byname();
167 _STLP_DECLSPEC virtual int do_compare(const wchar_t*, const wchar_t*,
168 const wchar_t*, const wchar_t*) const;
169 _STLP_DECLSPEC virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
172 _Locale_collate* _M_collate;
173 collate_byname(const collate_byname<wchar_t>&);
174 collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
177 # endif /* NO_WCHAR_T */
180 template <class _CharT, class _Traits, class _Alloc>
182 __locale_do_operator_call (const locale* __that,
183 const basic_string<_CharT, _Traits, _Alloc >& __x,
184 const basic_string<_CharT, _Traits, _Alloc >& __y)
186 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
187 collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::GetFacetLocaleId());
189 collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::id);
192 __that->_M_throw_runtime_error();
193 return __f->compare(__x.data(), __x.data() + __x.size(),
194 __y.data(), __y.data() + __y.size()) < 0;
200 #endif /* _STLP_INTERNAL_COLLATE_H */