Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

localefwd.h

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

Generated on Mon Apr 8 03:11:29 2002 for libstdc++-v3 Source by doxygen1.2.15