epoc32/include/tools/stlport/stl/_locale.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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 
    47 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
    48 class locale;
    49 #  define locale _STLP_NO_MEM_T_NAME(loc)
    50 #endif
    51 
    52 class locale;
    53 
    54 template <class _CharT, class _Traits, class _Alloc>
    55 bool __locale_do_operator_call (const locale* __that,
    56                                 const basic_string<_CharT, _Traits, _Alloc>& __x,
    57                                 const basic_string<_CharT, _Traits, _Alloc>& __y);
    58 
    59 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
    60 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
    61 
    62 class _STLP_CLASS_DECLSPEC locale {
    63 public:
    64   // types:
    65   class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
    66   protected:
    67     /* Here we filter __init_count user value to 0 or 1 because __init_count is a
    68      * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
    69      * have lower sizeof and generate roll issues. 1 is enough to keep the facet
    70      * alive when required.
    71      */
    72     explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 ) {}
    73     virtual ~facet();
    74     friend class locale;
    75     friend class _Locale_impl;
    76     friend facet * _STLP_CALL _get_facet( facet * );
    77     friend void _STLP_CALL _release_facet( facet *& );
    78 
    79   private:                        // Invalidate assignment and copying.
    80     facet(const facet& ) /* : _Refcount_Base(1) {} */;
    81     void operator=(const facet&);
    82   };
    83 
    84 #if defined (__MVS__) || defined (__OS400__)
    85   struct
    86 #else
    87   class
    88 #endif
    89   _STLP_CLASS_DECLSPEC id {
    90     friend class locale;
    91     friend class _Locale_impl;
    92   public:
    93     size_t _M_index;
    94     static size_t _S_max;
    95   };
    96 
    97   typedef int category;
    98 #if defined (_STLP_STATIC_CONST_INIT_BUG)
    99   enum _Category {
   100 #else
   101   static const category
   102 #endif
   103     none      = 0x000,
   104     collate   = 0x010,
   105     ctype     = 0x020,
   106     monetary  = 0x040,
   107     numeric   = 0x100,
   108     time      = 0x200,
   109     messages  = 0x400,
   110     all       = collate | ctype | monetary | numeric | time | messages
   111 #if defined (_STLP_STATIC_CONST_INIT_BUG)
   112   }
   113 #endif
   114   ;
   115 
   116   // construct/copy/destroy:
   117   locale();
   118   locale(const locale&) _STLP_NOTHROW;
   119   explicit locale(const char *);
   120   locale(const locale&, const char*, category);
   121 
   122 #if defined (_STLP_MEMBER_TEMPLATES) && !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   123   template <class _Facet>
   124   locale(const locale& __loc, _Facet* __f) {
   125     if ( __f != 0 ) {
   126       this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
   127       this->_M_insert(__f, _Facet::id);
   128     } else {
   129       this->_M_impl = _get_Locale_impl( __loc._M_impl );
   130     }
   131   }
   132 #endif // _STLP_MEMBER_TEMPLATES
   133 
   134 protected:
   135   // those are for internal use
   136   locale(_Locale_impl*);
   137 
   138 public:
   139 
   140   locale(const locale&, const locale&, category);
   141   const locale& operator=(const locale&) _STLP_NOTHROW;
   142 
   143 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   144   virtual
   145 #endif
   146    ~locale() _STLP_NOTHROW;
   147 
   148 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
   149    !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   150   template <class _Facet>
   151   locale combine(const locale& __loc) {
   152     facet* __f = __loc._M_get_facet( _Facet::id );
   153     if ( __f == 0 )
   154       _M_throw_runtime_error();
   155 
   156     locale __result(__loc._M_impl);
   157 
   158     __result._M_insert(__f, _Facet::id);
   159 
   160     return __result;
   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 #else
   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   }
   181 #endif
   182 
   183   // global locale objects:
   184   static locale _STLP_CALL global(const locale&);
   185   static const locale& _STLP_CALL classic();
   186 
   187 //protected:                         // Helper functions for locale globals.
   188   facet* _M_get_facet(const id&) const;
   189   // same, but throws
   190   facet* _M_use_facet(const id&) const;
   191   static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_runtime_error(const char* = 0);
   192 
   193 protected:                        // More helper functions.
   194   void _M_insert(facet* __f, id& __id);
   195 
   196   // friends:
   197   friend class _Locale_impl;
   198   friend class ios_base;
   199 
   200 protected:                        // Data members
   201   _Locale_impl* _M_impl;
   202   _Locale_impl* _M_get_impl() const { return _M_impl; }
   203 };
   204 
   205 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   206 #  undef locale
   207 #  define _Locale _STLP_NO_MEM_T_NAME(loc)
   208 
   209 class locale : public _Locale {
   210 public:
   211 
   212   // construct/copy/destroy:
   213   locale() {}
   214   locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
   215   explicit locale(const char *__str) : _Locale(__str) {}
   216   locale(const locale& __loc, const char* __str, category __cat)
   217     : _Locale(__loc, __str, __cat) {}
   218 
   219   template <class _Facet>
   220   locale(const locale& __loc, _Facet* __f) {
   221     if ( __f != 0 ) {
   222       this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
   223       this->_M_insert(__f, _Facet::id);
   224     } else {
   225       this->_M_impl = _get_Locale_impl( __loc._M_impl );
   226     }
   227   }
   228 
   229 private:
   230   // those are for internal use
   231   locale(_Locale_impl* __impl) : _Locale(__impl) {}
   232   locale(const _Locale& __loc) : _Locale(__loc) {}
   233 
   234 public:
   235 
   236   locale(const locale& __loc1, const locale& __loc2, category __cat)
   237     : _Locale(__loc1, __loc2, __cat) {}
   238 
   239   const locale& operator=(const locale& __loc) _STLP_NOTHROW {
   240     _Locale::operator=(__loc);
   241     return *this;
   242   }
   243 
   244   template <class _Facet>
   245   locale combine(const locale& __loc) {
   246     facet* __f = __loc._M_get_facet( _Facet::id );
   247     if ( __f == 0 )
   248       _M_throw_runtime_error();
   249 
   250     locale __result(__loc._M_impl);
   251 
   252     __result._M_insert(__f, _Facet::id);
   253 
   254     return __result;
   255   }
   256 
   257   // locale operations:
   258   bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
   259   bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
   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 //----------------------------------------------------------------------
   278 // locale globals
   279 
   280 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
   281 template <class _Facet>
   282 inline const _Facet&
   283 _Use_facet<_Facet>::operator *() const
   284 # else
   285 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
   286 # endif
   287 {
   288   return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::id));
   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   return (__loc._M_get_facet(_Facet::id) != 0);
   303 }
   304 
   305 # ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
   306   // close class definition
   307 };
   308 # endif
   309 
   310 _STLP_END_NAMESPACE
   311 
   312 #endif /* _STLP_INTERNAL_LOCALE_H */
   313 
   314 // Local Variables:
   315 // mode:C++
   316 // End:
   317