_locale.h

00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999 
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted 
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */ 
00018 // WARNING: This is an internal header file, included by other C++
00019 // standard library headers.  You should not attempt to use this header
00020 // file directly.
00021 
00022 
00023 #ifndef _STLP_INTERNAL_LOCALE_H
00024 #define _STLP_INTERNAL_LOCALE_H
00025 
00026 #ifndef _STLP_CSTDLIB
00027 # include <cstdlib>
00028 #endif
00029 
00030 #ifndef _STLP_CWCHAR
00031 # include <cwchar>
00032 #endif
00033 
00034 #ifndef _STLP_INTERNAL_THREADS_H
00035 # include <stl/_threads.h>
00036 #endif
00037 
00038 #ifndef _STLP_STRING_FWD_H
00039 # include <stl/_string_fwd.h>
00040 #endif
00041 
00042 _STLP_BEGIN_NAMESPACE
00043 
00044 class _STLP_CLASS_DECLSPEC _Locale_impl;             // Forward declaration of opaque type.
00045 class _STLP_CLASS_DECLSPEC _Locale;             // Forward declaration of opaque type.
00046 class _STLP_CLASS_DECLSPEC locale;
00047 class _STLP_CLASS_DECLSPEC ios_base;
00048 
00049 
00050 template <class _CharT>
00051 bool 
00052 __locale_do_operator_call (const locale* __that, 
00053                            const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __x,
00054                            const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __y);
00055 
00056 #  define _BaseFacet locale::facet
00057 
00058 class _STLP_CLASS_DECLSPEC locale {
00059 public:
00060   // types:
00061 
00062   class _STLP_DECLSPEC facet : private _Refcount_Base {
00063   protected:
00064     explicit facet(size_t __no_del = 0) : _Refcount_Base(1), _M_delete(__no_del == 0) {}
00065     virtual ~facet();
00066     friend class locale;
00067     friend class _Locale_impl;
00068     friend class _Locale;
00069     
00070   private:                        // Invalidate assignment and copying.
00071     facet(const facet& __f) : _Refcount_Base(1), _M_delete(__f._M_delete == 0)  {};       
00072     void operator=(const facet&); 
00073     
00074   private:                        // Data members.
00075     const bool _M_delete;
00076   };
00077   
00078 #if defined(__MVS__) || defined(__OS400__)
00079   struct
00080 #else
00081   class
00082 #endif
00083   _STLP_DECLSPEC id {
00084     friend class locale;
00085     friend class _Locale_impl;
00086   public:
00087     size_t _M_index;
00088     static size_t _S_max;
00089   };
00090 
00091   typedef int category;
00092 # if defined (_STLP_STATIC_CONST_INIT_BUG)
00093   enum _Category {
00094 # else
00095   static const category
00096 # endif
00097     none      = 0x000,
00098     collate   = 0x010,
00099     ctype     = 0x020,
00100     monetary  = 0x040,
00101     numeric   = 0x100,
00102     time      = 0x200,
00103     messages  = 0x400,
00104     all       = collate | ctype | monetary | numeric | time | messages
00105 # if defined (_STLP_STATIC_CONST_INIT_BUG)
00106   }
00107 # endif
00108   ;
00109 
00110   // construct/copy/destroy:
00111   locale();
00112   locale(const locale&) _STLP_NOTHROW;
00113   explicit locale(const char *);
00114   locale(const locale&, const char*, category);
00115 
00116   // those are for internal use
00117   locale(_Locale_impl*);
00118   locale(_Locale_impl*, bool);
00119 
00120 public:
00121 
00122 # if defined ( _STLP_MEMBER_TEMPLATES ) /* && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) */
00123   template <class _Facet> 
00124   locale(const locale& __loc, _Facet* __f) : _M_impl(0)
00125     {
00126       //      _M_impl = this->_S_copy_impl(__loc._M_impl, __f != 0);
00127       new(this) locale(__loc._M_impl, __f != 0);
00128       if (__f != 0)
00129         this->_M_insert(__f, _Facet::id);
00130     }
00131 # endif
00132 
00133   locale(const locale&, const locale&, category);
00134   ~locale() _STLP_NOTHROW;
00135   const locale& operator=(const locale&) _STLP_NOTHROW;
00136 
00137 # if !(defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))
00138   template <class _Facet> locale combine(const locale& __loc) {
00139     locale __result(__loc._M_impl, true);
00140     if (facet* __f = __loc._M_get_facet(_Facet::id)) {
00141       __result._M_insert(__f, _Facet::id);
00142       __f->_M_incr();
00143     }
00144     else
00145       _M_throw_runtime_error();    
00146     return __result;
00147   }
00148 # endif
00149   // locale operations:
00150   string name() const;
00151 
00152   bool operator==(const locale&) const;
00153   bool operator!=(const locale&) const;
00154 
00155 # if ! defined ( _STLP_MEMBER_TEMPLATES ) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
00156   bool operator()(const string& __x, const string& __y) const;
00157 #  ifndef _STLP_NO_WCHAR_T
00158   bool operator()(const wstring& __x, const wstring& __y) const;
00159 #  endif
00160 # else
00161   template <class _CharT, class _Traits, class _Alloc>
00162   bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
00163                   const basic_string<_CharT, _Traits, _Alloc>& __y) const  {
00164     return __locale_do_operator_call(this, __x, __y);
00165   }              
00166 # endif
00167 
00168   // global locale objects:
00169   static locale _STLP_CALL global(const locale&);
00170   static const locale& _STLP_CALL classic();
00171 
00172 public:                         // Helper functions for locale globals.
00173   facet* _M_get_facet(const id&) const;
00174   // same, but throws
00175   facet* _M_use_facet(const id&) const;
00176   static void _STLP_CALL _M_throw_runtime_error(const char* = 0);
00177   static void _STLP_CALL _S_initialize();
00178   static void _STLP_CALL _S_uninitialize();
00179 
00180 private:                        // More helper functions.
00181   //  static _Locale_impl* _STLP_CALL _S_copy_impl(_Locale_impl*, bool);
00182   void _M_insert(facet* __f, id& __id);
00183 
00184   // friends:
00185   friend class _Locale_impl;
00186   friend class _Locale;
00187   friend class ios_base;
00188 
00189 private:                        // Data members
00190   _Locale_impl* _M_impl;
00191 };
00192 
00193 //----------------------------------------------------------------------
00194 // locale globals
00195 
00196 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
00197 template <class _Facet>
00198 inline const _Facet& 
00199 _Use_facet<_Facet>::operator *() const
00200 # else
00201 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
00202 # endif
00203 {
00204   return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::id));
00205 }
00206 
00207  
00208 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
00209 template <class _Facet> 
00210 struct has_facet {
00211   const locale& __loc;
00212   has_facet(const locale& __p_loc) : __loc(__p_loc) {}
00213   operator bool() const _STLP_NOTHROW
00214 # else
00215 template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW 
00216 # endif
00217 {
00218   return (__loc._M_get_facet(_Facet::id) != 0);
00219 }
00220 
00221 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
00222   // close class definition
00223 };
00224 # endif
00225 
00226 _STLP_END_NAMESPACE
00227 
00228 #endif /* _STLP_INTERNAL_LOCALE_H */
00229 
00230 // Local Variables:
00231 // mode:C++
00232 // End:
00233 

Generated on Mon Jun 5 10:20:46 2006 for Intelligence.kdevelop by  doxygen 1.4.6