epoc32/include/stdapis/stlportv5/stl/_locale.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
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  * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3  *
     4  * Copyright (c) 1999 
     5  * Silicon Graphics Computer Systems, Inc.
     6  *
     7  * Copyright (c) 1999
     8  * Boris Fomitchev
     9  *
    10  * This material is provided "as is", with absolutely no warranty expressed
    11  * or implied. Any use is at your own risk.
    12  *
    13  * Permission to use or copy this software for any purpose is hereby granted
    14  * without fee, provided the above notices are retained on all copies.
    15  * Permission to modify the code and to distribute modified code is granted,
    16  * provided the above notices are retained, and a notice that the code was
    17  * modified is included with the above copyright notice.
    18  *
    19  */
    20 // WARNING: This is an internal header file, included by other C++
    21 // standard library headers.  You should not attempt to use this header
    22 // file directly.
    23 
    24 
    25 #ifndef _STLP_INTERNAL_LOCALE_H
    26 #define _STLP_INTERNAL_LOCALE_H
    27 
    28 #ifndef _STLP_INTERNAL_CSTDLIB
    29 #  include <stl/_cstdlib.h>
    30 #endif
    31 
    32 #ifndef _STLP_INTERNAL_CWCHAR
    33 #  include <stl/_cwchar.h>
    34 #endif
    35 
    36 #ifndef _STLP_INTERNAL_THREADS_H
    37 #  include <stl/_threads.h>
    38 #endif
    39 
    40 #ifndef _STLP_STRING_FWD_H
    41 #  include <stl/_string_fwd.h>
    42 #endif
    43 
    44 _STLP_BEGIN_NAMESPACE
    45 
    46 class _Locale_impl;        // Forward declaration of opaque type.
    47 class ios_base;
    48 class locale;
    49 
    50 template <class _CharT, class _Traits, class _Alloc>
    51 bool __locale_do_operator_call (const locale& __loc,
    52                                 const basic_string<_CharT, _Traits, _Alloc>& __x,
    53                                 const basic_string<_CharT, _Traits, _Alloc>& __y);
    54 
    55 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _get_Locale_impl( _Locale_impl *locimpl );
    56 _STLP_DECLSPEC _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl *locimpl );
    57 
    58 template <class _Facet>
    59 bool _HasFacet(const locale& __loc, const _Facet*  /*__facet */ ) _STLP_NOTHROW;
    60 
    61 template <class _Facet>
    62 _Facet* _UseFacet(const locale& __loc, const _Facet* /* __facet */);
    63 
    64 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
    65 #  define locale _STLP_NO_MEM_T_NAME(loc)
    66 #endif
    67 
    68 class _STLP_CLASS_DECLSPEC locale {
    69 public:
    70   // types:
    71   class _STLP_CLASS_DECLSPEC facet : protected _Refcount_Base {
    72   protected:
    73     /* Here we filter __init_count user value to 0 or 1 because __init_count is a
    74      * size_t instance and _Refcount_Base use __stl_atomic_t instances that might
    75      * have lower sizeof and generate roll issues. 1 is enough to keep the facet
    76      * alive when required.
    77      */
    78     explicit facet(size_t __init_count = 0) : _Refcount_Base( __init_count == 0 ? 0 : 1 )
    79     	{ if (__init_count ) {/* do nothing. to avoid warnings */} }
    80     _STLP_DECLSPEC virtual ~facet();
    81     friend class locale;
    82     friend class _Locale_impl;
    83     friend facet * _STLP_CALL _get_facet( facet * );
    84     friend void _STLP_CALL _release_facet( facet *& );
    85 
    86   private:                        // Invalidate assignment and copying.
    87     facet(const facet& ) /* : _Refcount_Base(1) {} */;
    88     void operator=(const facet&);
    89   };
    90 
    91 #if defined (__MVS__) || defined (__OS400__)
    92   struct
    93 #else
    94   class
    95 #endif
    96   _STLP_CLASS_DECLSPEC id {
    97     friend class locale;
    98     friend class _Locale_impl;
    99   public:
   100     size_t _M_index;
   101 #if defined(__SYMBIAN32__WSD__)
   102     static inline size_t& get_locale_id_S_max();
   103 # else
   104     static size_t _S_max;
   105 # endif
   106   };
   107 
   108   typedef int category;
   109 #if defined (_STLP_STATIC_CONST_INIT_BUG)
   110   enum _Category {
   111 #else
   112   static const category
   113 #endif
   114     none      = 0x000,
   115     collate   = 0x010,
   116     ctype     = 0x020,
   117     monetary  = 0x040,
   118     numeric   = 0x100,
   119     time      = 0x200,
   120     messages  = 0x400,
   121     all       = collate | ctype | monetary | numeric | time | messages
   122 #if defined (_STLP_STATIC_CONST_INIT_BUG)
   123   }
   124 #endif
   125   ;
   126 
   127   // construct/copy/destroy:
   128   _STLP_DECLSPEC locale() _STLP_NOTHROW;
   129   _STLP_DECLSPEC locale(const locale&) _STLP_NOTHROW;
   130   _STLP_DECLSPEC explicit locale(const char *);
   131   locale(const locale&, const char*, category);
   132 
   133 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__) 
   134 #define id GetFacetLocaleId()
   135 #endif
   136 
   137 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   138   template <class _Facet>
   139   locale(const locale& __loc, _Facet* __f) {
   140     if ( __f != 0 ) {
   141       this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
   142       this->_M_insert(__f, _Facet::id);
   143     } else {
   144       this->_M_impl = _get_Locale_impl( __loc._M_impl );
   145     }
   146   }
   147 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__) 
   148 #undef id 
   149 #endif
   150 #endif // _STLP_MEMBER_TEMPLATES
   151 
   152 protected:
   153   // those are for internal use
   154   locale(_Locale_impl*);
   155 
   156 public:
   157 
   158   locale(const locale&, const locale&, category);
   159   _STLP_DECLSPEC const locale& operator=(const locale&) _STLP_NOTHROW;
   160 
   161 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   162   virtual
   163 #endif
   164    _STLP_DECLSPEC ~locale() _STLP_NOTHROW;
   165 
   166 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && \
   167    !defined(_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   168   template <class _Facet>
   169   locale combine(const locale& __loc) const {
   170     _Facet *__facet = 0;
   171     if (!_HasFacet(__loc, __facet))
   172       _M_throw_runtime_error();
   173 
   174     return locale(*this, _UseFacet(__loc, __facet));
   175   }
   176 #endif // _STLP_MEMBER_TEMPLATES && !_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
   177 
   178   // locale operations:
   179   _STLP_DECLSPEC  string name() const;
   180 
   181   _STLP_DECLSPEC bool operator==(const locale&) const;
   182   _STLP_DECLSPEC bool operator!=(const locale&) const;
   183 
   184 #if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
   185   _STLP_DECLSPEC bool operator()(const string& __x, const string& __y) const;
   186 #  ifndef _STLP_NO_WCHAR_T
   187   _STLP_DECLSPEC bool operator()(const wstring& __x, const wstring& __y) const;
   188 #  endif
   189 #elif !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   190   template <class _CharT, class _Traits, class _Alloc>
   191   bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
   192                   const basic_string<_CharT, _Traits, _Alloc>& __y) const
   193   { return __locale_do_operator_call(*this, __x, __y); }
   194 #endif
   195 
   196   // global locale objects:
   197   _STLP_DECLSPEC static locale _STLP_CALL global(const locale&);
   198   _STLP_DECLSPEC static const locale& _STLP_CALL classic();
   199 
   200 //protected:                         // Helper functions for locale globals.
   201   _STLP_DECLSPEC facet* _M_get_facet(const id&) const;
   202   // same, but throws
   203   _STLP_DECLSPEC facet* _M_use_facet(const id&) const;
   204   _STLP_DECLSPEC static void _STLP_FUNCTION_THROWS _M_throw_runtime_error(const char* = 0);
   205 
   206 protected:                        // More helper functions.
   207   _STLP_DECLSPEC void _M_insert(facet* __f, id& __id);
   208 
   209   // friends:
   210   friend class _Locale_impl;
   211   friend class ios_base;
   212 
   213 protected:                        // Data members
   214   _Locale_impl* _M_impl;
   215   _Locale_impl* _M_get_impl() const { return _M_impl; }
   216 };
   217 
   218 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
   219 #  undef locale
   220 #  define _Locale _STLP_NO_MEM_T_NAME(loc)
   221 
   222 class locale : public _Locale {
   223 public:
   224 
   225   // construct/copy/destroy:
   226   _STLP_DECLSPEC locale() _STLP_NOTHROW {}
   227   locale(const locale& __loc) _STLP_NOTHROW : _Locale(__loc) {}
   228   explicit locale(const char *__str) : _Locale(__str) {}
   229   locale(const locale& __loc, const char* __str, category __cat)
   230     : _Locale(__loc, __str, __cat) {}
   231 
   232   template <class _Facet>
   233   locale(const locale& __loc, _Facet* __f) {
   234     if ( __f != 0 ) {
   235       this->_M_impl = _get_Locale_impl( _copy_Nameless_Locale_impl( __loc._M_impl ) );
   236       this->_M_insert(__f, _Facet::id);
   237     } else {
   238       this->_M_impl = _get_Locale_impl( __loc._M_impl );
   239     }
   240   }
   241 
   242 private:
   243   // those are for internal use
   244   locale(_Locale_impl* __impl) : _Locale(__impl) {}
   245   locale(const _Locale& __loc) : _Locale(__loc) {}
   246 
   247 public:
   248 
   249   locale(const locale& __loc1, const locale& __loc2, category __cat)
   250     : _Locale(__loc1, __loc2, __cat) {}
   251 
   252   const locale& operator=(const locale& __loc) _STLP_NOTHROW {
   253     _Locale::operator=(__loc);
   254     return *this;
   255   }
   256 
   257   template <class _Facet>
   258   locale combine(const locale& __loc) const {
   259     _Facet *__facet = 0;
   260     if (!_HasFacet(__loc, __facet))
   261       _M_throw_runtime_error();
   262 
   263     return locale(*this, _UseFacet(__loc, __facet));
   264   }
   265 
   266   // locale operations:
   267   bool operator==(const locale& __loc) const { return _Locale::operator==(__loc); }
   268   bool operator!=(const locale& __loc) const { return _Locale::operator!=(__loc); }
   269 
   270   template <class _CharT, class _Traits, class _Alloc>
   271   bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
   272                   const basic_string<_CharT, _Traits, _Alloc>& __y) const
   273   { return __locale_do_operator_call(*this, __x, __y); }
   274 
   275   // global locale objects:
   276   static locale _STLP_CALL global(const locale& __loc) {
   277     return _Locale::global(__loc);
   278   }
   279   static const locale& _STLP_CALL classic() {
   280     return __STATIC_CAST(const locale&, _Locale::classic());
   281   }
   282 
   283   // friends:
   284   friend class _Locale_impl;
   285   friend class ios_base;
   286 };
   287 
   288 #endif /* _STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND */
   289 
   290 //----------------------------------------------------------------------
   291 // locale globals
   292 
   293 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
   294 template <class _Facet>
   295 inline const _Facet&
   296 _Use_facet<_Facet>::operator *() const
   297 #else
   298 template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
   299 #endif
   300 {
   301   _Facet *__facet = 0;
   302   return *_UseFacet(__loc, __facet);
   303 }
   304 
   305 
   306 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
   307 template <class _Facet>
   308 struct has_facet {
   309   const locale& __loc;
   310   has_facet(const locale& __p_loc) : __loc(__p_loc) {}
   311   operator bool() const _STLP_NOTHROW
   312 #else
   313 template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
   314 #endif
   315 {
   316   _Facet *__facet = 0;
   317   return _HasFacet(__loc, __facet);
   318 }
   319 
   320 #ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
   321 }; // close class definition
   322 #endif
   323 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__) 
   324 #define id GetFacetLocaleId()
   325 #endif
   326 
   327 template <class _Facet>
   328 bool _HasFacet(const locale& __loc, const _Facet* ) _STLP_NOTHROW
   329 { return (__loc._M_get_facet(_Facet::id) != 0); }
   330 
   331 template <class _Facet>
   332 _Facet* _UseFacet(const locale& __loc, const _Facet* )
   333 { return __STATIC_CAST(_Facet*, __loc._M_use_facet(_Facet::id)); }
   334 
   335 #if defined(__SYMBIAN32__WSD__)  || defined (__SYMBIAN32__NO_STATIC_IMPORTS__) 
   336 #undef id 
   337 #endif
   338 _STLP_END_NAMESPACE
   339 
   340 #endif /* _STLP_INTERNAL_LOCALE_H */
   341 
   342 // Local Variables:
   343 // mode:C++
   344 // End:
   345