1 // std::messages implementation details, GNU version -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 2, 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 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file messages_members.h
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
37 // ISO C++ 14882: 22.2.7.1.2 messages functions
40 // Written by Benjamin Kosnik <bkoz@redhat.com>
44 _GLIBCXX_BEGIN_NAMESPACE(std)
46 // Non-virtual member functions.
47 template<typename _CharT>
48 messages<_CharT>::messages(size_t __refs)
49 : facet(__refs), _M_c_locale_messages(_S_get_c_locale()),
50 _M_name_messages(_S_get_c_name())
53 template<typename _CharT>
54 messages<_CharT>::messages(__c_locale __cloc, const char* __s,
56 : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
58 if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
60 const size_t __len = __builtin_strlen(__s) + 1;
61 char* __tmp = new char[__len];
62 __builtin_memcpy(__tmp, __s, __len);
63 _M_name_messages = __tmp;
66 _M_name_messages = _S_get_c_name();
68 // Last to avoid leaking memory if new throws.
69 _M_c_locale_messages = _S_clone_c_locale(__cloc);
72 template<typename _CharT>
73 typename messages<_CharT>::catalog
74 messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc,
75 const char* __dir) const
77 bindtextdomain(__s.c_str(), __dir);
78 return this->do_open(__s, __loc);
81 // Virtual member functions.
82 template<typename _CharT>
83 messages<_CharT>::~messages()
85 if (_M_name_messages != _S_get_c_name())
86 delete [] _M_name_messages;
87 _S_destroy_c_locale(_M_c_locale_messages);
90 template<typename _CharT>
91 typename messages<_CharT>::catalog
92 messages<_CharT>::do_open(const basic_string<char>& __s,
95 // No error checking is done, assume the catalog exists and can
97 textdomain(__s.c_str());
101 template<typename _CharT>
103 messages<_CharT>::do_close(catalog) const
107 template<typename _CharT>
108 messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
109 : messages<_CharT>(__refs)
111 if (this->_M_name_messages != locale::facet::_S_get_c_name())
113 delete [] this->_M_name_messages;
114 if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
116 const size_t __len = __builtin_strlen(__s) + 1;
117 char* __tmp = new char[__len];
118 __builtin_memcpy(__tmp, __s, __len);
119 this->_M_name_messages = __tmp;
122 this->_M_name_messages = locale::facet::_S_get_c_name();
125 if (__builtin_strcmp(__s, "C") != 0
126 && __builtin_strcmp(__s, "POSIX") != 0)
128 this->_S_destroy_c_locale(this->_M_c_locale_messages);
129 this->_S_create_c_locale(this->_M_c_locale_messages, __s);
133 _GLIBCXX_END_NAMESPACE