# messages_members.h

Go to the documentation of this file.

    00001 // std::messages implementation details, GNU version -*- C++ -*-
    00002
    00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
    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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
    00018 // permissions described in the GCC Runtime Library Exception, version
    00019 // 3.1, as published by the Free Software Foundation.
    00020
    00021 // You should have received a copy of the GNU General Public License and
    00022 // a copy of the GCC Runtime Library Exception along with this program;
    00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00024 // <http://www.gnu.org/licenses/>.
    00025
    00026 /** @file messages_members.h
    00027  *  This is an internal header file, included by other library headers.
    00028  *  You should not attempt to use it directly.
    00029  */
    00030
    00031 //
    00032 // ISO C++ 14882: 22.2.7.1.2  messages functions
    00033 //
    00034
    00035 // Written by Benjamin Kosnik <bkoz@redhat.com>
    00036
    00037 #include <libintl.h>
    00038
    00039 _GLIBCXX_BEGIN_NAMESPACE(std)
    00040
    00041   // Non-virtual member functions.
    00042   template<typename _CharT>
    00043      messages<_CharT>::messages(size_t __refs)
    00044      : facet(__refs), _M_c_locale_messages(_S_get_c_locale()),
    00045        _M_name_messages(_S_get_c_name())
    00046      { }
    00047
    00048   template<typename _CharT>
    00049      messages<_CharT>::messages(__c_locale __cloc, const char* __s,
    00050                 size_t __refs)
    00051      : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
    00052      {
    00053        if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
    00054      {
    00055        const size_t __len = __builtin_strlen(__s) + 1;
    00056        char* __tmp = new char[__len];
    00057        __builtin_memcpy(__tmp, __s, __len);
    00058        _M_name_messages = __tmp;
    00059      }
    00060        else
    00061      _M_name_messages = _S_get_c_name();
    00062
    00063        // Last to avoid leaking memory if new throws.
    00064        _M_c_locale_messages = _S_clone_c_locale(__cloc);
    00065      }
    00066
    00067   template<typename _CharT>
    00068     typename messages<_CharT>::catalog
    00069     messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc,
    00070                const char* __dir) const
    00071     {
    00072       bindtextdomain(__s.c_str(), __dir);
    00073       return this->do_open(__s, __loc);
    00074     }
    00075
    00076   // Virtual member functions.
    00077   template<typename _CharT>
    00078     messages<_CharT>::~messages()
    00079     {
    00080       if (_M_name_messages != _S_get_c_name())
    00081     delete [] _M_name_messages;
    00082       _S_destroy_c_locale(_M_c_locale_messages);
    00083     }
    00084
    00085   template<typename _CharT>
    00086     typename messages<_CharT>::catalog
    00087     messages<_CharT>::do_open(const basic_string<char>& __s,
    00088                   const locale&) const
    00089     {
    00090       // No error checking is done, assume the catalog exists and can
    00091       // be used.
    00092       textdomain(__s.c_str());
    00093       return 0;
    00094     }
    00095
    00096   template<typename _CharT>
    00097     void
    00098     messages<_CharT>::do_close(catalog) const
    00099     { }
    00100
    00101    // messages_byname
    00102    template<typename _CharT>
    00103      messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
    00104      : messages<_CharT>(__refs)
    00105      {
    00106        if (this->_M_name_messages != locale::facet::_S_get_c_name())
    00107      {
    00108        delete [] this->_M_name_messages;
    00109        if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
    00110          {
    00111            const size_t __len = __builtin_strlen(__s) + 1;
    00112            char* __tmp = new char[__len];
    00113            __builtin_memcpy(__tmp, __s, __len);
    00114            this->_M_name_messages = __tmp;
    00115          }
    00116        else
    00117          this->_M_name_messages = locale::facet::_S_get_c_name();
    00118      }
    00119
    00120        if (__builtin_strcmp(__s, "C") != 0
    00121        && __builtin_strcmp(__s, "POSIX") != 0)
    00122      {
    00123        this->_S_destroy_c_locale(this->_M_c_locale_messages);
    00124        this->_S_create_c_locale(this->_M_c_locale_messages, __s);
    00125      }
    00126      }
    00127
    00128 _GLIBCXX_END_NAMESPACE