00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _STLP_INTERNAL_COLLATE_H
00023 #define _STLP_INTERNAL_COLLATE_H
00024
00025 #ifndef _STLP_C_LOCALE_H
00026 # include <stl/c_locale.h>
00027 #endif
00028
00029 #ifndef _STLP_INTERNAL_LOCALE_H
00030 # include <stl/_locale.h>
00031 #endif
00032
00033 #ifndef _STLP_STRING_H
00034 # include <stl/_string.h>
00035 #endif
00036
00037 _STLP_BEGIN_NAMESPACE
00038
00039
00040 template <class _CharT> class collate {};
00041 template <class _CharT> class collate_byname {};
00042
00043 _STLP_TEMPLATE_NULL
00044 class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
00045 {
00046 friend class _Locale;
00047 public:
00048 typedef char char_type;
00049 typedef string string_type;
00050
00051 explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
00052
00053 int compare(const char* __low1, const char* __high1,
00054 const char* __low2, const char* __high2) const {
00055 return do_compare( __low1, __high1, __low2, __high2);
00056 }
00057
00058 string_type transform(const char* __low, const char* __high) const {
00059 return do_transform(__low, __high);
00060 }
00061
00062 long hash(const char* __low, const char* __high) const
00063 { return do_hash(__low, __high); }
00064
00065 _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
00066
00067 protected:
00068 ~collate();
00069
00070 virtual int do_compare(const char*, const char*,
00071 const char*, const char*) const;
00072 virtual string_type do_transform(const char*, const char*) const;
00073 virtual long do_hash(const char*, const char*) const;
00074 private:
00075 collate(const collate<char>&);
00076 collate<char>& operator =(const collate<char>&);
00077 };
00078
00079 # ifndef _STLP_NO_WCHAR_T
00080
00081 _STLP_TEMPLATE_NULL
00082 class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
00083 {
00084 friend class _Locale;
00085 public:
00086 typedef wchar_t char_type;
00087 typedef wstring string_type;
00088
00089 explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
00090
00091 int compare(const wchar_t* __low1, const wchar_t* __high1,
00092 const wchar_t* __low2, const wchar_t* __high2) const {
00093 return do_compare( __low1, __high1, __low2, __high2);
00094 }
00095
00096 string_type transform(const wchar_t* __low, const wchar_t* __high) const {
00097 return do_transform(__low, __high);
00098 }
00099
00100 long hash(const wchar_t* __low, const wchar_t* __high) const
00101 { return do_hash(__low, __high); }
00102
00103 _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
00104
00105 protected:
00106 ~collate();
00107
00108 virtual int do_compare(const wchar_t*, const wchar_t*,
00109 const wchar_t*, const wchar_t*) const;
00110 virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
00111 virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
00112 private:
00113 collate(const collate<wchar_t>&);
00114 collate<wchar_t>& operator = (const collate<wchar_t>&);
00115 };
00116
00117 # endif
00118
00119 _STLP_TEMPLATE_NULL
00120 class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
00121 {
00122 public:
00123 explicit collate_byname(const char* __name, size_t __refs = 0);
00124
00125 protected:
00126 ~collate_byname();
00127
00128 virtual int do_compare(const char*, const char*,
00129 const char*, const char*) const;
00130 virtual string_type do_transform(const char*, const char*) const;
00131
00132 private:
00133 _Locale_collate* _M_collate;
00134 collate_byname(const collate_byname<char>&);
00135 collate_byname<char>& operator =(const collate_byname<char>&);
00136 };
00137
00138 # ifndef _STLP_NO_WCHAR_T
00139
00140 _STLP_TEMPLATE_NULL
00141 class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
00142 {
00143 public:
00144 explicit collate_byname(const char * __name, size_t __refs = 0);
00145
00146 protected:
00147 ~collate_byname();
00148
00149 virtual int do_compare(const wchar_t*, const wchar_t*,
00150 const wchar_t*, const wchar_t*) const;
00151 virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
00152
00153 private:
00154 _Locale_collate* _M_collate;
00155 collate_byname(const collate_byname<wchar_t>&);
00156 collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
00157 };
00158
00159 # endif
00160
00161
00162 template <class _CharT>
00163 bool
00164 __locale_do_operator_call (const locale* __that,
00165 const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __x,
00166 const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __y)
00167 {
00168 collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::id);
00169 if (!__f)
00170 __that->_M_throw_runtime_error();
00171 return __f->compare(__x.data(), __x.data() + __x.size(),
00172 __y.data(), __y.data() + __y.size());
00173
00174 }
00175
00176 _STLP_END_NAMESPACE
00177
00178 #endif
00179
00180
00181
00182