]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/config/locale/gnu/messages_members.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / 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
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 2, 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 // 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,
20 // USA.
21
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.
30
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.
34  */
35
36 //
37 // ISO C++ 14882: 22.2.7.1.2  messages functions
38 //
39
40 // Written by Benjamin Kosnik <bkoz@redhat.com>
41
42 #include <libintl.h>
43
44 _GLIBCXX_BEGIN_NAMESPACE(std)
45
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())
51      { }
52
53   template<typename _CharT>
54      messages<_CharT>::messages(__c_locale __cloc, const char* __s, 
55                                 size_t __refs) 
56      : facet(__refs), _M_c_locale_messages(NULL), _M_name_messages(NULL)
57      {
58        if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
59          {
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;
64          }
65        else
66          _M_name_messages = _S_get_c_name();
67
68        // Last to avoid leaking memory if new throws.
69        _M_c_locale_messages = _S_clone_c_locale(__cloc);
70      }
71
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
76     { 
77       bindtextdomain(__s.c_str(), __dir);
78       return this->do_open(__s, __loc); 
79     }
80
81   // Virtual member functions.
82   template<typename _CharT>
83     messages<_CharT>::~messages()
84     { 
85       if (_M_name_messages != _S_get_c_name())
86         delete [] _M_name_messages;
87       _S_destroy_c_locale(_M_c_locale_messages); 
88     }
89
90   template<typename _CharT>
91     typename messages<_CharT>::catalog 
92     messages<_CharT>::do_open(const basic_string<char>& __s, 
93                               const locale&) const
94     { 
95       // No error checking is done, assume the catalog exists and can
96       // be used.
97       textdomain(__s.c_str());
98       return 0;
99     }
100
101   template<typename _CharT>
102     void    
103     messages<_CharT>::do_close(catalog) const 
104     { }
105
106    // messages_byname
107    template<typename _CharT>
108      messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
109      : messages<_CharT>(__refs) 
110      { 
111        if (this->_M_name_messages != locale::facet::_S_get_c_name())
112          {
113            delete [] this->_M_name_messages;
114            if (__builtin_strcmp(__s, locale::facet::_S_get_c_name()) != 0)
115              {
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;
120              }
121            else
122              this->_M_name_messages = locale::facet::_S_get_c_name();
123          }
124
125        if (__builtin_strcmp(__s, "C") != 0
126            && __builtin_strcmp(__s, "POSIX") != 0)
127          {
128            this->_S_destroy_c_locale(this->_M_c_locale_messages);
129            this->_S_create_c_locale(this->_M_c_locale_messages, __s); 
130          }
131      }
132
133 _GLIBCXX_END_NAMESPACE