Fix typo.
[official-gcc.git] / libstdc++-v3 / src / c++11 / cow-locale_init.cc
blob83c9733de1c37b736d955e6358af910b754626b8
1 // Copyright (C) 2014-2016 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 // <http://www.gnu.org/licenses/>.
23 // Instantiate the facets using old std::string ABI.
24 #define _GLIBCXX_USE_CXX11_ABI 0
25 #include <locale>
27 #if ! _GLIBCXX_USE_DUAL_ABI
28 # error This file should not be compiled for this configuration.
29 #endif
31 namespace std _GLIBCXX_VISIBILITY(default)
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
35 namespace
37 typedef char fake_collate_c[sizeof(std::collate<char>)]
38 __attribute__ ((aligned(__alignof__(std::collate<char>))));
39 fake_collate_c collate_c;
41 typedef char fake_numpunct_c[sizeof(numpunct<char>)]
42 __attribute__ ((aligned(__alignof__(numpunct<char>))));
43 fake_numpunct_c numpunct_c;
45 typedef char fake_moneypunct_c[sizeof(moneypunct<char, true>)]
46 __attribute__ ((aligned(__alignof__(moneypunct<char, true>))));
47 fake_moneypunct_c moneypunct_ct;
48 fake_moneypunct_c moneypunct_cf;
50 typedef char fake_money_get_c[sizeof(money_get<char>)]
51 __attribute__ ((aligned(__alignof__(money_get<char>))));
52 fake_money_get_c money_get_c;
54 typedef char fake_money_put_c[sizeof(money_put<char>)]
55 __attribute__ ((aligned(__alignof__(money_put<char>))));
56 fake_money_put_c money_put_c;
58 typedef char fake_time_get_c[sizeof(time_get<char>)]
59 __attribute__ ((aligned(__alignof__(time_get<char>))));
60 fake_time_get_c time_get_c;
62 typedef char fake_messages_c[sizeof(messages<char>)]
63 __attribute__ ((aligned(__alignof__(messages<char>))));
64 fake_messages_c messages_c;
66 #ifdef _GLIBCXX_USE_WCHAR_T
67 typedef char fake_wollate_w[sizeof(std::collate<wchar_t>)]
68 __attribute__ ((aligned(__alignof__(std::collate<wchar_t>))));
69 fake_wollate_w collate_w;
71 typedef char fake_numpunct_w[sizeof(numpunct<wchar_t>)]
72 __attribute__ ((aligned(__alignof__(numpunct<wchar_t>))));
73 fake_numpunct_w numpunct_w;
75 typedef char fake_moneypunct_w[sizeof(moneypunct<wchar_t, true>)]
76 __attribute__ ((aligned(__alignof__(moneypunct<wchar_t, true>))));
77 fake_moneypunct_w moneypunct_wt;
78 fake_moneypunct_w moneypunct_wf;
80 typedef char fake_money_get_w[sizeof(money_get<wchar_t>)]
81 __attribute__ ((aligned(__alignof__(money_get<wchar_t>))));
82 fake_money_get_w money_get_w;
84 typedef char fake_money_put_w[sizeof(money_put<wchar_t>)]
85 __attribute__ ((aligned(__alignof__(money_put<wchar_t>))));
86 fake_money_put_w money_put_w;
88 typedef char fake_time_get_w[sizeof(time_get<wchar_t>)]
89 __attribute__ ((aligned(__alignof__(time_get<wchar_t>))));
90 fake_time_get_w time_get_w;
92 typedef char fake_messages_w[sizeof(messages<wchar_t>)]
93 __attribute__ ((aligned(__alignof__(messages<wchar_t>))));
94 fake_messages_w messages_w;
95 #endif
96 } // anonymous namespace
98 void
99 locale::_Impl::_M_init_extra(facet** caches)
101 auto __npc = static_cast<__numpunct_cache<char>*>(caches[0]);
102 auto __mpcf = static_cast<__moneypunct_cache<char, false>*>(caches[1]);
103 auto __mpct = static_cast<__moneypunct_cache<char, true>*>(caches[2]);
105 _M_init_facet_unchecked(new (&numpunct_c) numpunct<char>(__npc, 1));
106 _M_init_facet_unchecked(new (&collate_c) std::collate<char>(1));
107 _M_init_facet_unchecked(new (&moneypunct_cf) moneypunct<char, false>(__mpcf, 1));
108 _M_init_facet_unchecked(new (&moneypunct_ct) moneypunct<char, true>(__mpct, 1));
109 _M_init_facet_unchecked(new (&money_get_c) money_get<char>(1));
110 _M_init_facet_unchecked(new (&money_put_c) money_put<char>(1));
111 _M_init_facet_unchecked(new (&time_get_c) time_get<char>(1));
112 _M_init_facet_unchecked(new (&messages_c) std::messages<char>(1));
113 #ifdef _GLIBCXX_USE_WCHAR_T
114 auto __npw = static_cast<__numpunct_cache<wchar_t>*>(caches[3]);
115 auto __mpwf = static_cast<__moneypunct_cache<wchar_t, false>*>(caches[4]);
116 auto __mpwt = static_cast<__moneypunct_cache<wchar_t, true>*>(caches[5]);
118 _M_init_facet_unchecked(new (&numpunct_w) numpunct<wchar_t>(__npw, 1));
119 _M_init_facet_unchecked(new (&collate_w) std::collate<wchar_t>(1));
120 _M_init_facet_unchecked(new (&moneypunct_wf) moneypunct<wchar_t, false>(__mpwf, 1));
121 _M_init_facet_unchecked(new (&moneypunct_wt) moneypunct<wchar_t, true>(__mpwt, 1));
122 _M_init_facet_unchecked(new (&money_get_w) money_get<wchar_t>(1));
123 _M_init_facet_unchecked(new (&money_put_w) money_put<wchar_t>(1));
124 _M_init_facet_unchecked(new (&time_get_w) time_get<wchar_t>(1));
125 _M_init_facet_unchecked(new (&messages_w) std::messages<wchar_t>(1));
126 #endif
128 _M_caches[numpunct<char>::id._M_id()] = __npc;
129 _M_caches[moneypunct<char, false>::id._M_id()] = __mpcf;
130 _M_caches[moneypunct<char, true>::id._M_id()] = __mpct;
131 #ifdef _GLIBCXX_USE_WCHAR_T
132 _M_caches[numpunct<wchar_t>::id._M_id()] = __npw;
133 _M_caches[moneypunct<wchar_t, false>::id._M_id()] = __mpwf;
134 _M_caches[moneypunct<wchar_t, true>::id._M_id()] = __mpwt;
135 #endif
138 void
139 locale::_Impl::_M_init_extra(void* cloc, void* clocm,
140 const char* __s, const char* __smon)
142 auto& __cloc = *static_cast<__c_locale*>(cloc);
144 _M_init_facet_unchecked(new numpunct<char>(__cloc));
145 _M_init_facet_unchecked(new std::collate<char>(__cloc));
146 _M_init_facet_unchecked(new moneypunct<char, false>(__cloc, 0));
147 _M_init_facet_unchecked(new moneypunct<char, true>(__cloc, 0));
148 _M_init_facet_unchecked(new money_get<char>);
149 _M_init_facet_unchecked(new money_put<char>);
150 _M_init_facet_unchecked(new time_get<char>);
151 _M_init_facet_unchecked(new std::messages<char>(__cloc, __s));
153 #ifdef _GLIBCXX_USE_WCHAR_T
154 auto& __clocm = *static_cast<__c_locale*>(clocm);
156 _M_init_facet_unchecked(new numpunct<wchar_t>(__cloc));
157 _M_init_facet_unchecked(new std::collate<wchar_t>(__cloc));
158 _M_init_facet_unchecked(new moneypunct<wchar_t, false>(__clocm, __smon));
159 _M_init_facet_unchecked(new moneypunct<wchar_t, true>(__clocm, __smon));
160 _M_init_facet_unchecked(new money_get<wchar_t>);
161 _M_init_facet_unchecked(new money_put<wchar_t>);
162 _M_init_facet_unchecked(new time_get<wchar_t>);
163 _M_init_facet_unchecked(new std::messages<wchar_t>(__cloc, __s));
164 #endif
167 // TODO should be in another file
168 string
169 locale::name() const
171 string __ret;
172 if (!_M_impl->_M_names[0])
173 __ret = '*';
174 else if (_M_impl->_M_check_same_name())
175 __ret = _M_impl->_M_names[0];
176 else
178 __ret.reserve(128);
179 __ret += _S_categories[0];
180 __ret += '=';
181 __ret += _M_impl->_M_names[0];
182 for (size_t __i = 1; __i < _S_categories_size; ++__i)
184 __ret += ';';
185 __ret += _S_categories[__i];
186 __ret += '=';
187 __ret += _M_impl->_M_names[__i];
190 return __ret;
193 _GLIBCXX_END_NAMESPACE_VERSION