localefwd.h

Go to the documentation of this file.
00001 // Locale support -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 //
00032 // ISO C++ 14882: 22.1  Locales
00033 //
00034 
00040 #ifndef _CPP_BITS_LOCCORE_H
00041 #define _CPP_BITS_LOCCORE_H 1
00042 
00043 #pragma GCC system_header
00044 
00045 #include <bits/c++config.h>
00046 #include <bits/c++locale.h>     // Defines __c_locale, config-specific includes
00047 #include <climits>      // For CHAR_BIT
00048 #include <cctype>       // For isspace, etc.
00049 #include <string>       // For string.
00050 #include <bits/functexcept.h>
00051 #include <bits/atomicity.h>
00052 
00053 namespace std
00054 {
00055   // 22.1.1 Locale
00056   class locale;
00057 
00058   // 22.1.3 Convenience interfaces
00059   template<typename _CharT> 
00060     inline bool 
00061     isspace(_CharT, const locale&);
00062 
00063   template<typename _CharT> 
00064     inline bool 
00065     isprint(_CharT, const locale&);
00066 
00067   template<typename _CharT> 
00068     inline bool 
00069     iscntrl(_CharT, const locale&);
00070 
00071   template<typename _CharT> 
00072     inline bool 
00073     isupper(_CharT, const locale&);
00074 
00075   template<typename _CharT> 
00076     inline bool 
00077     islower(_CharT, const locale&);
00078 
00079   template<typename _CharT> 
00080     inline bool 
00081     isalpha(_CharT, const locale&);
00082 
00083   template<typename _CharT> 
00084     inline bool 
00085     isdigit(_CharT, const locale&);
00086 
00087   template<typename _CharT> 
00088     inline bool 
00089     ispunct(_CharT, const locale&);
00090 
00091   template<typename _CharT> 
00092     inline bool 
00093     isxdigit(_CharT, const locale&);
00094 
00095   template<typename _CharT> 
00096     inline bool 
00097     isalnum(_CharT, const locale&);
00098 
00099   template<typename _CharT> 
00100     inline bool 
00101     isgraph(_CharT, const locale&);
00102 
00103   template<typename _CharT> 
00104     inline _CharT 
00105     toupper(_CharT, const locale&);
00106 
00107   template<typename _CharT> 
00108     inline _CharT 
00109     tolower(_CharT, const locale&);
00110 
00111 
00112   // 22.2.1 and 22.2.1.3 ctype
00113   class ctype_base;
00114   template<typename _CharT> 
00115     class ctype;
00116   template<> class ctype<char>;
00117 #ifdef _GLIBCPP_USE_WCHAR_T
00118   template<> class ctype<wchar_t>;
00119 #endif
00120   template<typename _CharT> 
00121     class ctype_byname;
00122   // NB: Specialized for char and wchar_t in locale_facets.h.
00123 
00124   class codecvt_base;
00125   class __enc_traits;
00126   template<typename _InternT, typename _ExternT, typename _StateT>
00127     class codecvt;
00128   template<> class codecvt<char, char, mbstate_t>;
00129 #ifdef _GLIBCPP_USE_WCHAR_T
00130   template<> class codecvt<wchar_t, char, mbstate_t>;
00131 #endif
00132   template<typename _InternT, typename _ExternT, typename _StateT>
00133     class codecvt_byname;
00134 
00135   // 22.2.2 and 22.2.3 numeric
00136   template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
00137     class num_get;
00138   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00139     class num_put;
00140   template<typename _CharT> class numpunct;
00141   template<typename _CharT> class numpunct_byname;
00142 
00143   // 22.2.4 collation
00144   template<typename _CharT> 
00145     class collate;
00146   template<typename _CharT> class 
00147     collate_byname;
00148 
00149   // 22.2.5 date and time
00150   class time_base;
00151   template<typename _CharT, typename _InIter =  istreambuf_iterator<_CharT> >
00152     class time_get;
00153   template<typename _CharT, typename _InIter =  istreambuf_iterator<_CharT> >
00154     class time_get_byname;
00155   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00156     class time_put;
00157   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00158     class time_put_byname;
00159 
00160   // 22.2.6 money
00161   class money_base;
00162   template<typename _CharT, typename _InIter =  istreambuf_iterator<_CharT> >
00163     class money_get;
00164   template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
00165     class money_put;
00166   template<typename _CharT, bool _Intl = false> 
00167     class moneypunct;
00168   template<typename _CharT, bool _Intl = false> 
00169     class moneypunct_byname;
00170 
00171   // 22.2.7 message retrieval
00172   class messages_base;
00173   template<typename _CharT> 
00174     class messages;
00175   template<typename _CharT> 
00176     class messages_byname;
00177 
00178   // 22.1.1 Class locale
00179   class locale
00180   {
00181   public:
00182     // Types:
00183     typedef unsigned int    category;
00184 
00185     // Forward decls and friends:
00186     class facet;
00187     class id;
00188     class _Impl;
00189 
00190     friend class facet;
00191     friend class _Impl;
00192 
00193     template<typename _Facet>
00194       friend const _Facet& 
00195       use_facet(const locale&);
00196     
00197     template<typename _Facet>
00198       friend bool 
00199       has_facet(const locale&) throw();
00200  
00201     // Category values:
00202     // NB: Order must match _S_facet_categories definition in locale.cc
00203     static const category none      = 0;
00204     static const category ctype     = 1L << 0;
00205     static const category numeric   = 1L << 1;
00206     static const category collate   = 1L << 2;
00207     static const category time      = 1L << 3;
00208     static const category monetary  = 1L << 4;
00209     static const category messages  = 1L << 5;
00210     static const category all       = (ctype | numeric | collate |
00211                        time  | monetary | messages);
00212 
00213     // Construct/copy/destroy:
00214     locale() throw();
00215 
00216     locale(const locale& __other) throw();
00217 
00218     explicit  
00219     locale(const char* __s);
00220 
00221     locale(const locale& __base, const char* __s, category __cat);
00222 
00223     locale(const locale& __base, const locale& __add, category __cat);
00224 
00225     template<typename _Facet>
00226       locale(const locale& __other, _Facet* __f);
00227 
00228     ~locale() throw();
00229 
00230     const locale&  
00231     operator=(const locale& __other) throw();
00232 
00233     template<typename _Facet>
00234       locale  
00235       combine(const locale& __other) const;
00236 
00237     // Locale operations:
00238     string 
00239     name() const;
00240 
00241     bool 
00242     operator==(const locale& __other) const throw ();
00243 
00244     inline bool  
00245     operator!=(const locale& __other) const throw ()
00246     { return !(this->operator==(__other));  }
00247 
00248     template<typename _Char, typename _Traits, typename _Alloc>
00249       bool  
00250       operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
00251          const basic_string<_Char, _Traits, _Alloc>& __s2) const;
00252 
00253     // Global locale objects:
00254     static locale 
00255     global(const locale&);
00256 
00257     static const locale& 
00258     classic();
00259 
00260   private:
00261     // The (shared) implementation
00262     _Impl*      _M_impl;  
00263 
00264     // The "C" reference locale
00265     static _Impl*   _S_classic; 
00266 
00267     // Current global locale
00268     static _Impl*   _S_global;  
00269 
00270     // Number of standard categories. For C++, these categories are
00271     // collate, ctype, monetary, numeric, time, and messages. These
00272     // directly correspond to ISO C99 macros LC_COLLATE, LC_CTYPE,
00273     // LC_MONETARY, LC_NUMERIC, and LC_TIME. In addition, POSIX (IEEE
00274     // 1003.1-2001) specifies LC_MESSAGES.
00275     static const size_t _S_categories_size = 6;
00276 
00277     // In addition to the standard categories, the underlying
00278     // operating system is allowed to define extra LC_*
00279     // macros. For GNU systems, the following are also valid:
00280     // LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT,
00281     // and LC_IDENTIFICATION.
00282     static const size_t _S_extra_categories_size = _GLIBCPP_NUM_CATEGORIES;
00283 
00284     // Names of underlying locale categories.  
00285     // NB: locale::global() has to know how to modify all the
00286     // underlying categories, not just the ones required by the C++
00287     // standard.
00288     static const char*  _S_categories[_S_categories_size 
00289                       + _S_extra_categories_size];
00290 
00291     explicit 
00292     locale(_Impl*) throw();
00293 
00294     static inline void  
00295     _S_initialize()
00296     { 
00297       if (!_S_classic) 
00298     classic();  
00299     }
00300 
00301     static category  
00302     _S_normalize_category(category);
00303 
00304     void
00305     _M_coalesce(const locale& __base, const locale& __add, category __cat);
00306   };
00307 
00308 
00309   // Implementation object for locale 
00310   class locale::_Impl
00311   {
00312   public:
00313     // Friends.
00314     friend class locale;
00315     friend class locale::facet;
00316 
00317     template<typename _Facet>
00318       friend const _Facet&  
00319       use_facet(const locale&);
00320 
00321     template<typename _Facet>
00322       friend bool  
00323       has_facet(const locale&) throw();
00324 
00325   private:
00326     // Data Members.
00327     _Atomic_word            _M_references;
00328     facet**                 _M_facets;
00329     size_t              _M_facets_size;
00330 
00331     char*               _M_names[_S_categories_size
00332                          + _S_extra_categories_size];
00333     static const locale::id* const  _S_id_ctype[];
00334     static const locale::id* const  _S_id_numeric[];
00335     static const locale::id* const  _S_id_collate[];
00336     static const locale::id* const  _S_id_time[];
00337     static const locale::id* const  _S_id_monetary[];
00338     static const locale::id* const  _S_id_messages[];
00339     static const locale::id* const* const _S_facet_categories[];
00340 
00341     inline void 
00342     _M_add_reference() throw()
00343     { __atomic_add(&_M_references, 1); }
00344 
00345     inline void 
00346     _M_remove_reference() throw()
00347     {
00348       if (__exchange_and_add(&_M_references, -1) == 1)
00349     {
00350       try 
00351         { delete this; } 
00352       catch(...) 
00353         { }
00354     }
00355     }
00356 
00357     _Impl(const _Impl&, size_t);
00358     _Impl(const char*, size_t);
00359     _Impl(facet**, size_t, bool);
00360 
00361    ~_Impl() throw();
00362 
00363     _Impl(const _Impl&);  // Not defined.
00364 
00365     void 
00366     operator=(const _Impl&);  // Not defined.
00367 
00368     inline bool
00369     _M_check_same_name()
00370     {
00371       bool __ret = true;
00372       for (size_t __i = 0; 
00373        __ret && __i < _S_categories_size + _S_extra_categories_size - 1; 
00374        ++__i)
00375     __ret &= (strcmp(_M_names[__i], _M_names[__i + 1]) == 0);
00376       return __ret;
00377     }
00378 
00379     void 
00380     _M_replace_categories(const _Impl*, category);
00381 
00382     void 
00383     _M_replace_category(const _Impl*, const locale::id* const*);
00384 
00385     void 
00386     _M_replace_facet(const _Impl*, const locale::id*);
00387 
00388     void 
00389     _M_install_facet(const locale::id*, facet*);
00390 
00391     template<typename _Facet>
00392       inline void 
00393       _M_init_facet(_Facet* __facet)
00394       { _M_install_facet(&_Facet::id, __facet);  }
00395   };
00396 
00397   template<typename _Facet>
00398     locale::locale(const locale& __other, _Facet* __f)
00399     {
00400       _M_impl = new _Impl(*__other._M_impl, 1);
00401       _M_impl->_M_install_facet(&_Facet::id, __f);
00402       for (size_t __i = 0; 
00403        __i < _S_categories_size + _S_extra_categories_size; ++__i)
00404     {
00405       delete [] _M_impl->_M_names[__i];
00406       char* __new = new char[2];
00407       strcpy(__new, "*");
00408       _M_impl->_M_names[__i] = __new;
00409     }
00410     }
00411 
00412   // 22.1.1.1.2  Class locale::facet
00413   class locale::facet
00414   {
00415   private:
00416     friend class locale;
00417     friend class locale::_Impl;
00418 
00419     _Atomic_word _M_references;
00420 
00421   protected:
00422     // Contains data from the underlying "C" library for for the
00423     // classic locale.
00424     static __c_locale               _S_c_locale;
00425 
00426     // String literal for the name of the classic locale.
00427     static char                         _S_c_name[2];
00428    
00429     explicit 
00430     facet(size_t __refs = 0) throw();
00431 
00432     virtual 
00433     ~facet();
00434 
00435     static void
00436     _S_create_c_locale(__c_locale& __cloc, const char* __s, 
00437                __c_locale __old = 0);
00438 
00439     static __c_locale
00440     _S_clone_c_locale(__c_locale& __cloc);
00441 
00442     static void
00443     _S_destroy_c_locale(__c_locale& __cloc);
00444 
00445   private:
00446     void 
00447     _M_add_reference() throw();
00448 
00449     void 
00450     _M_remove_reference() throw();
00451 
00452     facet(const facet&);  // Not defined.
00453 
00454     void 
00455     operator=(const facet&);  // Not defined.
00456   };
00457 
00458 
00459   // 22.1.1.1.3 Class locale::id
00460   class locale::id
00461   {
00462   private:
00463     friend class locale;
00464     friend class locale::_Impl;
00465     template<typename _Facet>
00466       friend const _Facet&  
00467       use_facet(const locale&);
00468     template<typename _Facet>
00469       friend bool           
00470       has_facet(const locale&) throw ();
00471 
00472     // NB: There is no accessor for _M_index because it may be used
00473     // before the constructor is run; the effect of calling a member
00474     // function (even an inline) would be undefined.
00475     mutable size_t      _M_index;
00476 
00477     // Last id number assigned.
00478     static _Atomic_word     _S_highwater;   
00479 
00480     void 
00481     operator=(const id&);  // Not defined.
00482 
00483     id(const id&);  // Not defined.
00484 
00485   public:
00486     // NB: This class is always a static data member, and thus can be
00487     // counted on to be zero-initialized.
00488     id();
00489 
00490     inline size_t
00491     _M_id() const
00492     {
00493       if (!_M_index)
00494     _M_index = 1 + __exchange_and_add(&_S_highwater, 1);
00495       return _M_index - 1;
00496     }
00497   };
00498 
00499   template<typename _Facet>
00500     const _Facet&
00501     use_facet(const locale& __loc);
00502 
00503   template<typename _Facet>
00504     bool
00505     has_facet(const locale& __loc) throw();
00506 } // namespace std
00507 
00508 #endif

Generated on Tue Dec 23 12:34:01 2003 for libstdc++-v3 Source by doxygen 1.3.4