1 // std::messages implementation details, GNU version -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file messages_members.h
27 * This is an internal header file, included by other library headers.
28 * You should not attempt to use it directly.
32 // ISO C++ 14882: 22.2.7.1.2 messages functions
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
39 _GLIBCXX_BEGIN_NAMESPACE(std)
41 // Non-virtual member functions.
42 template<typename _CharT>
43 messages<_CharT>::messages(size_t __refs)
44 : facet(__refs), _M_c_locale_messages(_S_get_c_locale()),
45 _M_name_messages(_S_get_c_name())
48 template<typename _CharT>
49 messages<_CharT>::messages(__c_locale __cloc, const char* __s,
51 : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
53 if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
55 const size_t __len = __builtin_strlen(__s) + 1;
56 char* __tmp = new char[__len];
57 __builtin_memcpy(__tmp, __s, __len);
58 _M_name_messages = __tmp;
61 _M_name_messages = _S_get_c_name();
63 // Last to avoid leaking memory if new throws.
64 _M_c_locale_messages = _S_clone_c_locale(__cloc);
67 template<typename _CharT>
68 typename messages<_CharT>::catalog
69 messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc,
70 const char* __dir) const
72 bindtextdomain(__s.c_str(), __dir);
73 return this->do_open(__s, __loc);
76 // Virtual member functions.
77 template<typename _CharT>
78 messages<_CharT>::~messages()
80 if (_M_name_messages != _S_get_c_name())
81 delete [] _M_name_messages;
82 _S_destroy_c_locale(_M_c_locale_messages);
85 template<typename _CharT>
86 typename messages<_CharT>::catalog
87 messages<_CharT>::do_open(const basic_string<char>& __s,
90 // No error checking is done, assume the catalog exists and can
92 textdomain(__s.c_str());
96 template<typename _CharT>
98 messages<_CharT>::do_close(catalog) const
102 template<typename _CharT>
103 messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
104 : messages<_CharT>(__refs)
106 if (this->_M_name_messages != locale::facet::_S_get_c_name())
108 delete [] this->_M_name_messages;
109 if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
111 const size_t __len = __builtin_strlen(__s) + 1;
112 char* __tmp = new char[__len];
113 __builtin_memcpy(__tmp, __s, __len);
114 this->_M_name_messages = __tmp;
117 this->_M_name_messages = locale::facet::_S_get_c_name();
120 if (__builtin_strcmp(__s, "C") != 0
121 && __builtin_strcmp(__s, "POSIX") != 0)
123 this->_S_destroy_c_locale(this->_M_c_locale_messages);
124 this->_S_create_c_locale(this->_M_c_locale_messages, __s);
128 _GLIBCXX_END_NAMESPACE