]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_locale.h
Add STLport 5.1.4
[polintos/scott/priv.git] / include / c++ / stl / stl / _locale.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
23 #ifndef _STLP_INTERNAL_LOCALE_H
24 #define _STLP_INTERNAL_LOCALE_H
25
26 #ifndef _STLP_INTERNAL_CSTDLIB
27 #  include <stl/_cstdlib.h>
28 #endif
29
30 #ifndef _STLP_INTERNAL_CWCHAR
31 #  include <stl/_cwchar.h>
32 #endif
33
34 #ifndef _STLP_INTERNAL_THREADS_H
35 #  include <stl/_threads.h>
36 #endif
37
38 #ifndef _STLP_STRING_FWD_H
39 #  include <stl/_string_fwd.h>
40 #endif
41
42 _STLP_BEGIN_NAMESPACE
43
44 class _Locale_impl;        // Forward declaration of opaque type.
45 class ios_base;
46 class locale;
47
48 template <class _CharT, class _Traits, class _Alloc>
49 bool __locale_do_operator_call (const locale& __loc,
50                                 const basic_string<_CharT, _Traits, _Alloc>& __x,
51                                 const basic_string<_CharT, _Traits, _Alloc>& __y);
52
53 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
54 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
55
56 template <class _Facet>
57 bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW;
58
59 template <class _Facet>
60 _Facet* _UseFacet(const locale& __loc, const _Facet* __facet);
61
62 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
63 #  define locale _STLP_NO_MEM_T_NAME(loc)
64 #endif
65
66 class _STLP_CLASS_DECLSPEC locale {
67 public:
68   // types:
69   class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
70   protected:
71     /* Here we filter __init_count user value to 0 or 1 because __init_count is a
72      * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
73      * have lower sizeof and generate roll issues. 1 is enough to keep the facet
74      * alive when required.
75      */
76     explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 ) {}
77     virtual ~facet();
78     friend class locale;
79     friend class _Locale_impl;
80     friend facet * _STLP_CALL _get_facet( facet * );
81     friend void _STLP_CALL _release_facet( facet *& );
82
83   private:                        // Invalidate assignment and copying.
84     facet(const facet& ) /* : _Refcount_Base(1) {} */;
85     void operator=(const facet&);
86   };
87
88 #if defined (__MVS__) || defined (__OS400__)
89   struct
90 #else
91   class
92 #endif
93   _STLP_CLASS_DECLSPEC id {
94     friend class locale;
95     friend class _Locale_impl;
96   public:
97     size_t _M_index;
98     static size_t _S_max;
99   };
100
101   typedef int category;
102 #if defined (_STLP_STATIC_CONST_INIT_BUG)
103   enum _Category {
104 #else
105   static const category
106 #endif
107     none      = 0x000,
108     collate   = 0x010,
109     ctype     = 0x020,
110     monetary  = 0x040,
111     numeric   = 0x100,
112     time      = 0x200,
113     messages  = 0x400,
114     all       = collate | ctype | monetary | numeric | time | messages
115 #if defined (_STLP_STATIC_CONST_INIT_BUG)
116   }
117 #endif
118   ;
119
120   // construct/copy/destroy:
121   locale() _STLP_NOTHROW;
122   locale(const locale&) _STLP_NOTHROW;
123   explicit locale(const char *);
124   locale(const locale&, const char*, category);
125
126 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
127   template <class _Facet>
128   locale(const locale& __loc, _Facet* __f) {
129     if ( __f != 0 ) {
130       this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
131       this->_M_insert(__f, _Facet::id);
132     } else {
133       this->_M_impl = _get_Locale_impl( __loc._M_impl );
134     }
135   }
136 #endif // _STLP_MEMBER_TEMPLATES
137
138 protected:
139   // those are for internal use
140   locale(_Locale_impl*);
141
142 public:
143
144   locale(const locale&, const locale&, category);
145   const locale& operator=(const locale&) _STLP_NOTHROW;
146
147 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
148   virtual
149 #endif
150    ~locale() _STLP_NOTHROW;
151
152 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
153    !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
154   template <class _Facet>
155   locale combine(const locale& __loc) const {
156     _Facet *__facet = 0;
157     if (!_HasFacet(__loc, __facet))
158       _M_throw_runtime_error();
159
160     return locale(*this, _UseFacet(__loc, __facet));
161   }
162 #endif // _STLP_MEMBER_TEMPLATES && !_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
163
164   // locale operations:
165   string name() const;
166
167   bool operator==(const locale&) const;
168   bool operator!=(const locale&) const;
169
170 #if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
171   bool operator()(const string& __x, const string& __y) const;
172 #  ifndef _STLP_NO_WCHAR_T
173   bool operator()(const wstring& __x, const wstring& __y) const;
174 #  endif
175 #elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
176   template <class _CharT, class _Traits, class _Alloc>
177   bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
178                   const basic_string<_CharT, _Traits, _Alloc>& __y) const
179   { return __locale_do_operator_call(*this, __x, __y); }
180 #endif
181
182   // global locale objects:
183   static locale _STLP_CALL global(const locale&);
184   static const locale& _STLP_CALL classic();
185
186 //protected:                         // Helper functions for locale globals.
187   facet* _M_get_facet(const id&) const;
188   // same, but throws
189   facet* _M_use_facet(const id&) const;
190   static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_runtime_error(const char* = 0);
191
192 protected:                        // More helper functions.
193   void _M_insert(facet* __f, id& __id);
194
195   // friends:
196   friend class _Locale_impl;
197   friend class ios_base;
198
199 protected:                        // Data members
200   _Locale_impl* _M_impl;
201   _Locale_impl* _M_get_impl() const { return _M_impl; }
202 };
203
204 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
205 #  undef locale
206 #  define _Locale _STLP_NO_MEM_T_NAME(loc)
207
208 class locale : public _Locale {
209 public:
210
211   // construct/copy/destroy:
212   locale() _STLP_NOTHROW {}
213   locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
214   explicit locale(const char *__str) : _Locale(__str) {}
215   locale(const locale& __loc, const char* __str, category __cat)
216     : _Locale(__loc, __str, __cat) {}
217
218   template <class _Facet>
219   locale(const locale& __loc, _Facet* __f) {
220     if ( __f != 0 ) {
221       this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
222       this->_M_insert(__f, _Facet::id);
223     } else {
224       this->_M_impl = _get_Locale_impl( __loc._M_impl );
225     }
226   }
227
228 private:
229   // those are for internal use
230   locale(_Locale_impl* __impl) : _Locale(__impl) {}
231   locale(const _Locale& __loc) : _Locale(__loc) {}
232
233 public:
234
235   locale(const locale& __loc1, const locale& __loc2, category __cat)
236     : _Locale(__loc1, __loc2, __cat) {}
237
238   const locale& operator=(const locale& __loc) _STLP_NOTHROW {
239     _Locale::operator=(__loc);
240     return *this;
241   }
242
243   template <class _Facet>
244   locale combine(const locale& __loc) const {
245     _Facet *__facet = 0;
246     if (!_HasFacet(__loc, __facet))
247       _M_throw_runtime_error();
248
249     return locale(*this, _UseFacet(__loc, __facet));
250   }
251
252   // locale operations:
253   bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
254   bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
255
256   template <class _CharT, class _Traits, class _Alloc>
257   bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
258                   const basic_string<_CharT, _Traits, _Alloc>& __y) const
259   { return __locale_do_operator_call(*this, __x, __y); }
260
261   // global locale objects:
262   static locale _STLP_CALL global(const locale& __loc) {
263     return _Locale::global(__loc);
264   }
265   static const locale& _STLP_CALL classic() {
266     return __STATIC_CAST(const locale&, _Locale::classic());
267   }
268
269   // friends:
270   friend class _Locale_impl;
271   friend class ios_base;
272 };
273
274 #endif /* _STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND */
275
276 //----------------------------------------------------------------------
277 // locale globals
278
279 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
280 template <class _Facet>
281 inline const _Facet&
282 _Use_facet<_Facet>::operator *() const
283 #else
284 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
285 #endif
286 {
287   _Facet *__facet = 0;
288   return *_UseFacet(__loc, __facet);
289 }
290
291
292 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
293 template <class _Facet>
294 struct has_facet {
295   const locale& __loc;
296   has_facet(const locale& __p_loc) : __loc(__p_loc) {}
297   operator bool() const _STLP_NOTHROW
298 #else
299 template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
300 #endif
301 {
302   _Facet *__facet = 0;
303   return _HasFacet(__loc, __facet);
304 }
305
306 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
307 }; // close class definition
308 #endif
309
310 template <class _Facet>
311 bool _HasFacet(const locale& __loc, const _Facet* __facet) _STLP_NOTHROW
312 { return (__loc._M_get_facet(_Facet::id) != 0); }
313
314 template <class _Facet>
315 _Facet* _UseFacet(const locale& __loc, const _Facet* __facet)
316 { return __STATIC_CAST(_Facet*, __loc._M_use_facet(_Facet::id)); }
317
318 _STLP_END_NAMESPACE
319
320 #endif /* _STLP_INTERNAL_LOCALE_H */
321
322 // Local Variables:
323 // mode:C++
324 // End:
325