libstdc++
|
00001 // std::messages implementation details, GNU version -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 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 bits/messages_members.h 00027 * This is an internal header file, included by other library headers. 00028 * Do not attempt to use it directly. @headername{locale} 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 namespace std _GLIBCXX_VISIBILITY(default) 00040 { 00041 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00042 00043 // Non-virtual member functions. 00044 template<typename _CharT> 00045 messages<_CharT>::messages(size_t __refs) 00046 : facet(__refs), _M_c_locale_messages(_S_get_c_locale()), 00047 _M_name_messages(_S_get_c_name()) 00048 { } 00049 00050 template<typename _CharT> 00051 messages<_CharT>::messages(__c_locale __cloc, const char* __s, 00052 size_t __refs) 00053 : facet(__refs), _M_c_locale_messages(0), _M_name_messages(0) 00054 { 00055 if (__builtin_strcmp(__s, _S_get_c_name()) != 0) 00056 { 00057 const size_t __len = __builtin_strlen(__s) + 1; 00058 char* __tmp = new char[__len]; 00059 __builtin_memcpy(__tmp, __s, __len); 00060 _M_name_messages = __tmp; 00061 } 00062 else 00063 _M_name_messages = _S_get_c_name(); 00064 00065 // Last to avoid leaking memory if new throws. 00066 _M_c_locale_messages = _S_clone_c_locale(__cloc); 00067 } 00068 00069 template<typename _CharT> 00070 typename messages<_CharT>::catalog 00071 messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc, 00072 const char* __dir) const 00073 { 00074 bindtextdomain(__s.c_str(), __dir); 00075 return this->do_open(__s, __loc); 00076 } 00077 00078 // Virtual member functions. 00079 template<typename _CharT> 00080 messages<_CharT>::~messages() 00081 { 00082 if (_M_name_messages != _S_get_c_name()) 00083 delete [] _M_name_messages; 00084 _S_destroy_c_locale(_M_c_locale_messages); 00085 } 00086 00087 template<typename _CharT> 00088 typename messages<_CharT>::catalog 00089 messages<_CharT>::do_open(const basic_string<char>& __s, 00090 const locale&) const 00091 { 00092 // No error checking is done, assume the catalog exists and can 00093 // be used. 00094 textdomain(__s.c_str()); 00095 return 0; 00096 } 00097 00098 template<typename _CharT> 00099 void 00100 messages<_CharT>::do_close(catalog) const 00101 { } 00102 00103 // messages_byname 00104 template<typename _CharT> 00105 messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs) 00106 : messages<_CharT>(__refs) 00107 { 00108 if (this->_M_name_messages != locale::facet::_S_get_c_name()) 00109 { 00110 delete [] this->_M_name_messages; 00111 if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0) 00112 { 00113 const size_t __len = __builtin_strlen(__s) + 1; 00114 char* __tmp = new char[__len]; 00115 __builtin_memcpy(__tmp, __s, __len); 00116 this->_M_name_messages = __tmp; 00117 } 00118 else 00119 this->_M_name_messages = locale::facet::_S_get_c_name(); 00120 } 00121 00122 if (__builtin_strcmp(__s, "C") != 0 00123 && __builtin_strcmp(__s, "POSIX") != 0) 00124 { 00125 this->_S_destroy_c_locale(this->_M_c_locale_messages); 00126 this->_S_create_c_locale(this->_M_c_locale_messages, __s); 00127 } 00128 } 00129 00130 _GLIBCXX_END_NAMESPACE_VERSION 00131 } // namespace