197403Sobrien// std::messages implementation details, GNU version -*- C++ -*-
297403Sobrien
3169691Skan// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
497403Sobrien//
597403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
697403Sobrien// software; you can redistribute it and/or modify it under the
797403Sobrien// terms of the GNU General Public License as published by the
897403Sobrien// Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien
1197403Sobrien// This library is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien
1697403Sobrien// You should have received a copy of the GNU General Public License along
1797403Sobrien// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1997403Sobrien// USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
30169691Skan/** @file messages_members.h
31169691Skan *  This is an internal header file, included by other library headers.
32169691Skan *  You should not attempt to use it directly.
33169691Skan */
34169691Skan
3597403Sobrien//
36110614Skan// ISO C++ 14882: 22.2.7.1.2  messages functions
3797403Sobrien//
3897403Sobrien
3997403Sobrien// Written by Benjamin Kosnik <bkoz@redhat.com>
4097403Sobrien
41169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
42169691Skan
4397403Sobrien  // Non-virtual member functions.
4497403Sobrien  template<typename _CharT>
45110614Skan     messages<_CharT>::messages(size_t __refs)
46132720Skan     : facet(__refs), _M_c_locale_messages(_S_get_c_locale()),
47169691Skan       _M_name_messages(_S_get_c_name())
48132720Skan     { }
49110614Skan
50110614Skan  template<typename _CharT>
51132720Skan     messages<_CharT>::messages(__c_locale __cloc, const char* __s,
52132720Skan				size_t __refs)
53169691Skan     : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
54110614Skan     {
55169691Skan       const size_t __len = std::strlen(__s) + 1;
56169691Skan       char* __tmp = new char[__len];
57169691Skan       std::memcpy(__tmp, __s, __len);
58132720Skan       _M_name_messages = __tmp;
59169691Skan
60169691Skan       // Last to avoid leaking memory if new throws.
61169691Skan       _M_c_locale_messages = _S_clone_c_locale(__cloc);
62110614Skan     }
63110614Skan
64110614Skan  template<typename _CharT>
6597403Sobrien    typename messages<_CharT>::catalog
6697403Sobrien    messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc,
6797403Sobrien			   const char* __dir) const
6897403Sobrien    {
6997403Sobrien      bindtextdomain(__s.c_str(), __dir);
7097403Sobrien      return this->do_open(__s, __loc);
7197403Sobrien    }
7297403Sobrien
73110614Skan  // Virtual member functions.
7497403Sobrien  template<typename _CharT>
75110614Skan    messages<_CharT>::~messages()
76110614Skan    {
77132720Skan      if (_M_name_messages != _S_get_c_name())
78110614Skan	delete [] _M_name_messages;
79110614Skan      _S_destroy_c_locale(_M_c_locale_messages);
80110614Skan    }
81110614Skan
82110614Skan  template<typename _CharT>
8397403Sobrien    typename messages<_CharT>::catalog
8497403Sobrien    messages<_CharT>::do_open(const basic_string<char>& __s,
8597403Sobrien			      const locale&) const
8697403Sobrien    {
8797403Sobrien      // No error checking is done, assume the catalog exists and can
8897403Sobrien      // be used.
8997403Sobrien      textdomain(__s.c_str());
9097403Sobrien      return 0;
9197403Sobrien    }
9297403Sobrien
9397403Sobrien  template<typename _CharT>
9497403Sobrien    void
9597403Sobrien    messages<_CharT>::do_close(catalog) const
9697403Sobrien    { }
97110614Skan
98110614Skan   // messages_byname
99110614Skan   template<typename _CharT>
100110614Skan     messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
101110614Skan     : messages<_CharT>(__refs)
102110614Skan     {
103132720Skan       if (this->_M_name_messages != locale::facet::_S_get_c_name())
104132720Skan	 delete [] this->_M_name_messages;
105132720Skan       char* __tmp = new char[std::strlen(__s) + 1];
106132720Skan       std::strcpy(__tmp, __s);
107132720Skan       this->_M_name_messages = __tmp;
108132720Skan
109132720Skan       if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
110132720Skan	 {
111132720Skan	   this->_S_destroy_c_locale(this->_M_c_locale_messages);
112132720Skan	   this->_S_create_c_locale(this->_M_c_locale_messages, __s);
113132720Skan	 }
114110614Skan     }
115169691Skan
116169691Skan_GLIBCXX_END_NAMESPACE
117