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
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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 /** @file messages_members.h
00032  *  This is an internal header file, included by other library headers.
00033  *  You should not attempt to use it directly.
00034  */
00035 
00036 //
00037 // ISO C++ 14882: 22.2.7.1.2  messages functions
00038 //
00039 
00040 // Written by Benjamin Kosnik <bkoz@redhat.com>
00041 
00042 #include <libintl.h>
00043 
00044 _GLIBCXX_BEGIN_NAMESPACE(std)
00045 
00046   // Non-virtual member functions.
00047   template<typename _CharT>
00048      messages<_CharT>::messages(size_t __refs)
00049      : facet(__refs), _M_c_locale_messages(_S_get_c_locale()), 
00050        _M_name_messages(_S_get_c_name())
00051      { }
00052 
00053   template<typename _CharT>
00054      messages<_CharT>::messages(__c_locale __cloc, const char* __s, 
00055                 size_t __refs) 
00056      : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
00057      {
00058        if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
00059      {
00060        const size_t __len = __builtin_strlen(__s) + 1;
00061        char* __tmp = new char[__len];
00062        __builtin_memcpy(__tmp, __s, __len);
00063        _M_name_messages = __tmp;
00064      }
00065        else
00066      _M_name_messages = _S_get_c_name();
00067 
00068        // Last to avoid leaking memory if new throws.
00069        _M_c_locale_messages = _S_clone_c_locale(__cloc);
00070      }
00071 
00072   template<typename _CharT>
00073     typename messages<_CharT>::catalog 
00074     messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc, 
00075                const char* __dir) const
00076     { 
00077       bindtextdomain(__s.c_str(), __dir);
00078       return this->do_open(__s, __loc); 
00079     }
00080 
00081   // Virtual member functions.
00082   template<typename _CharT>
00083     messages<_CharT>::~messages()
00084     { 
00085       if (_M_name_messages != _S_get_c_name())
00086     delete [] _M_name_messages;
00087       _S_destroy_c_locale(_M_c_locale_messages); 
00088     }
00089 
00090   template<typename _CharT>
00091     typename messages<_CharT>::catalog 
00092     messages<_CharT>::do_open(const basic_string<char>& __s, 
00093                   const locale&) const
00094     { 
00095       // No error checking is done, assume the catalog exists and can
00096       // be used.
00097       textdomain(__s.c_str());
00098       return 0;
00099     }
00100 
00101   template<typename _CharT>
00102     void    
00103     messages<_CharT>::do_close(catalog) const 
00104     { }
00105 
00106    // messages_byname
00107    template<typename _CharT>
00108      messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
00109      : messages<_CharT>(__refs) 
00110      { 
00111        if (this->_M_name_messages != locale::facet::_S_get_c_name())
00112      {
00113        delete [] this->_M_name_messages;
00114        if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
00115          {
00116            const size_t __len = __builtin_strlen(__s) + 1;
00117            char* __tmp = new char[__len];
00118            __builtin_memcpy(__tmp, __s, __len);
00119            this->_M_name_messages = __tmp;
00120          }
00121        else
00122          this->_M_name_messages = locale::facet::_S_get_c_name();
00123      }
00124 
00125        if (__builtin_strcmp(__s, "C") != 0
00126        && __builtin_strcmp(__s, "POSIX") != 0)
00127      {
00128        this->_S_destroy_c_locale(this->_M_c_locale_messages);
00129        this->_S_create_c_locale(this->_M_c_locale_messages, __s); 
00130      }
00131      }
00132 
00133 _GLIBCXX_END_NAMESPACE

Generated on Sat Dec 12 09:40:12 2009 for libstdc++ by  doxygen 1.5.6