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
39template <class _CharT> class collate {};
40template <class _CharT> class collate_byname {};
41
42_STLP_TEMPLATE_NULL
43class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet {
44public:
45  typedef char   char_type;
46  typedef string string_type;
47
48  explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
49
50  int compare(const char* __low1, const char* __high1,
51              const char* __low2, const char* __high2) const {
52    return do_compare( __low1, __high1, __low2, __high2);
53  }
54
55  string_type transform(const char* __low, const char* __high) const {
56    return do_transform(__low, __high);
57  }
58
59  long hash(const char* __low, const char* __high) const
60    { return do_hash(__low, __high); }
61
62  static _STLP_STATIC_DECLSPEC locale::id id;
63
64protected:
65  ~collate();
66
67  virtual int do_compare(const char*, const char*,
68                         const char*, const char*) const;
69  virtual string_type do_transform(const char*, const char*) const;
70  virtual long do_hash(const char*, const char*) const;
71private:
72  collate(const collate<char>&);
73  collate<char>& operator =(const collate<char>&);
74};
75
76# ifndef _STLP_NO_WCHAR_T
77
78_STLP_TEMPLATE_NULL
79class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet {
80public:
81  typedef wchar_t char_type;
82  typedef wstring string_type;
83
84  explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
85
86  int compare(const wchar_t* __low1, const wchar_t* __high1,
87              const wchar_t* __low2, const wchar_t* __high2) const {
88    return do_compare( __low1, __high1, __low2, __high2);
89  }
90
91  string_type transform(const wchar_t* __low, const wchar_t* __high) const {
92    return do_transform(__low, __high);
93  }
94
95  long hash(const wchar_t* __low, const wchar_t* __high) const
96    { return do_hash(__low, __high); }
97
98  static _STLP_STATIC_DECLSPEC locale::id id;
99
100protected:
101  ~collate();
102
103  virtual int do_compare(const wchar_t*, const wchar_t*,
104                         const wchar_t*, const wchar_t*) const;
105  virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
106  virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
107private:
108  collate(const collate<wchar_t>&);
109  collate<wchar_t>& operator = (const collate<wchar_t>&);
110};
111
112# endif /* NO_WCHAR_T */
113
114_STLP_TEMPLATE_NULL
115class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char> {
116  friend class _Locale_impl;
117public:
118  explicit collate_byname(const char* __name, size_t __refs = 0);
119
120protected:
121  ~collate_byname();
122
123  virtual int do_compare(const char*, const char*,
124                         const char*, const char*) const;
125  virtual string_type do_transform(const char*, const char*) const;
126
127private:
128  collate_byname(_Locale_collate *__coll)
129    : _M_collate(__coll) {}
130  _Locale_collate* _M_collate;
131  collate_byname(const collate_byname<char>&);
132  collate_byname<char>& operator =(const collate_byname<char>&);
133};
134
135# ifndef _STLP_NO_WCHAR_T
136
137_STLP_TEMPLATE_NULL
138class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t> {
139  friend class _Locale_impl;
140public:
141  explicit collate_byname(const char * __name, size_t __refs = 0);
142
143protected:
144  ~collate_byname();
145
146  virtual int do_compare(const wchar_t*, const wchar_t*,
147                         const wchar_t*, const wchar_t*) const;
148  virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
149
150private:
151  collate_byname(_Locale_collate *__coll)
152    : _M_collate(__coll) {}
153  _Locale_collate* _M_collate;
154  collate_byname(const collate_byname<wchar_t>&);
155  collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
156};
157
158# endif /* NO_WCHAR_T */
159
160template <class _CharT, class _Traits, class _Alloc>
161bool
162__locale_do_operator_call (const locale& __loc,
163                           const basic_string<_CharT, _Traits, _Alloc>& __x,
164                           const basic_string<_CharT, _Traits, _Alloc>& __y) {
165  collate<_CharT> const& __coll = use_facet<collate<_CharT> >(__loc);
166  return __coll.compare(__x.data(), __x.data() + __x.size(),
167                        __y.data(), __y.data() + __y.size()) < 0;
168}
169
170_STLP_END_NAMESPACE
171
172#endif /* _STLP_INTERNAL_COLLATE_H */
173
174// Local Variables:
175// mode:C++
176// End:
177