home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _locale.h < prev    next >
C/C++ Source or Header  |  2001-11-21  |  7KB  |  234 lines

  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_CSTDLIB
  27. # include <cstdlib>
  28. #endif
  29.  
  30. #ifndef _STLP_CWCHAR
  31. # include <cwchar>
  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 _STLP_CLASS_DECLSPEC _Locale_impl;             // Forward declaration of opaque type.
  45. class _STLP_CLASS_DECLSPEC _Locale;             // Forward declaration of opaque type.
  46. class _STLP_CLASS_DECLSPEC locale;
  47. class _STLP_CLASS_DECLSPEC ios_base;
  48.  
  49.  
  50. template <class _CharT>
  51. bool 
  52. __locale_do_operator_call (const locale* __that, 
  53.                            const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __x,
  54.                            const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __y);
  55.  
  56. #  define _BaseFacet locale::facet
  57.  
  58. class _STLP_CLASS_DECLSPEC locale {
  59. public:
  60.   // types:
  61.  
  62.   class _STLP_DECLSPEC facet : private _Refcount_Base {
  63.   protected:
  64.     explicit facet(size_t __no_del = 0) : _Refcount_Base(1), _M_delete(__no_del == 0) {}
  65.     virtual ~facet();
  66.     friend class locale;
  67.     friend class _Locale_impl;
  68.     friend class _Locale;
  69.     
  70.   private:                        // Invalidate assignment and copying.
  71.     facet(const facet& __f) : _Refcount_Base(1), _M_delete(__f._M_delete == 0)  {};       
  72.     void operator=(const facet&); 
  73.     
  74.   private:                        // Data members.
  75.     const bool _M_delete;
  76.   };
  77.   
  78. #if defined(__MVS__) || defined(__OS400__)
  79.   struct
  80. #else
  81.   class
  82. #endif
  83.   _STLP_DECLSPEC id {
  84.     friend class locale;
  85.     friend class _Locale_impl;
  86.   public:
  87.     size_t _M_index;
  88.     static size_t _S_max;
  89.   };
  90.  
  91.   typedef int category;
  92. # if defined (_STLP_STATIC_CONST_INIT_BUG)
  93.   enum _Category {
  94. # else
  95.   static const category
  96. # endif
  97.     none      = 0x000,
  98.     collate   = 0x010,
  99.     ctype     = 0x020,
  100.     monetary  = 0x040,
  101.     numeric   = 0x100,
  102.     time      = 0x200,
  103.     messages  = 0x400,
  104.     all       = collate | ctype | monetary | numeric | time | messages
  105. # if defined (_STLP_STATIC_CONST_INIT_BUG)
  106.   }
  107. # endif
  108.   ;
  109.  
  110.   // construct/copy/destroy:
  111.   locale();
  112.   locale(const locale&) _STLP_NOTHROW;
  113.   explicit locale(const char *);
  114.   locale(const locale&, const char*, category);
  115.  
  116.   // those are for internal use
  117.   locale(_Locale_impl*);
  118.   locale(_Locale_impl*, bool);
  119.  
  120. public:
  121.  
  122. # if defined ( _STLP_MEMBER_TEMPLATES ) /* && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) */
  123.   template <class _Facet> 
  124.   locale(const locale& __loc, _Facet* __f) : _M_impl(0)
  125.     {
  126.       //      _M_impl = this->_S_copy_impl(__loc._M_impl, __f != 0);
  127.       new(this) locale(__loc._M_impl, __f != 0);
  128.       if (__f != 0)
  129.         this->_M_insert(__f, _Facet::id);
  130.     }
  131. # endif
  132.  
  133.   locale(const locale&, const locale&, category);
  134.   ~locale() _STLP_NOTHROW;
  135.   const locale& operator=(const locale&) _STLP_NOTHROW;
  136.  
  137. # if !(defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))
  138.   template <class _Facet> locale combine(const locale& __loc) {
  139.     locale __result(__loc._M_impl, true);
  140.     if (facet* __f = __loc._M_get_facet(_Facet::id)) {
  141.       __result._M_insert(__f, _Facet::id);
  142.       __f->_M_incr();
  143.     }
  144.     else
  145.       _M_throw_runtime_error();    
  146.     return __result;
  147.   }
  148. # endif
  149.   // locale operations:
  150.   string name() const;
  151.  
  152.   bool operator==(const locale&) const;
  153.   bool operator!=(const locale&) const;
  154.  
  155. # if ! defined ( _STLP_MEMBER_TEMPLATES ) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
  156.   bool operator()(const string& __x, const string& __y) const;
  157. #  ifndef _STLP_NO_WCHAR_T
  158.   bool operator()(const wstring& __x, const wstring& __y) const;
  159. #  endif
  160. # else
  161.   template <class _CharT, class _Traits, class _Alloc>
  162.   bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
  163.                   const basic_string<_CharT, _Traits, _Alloc>& __y) const  {
  164.     return __locale_do_operator_call(this, __x, __y);
  165.   }              
  166. # endif
  167.  
  168.   // global locale objects:
  169.   static locale _STLP_CALL global(const locale&);
  170.   static const locale& _STLP_CALL classic();
  171.  
  172. public:                         // Helper functions for locale globals.
  173.   facet* _M_get_facet(const id&) const;
  174.   // same, but throws
  175.   facet* _M_use_facet(const id&) const;
  176.   static void _STLP_CALL _M_throw_runtime_error(const char* = 0);
  177.   static void _STLP_CALL _S_initialize();
  178.   static void _STLP_CALL _S_uninitialize();
  179.  
  180. private:                        // More helper functions.
  181.   //  static _Locale_impl* _STLP_CALL _S_copy_impl(_Locale_impl*, bool);
  182.   void _M_insert(facet* __f, id& __id);
  183.  
  184.   // friends:
  185.   friend class _Locale_impl;
  186.   friend class _Locale;
  187.   friend class ios_base;
  188.  
  189. private:                        // Data members
  190.   _Locale_impl* _M_impl;
  191. };
  192.  
  193. //----------------------------------------------------------------------
  194. // locale globals
  195.  
  196. # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
  197. template <class _Facet>
  198. inline const _Facet& 
  199. _Use_facet<_Facet>::operator *() const
  200. # else
  201. template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
  202. # endif
  203. {
  204.   return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::id));
  205. }
  206.  
  207.  
  208. # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
  209. template <class _Facet> 
  210. struct has_facet {
  211.   const locale& __loc;
  212.   has_facet(const locale& __p_loc) : __loc(__p_loc) {}
  213.   operator bool() const _STLP_NOTHROW
  214. # else
  215. template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW 
  216. # endif
  217. {
  218.   return (__loc._M_get_facet(_Facet::id) != 0);
  219. }
  220.  
  221. # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
  222.   // close class definition
  223. };
  224. # endif
  225.  
  226. _STLP_END_NAMESPACE
  227.  
  228. #endif /* _STLP_INTERNAL_LOCALE_H */
  229.  
  230. // Local Variables:
  231. // mode:C++
  232. // End:
  233.  
  234.