OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / config / locale / gnu / messages_members.h
1 // std::messages implementation details, GNU version -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11
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.
16
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.
20
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/>.
25
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.
29  */
30
31 //
32 // ISO C++ 14882: 22.2.7.1.2  messages functions
33 //
34
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
36
37 #include <libintl.h>
38
39 _GLIBCXX_BEGIN_NAMESPACE(std)
40
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())
46      { }
47
48   template<typename _CharT>
49      messages<_CharT>::messages(__c_locale __cloc, const char* __s, 
50                                 size_t __refs) 
51      : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
52      {
53        if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
54          {
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;
59          }
60        else
61          _M_name_messages = _S_get_c_name();
62
63        // Last to avoid leaking memory if new throws.
64        _M_c_locale_messages = _S_clone_c_locale(__cloc);
65      }
66
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
71     { 
72       bindtextdomain(__s.c_str(), __dir);
73       return this->do_open(__s, __loc); 
74     }
75
76   // Virtual member functions.
77   template<typename _CharT>
78     messages<_CharT>::~messages()
79     { 
80       if (_M_name_messages != _S_get_c_name())
81         delete [] _M_name_messages;
82       _S_destroy_c_locale(_M_c_locale_messages); 
83     }
84
85   template<typename _CharT>
86     typename messages<_CharT>::catalog 
87     messages<_CharT>::do_open(const basic_string<char>& __s, 
88                               const locale&) const
89     { 
90       // No error checking is done, assume the catalog exists and can
91       // be used.
92       textdomain(__s.c_str());
93       return 0;
94     }
95
96   template<typename _CharT>
97     void    
98     messages<_CharT>::do_close(catalog) const 
99     { }
100
101    // messages_byname
102    template<typename _CharT>
103      messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
104      : messages<_CharT>(__refs) 
105      { 
106        if (this->_M_name_messages != locale::facet::_S_get_c_name())
107          {
108            delete [] this->_M_name_messages;
109            if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
110              {
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;
115              }
116            else
117              this->_M_name_messages = locale::facet::_S_get_c_name();
118          }
119
120        if (__builtin_strcmp(__s, "C") != 0
121            && __builtin_strcmp(__s, "POSIX") != 0)
122          {
123            this->_S_destroy_c_locale(this->_M_c_locale_messages);
124            this->_S_create_c_locale(this->_M_c_locale_messages, __s); 
125          }
126      }
127
128 _GLIBCXX_END_NAMESPACE