]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_collate.h
minor doc updates
[polintos/scott/priv.git] / include / c++ / stl / stl / _collate.h
1 /*
2  * Copyright (c) 1999
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 // WARNING: This is an internal header file, included by other C++
19 // standard library headers.  You should not attempt to use this header
20 // file directly.
21
22 #ifndef _STLP_INTERNAL_COLLATE_H
23 #define _STLP_INTERNAL_COLLATE_H
24
25 #ifndef _STLP_C_LOCALE_H
26 # include <stl/c_locale.h>
27 #endif
28
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 # include <stl/_locale.h>
31 #endif
32
33 #ifndef _STLP_INTERNAL_STRING_H
34 # include <stl/_string.h>
35 #endif
36
37 _STLP_BEGIN_NAMESPACE
38
39 template <class _CharT> class collate {};
40 template <class _CharT> class collate_byname {};
41
42 _STLP_TEMPLATE_NULL
43 class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
44 {
45   friend class _Locale_impl;
46
47 public:
48   typedef char   char_type;
49   typedef string string_type;
50
51   explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
52
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);
56   }
57
58   string_type transform(const char* __low, const char* __high) const {
59     return do_transform(__low, __high);
60   }
61
62   long hash(const char* __low, const char* __high) const
63     { return do_hash(__low, __high); }
64
65   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
66
67 protected:
68   ~collate();
69
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;
74 private:
75   collate(const collate<char>&);
76   collate<char>& operator =(const collate<char>&);
77 };
78
79 # ifndef _STLP_NO_WCHAR_T
80
81 _STLP_TEMPLATE_NULL
82 class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
83 {
84   friend class _Locale_impl;
85
86 public:
87   typedef wchar_t char_type;
88   typedef wstring string_type;
89
90   explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
91
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);
95   }
96
97   string_type transform(const wchar_t* __low, const wchar_t* __high) const {
98     return do_transform(__low, __high);
99   }
100
101   long hash(const wchar_t* __low, const wchar_t* __high) const
102     { return do_hash(__low, __high); }
103
104   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
105
106 protected:
107   ~collate();
108
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;
113 private:
114   collate(const collate<wchar_t>&);
115   collate<wchar_t>& operator = (const collate<wchar_t>&);
116 };
117
118 # endif /* NO_WCHAR_T */
119
120 _STLP_TEMPLATE_NULL
121 class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
122 {
123 public:
124   explicit collate_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
125
126 protected:
127   ~collate_byname();
128
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;
132
133 private:
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>*);
138 };
139
140 # ifndef _STLP_NO_WCHAR_T
141
142 _STLP_TEMPLATE_NULL
143 class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
144 {
145 public:
146   explicit collate_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
147
148 protected:
149   ~collate_byname();
150
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;
154
155 private:
156   _Locale_collate* _M_collate;
157   collate_byname(const collate_byname<wchar_t>&);
158   collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
159 };
160
161 # endif /* NO_WCHAR_T */
162
163 template <class _CharT, class _Traits, class _Alloc>
164 bool
165 __locale_do_operator_call (const locale& __loc,
166                            const basic_string<_CharT, _Traits, _Alloc>& __x,
167                            const basic_string<_CharT, _Traits, _Alloc>& __y) {
168   collate<_CharT> const& __coll = use_facet<collate<_CharT> >(__loc);
169   return __coll.compare(__x.data(), __x.data() + __x.size(),
170                         __y.data(), __y.data() + __y.size()) < 0;
171 }
172
173 _STLP_END_NAMESPACE
174
175 #endif /* _STLP_INTERNAL_COLLATE_H */
176
177 // Local Variables:
178 // mode:C++
179 // End: