1 // std::messages implementation details, GNU version -*- C++ -*-
3 // Copyright (C) 2001-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/messages_members.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{locale}
31 // ISO C++ 14882: 22.2.7.1.2 messages functions
34 // Written by Benjamin Kosnik <bkoz@redhat.com>
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
42 // Non-virtual member functions.
43 template<typename _CharT>
44 messages<_CharT>::messages(size_t __refs)
45 : facet(__refs), _M_c_locale_messages(_S_get_c_locale()),
46 _M_name_messages(_S_get_c_name())
49 template<typename _CharT>
50 messages<_CharT>::messages(__c_locale __cloc, const char* __s,
52 : facet(__refs), _M_c_locale_messages(0), _M_name_messages(0)
54 if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
56 const size_t __len = __builtin_strlen(__s) + 1;
57 char* __tmp = new char[__len];
58 __builtin_memcpy(__tmp, __s, __len);
59 _M_name_messages = __tmp;
62 _M_name_messages = _S_get_c_name();
64 // Last to avoid leaking memory if new throws.
65 _M_c_locale_messages = _S_clone_c_locale(__cloc);
68 template<typename _CharT>
69 typename messages<_CharT>::catalog
70 messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc,
71 const char* __dir) const
73 bindtextdomain(__s.c_str(), __dir);
74 return this->do_open(__s, __loc);
77 // Virtual member functions.
78 template<typename _CharT>
79 messages<_CharT>::~messages()
81 if (_M_name_messages != _S_get_c_name())
82 delete [] _M_name_messages;
83 _S_destroy_c_locale(_M_c_locale_messages);
86 template<typename _CharT>
87 typename messages<_CharT>::catalog
88 messages<_CharT>::do_open(const basic_string<char>& __s,
91 // No error checking is done, assume the catalog exists and can
93 textdomain(__s.c_str());
97 template<typename _CharT>
99 messages<_CharT>::do_close(catalog) const
103 template<typename _CharT>
104 messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
105 : messages<_CharT>(__refs)
107 if (this->_M_name_messages != locale::facet::_S_get_c_name())
109 delete [] this->_M_name_messages;
110 if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
112 const size_t __len = __builtin_strlen(__s) + 1;
113 char* __tmp = new char[__len];
114 __builtin_memcpy(__tmp, __s, __len);
115 this->_M_name_messages = __tmp;
118 this->_M_name_messages = locale::facet::_S_get_c_name();
121 if (__builtin_strcmp(__s, "C") != 0
122 && __builtin_strcmp(__s, "POSIX") != 0)
124 this->_S_destroy_c_locale(this->_M_c_locale_messages);
125 this->_S_create_c_locale(this->_M_c_locale_messages, __s);
129 _GLIBCXX_END_NAMESPACE_VERSION