1 // std::moneypunct implementation details, generic version -*- C++ -*-
2 
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009, 2010
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 //
27 // ISO C++ 14882: 22.2.6.3.2  moneypunct virtual functions
28 //
29 
30 // Written by Benjamin Kosnik <bkoz@redhat.com>
31 
32 #include <locale>
33 
34 namespace std _GLIBCXX_VISIBILITY(default)
35 {
36 _GLIBCXX_BEGIN_NAMESPACE_VERSION
37 
38   // Construct and return valid pattern consisting of some combination of:
39   // space none symbol sign value
40   money_base::pattern
41   money_base::_S_construct_pattern(char, char, char) throw()
42   { return _S_default_pattern; }
43 
44   template<>
45     void
46     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*)
47     {
48       // "C" locale.
49       if (!_M_data)
50 	_M_data = new __moneypunct_cache<char, true>;
51 
52       _M_data->_M_decimal_point = '.';
53       _M_data->_M_thousands_sep = ',';
54       _M_data->_M_grouping = "";
55       _M_data->_M_grouping_size = 0;
56       _M_data->_M_curr_symbol = "";
57       _M_data->_M_curr_symbol_size = 0;
58       _M_data->_M_positive_sign = "";
59       _M_data->_M_positive_sign_size = 0;
60       _M_data->_M_negative_sign = "";
61       _M_data->_M_negative_sign_size = 0;
62       _M_data->_M_frac_digits = 0;
63       _M_data->_M_pos_format = money_base::_S_default_pattern;
64       _M_data->_M_neg_format = money_base::_S_default_pattern;
65 
66       for (size_t __i = 0; __i < money_base::_S_end; ++__i)
67 	_M_data->_M_atoms[__i] = money_base::_S_atoms[__i];
68     }
69 
70   template<>
71     void
72     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*)
73     {
74       // "C" locale.
75       if (!_M_data)
76 	_M_data = new __moneypunct_cache<char, false>;
77 
78       _M_data->_M_decimal_point = '.';
79       _M_data->_M_thousands_sep = ',';
80       _M_data->_M_grouping = "";
81       _M_data->_M_grouping_size = 0;
82       _M_data->_M_curr_symbol = "";
83       _M_data->_M_curr_symbol_size = 0;
84       _M_data->_M_positive_sign = "";
85       _M_data->_M_positive_sign_size = 0;
86       _M_data->_M_negative_sign = "";
87       _M_data->_M_negative_sign_size = 0;
88       _M_data->_M_frac_digits = 0;
89       _M_data->_M_pos_format = money_base::_S_default_pattern;
90       _M_data->_M_neg_format = money_base::_S_default_pattern;
91 
92       for (size_t __i = 0; __i < money_base::_S_end; ++__i)
93 	_M_data->_M_atoms[__i] = money_base::_S_atoms[__i];
94     }
95 
96   template<>
97     moneypunct<char, true>::~moneypunct()
98     { delete _M_data; }
99 
100   template<>
101     moneypunct<char, false>::~moneypunct()
102     { delete _M_data; }
103 
104 #ifdef _GLIBCXX_USE_WCHAR_T
105   template<>
106     void
107     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale,
108 							const char*)
109     {
110       // "C" locale
111       if (!_M_data)
112 	_M_data = new __moneypunct_cache<wchar_t, true>;
113 
114       _M_data->_M_decimal_point = L'.';
115       _M_data->_M_thousands_sep = L',';
116       _M_data->_M_grouping = "";
117       _M_data->_M_grouping_size = 0;
118       _M_data->_M_curr_symbol = L"";
119       _M_data->_M_curr_symbol_size = 0;
120       _M_data->_M_positive_sign = L"";
121       _M_data->_M_positive_sign_size = 0;
122       _M_data->_M_negative_sign = L"";
123       _M_data->_M_negative_sign_size = 0;
124       _M_data->_M_frac_digits = 0;
125       _M_data->_M_pos_format = money_base::_S_default_pattern;
126       _M_data->_M_neg_format = money_base::_S_default_pattern;
127 
128       for (size_t __i = 0; __i < money_base::_S_end; ++__i)
129 	_M_data->_M_atoms[__i] =
130 	  static_cast<wchar_t>(money_base::_S_atoms[__i]);
131     }
132 
133   template<>
134     void
135     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale,
136 							 const char*)
137     {
138       // "C" locale
139       if (!_M_data)
140 	_M_data = new __moneypunct_cache<wchar_t, false>;
141 
142       _M_data->_M_decimal_point = L'.';
143       _M_data->_M_thousands_sep = L',';
144       _M_data->_M_grouping = "";
145       _M_data->_M_grouping_size = 0;
146       _M_data->_M_curr_symbol = L"";
147       _M_data->_M_curr_symbol_size = 0;
148       _M_data->_M_positive_sign = L"";
149       _M_data->_M_positive_sign_size = 0;
150       _M_data->_M_negative_sign = L"";
151       _M_data->_M_negative_sign_size = 0;
152       _M_data->_M_frac_digits = 0;
153       _M_data->_M_pos_format = money_base::_S_default_pattern;
154       _M_data->_M_neg_format = money_base::_S_default_pattern;
155 
156       for (size_t __i = 0; __i < money_base::_S_end; ++__i)
157 	_M_data->_M_atoms[__i] =
158 	  static_cast<wchar_t>(money_base::_S_atoms[__i]);
159     }
160 
161   template<>
162     moneypunct<wchar_t, true>::~moneypunct()
163     { delete _M_data; }
164 
165   template<>
166     moneypunct<wchar_t, false>::~moneypunct()
167     { delete _M_data; }
168 #endif
169 
170 _GLIBCXX_END_NAMESPACE_VERSION
171 } // namespace
172