]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/localename.cc
rtlanal.c (note_stores): Don't present PARALLEL SET_DESTs as being CLOBBERed.
[thirdparty/gcc.git] / libstdc++-v3 / src / localename.cc
CommitLineData
8dba028f
BK
1// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
2// Free Software Foundation, Inc.
b2dad0e3
BK
3//
4// This file is part of the GNU ISO C++ Library. This library is free
5// software; you can redistribute it and/or modify it under the
6// terms of the GNU General Public License as published by the
7// Free Software Foundation; either version 2, or (at your option)
8// any later version.
9
10// This library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License along
16// with this library; see the file COPYING. If not, write to the Free
17// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18// USA.
19
20// As a special exception, you may use this file as part of a free software
21// library without restriction. Specifically, if other files instantiate
22// templates or use macros or inline functions from this file, or you compile
23// this file and link it with other files to produce an executable, this
24// file does not by itself cause the resulting executable to be covered by
25// the GNU General Public License. This exception does not however
26// invalidate any other reasons why the executable file might be covered by
27// the GNU General Public License.
28
54c1bf78
BK
29#include <clocale>
30#include <cstring>
31#include <locale>
32#include <vector>
b2dad0e3 33
d53d7f6e
PE
34namespace std
35{
e4cc8659
BK
36 locale::_Impl::
37 ~_Impl() throw()
38 {
0dba73e0
BK
39 __vec_facet::iterator __it = _M_facets.begin();
40 __vec_facet::iterator __end = _M_facets.end();
41 for (; __it != __end; ++__it)
42 if (*__it)
43 (*__it)->_M_remove_reference();
e4cc8659 44 }
b2dad0e3 45
0214010c 46 // Clone existing _Impl object.
e4cc8659 47 locale::_Impl::
d358ecd0 48 _Impl(const _Impl& __imp, size_t __refs)
0dba73e0 49 : _M_references(__refs) // XXX
e4cc8659 50 {
0dba73e0
BK
51 _M_facets = __imp._M_facets;
52 for (size_t __i = 0; __i < _S_num_categories; ++__i)
53 _M_names[__i] = __imp._M_names[__i];
e4cc8659 54
0dba73e0
BK
55 __vec_facet::iterator __it = _M_facets.begin();
56 __vec_facet::iterator __end = _M_facets.end();
57 for (; __it != __end; ++__it)
0214010c
BK
58 if (*__it)
59 (*__it)->_M_add_reference();
e4cc8659
BK
60 }
61
0214010c 62 // Construct named _Impl, including the standard "C" locale.
22b9554c 63 locale::_Impl::
0214010c 64 _Impl(string __str, size_t __refs)
0dba73e0 65 : _M_references(__refs)
7dc08a20 66 {
0214010c
BK
67 // Initialize the underlying locale model, which also checks to
68 // see if the given name is valid.
def9790d
BK
69 __c_locale __cloc;
70 locale::facet::_S_create_c_locale(__cloc, __str.c_str());
71
72 // This is needed as presently "C" locales != required data in
73 // __timepunct, numpunct, and moneypunct.
74 __c_locale __cloc_c = NULL;
0214010c 75 if (__str != "C" && __str != "POSIX")
def9790d 76 __cloc_c = __cloc;
0214010c 77
0dba73e0 78 _M_facets = __vec_facet(_S_num_facets, NULL);
22b9554c 79
0214010c
BK
80 // Name all the categories.
81 for (size_t i = 0; i < _S_num_categories; ++i)
82 _M_names[i] = __str;
83
84 // Construct all standard facets and add them to _M_facets.
ea0c0b6e 85 _M_init_facet(new std::collate<char>(__cloc));
9e5c7dba 86 _M_init_facet(new std::ctype<char>(__cloc));
0214010c 87 _M_init_facet(new codecvt<char, char, mbstate_t>);
def9790d
BK
88 _M_init_facet(new moneypunct<char, false>(__cloc_c));
89 _M_init_facet(new moneypunct<char, true>(__cloc_c));
0214010c
BK
90 _M_init_facet(new money_get<char>);
91 _M_init_facet(new money_put<char>);
def9790d 92 _M_init_facet(new numpunct<char>(__cloc_c));
0214010c
BK
93 _M_init_facet(new num_get<char>);
94 _M_init_facet(new num_put<char>);
def9790d 95 _M_init_facet(new __timepunct<char>(__cloc_c, __str.c_str()));
0214010c
BK
96 _M_init_facet(new time_get<char>);
97 _M_init_facet(new time_put<char>);
33590f13 98 _M_init_facet(new std::messages<char>(__cloc, __str.c_str()));
b2dad0e3 99
0214010c 100#ifdef _GLIBCPP_USE_WCHAR_T
ea0c0b6e 101 _M_init_facet(new std::collate<wchar_t>(__cloc));
9e5c7dba 102 _M_init_facet(new std::ctype<wchar_t>(__cloc));
0214010c 103 _M_init_facet(new codecvt<wchar_t, char, mbstate_t>);
def9790d
BK
104 _M_init_facet(new moneypunct<wchar_t, false>(__cloc_c));
105 _M_init_facet(new moneypunct<wchar_t, true>(__cloc_c));
0214010c
BK
106 _M_init_facet(new money_get<wchar_t>);
107 _M_init_facet(new money_put<wchar_t>);
def9790d 108 _M_init_facet(new numpunct<wchar_t>(__cloc_c));
0214010c
BK
109 _M_init_facet(new num_get<wchar_t>);
110 _M_init_facet(new num_put<wchar_t>);
def9790d 111 _M_init_facet(new __timepunct<wchar_t>(__cloc_c, __str.c_str()));
0214010c
BK
112 _M_init_facet(new time_get<wchar_t>);
113 _M_init_facet(new time_put<wchar_t>);
33590f13 114 _M_init_facet(new std::messages<wchar_t>(__cloc, __str.c_str()));
0214010c 115#endif
33590f13 116 locale::facet::_S_destroy_c_locale(__cloc);
b2dad0e3 117 }
e4cc8659
BK
118
119 void
120 locale::_Impl::
d358ecd0 121 _M_replace_categories(const _Impl* __imp, category __cat)
e4cc8659 122 {
0214010c
BK
123 const string __none("*");
124 category __mask;
125 for (unsigned int __ix = 0; __ix < _S_num_categories; ++__ix)
e4cc8659 126 {
0214010c 127 __mask = 1 << __ix;
e4cc8659
BK
128 if (__mask & __cat)
129 {
0214010c 130 // Need to replace entry in _M_facets with other locale's info.
d358ecd0 131 _M_replace_category(__imp, _S_facet_categories[__ix]);
0214010c
BK
132 // If both have names, go ahead and mangle.
133 if (_M_names[__ix] != __none && __imp->_M_names[__ix] != __none)
134 _M_names[__ix] = __imp->_M_names[__ix];
e4cc8659
BK
135 }
136 }
137 }
138
139 void
140 locale::_Impl::
d358ecd0 141 _M_replace_category(const _Impl* __imp, const locale::id* const* __idpp)
e4cc8659
BK
142 {
143 for (; *__idpp; ++__idpp)
d358ecd0 144 _M_replace_facet(__imp, *__idpp);
e4cc8659
BK
145 }
146
147 void
148 locale::_Impl::
d358ecd0 149 _M_replace_facet(const _Impl* __imp, const locale::id* __idp)
e4cc8659
BK
150 {
151 size_t __index = __idp->_M_index;
0dba73e0
BK
152 if (__index == 0 || __imp->_M_facets.size() <= __index
153 || __imp->_M_facets[__index] == 0)
e2c09482 154 __throw_runtime_error("no locale facet");
e4cc8659 155
0dba73e0 156 _M_install_facet(__idp, __imp->_M_facets[__index]);
e4cc8659
BK
157 }
158
159 void
160 locale::_Impl::
161 _M_install_facet(const locale::id* __idp, facet* __fp)
162 {
0214010c
BK
163 if (__fp)
164 {
165 size_t& __index = __idp->_M_index;
166 if (!__index)
17325050 167 __index = 1 + __exchange_and_add(&locale::id::_S_highwater, 1);
0214010c 168
0dba73e0
BK
169 if (__index >= _M_facets.size())
170 _M_facets.resize(__index + 1, 0); // might throw
b2dad0e3 171
0dba73e0 172 facet*& __fpr = _M_facets[__index];
0214010c
BK
173 if (__fpr)
174 {
0dba73e0 175 // Replacing an existing facet. Order matters.
0214010c 176 __fp->_M_add_reference();
13f83598 177 __fpr->_M_remove_reference();
0214010c
BK
178 __fpr = __fp;
179 }
180 else
181 {
182 // Installing a newly created facet into an empty
183 // _M_facets container, say a newly-constructed,
184 // swanky-fresh _Impl.
0dba73e0 185 _M_facets[__index] = __fp;
0214010c
BK
186 }
187 }
b2dad0e3 188 }
d53d7f6e 189} // namespace std