locale_classes.h

Go to the documentation of this file.
00001 // Locale support -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00004 // 2006, 2007, 2008
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 2, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // You should have received a copy of the GNU General Public License along
00019 // with this library; see the file COPYING.  If not, write to the Free
00020 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00021 // USA.
00022 
00023 // As a special exception, you may use this file as part of a free software
00024 // library without restriction.  Specifically, if other files instantiate
00025 // templates or use macros or inline functions from this file, or you compile
00026 // this file and link it with other files to produce an executable, this
00027 // file does not by itself cause the resulting executable to be covered by
00028 // the GNU General Public License.  This exception does not however
00029 // invalidate any other reasons why the executable file might be covered by
00030 // the GNU General Public License.
00031 
00032 /** @file locale_classes.h
00033  *  This is an internal header file, included by other library headers.
00034  *  You should not attempt to use it directly.
00035  */
00036 
00037 //
00038 // ISO C++ 14882: 22.1  Locales
00039 //
00040 
00041 #ifndef _LOCALE_CLASSES_H
00042 #define _LOCALE_CLASSES_H 1
00043 
00044 #pragma GCC system_header
00045 
00046 #include <bits/localefwd.h>
00047 #include <string>
00048 #include <ext/atomicity.h>
00049 
00050 _GLIBCXX_BEGIN_NAMESPACE(std)
00051 
00052   // 22.1.1 Class locale
00053   /**
00054    *  @brief  Container class for localization functionality.
00055    *
00056    *  The locale class is first a class wrapper for C library locales.  It is
00057    *  also an extensible container for user-defined localization.  A locale is
00058    *  a collection of facets that implement various localization features such
00059    *  as money, time, and number printing.
00060    *
00061    *  Constructing C++ locales does not change the C library locale.
00062    *
00063    *  This library supports efficient construction and copying of locales
00064    *  through a reference counting implementation of the locale class.
00065   */
00066   class locale
00067   {
00068   public:
00069     // Types:
00070     /// Definition of locale::category.
00071     typedef int category;
00072 
00073     // Forward decls and friends:
00074     class facet;
00075     class id;
00076     class _Impl;
00077 
00078     friend class facet;
00079     friend class _Impl;
00080 
00081     template<typename _Facet>
00082       friend bool
00083       has_facet(const locale&) throw();
00084 
00085     template<typename _Facet>
00086       friend const _Facet&
00087       use_facet(const locale&);
00088 
00089     template<typename _Cache>
00090       friend struct __use_cache;
00091 
00092     //@{
00093     /**
00094      *  @brief  Category values.
00095      *
00096      *  The standard category values are none, ctype, numeric, collate, time,
00097      *  monetary, and messages.  They form a bitmask that supports union and
00098      *  intersection.  The category all is the union of these values.
00099      *
00100      *  NB: Order must match _S_facet_categories definition in locale.cc
00101     */
00102     static const category none      = 0;
00103     static const category ctype     = 1L << 0;
00104     static const category numeric   = 1L << 1;
00105     static const category collate   = 1L << 2;
00106     static const category time      = 1L << 3;
00107     static const category monetary  = 1L << 4;
00108     static const category messages  = 1L << 5;
00109     static const category all       = (ctype | numeric | collate |
00110                        time  | monetary | messages);
00111     //@}
00112 
00113     // Construct/copy/destroy:
00114 
00115     /**
00116      *  @brief  Default constructor.
00117      *
00118      *  Constructs a copy of the global locale.  If no locale has been
00119      *  explicitly set, this is the "C" locale.
00120     */
00121     locale() throw();
00122 
00123     /**
00124      *  @brief  Copy constructor.
00125      *
00126      *  Constructs a copy of @a other.
00127      *
00128      *  @param  other  The locale to copy.
00129     */
00130     locale(const locale& __other) throw();
00131 
00132     /**
00133      *  @brief  Named locale constructor.
00134      *
00135      *  Constructs a copy of the named C library locale.
00136      *
00137      *  @param  s  Name of the locale to construct.
00138      *  @throw  std::runtime_error if s is null or an undefined locale.
00139     */
00140     explicit
00141     locale(const char* __s);
00142 
00143     /**
00144      *  @brief  Construct locale with facets from another locale.
00145      *
00146      *  Constructs a copy of the locale @a base.  The facets specified by @a
00147      *  cat are replaced with those from the locale named by @a s.  If base is
00148      *  named, this locale instance will also be named.
00149      *
00150      *  @param  base  The locale to copy.
00151      *  @param  s  Name of the locale to use facets from.
00152      *  @param  cat  Set of categories defining the facets to use from s.
00153      *  @throw  std::runtime_error if s is null or an undefined locale.
00154     */
00155     locale(const locale& __base, const char* __s, category __cat);
00156 
00157     /**
00158      *  @brief  Construct locale with facets from another locale.
00159      *
00160      *  Constructs a copy of the locale @a base.  The facets specified by @a
00161      *  cat are replaced with those from the locale @a add.  If @a base and @a
00162      *  add are named, this locale instance will also be named.
00163      *
00164      *  @param  base  The locale to copy.
00165      *  @param  add  The locale to use facets from.
00166      *  @param  cat  Set of categories defining the facets to use from add.
00167     */
00168     locale(const locale& __base, const locale& __add, category __cat);
00169 
00170     /**
00171      *  @brief  Construct locale with another facet.
00172      *
00173      *  Constructs a copy of the locale @a other.  The facet @f is added to
00174      *  @other, replacing an existing facet of type Facet if there is one.  If
00175      *  @f is null, this locale is a copy of @a other.
00176      *
00177      *  @param  other  The locale to copy.
00178      *  @param  f  The facet to add in.
00179     */
00180     template<typename _Facet>
00181       locale(const locale& __other, _Facet* __f);
00182 
00183     /// Locale destructor.
00184     ~locale() throw();
00185 
00186     /**
00187      *  @brief  Assignment operator.
00188      *
00189      *  Set this locale to be a copy of @a other.
00190      *
00191      *  @param  other  The locale to copy.
00192      *  @return  A reference to this locale.
00193     */
00194     const locale&
00195     operator=(const locale& __other) throw();
00196 
00197     /**
00198      *  @brief  Construct locale with another facet.
00199      *
00200      *  Constructs and returns a new copy of this locale.  Adds or replaces an
00201      *  existing facet of type Facet from the locale @a other into the new
00202      *  locale.
00203      *
00204      *  @param  Facet  The facet type to copy from other
00205      *  @param  other  The locale to copy from.
00206      *  @return  Newly constructed locale.
00207      *  @throw  std::runtime_error if other has no facet of type Facet.
00208     */
00209     template<typename _Facet>
00210       locale
00211       combine(const locale& __other) const;
00212 
00213     // Locale operations:
00214     /**
00215      *  @brief  Return locale name.
00216      *  @return  Locale name or "*" if unnamed.
00217     */
00218     string
00219     name() const;
00220 
00221     /**
00222      *  @brief  Locale equality.
00223      *
00224      *  @param  other  The locale to compare against.
00225      *  @return  True if other and this refer to the same locale instance, are
00226      *       copies, or have the same name.  False otherwise.
00227     */
00228     bool
00229     operator==(const locale& __other) const throw ();
00230 
00231     /**
00232      *  @brief  Locale inequality.
00233      *
00234      *  @param  other  The locale to compare against.
00235      *  @return  ! (*this == other)
00236     */
00237     bool
00238     operator!=(const locale& __other) const throw ()
00239     { return !(this->operator==(__other)); }
00240 
00241     /**
00242      *  @brief  Compare two strings according to collate.
00243      *
00244      *  Template operator to compare two strings using the compare function of
00245      *  the collate facet in this locale.  One use is to provide the locale to
00246      *  the sort function.  For example, a vector v of strings could be sorted
00247      *  according to locale loc by doing:
00248      *  @code
00249      *  std::sort(v.begin(), v.end(), loc);
00250      *  @endcode
00251      *
00252      *  @param  s1  First string to compare.
00253      *  @param  s2  Second string to compare.
00254      *  @return  True if collate<Char> facet compares s1 < s2, else false.
00255     */
00256     template<typename _Char, typename _Traits, typename _Alloc>
00257       bool
00258       operator()(const basic_string<_Char, _Traits, _Alloc>& __s1,
00259          const basic_string<_Char, _Traits, _Alloc>& __s2) const;
00260 
00261     // Global locale objects:
00262     /**
00263      *  @brief  Set global locale
00264      *
00265      *  This function sets the global locale to the argument and returns a
00266      *  copy of the previous global locale.  If the argument has a name, it
00267      *  will also call std::setlocale(LC_ALL, loc.name()).
00268      *
00269      *  @param  locale  The new locale to make global.
00270      *  @return  Copy of the old global locale.
00271     */
00272     static locale
00273     global(const locale&);
00274 
00275     /**
00276      *  @brief  Return reference to the "C" locale.
00277     */
00278     static const locale&
00279     classic();
00280 
00281   private:
00282     // The (shared) implementation
00283     _Impl*      _M_impl;
00284 
00285     // The "C" reference locale
00286     static _Impl*       _S_classic;
00287 
00288     // Current global locale
00289     static _Impl*   _S_global;
00290 
00291     // Names of underlying locale categories.
00292     // NB: locale::global() has to know how to modify all the
00293     // underlying categories, not just the ones required by the C++
00294     // standard.
00295     static const char* const* const _S_categories;
00296 
00297     // Number of standard categories. For C++, these categories are
00298     // collate, ctype, monetary, numeric, time, and messages. These
00299     // directly correspond to ISO C99 macros LC_COLLATE, LC_CTYPE,
00300     // LC_MONETARY, LC_NUMERIC, and LC_TIME. In addition, POSIX (IEEE
00301     // 1003.1-2001) specifies LC_MESSAGES.
00302     // In addition to the standard categories, the underlying
00303     // operating system is allowed to define extra LC_*
00304     // macros. For GNU systems, the following are also valid:
00305     // LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT,
00306     // and LC_IDENTIFICATION.
00307     enum { _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES };
00308 
00309 #ifdef __GTHREADS
00310     static __gthread_once_t _S_once;
00311 #endif
00312 
00313     explicit
00314     locale(_Impl*) throw();
00315 
00316     static void
00317     _S_initialize();
00318 
00319     static void
00320     _S_initialize_once();
00321 
00322     static category
00323     _S_normalize_category(category);
00324 
00325     void
00326     _M_coalesce(const locale& __base, const locale& __add, category __cat);
00327   };
00328 
00329 
00330   // 22.1.1.1.2  Class locale::facet
00331   /**
00332    *  @brief  Localization functionality base class.
00333    *
00334    *  The facet class is the base class for a localization feature, such as
00335    *  money, time, and number printing.  It provides common support for facets
00336    *  and reference management.
00337    *
00338    *  Facets may not be copied or assigned.
00339   */
00340   class locale::facet
00341   {
00342   private:
00343     friend class locale;
00344     friend class locale::_Impl;
00345 
00346     mutable _Atomic_word        _M_refcount;
00347 
00348     // Contains data from the underlying "C" library for the classic locale.
00349     static __c_locale                   _S_c_locale;
00350 
00351     // String literal for the name of the classic locale.
00352     static const char           _S_c_name[2];
00353 
00354 #ifdef __GTHREADS
00355     static __gthread_once_t     _S_once;
00356 #endif
00357 
00358     static void
00359     _S_initialize_once();
00360 
00361   protected:
00362     /**
00363      *  @brief  Facet constructor.
00364      *
00365      *  This is the constructor provided by the standard.  If refs is 0, the
00366      *  facet is destroyed when the last referencing locale is destroyed.
00367      *  Otherwise the facet will never be destroyed.
00368      *
00369      *  @param refs  The initial value for reference count.
00370     */
00371     explicit
00372     facet(size_t __refs = 0) throw() : _M_refcount(__refs ? 1 : 0)
00373     { }
00374 
00375     /// Facet destructor.
00376     virtual
00377     ~facet();
00378 
00379     static void
00380     _S_create_c_locale(__c_locale& __cloc, const char* __s,
00381                __c_locale __old = 0);
00382 
00383     static __c_locale
00384     _S_clone_c_locale(__c_locale& __cloc);
00385 
00386     static void
00387     _S_destroy_c_locale(__c_locale& __cloc);
00388 
00389     // Returns data from the underlying "C" library data for the
00390     // classic locale.
00391     static __c_locale
00392     _S_get_c_locale();
00393 
00394     static const char*
00395     _S_get_c_name();
00396 
00397   private:
00398     void
00399     _M_add_reference() const throw()
00400     { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00401 
00402     void
00403     _M_remove_reference() const throw()
00404     {
00405       if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
00406     {
00407       try
00408         { delete this; }
00409       catch(...)
00410         { }
00411     }
00412     }
00413 
00414     facet(const facet&);  // Not defined.
00415 
00416     facet&
00417     operator=(const facet&);  // Not defined.
00418   };
00419 
00420 
00421   // 22.1.1.1.3 Class locale::id
00422   /**
00423    *  @brief  Facet ID class.
00424    *
00425    *  The ID class provides facets with an index used to identify them.
00426    *  Every facet class must define a public static member locale::id, or be
00427    *  derived from a facet that provides this member, otherwise the facet
00428    *  cannot be used in a locale.  The locale::id ensures that each class
00429    *  type gets a unique identifier.
00430   */
00431   class locale::id
00432   {
00433   private:
00434     friend class locale;
00435     friend class locale::_Impl;
00436 
00437     template<typename _Facet>
00438       friend const _Facet&
00439       use_facet(const locale&);
00440 
00441     template<typename _Facet>
00442       friend bool
00443       has_facet(const locale&) throw ();
00444 
00445     // NB: There is no accessor for _M_index because it may be used
00446     // before the constructor is run; the effect of calling a member
00447     // function (even an inline) would be undefined.
00448     mutable size_t      _M_index;
00449 
00450     // Last id number assigned.
00451     static _Atomic_word     _S_refcount;
00452 
00453     void
00454     operator=(const id&);  // Not defined.
00455 
00456     id(const id&);  // Not defined.
00457 
00458   public:
00459     // NB: This class is always a static data member, and thus can be
00460     // counted on to be zero-initialized.
00461     /// Constructor.
00462     id() { }
00463 
00464     size_t
00465     _M_id() const;
00466   };
00467 
00468 
00469   // Implementation object for locale.
00470   class locale::_Impl
00471   {
00472   public:
00473     // Friends.
00474     friend class locale;
00475     friend class locale::facet;
00476 
00477     template<typename _Facet>
00478       friend bool
00479       has_facet(const locale&) throw();
00480 
00481     template<typename _Facet>
00482       friend const _Facet&
00483       use_facet(const locale&);
00484 
00485     template<typename _Cache>
00486       friend struct __use_cache;
00487 
00488   private:
00489     // Data Members.
00490     _Atomic_word            _M_refcount;
00491     const facet**           _M_facets;
00492     size_t              _M_facets_size;
00493     const facet**           _M_caches;
00494     char**              _M_names;
00495     static const locale::id* const  _S_id_ctype[];
00496     static const locale::id* const  _S_id_numeric[];
00497     static const locale::id* const  _S_id_collate[];
00498     static const locale::id* const  _S_id_time[];
00499     static const locale::id* const  _S_id_monetary[];
00500     static const locale::id* const  _S_id_messages[];
00501     static const locale::id* const* const _S_facet_categories[];
00502 
00503     void
00504     _M_add_reference() throw()
00505     { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00506 
00507     void
00508     _M_remove_reference() throw()
00509     {
00510       if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
00511     {
00512       try
00513         { delete this; }
00514       catch(...)
00515         { }
00516     }
00517     }
00518 
00519     _Impl(const _Impl&, size_t);
00520     _Impl(const char*, size_t);
00521     _Impl(size_t) throw();
00522 
00523    ~_Impl() throw();
00524 
00525     _Impl(const _Impl&);  // Not defined.
00526 
00527     void
00528     operator=(const _Impl&);  // Not defined.
00529 
00530     bool
00531     _M_check_same_name()
00532     {
00533       bool __ret = true;
00534       if (_M_names[1])
00535     // We must actually compare all the _M_names: can be all equal!
00536     for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i)
00537       __ret = __builtin_strcmp(_M_names[__i], _M_names[__i + 1]) == 0;
00538       return __ret;
00539     }
00540 
00541     void
00542     _M_replace_categories(const _Impl*, category);
00543 
00544     void
00545     _M_replace_category(const _Impl*, const locale::id* const*);
00546 
00547     void
00548     _M_replace_facet(const _Impl*, const locale::id*);
00549 
00550     void
00551     _M_install_facet(const locale::id*, const facet*);
00552 
00553     template<typename _Facet>
00554       void
00555       _M_init_facet(_Facet* __facet)
00556       { _M_install_facet(&_Facet::id, __facet); }
00557 
00558     void
00559     _M_install_cache(const facet*, size_t);
00560   };
00561 
00562 
00563   /**
00564    *  @brief  Test for the presence of a facet.
00565    *
00566    *  has_facet tests the locale argument for the presence of the facet type
00567    *  provided as the template parameter.  Facets derived from the facet
00568    *  parameter will also return true.
00569    *
00570    *  @param  Facet  The facet type to test the presence of.
00571    *  @param  locale  The locale to test.
00572    *  @return  true if locale contains a facet of type Facet, else false.
00573   */
00574   template<typename _Facet>
00575     bool
00576     has_facet(const locale& __loc) throw();
00577 
00578   /**
00579    *  @brief  Return a facet.
00580    *
00581    *  use_facet looks for and returns a reference to a facet of type Facet
00582    *  where Facet is the template parameter.  If has_facet(locale) is true,
00583    *  there is a suitable facet to return.  It throws std::bad_cast if the
00584    *  locale doesn't contain a facet of type Facet.
00585    *
00586    *  @param  Facet  The facet type to access.
00587    *  @param  locale  The locale to use.
00588    *  @return  Reference to facet of type Facet.
00589    *  @throw  std::bad_cast if locale doesn't contain a facet of type Facet.
00590   */
00591   template<typename _Facet>
00592     const _Facet&
00593     use_facet(const locale& __loc);
00594 
00595 
00596   /**
00597    *  @brief  Facet for localized string comparison.
00598    *
00599    *  This facet encapsulates the code to compare strings in a localized
00600    *  manner.
00601    *
00602    *  The collate template uses protected virtual functions to provide
00603    *  the actual results.  The public accessors forward the call to
00604    *  the virtual functions.  These virtual functions are hooks for
00605    *  developers to implement the behavior they require from the
00606    *  collate facet.
00607   */
00608   template<typename _CharT>
00609     class collate : public locale::facet
00610     {
00611     public:
00612       // Types:
00613       //@{
00614       /// Public typedefs
00615       typedef _CharT            char_type;
00616       typedef basic_string<_CharT>  string_type;
00617       //@}
00618 
00619     protected:
00620       // Underlying "C" library locale information saved from
00621       // initialization, needed by collate_byname as well.
00622       __c_locale            _M_c_locale_collate;
00623 
00624     public:
00625       /// Numpunct facet id.
00626       static locale::id         id;
00627 
00628       /**
00629        *  @brief  Constructor performs initialization.
00630        *
00631        *  This is the constructor provided by the standard.
00632        *
00633        *  @param refs  Passed to the base facet class.
00634       */
00635       explicit
00636       collate(size_t __refs = 0)
00637       : facet(__refs), _M_c_locale_collate(_S_get_c_locale())
00638       { }
00639 
00640       /**
00641        *  @brief  Internal constructor. Not for general use.
00642        *
00643        *  This is a constructor for use by the library itself to set up new
00644        *  locales.
00645        *
00646        *  @param cloc  The "C" locale.
00647        *  @param refs  Passed to the base facet class.
00648       */
00649       explicit
00650       collate(__c_locale __cloc, size_t __refs = 0)
00651       : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc))
00652       { }
00653 
00654       /**
00655        *  @brief  Compare two strings.
00656        *
00657        *  This function compares two strings and returns the result by calling
00658        *  collate::do_compare().
00659        *
00660        *  @param lo1  Start of string 1.
00661        *  @param hi1  End of string 1.
00662        *  @param lo2  Start of string 2.
00663        *  @param hi2  End of string 2.
00664        *  @return  1 if string1 > string2, -1 if string1 < string2, else 0.
00665       */
00666       int
00667       compare(const _CharT* __lo1, const _CharT* __hi1,
00668           const _CharT* __lo2, const _CharT* __hi2) const
00669       { return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
00670 
00671       /**
00672        *  @brief  Transform string to comparable form.
00673        *
00674        *  This function is a wrapper for strxfrm functionality.  It takes the
00675        *  input string and returns a modified string that can be directly
00676        *  compared to other transformed strings.  In the "C" locale, this
00677        *  function just returns a copy of the input string.  In some other
00678        *  locales, it may replace two chars with one, change a char for
00679        *  another, etc.  It does so by returning collate::do_transform().
00680        *
00681        *  @param lo  Start of string.
00682        *  @param hi  End of string.
00683        *  @return  Transformed string_type.
00684       */
00685       string_type
00686       transform(const _CharT* __lo, const _CharT* __hi) const
00687       { return this->do_transform(__lo, __hi); }
00688 
00689       /**
00690        *  @brief  Return hash of a string.
00691        *
00692        *  This function computes and returns a hash on the input string.  It
00693        *  does so by returning collate::do_hash().
00694        *
00695        *  @param lo  Start of string.
00696        *  @param hi  End of string.
00697        *  @return  Hash value.
00698       */
00699       long
00700       hash(const _CharT* __lo, const _CharT* __hi) const
00701       { return this->do_hash(__lo, __hi); }
00702 
00703       // Used to abstract out _CharT bits in virtual member functions, below.
00704       int
00705       _M_compare(const _CharT*, const _CharT*) const;
00706 
00707       size_t
00708       _M_transform(_CharT*, const _CharT*, size_t) const;
00709 
00710   protected:
00711       /// Destructor.
00712       virtual
00713       ~collate()
00714       { _S_destroy_c_locale(_M_c_locale_collate); }
00715 
00716       /**
00717        *  @brief  Compare two strings.
00718        *
00719        *  This function is a hook for derived classes to change the value
00720        *  returned.  @see compare().
00721        *
00722        *  @param lo1  Start of string 1.
00723        *  @param hi1  End of string 1.
00724        *  @param lo2  Start of string 2.
00725        *  @param hi2  End of string 2.
00726        *  @return  1 if string1 > string2, -1 if string1 < string2, else 0.
00727       */
00728       virtual int
00729       do_compare(const _CharT* __lo1, const _CharT* __hi1,
00730          const _CharT* __lo2, const _CharT* __hi2) const;
00731 
00732       /**
00733        *  @brief  Transform string to comparable form.
00734        *
00735        *  This function is a hook for derived classes to change the value
00736        *  returned.
00737        *
00738        *  @param lo1  Start of string 1.
00739        *  @param hi1  End of string 1.
00740        *  @param lo2  Start of string 2.
00741        *  @param hi2  End of string 2.
00742        *  @return  1 if string1 > string2, -1 if string1 < string2, else 0.
00743       */
00744       virtual string_type
00745       do_transform(const _CharT* __lo, const _CharT* __hi) const;
00746 
00747       /**
00748        *  @brief  Return hash of a string.
00749        *
00750        *  This function computes and returns a hash on the input string.  This
00751        *  function is a hook for derived classes to change the value returned.
00752        *
00753        *  @param lo  Start of string.
00754        *  @param hi  End of string.
00755        *  @return  Hash value.
00756       */
00757       virtual long
00758       do_hash(const _CharT* __lo, const _CharT* __hi) const;
00759     };
00760 
00761   template<typename _CharT>
00762     locale::id collate<_CharT>::id;
00763 
00764   // Specializations.
00765   template<>
00766     int
00767     collate<char>::_M_compare(const char*, const char*) const;
00768 
00769   template<>
00770     size_t
00771     collate<char>::_M_transform(char*, const char*, size_t) const;
00772 
00773 #ifdef _GLIBCXX_USE_WCHAR_T
00774   template<>
00775     int
00776     collate<wchar_t>::_M_compare(const wchar_t*, const wchar_t*) const;
00777 
00778   template<>
00779     size_t
00780     collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const;
00781 #endif
00782 
00783   /// class collate_byname [22.2.4.2].
00784   template<typename _CharT>
00785     class collate_byname : public collate<_CharT>
00786     {
00787     public:
00788       //@{
00789       /// Public typedefs
00790       typedef _CharT               char_type;
00791       typedef basic_string<_CharT> string_type;
00792       //@}
00793 
00794       explicit
00795       collate_byname(const char* __s, size_t __refs = 0)
00796       : collate<_CharT>(__refs)
00797       {
00798     if (__builtin_strcmp(__s, "C") != 0
00799         && __builtin_strcmp(__s, "POSIX") != 0)
00800       {
00801         this->_S_destroy_c_locale(this->_M_c_locale_collate);
00802         this->_S_create_c_locale(this->_M_c_locale_collate, __s);
00803       }
00804       }
00805 
00806     protected:
00807       virtual
00808       ~collate_byname() { }
00809     };
00810 
00811 _GLIBCXX_END_NAMESPACE
00812 
00813 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00814 # include <bits/locale_classes.tcc>
00815 #endif
00816 
00817 #endif

Generated on Wed Mar 26 00:43:00 2008 for libstdc++ by  doxygen 1.5.1