]>
Commit | Line | Data |
---|---|---|
f749a55b PC |
1 | // Locale support -*- C++ -*- |
2 | ||
ac2bb437 | 3 | // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
f749a55b PC |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
f749a55b PC |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
f749a55b | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
f749a55b | 24 | |
f910786b | 25 | /** @file bits/locale_facets_nonio.h |
f749a55b | 26 | * This is an internal header file, included by other library headers. |
f910786b | 27 | * Do not attempt to use it directly. @headername{locale} |
f749a55b PC |
28 | */ |
29 | ||
30 | // | |
31 | // ISO C++ 14882: 22.1 Locales | |
32 | // | |
33 | ||
34 | #ifndef _LOCALE_FACETS_NONIO_H | |
35 | #define _LOCALE_FACETS_NONIO_H 1 | |
36 | ||
84b31797 PC |
37 | #pragma GCC system_header |
38 | ||
f749a55b PC |
39 | #include <ctime> // For struct tm |
40 | ||
41 | _GLIBCXX_BEGIN_NAMESPACE(std) | |
42 | ||
43 | /** | |
44 | * @brief Time format ordering data. | |
0eb95b0d | 45 | * @ingroup locales |
f749a55b | 46 | * |
0eb95b0d BK |
47 | * This class provides an enum representing different orderings of |
48 | * time: day, month, and year. | |
f749a55b PC |
49 | */ |
50 | class time_base | |
51 | { | |
52 | public: | |
53 | enum dateorder { no_order, dmy, mdy, ymd, ydm }; | |
54 | }; | |
55 | ||
56 | template<typename _CharT> | |
57 | struct __timepunct_cache : public locale::facet | |
58 | { | |
59 | // List of all known timezones, with GMT first. | |
60 | static const _CharT* _S_timezones[14]; | |
61 | ||
62 | const _CharT* _M_date_format; | |
63 | const _CharT* _M_date_era_format; | |
64 | const _CharT* _M_time_format; | |
65 | const _CharT* _M_time_era_format; | |
66 | const _CharT* _M_date_time_format; | |
67 | const _CharT* _M_date_time_era_format; | |
68 | const _CharT* _M_am; | |
69 | const _CharT* _M_pm; | |
70 | const _CharT* _M_am_pm_format; | |
71 | ||
72 | // Day names, starting with "C"'s Sunday. | |
73 | const _CharT* _M_day1; | |
74 | const _CharT* _M_day2; | |
75 | const _CharT* _M_day3; | |
76 | const _CharT* _M_day4; | |
77 | const _CharT* _M_day5; | |
78 | const _CharT* _M_day6; | |
79 | const _CharT* _M_day7; | |
80 | ||
81 | // Abbreviated day names, starting with "C"'s Sun. | |
82 | const _CharT* _M_aday1; | |
83 | const _CharT* _M_aday2; | |
84 | const _CharT* _M_aday3; | |
85 | const _CharT* _M_aday4; | |
86 | const _CharT* _M_aday5; | |
87 | const _CharT* _M_aday6; | |
88 | const _CharT* _M_aday7; | |
89 | ||
90 | // Month names, starting with "C"'s January. | |
91 | const _CharT* _M_month01; | |
92 | const _CharT* _M_month02; | |
93 | const _CharT* _M_month03; | |
94 | const _CharT* _M_month04; | |
95 | const _CharT* _M_month05; | |
96 | const _CharT* _M_month06; | |
97 | const _CharT* _M_month07; | |
98 | const _CharT* _M_month08; | |
99 | const _CharT* _M_month09; | |
100 | const _CharT* _M_month10; | |
101 | const _CharT* _M_month11; | |
102 | const _CharT* _M_month12; | |
103 | ||
104 | // Abbreviated month names, starting with "C"'s Jan. | |
105 | const _CharT* _M_amonth01; | |
106 | const _CharT* _M_amonth02; | |
107 | const _CharT* _M_amonth03; | |
108 | const _CharT* _M_amonth04; | |
109 | const _CharT* _M_amonth05; | |
110 | const _CharT* _M_amonth06; | |
111 | const _CharT* _M_amonth07; | |
112 | const _CharT* _M_amonth08; | |
113 | const _CharT* _M_amonth09; | |
114 | const _CharT* _M_amonth10; | |
115 | const _CharT* _M_amonth11; | |
116 | const _CharT* _M_amonth12; | |
117 | ||
118 | bool _M_allocated; | |
119 | ||
120 | __timepunct_cache(size_t __refs = 0) : facet(__refs), | |
8fc81078 PC |
121 | _M_date_format(0), _M_date_era_format(0), _M_time_format(0), |
122 | _M_time_era_format(0), _M_date_time_format(0), | |
123 | _M_date_time_era_format(0), _M_am(0), _M_pm(0), | |
124 | _M_am_pm_format(0), _M_day1(0), _M_day2(0), _M_day3(0), | |
125 | _M_day4(0), _M_day5(0), _M_day6(0), _M_day7(0), | |
126 | _M_aday1(0), _M_aday2(0), _M_aday3(0), _M_aday4(0), | |
127 | _M_aday5(0), _M_aday6(0), _M_aday7(0), _M_month01(0), | |
128 | _M_month02(0), _M_month03(0), _M_month04(0), _M_month05(0), | |
129 | _M_month06(0), _M_month07(0), _M_month08(0), _M_month09(0), | |
130 | _M_month10(0), _M_month11(0), _M_month12(0), _M_amonth01(0), | |
131 | _M_amonth02(0), _M_amonth03(0), _M_amonth04(0), | |
132 | _M_amonth05(0), _M_amonth06(0), _M_amonth07(0), | |
133 | _M_amonth08(0), _M_amonth09(0), _M_amonth10(0), | |
134 | _M_amonth11(0), _M_amonth12(0), _M_allocated(false) | |
f749a55b PC |
135 | { } |
136 | ||
137 | ~__timepunct_cache(); | |
138 | ||
139 | void | |
140 | _M_cache(const locale& __loc); | |
141 | ||
142 | private: | |
143 | __timepunct_cache& | |
144 | operator=(const __timepunct_cache&); | |
145 | ||
146 | explicit | |
147 | __timepunct_cache(const __timepunct_cache&); | |
148 | }; | |
149 | ||
150 | template<typename _CharT> | |
151 | __timepunct_cache<_CharT>::~__timepunct_cache() | |
152 | { | |
153 | if (_M_allocated) | |
154 | { | |
155 | // Unused. | |
156 | } | |
157 | } | |
158 | ||
159 | // Specializations. | |
160 | template<> | |
161 | const char* | |
162 | __timepunct_cache<char>::_S_timezones[14]; | |
163 | ||
164 | #ifdef _GLIBCXX_USE_WCHAR_T | |
165 | template<> | |
166 | const wchar_t* | |
167 | __timepunct_cache<wchar_t>::_S_timezones[14]; | |
168 | #endif | |
169 | ||
170 | // Generic. | |
171 | template<typename _CharT> | |
172 | const _CharT* __timepunct_cache<_CharT>::_S_timezones[14]; | |
173 | ||
174 | template<typename _CharT> | |
175 | class __timepunct : public locale::facet | |
176 | { | |
177 | public: | |
178 | // Types: | |
179 | typedef _CharT __char_type; | |
180 | typedef basic_string<_CharT> __string_type; | |
181 | typedef __timepunct_cache<_CharT> __cache_type; | |
182 | ||
183 | protected: | |
184 | __cache_type* _M_data; | |
185 | __c_locale _M_c_locale_timepunct; | |
186 | const char* _M_name_timepunct; | |
187 | ||
188 | public: | |
189 | /// Numpunct facet id. | |
190 | static locale::id id; | |
191 | ||
192 | explicit | |
193 | __timepunct(size_t __refs = 0); | |
194 | ||
195 | explicit | |
196 | __timepunct(__cache_type* __cache, size_t __refs = 0); | |
197 | ||
198 | /** | |
199 | * @brief Internal constructor. Not for general use. | |
200 | * | |
201 | * This is a constructor for use by the library itself to set up new | |
202 | * locales. | |
203 | * | |
2a60a9f6 | 204 | * @param cloc The C locale. |
f749a55b PC |
205 | * @param s The name of a locale. |
206 | * @param refs Passed to the base facet class. | |
207 | */ | |
208 | explicit | |
209 | __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0); | |
210 | ||
211 | // FIXME: for error checking purposes _M_put should return the return | |
212 | // value of strftime/wcsftime. | |
213 | void | |
214 | _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, | |
50a681c4 | 215 | const tm* __tm) const throw (); |
f749a55b PC |
216 | |
217 | void | |
218 | _M_date_formats(const _CharT** __date) const | |
219 | { | |
220 | // Always have default first. | |
221 | __date[0] = _M_data->_M_date_format; | |
222 | __date[1] = _M_data->_M_date_era_format; | |
223 | } | |
224 | ||
225 | void | |
226 | _M_time_formats(const _CharT** __time) const | |
227 | { | |
228 | // Always have default first. | |
229 | __time[0] = _M_data->_M_time_format; | |
230 | __time[1] = _M_data->_M_time_era_format; | |
231 | } | |
232 | ||
233 | void | |
234 | _M_date_time_formats(const _CharT** __dt) const | |
235 | { | |
236 | // Always have default first. | |
237 | __dt[0] = _M_data->_M_date_time_format; | |
238 | __dt[1] = _M_data->_M_date_time_era_format; | |
239 | } | |
240 | ||
241 | void | |
242 | _M_am_pm_format(const _CharT* __ampm) const | |
243 | { __ampm = _M_data->_M_am_pm_format; } | |
244 | ||
245 | void | |
246 | _M_am_pm(const _CharT** __ampm) const | |
247 | { | |
248 | __ampm[0] = _M_data->_M_am; | |
249 | __ampm[1] = _M_data->_M_pm; | |
250 | } | |
251 | ||
252 | void | |
253 | _M_days(const _CharT** __days) const | |
254 | { | |
255 | __days[0] = _M_data->_M_day1; | |
256 | __days[1] = _M_data->_M_day2; | |
257 | __days[2] = _M_data->_M_day3; | |
258 | __days[3] = _M_data->_M_day4; | |
259 | __days[4] = _M_data->_M_day5; | |
260 | __days[5] = _M_data->_M_day6; | |
261 | __days[6] = _M_data->_M_day7; | |
262 | } | |
263 | ||
264 | void | |
265 | _M_days_abbreviated(const _CharT** __days) const | |
266 | { | |
267 | __days[0] = _M_data->_M_aday1; | |
268 | __days[1] = _M_data->_M_aday2; | |
269 | __days[2] = _M_data->_M_aday3; | |
270 | __days[3] = _M_data->_M_aday4; | |
271 | __days[4] = _M_data->_M_aday5; | |
272 | __days[5] = _M_data->_M_aday6; | |
273 | __days[6] = _M_data->_M_aday7; | |
274 | } | |
275 | ||
276 | void | |
277 | _M_months(const _CharT** __months) const | |
278 | { | |
279 | __months[0] = _M_data->_M_month01; | |
280 | __months[1] = _M_data->_M_month02; | |
281 | __months[2] = _M_data->_M_month03; | |
282 | __months[3] = _M_data->_M_month04; | |
283 | __months[4] = _M_data->_M_month05; | |
284 | __months[5] = _M_data->_M_month06; | |
285 | __months[6] = _M_data->_M_month07; | |
286 | __months[7] = _M_data->_M_month08; | |
287 | __months[8] = _M_data->_M_month09; | |
288 | __months[9] = _M_data->_M_month10; | |
289 | __months[10] = _M_data->_M_month11; | |
290 | __months[11] = _M_data->_M_month12; | |
291 | } | |
292 | ||
293 | void | |
294 | _M_months_abbreviated(const _CharT** __months) const | |
295 | { | |
296 | __months[0] = _M_data->_M_amonth01; | |
297 | __months[1] = _M_data->_M_amonth02; | |
298 | __months[2] = _M_data->_M_amonth03; | |
299 | __months[3] = _M_data->_M_amonth04; | |
300 | __months[4] = _M_data->_M_amonth05; | |
301 | __months[5] = _M_data->_M_amonth06; | |
302 | __months[6] = _M_data->_M_amonth07; | |
303 | __months[7] = _M_data->_M_amonth08; | |
304 | __months[8] = _M_data->_M_amonth09; | |
305 | __months[9] = _M_data->_M_amonth10; | |
306 | __months[10] = _M_data->_M_amonth11; | |
307 | __months[11] = _M_data->_M_amonth12; | |
308 | } | |
309 | ||
310 | protected: | |
311 | virtual | |
312 | ~__timepunct(); | |
313 | ||
314 | // For use at construction time only. | |
315 | void | |
8fc81078 | 316 | _M_initialize_timepunct(__c_locale __cloc = 0); |
f749a55b PC |
317 | }; |
318 | ||
319 | template<typename _CharT> | |
320 | locale::id __timepunct<_CharT>::id; | |
321 | ||
322 | // Specializations. | |
323 | template<> | |
324 | void | |
325 | __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc); | |
326 | ||
327 | template<> | |
328 | void | |
50a681c4 | 329 | __timepunct<char>::_M_put(char*, size_t, const char*, const tm*) const throw (); |
f749a55b PC |
330 | |
331 | #ifdef _GLIBCXX_USE_WCHAR_T | |
332 | template<> | |
333 | void | |
334 | __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc); | |
335 | ||
336 | template<> | |
337 | void | |
338 | __timepunct<wchar_t>::_M_put(wchar_t*, size_t, const wchar_t*, | |
50a681c4 | 339 | const tm*) const throw (); |
f749a55b PC |
340 | #endif |
341 | ||
342 | _GLIBCXX_END_NAMESPACE | |
343 | ||
344 | // Include host and configuration specific timepunct functions. | |
345 | #include <bits/time_members.h> | |
346 | ||
347 | _GLIBCXX_BEGIN_NAMESPACE(std) | |
348 | ||
349 | /** | |
0eb95b0d BK |
350 | * @brief Primary class template time_get. |
351 | * @ingroup locales | |
f749a55b PC |
352 | * |
353 | * This facet encapsulates the code to parse and return a date or | |
354 | * time from a string. It is used by the istream numeric | |
355 | * extraction operators. | |
356 | * | |
357 | * The time_get template uses protected virtual functions to provide the | |
358 | * actual results. The public accessors forward the call to the virtual | |
359 | * functions. These virtual functions are hooks for developers to | |
360 | * implement the behavior they require from the time_get facet. | |
361 | */ | |
362 | template<typename _CharT, typename _InIter> | |
363 | class time_get : public locale::facet, public time_base | |
364 | { | |
365 | public: | |
366 | // Types: | |
367 | //@{ | |
368 | /// Public typedefs | |
369 | typedef _CharT char_type; | |
370 | typedef _InIter iter_type; | |
371 | //@} | |
372 | typedef basic_string<_CharT> __string_type; | |
373 | ||
374 | /// Numpunct facet id. | |
375 | static locale::id id; | |
376 | ||
377 | /** | |
378 | * @brief Constructor performs initialization. | |
379 | * | |
380 | * This is the constructor provided by the standard. | |
381 | * | |
382 | * @param refs Passed to the base facet class. | |
383 | */ | |
384 | explicit | |
385 | time_get(size_t __refs = 0) | |
386 | : facet (__refs) { } | |
387 | ||
388 | /** | |
389 | * @brief Return preferred order of month, day, and year. | |
390 | * | |
391 | * This function returns an enum from timebase::dateorder giving the | |
2a60a9f6 BK |
392 | * preferred ordering if the format @a x given to time_put::put() only |
393 | * uses month, day, and year. If the format @a x for the associated | |
f749a55b PC |
394 | * locale uses other fields, this function returns |
395 | * timebase::dateorder::noorder. | |
396 | * | |
397 | * NOTE: The library always returns noorder at the moment. | |
398 | * | |
399 | * @return A member of timebase::dateorder. | |
400 | */ | |
401 | dateorder | |
402 | date_order() const | |
403 | { return this->do_date_order(); } | |
404 | ||
405 | /** | |
406 | * @brief Parse input time string. | |
407 | * | |
94a9600c | 408 | * This function parses a time according to the format @a X and puts the |
f749a55b PC |
409 | * results into a user-supplied struct tm. The result is returned by |
410 | * calling time_get::do_get_time(). | |
411 | * | |
94a9600c | 412 | * If there is a valid time string according to format @a X, @a tm will |
f749a55b PC |
413 | * be filled in accordingly and the returned iterator will point to the |
414 | * first character beyond the time string. If an error occurs before | |
415 | * the end, err |= ios_base::failbit. If parsing reads all the | |
416 | * characters, err |= ios_base::eofbit. | |
417 | * | |
418 | * @param beg Start of string to parse. | |
419 | * @param end End of string to parse. | |
420 | * @param io Source of the locale. | |
421 | * @param err Error flags to set. | |
422 | * @param tm Pointer to struct tm to fill in. | |
423 | * @return Iterator to first char beyond time string. | |
424 | */ | |
425 | iter_type | |
426 | get_time(iter_type __beg, iter_type __end, ios_base& __io, | |
427 | ios_base::iostate& __err, tm* __tm) const | |
428 | { return this->do_get_time(__beg, __end, __io, __err, __tm); } | |
429 | ||
430 | /** | |
431 | * @brief Parse input date string. | |
432 | * | |
94a9600c | 433 | * This function parses a date according to the format @a x and puts the |
f749a55b PC |
434 | * results into a user-supplied struct tm. The result is returned by |
435 | * calling time_get::do_get_date(). | |
436 | * | |
94a9600c | 437 | * If there is a valid date string according to format @a x, @a tm will |
f749a55b PC |
438 | * be filled in accordingly and the returned iterator will point to the |
439 | * first character beyond the date string. If an error occurs before | |
440 | * the end, err |= ios_base::failbit. If parsing reads all the | |
441 | * characters, err |= ios_base::eofbit. | |
442 | * | |
443 | * @param beg Start of string to parse. | |
444 | * @param end End of string to parse. | |
445 | * @param io Source of the locale. | |
446 | * @param err Error flags to set. | |
447 | * @param tm Pointer to struct tm to fill in. | |
448 | * @return Iterator to first char beyond date string. | |
449 | */ | |
450 | iter_type | |
451 | get_date(iter_type __beg, iter_type __end, ios_base& __io, | |
452 | ios_base::iostate& __err, tm* __tm) const | |
453 | { return this->do_get_date(__beg, __end, __io, __err, __tm); } | |
454 | ||
455 | /** | |
456 | * @brief Parse input weekday string. | |
457 | * | |
458 | * This function parses a weekday name and puts the results into a | |
459 | * user-supplied struct tm. The result is returned by calling | |
460 | * time_get::do_get_weekday(). | |
461 | * | |
462 | * Parsing starts by parsing an abbreviated weekday name. If a valid | |
463 | * abbreviation is followed by a character that would lead to the full | |
464 | * weekday name, parsing continues until the full name is found or an | |
465 | * error occurs. Otherwise parsing finishes at the end of the | |
466 | * abbreviated name. | |
467 | * | |
468 | * If an error occurs before the end, err |= ios_base::failbit. If | |
469 | * parsing reads all the characters, err |= ios_base::eofbit. | |
470 | * | |
471 | * @param beg Start of string to parse. | |
472 | * @param end End of string to parse. | |
473 | * @param io Source of the locale. | |
474 | * @param err Error flags to set. | |
475 | * @param tm Pointer to struct tm to fill in. | |
476 | * @return Iterator to first char beyond weekday name. | |
477 | */ | |
478 | iter_type | |
479 | get_weekday(iter_type __beg, iter_type __end, ios_base& __io, | |
480 | ios_base::iostate& __err, tm* __tm) const | |
481 | { return this->do_get_weekday(__beg, __end, __io, __err, __tm); } | |
482 | ||
483 | /** | |
484 | * @brief Parse input month string. | |
485 | * | |
486 | * This function parses a month name and puts the results into a | |
487 | * user-supplied struct tm. The result is returned by calling | |
488 | * time_get::do_get_monthname(). | |
489 | * | |
490 | * Parsing starts by parsing an abbreviated month name. If a valid | |
491 | * abbreviation is followed by a character that would lead to the full | |
492 | * month name, parsing continues until the full name is found or an | |
493 | * error occurs. Otherwise parsing finishes at the end of the | |
494 | * abbreviated name. | |
495 | * | |
496 | * If an error occurs before the end, err |= ios_base::failbit. If | |
497 | * parsing reads all the characters, err |= | |
498 | * ios_base::eofbit. | |
499 | * | |
500 | * @param beg Start of string to parse. | |
501 | * @param end End of string to parse. | |
502 | * @param io Source of the locale. | |
503 | * @param err Error flags to set. | |
504 | * @param tm Pointer to struct tm to fill in. | |
505 | * @return Iterator to first char beyond month name. | |
506 | */ | |
507 | iter_type | |
508 | get_monthname(iter_type __beg, iter_type __end, ios_base& __io, | |
509 | ios_base::iostate& __err, tm* __tm) const | |
510 | { return this->do_get_monthname(__beg, __end, __io, __err, __tm); } | |
511 | ||
512 | /** | |
513 | * @brief Parse input year string. | |
514 | * | |
515 | * This function reads up to 4 characters to parse a year string and | |
516 | * puts the results into a user-supplied struct tm. The result is | |
517 | * returned by calling time_get::do_get_year(). | |
518 | * | |
519 | * 4 consecutive digits are interpreted as a full year. If there are | |
520 | * exactly 2 consecutive digits, the library interprets this as the | |
521 | * number of years since 1900. | |
522 | * | |
523 | * If an error occurs before the end, err |= ios_base::failbit. If | |
524 | * parsing reads all the characters, err |= ios_base::eofbit. | |
525 | * | |
526 | * @param beg Start of string to parse. | |
527 | * @param end End of string to parse. | |
528 | * @param io Source of the locale. | |
529 | * @param err Error flags to set. | |
530 | * @param tm Pointer to struct tm to fill in. | |
531 | * @return Iterator to first char beyond year. | |
532 | */ | |
533 | iter_type | |
534 | get_year(iter_type __beg, iter_type __end, ios_base& __io, | |
535 | ios_base::iostate& __err, tm* __tm) const | |
536 | { return this->do_get_year(__beg, __end, __io, __err, __tm); } | |
537 | ||
538 | protected: | |
539 | /// Destructor. | |
540 | virtual | |
541 | ~time_get() { } | |
542 | ||
543 | /** | |
544 | * @brief Return preferred order of month, day, and year. | |
545 | * | |
546 | * This function returns an enum from timebase::dateorder giving the | |
2a60a9f6 | 547 | * preferred ordering if the format @a x given to time_put::put() only |
f749a55b PC |
548 | * uses month, day, and year. This function is a hook for derived |
549 | * classes to change the value returned. | |
550 | * | |
551 | * @return A member of timebase::dateorder. | |
552 | */ | |
553 | virtual dateorder | |
554 | do_date_order() const; | |
555 | ||
556 | /** | |
557 | * @brief Parse input time string. | |
558 | * | |
2a60a9f6 | 559 | * This function parses a time according to the format @a x and puts the |
f749a55b PC |
560 | * results into a user-supplied struct tm. This function is a hook for |
561 | * derived classes to change the value returned. @see get_time() for | |
562 | * details. | |
563 | * | |
564 | * @param beg Start of string to parse. | |
565 | * @param end End of string to parse. | |
566 | * @param io Source of the locale. | |
567 | * @param err Error flags to set. | |
568 | * @param tm Pointer to struct tm to fill in. | |
569 | * @return Iterator to first char beyond time string. | |
570 | */ | |
571 | virtual iter_type | |
572 | do_get_time(iter_type __beg, iter_type __end, ios_base& __io, | |
573 | ios_base::iostate& __err, tm* __tm) const; | |
574 | ||
575 | /** | |
576 | * @brief Parse input date string. | |
577 | * | |
2a60a9f6 | 578 | * This function parses a date according to the format @a X and puts the |
f749a55b PC |
579 | * results into a user-supplied struct tm. This function is a hook for |
580 | * derived classes to change the value returned. @see get_date() for | |
581 | * details. | |
582 | * | |
583 | * @param beg Start of string to parse. | |
584 | * @param end End of string to parse. | |
585 | * @param io Source of the locale. | |
586 | * @param err Error flags to set. | |
587 | * @param tm Pointer to struct tm to fill in. | |
588 | * @return Iterator to first char beyond date string. | |
589 | */ | |
590 | virtual iter_type | |
591 | do_get_date(iter_type __beg, iter_type __end, ios_base& __io, | |
592 | ios_base::iostate& __err, tm* __tm) const; | |
593 | ||
594 | /** | |
595 | * @brief Parse input weekday string. | |
596 | * | |
597 | * This function parses a weekday name and puts the results into a | |
598 | * user-supplied struct tm. This function is a hook for derived | |
599 | * classes to change the value returned. @see get_weekday() for | |
600 | * details. | |
601 | * | |
602 | * @param beg Start of string to parse. | |
603 | * @param end End of string to parse. | |
604 | * @param io Source of the locale. | |
605 | * @param err Error flags to set. | |
606 | * @param tm Pointer to struct tm to fill in. | |
607 | * @return Iterator to first char beyond weekday name. | |
608 | */ | |
609 | virtual iter_type | |
610 | do_get_weekday(iter_type __beg, iter_type __end, ios_base&, | |
611 | ios_base::iostate& __err, tm* __tm) const; | |
612 | ||
613 | /** | |
614 | * @brief Parse input month string. | |
615 | * | |
616 | * This function parses a month name and puts the results into a | |
617 | * user-supplied struct tm. This function is a hook for derived | |
618 | * classes to change the value returned. @see get_monthname() for | |
619 | * details. | |
620 | * | |
621 | * @param beg Start of string to parse. | |
622 | * @param end End of string to parse. | |
623 | * @param io Source of the locale. | |
624 | * @param err Error flags to set. | |
625 | * @param tm Pointer to struct tm to fill in. | |
626 | * @return Iterator to first char beyond month name. | |
627 | */ | |
628 | virtual iter_type | |
629 | do_get_monthname(iter_type __beg, iter_type __end, ios_base&, | |
630 | ios_base::iostate& __err, tm* __tm) const; | |
631 | ||
632 | /** | |
633 | * @brief Parse input year string. | |
634 | * | |
635 | * This function reads up to 4 characters to parse a year string and | |
636 | * puts the results into a user-supplied struct tm. This function is a | |
637 | * hook for derived classes to change the value returned. @see | |
638 | * get_year() for details. | |
639 | * | |
640 | * @param beg Start of string to parse. | |
641 | * @param end End of string to parse. | |
642 | * @param io Source of the locale. | |
643 | * @param err Error flags to set. | |
644 | * @param tm Pointer to struct tm to fill in. | |
645 | * @return Iterator to first char beyond year. | |
646 | */ | |
647 | virtual iter_type | |
648 | do_get_year(iter_type __beg, iter_type __end, ios_base& __io, | |
649 | ios_base::iostate& __err, tm* __tm) const; | |
650 | ||
651 | // Extract numeric component of length __len. | |
652 | iter_type | |
653 | _M_extract_num(iter_type __beg, iter_type __end, int& __member, | |
654 | int __min, int __max, size_t __len, | |
655 | ios_base& __io, ios_base::iostate& __err) const; | |
656 | ||
ac2bb437 | 657 | // Extract any unique array of string literals in a const _CharT* array. |
f749a55b PC |
658 | iter_type |
659 | _M_extract_name(iter_type __beg, iter_type __end, int& __member, | |
660 | const _CharT** __names, size_t __indexlen, | |
661 | ios_base& __io, ios_base::iostate& __err) const; | |
662 | ||
ac2bb437 PC |
663 | // Extract day or month name in a const _CharT* array. |
664 | iter_type | |
665 | _M_extract_wday_or_month(iter_type __beg, iter_type __end, int& __member, | |
666 | const _CharT** __names, size_t __indexlen, | |
667 | ios_base& __io, ios_base::iostate& __err) const; | |
668 | ||
f749a55b PC |
669 | // Extract on a component-by-component basis, via __format argument. |
670 | iter_type | |
671 | _M_extract_via_format(iter_type __beg, iter_type __end, ios_base& __io, | |
672 | ios_base::iostate& __err, tm* __tm, | |
673 | const _CharT* __format) const; | |
674 | }; | |
675 | ||
676 | template<typename _CharT, typename _InIter> | |
677 | locale::id time_get<_CharT, _InIter>::id; | |
678 | ||
939759fc | 679 | /// class time_get_byname [22.2.5.2]. |
f749a55b PC |
680 | template<typename _CharT, typename _InIter> |
681 | class time_get_byname : public time_get<_CharT, _InIter> | |
682 | { | |
683 | public: | |
684 | // Types: | |
685 | typedef _CharT char_type; | |
686 | typedef _InIter iter_type; | |
687 | ||
688 | explicit | |
689 | time_get_byname(const char*, size_t __refs = 0) | |
690 | : time_get<_CharT, _InIter>(__refs) { } | |
691 | ||
692 | protected: | |
693 | virtual | |
694 | ~time_get_byname() { } | |
695 | }; | |
696 | ||
697 | /** | |
0eb95b0d BK |
698 | * @brief Primary class template time_put. |
699 | * @ingroup locales | |
f749a55b PC |
700 | * |
701 | * This facet encapsulates the code to format and output dates and times | |
702 | * according to formats used by strftime(). | |
703 | * | |
704 | * The time_put template uses protected virtual functions to provide the | |
705 | * actual results. The public accessors forward the call to the virtual | |
706 | * functions. These virtual functions are hooks for developers to | |
707 | * implement the behavior they require from the time_put facet. | |
708 | */ | |
709 | template<typename _CharT, typename _OutIter> | |
710 | class time_put : public locale::facet | |
711 | { | |
712 | public: | |
713 | // Types: | |
714 | //@{ | |
715 | /// Public typedefs | |
716 | typedef _CharT char_type; | |
717 | typedef _OutIter iter_type; | |
718 | //@} | |
719 | ||
720 | /// Numpunct facet id. | |
721 | static locale::id id; | |
722 | ||
723 | /** | |
724 | * @brief Constructor performs initialization. | |
725 | * | |
726 | * This is the constructor provided by the standard. | |
727 | * | |
728 | * @param refs Passed to the base facet class. | |
729 | */ | |
730 | explicit | |
731 | time_put(size_t __refs = 0) | |
732 | : facet(__refs) { } | |
733 | ||
734 | /** | |
735 | * @brief Format and output a time or date. | |
736 | * | |
737 | * This function formats the data in struct tm according to the | |
738 | * provided format string. The format string is interpreted as by | |
739 | * strftime(). | |
740 | * | |
741 | * @param s The stream to write to. | |
742 | * @param io Source of locale. | |
743 | * @param fill char_type to use for padding. | |
744 | * @param tm Struct tm with date and time info to format. | |
745 | * @param beg Start of format string. | |
746 | * @param end End of format string. | |
747 | * @return Iterator after writing. | |
748 | */ | |
749 | iter_type | |
750 | put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, | |
751 | const _CharT* __beg, const _CharT* __end) const; | |
752 | ||
753 | /** | |
754 | * @brief Format and output a time or date. | |
755 | * | |
756 | * This function formats the data in struct tm according to the | |
757 | * provided format char and optional modifier. The format and modifier | |
758 | * are interpreted as by strftime(). It does so by returning | |
759 | * time_put::do_put(). | |
760 | * | |
761 | * @param s The stream to write to. | |
762 | * @param io Source of locale. | |
763 | * @param fill char_type to use for padding. | |
764 | * @param tm Struct tm with date and time info to format. | |
765 | * @param format Format char. | |
766 | * @param mod Optional modifier char. | |
767 | * @return Iterator after writing. | |
768 | */ | |
769 | iter_type | |
770 | put(iter_type __s, ios_base& __io, char_type __fill, | |
771 | const tm* __tm, char __format, char __mod = 0) const | |
772 | { return this->do_put(__s, __io, __fill, __tm, __format, __mod); } | |
773 | ||
774 | protected: | |
775 | /// Destructor. | |
776 | virtual | |
777 | ~time_put() | |
778 | { } | |
779 | ||
780 | /** | |
781 | * @brief Format and output a time or date. | |
782 | * | |
783 | * This function formats the data in struct tm according to the | |
784 | * provided format char and optional modifier. This function is a hook | |
785 | * for derived classes to change the value returned. @see put() for | |
786 | * more details. | |
787 | * | |
788 | * @param s The stream to write to. | |
789 | * @param io Source of locale. | |
790 | * @param fill char_type to use for padding. | |
791 | * @param tm Struct tm with date and time info to format. | |
792 | * @param format Format char. | |
793 | * @param mod Optional modifier char. | |
794 | * @return Iterator after writing. | |
795 | */ | |
796 | virtual iter_type | |
797 | do_put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm, | |
798 | char __format, char __mod) const; | |
799 | }; | |
800 | ||
801 | template<typename _CharT, typename _OutIter> | |
802 | locale::id time_put<_CharT, _OutIter>::id; | |
803 | ||
939759fc | 804 | /// class time_put_byname [22.2.5.4]. |
f749a55b PC |
805 | template<typename _CharT, typename _OutIter> |
806 | class time_put_byname : public time_put<_CharT, _OutIter> | |
807 | { | |
808 | public: | |
809 | // Types: | |
810 | typedef _CharT char_type; | |
811 | typedef _OutIter iter_type; | |
812 | ||
813 | explicit | |
814 | time_put_byname(const char*, size_t __refs = 0) | |
815 | : time_put<_CharT, _OutIter>(__refs) | |
816 | { }; | |
817 | ||
818 | protected: | |
819 | virtual | |
820 | ~time_put_byname() { } | |
821 | }; | |
822 | ||
823 | ||
824 | /** | |
825 | * @brief Money format ordering data. | |
0eb95b0d | 826 | * @ingroup locales |
f749a55b PC |
827 | * |
828 | * This class contains an ordered array of 4 fields to represent the | |
829 | * pattern for formatting a money amount. Each field may contain one entry | |
830 | * from the part enum. symbol, sign, and value must be present and the | |
831 | * remaining field must contain either none or space. @see | |
832 | * moneypunct::pos_format() and moneypunct::neg_format() for details of how | |
833 | * these fields are interpreted. | |
834 | */ | |
835 | class money_base | |
836 | { | |
837 | public: | |
838 | enum part { none, space, symbol, sign, value }; | |
839 | struct pattern { char field[4]; }; | |
840 | ||
841 | static const pattern _S_default_pattern; | |
842 | ||
843 | enum | |
844 | { | |
845 | _S_minus, | |
846 | _S_zero, | |
847 | _S_end = 11 | |
848 | }; | |
849 | ||
850 | // String literal of acceptable (narrow) input/output, for | |
851 | // money_get/money_put. "-0123456789" | |
852 | static const char* _S_atoms; | |
853 | ||
854 | // Construct and return valid pattern consisting of some combination of: | |
855 | // space none symbol sign value | |
50a681c4 JH |
856 | _GLIBCXX_CONST static pattern |
857 | _S_construct_pattern(char __precedes, char __space, char __posn) throw (); | |
f749a55b PC |
858 | }; |
859 | ||
860 | template<typename _CharT, bool _Intl> | |
861 | struct __moneypunct_cache : public locale::facet | |
862 | { | |
863 | const char* _M_grouping; | |
864 | size_t _M_grouping_size; | |
865 | bool _M_use_grouping; | |
866 | _CharT _M_decimal_point; | |
867 | _CharT _M_thousands_sep; | |
868 | const _CharT* _M_curr_symbol; | |
869 | size_t _M_curr_symbol_size; | |
870 | const _CharT* _M_positive_sign; | |
871 | size_t _M_positive_sign_size; | |
872 | const _CharT* _M_negative_sign; | |
873 | size_t _M_negative_sign_size; | |
874 | int _M_frac_digits; | |
875 | money_base::pattern _M_pos_format; | |
876 | money_base::pattern _M_neg_format; | |
877 | ||
878 | // A list of valid numeric literals for input and output: in the standard | |
879 | // "C" locale, this is "-0123456789". This array contains the chars after | |
880 | // having been passed through the current locale's ctype<_CharT>.widen(). | |
881 | _CharT _M_atoms[money_base::_S_end]; | |
882 | ||
883 | bool _M_allocated; | |
884 | ||
885 | __moneypunct_cache(size_t __refs = 0) : facet(__refs), | |
8fc81078 | 886 | _M_grouping(0), _M_grouping_size(0), _M_use_grouping(false), |
f749a55b | 887 | _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()), |
8fc81078 PC |
888 | _M_curr_symbol(0), _M_curr_symbol_size(0), |
889 | _M_positive_sign(0), _M_positive_sign_size(0), | |
890 | _M_negative_sign(0), _M_negative_sign_size(0), | |
f749a55b PC |
891 | _M_frac_digits(0), |
892 | _M_pos_format(money_base::pattern()), | |
893 | _M_neg_format(money_base::pattern()), _M_allocated(false) | |
894 | { } | |
895 | ||
896 | ~__moneypunct_cache(); | |
897 | ||
898 | void | |
899 | _M_cache(const locale& __loc); | |
900 | ||
901 | private: | |
902 | __moneypunct_cache& | |
903 | operator=(const __moneypunct_cache&); | |
904 | ||
905 | explicit | |
906 | __moneypunct_cache(const __moneypunct_cache&); | |
907 | }; | |
908 | ||
909 | template<typename _CharT, bool _Intl> | |
910 | __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache() | |
911 | { | |
912 | if (_M_allocated) | |
913 | { | |
914 | delete [] _M_grouping; | |
915 | delete [] _M_curr_symbol; | |
916 | delete [] _M_positive_sign; | |
917 | delete [] _M_negative_sign; | |
918 | } | |
919 | } | |
920 | ||
921 | /** | |
0eb95b0d BK |
922 | * @brief Primary class template moneypunct. |
923 | * @ingroup locales | |
f749a55b PC |
924 | * |
925 | * This facet encapsulates the punctuation, grouping and other formatting | |
926 | * features of money amount string representations. | |
927 | */ | |
928 | template<typename _CharT, bool _Intl> | |
929 | class moneypunct : public locale::facet, public money_base | |
930 | { | |
931 | public: | |
932 | // Types: | |
933 | //@{ | |
934 | /// Public typedefs | |
935 | typedef _CharT char_type; | |
936 | typedef basic_string<_CharT> string_type; | |
937 | //@} | |
938 | typedef __moneypunct_cache<_CharT, _Intl> __cache_type; | |
939 | ||
940 | private: | |
941 | __cache_type* _M_data; | |
942 | ||
943 | public: | |
944 | /// This value is provided by the standard, but no reason for its | |
945 | /// existence. | |
946 | static const bool intl = _Intl; | |
947 | /// Numpunct facet id. | |
948 | static locale::id id; | |
949 | ||
950 | /** | |
951 | * @brief Constructor performs initialization. | |
952 | * | |
953 | * This is the constructor provided by the standard. | |
954 | * | |
955 | * @param refs Passed to the base facet class. | |
956 | */ | |
957 | explicit | |
8fc81078 PC |
958 | moneypunct(size_t __refs = 0) |
959 | : facet(__refs), _M_data(0) | |
f749a55b PC |
960 | { _M_initialize_moneypunct(); } |
961 | ||
962 | /** | |
963 | * @brief Constructor performs initialization. | |
964 | * | |
965 | * This is an internal constructor. | |
966 | * | |
967 | * @param cache Cache for optimization. | |
968 | * @param refs Passed to the base facet class. | |
969 | */ | |
970 | explicit | |
971 | moneypunct(__cache_type* __cache, size_t __refs = 0) | |
972 | : facet(__refs), _M_data(__cache) | |
973 | { _M_initialize_moneypunct(); } | |
974 | ||
975 | /** | |
976 | * @brief Internal constructor. Not for general use. | |
977 | * | |
978 | * This is a constructor for use by the library itself to set up new | |
979 | * locales. | |
980 | * | |
2a60a9f6 | 981 | * @param cloc The C locale. |
f749a55b PC |
982 | * @param s The name of a locale. |
983 | * @param refs Passed to the base facet class. | |
984 | */ | |
985 | explicit | |
986 | moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0) | |
8fc81078 | 987 | : facet(__refs), _M_data(0) |
f749a55b PC |
988 | { _M_initialize_moneypunct(__cloc, __s); } |
989 | ||
990 | /** | |
991 | * @brief Return decimal point character. | |
992 | * | |
993 | * This function returns a char_type to use as a decimal point. It | |
994 | * does so by returning returning | |
995 | * moneypunct<char_type>::do_decimal_point(). | |
996 | * | |
997 | * @return @a char_type representing a decimal point. | |
998 | */ | |
999 | char_type | |
1000 | decimal_point() const | |
1001 | { return this->do_decimal_point(); } | |
1002 | ||
1003 | /** | |
1004 | * @brief Return thousands separator character. | |
1005 | * | |
1006 | * This function returns a char_type to use as a thousands | |
1007 | * separator. It does so by returning returning | |
1008 | * moneypunct<char_type>::do_thousands_sep(). | |
1009 | * | |
1010 | * @return char_type representing a thousands separator. | |
1011 | */ | |
1012 | char_type | |
1013 | thousands_sep() const | |
1014 | { return this->do_thousands_sep(); } | |
1015 | ||
1016 | /** | |
1017 | * @brief Return grouping specification. | |
1018 | * | |
1019 | * This function returns a string representing groupings for the | |
1020 | * integer part of an amount. Groupings indicate where thousands | |
1021 | * separators should be inserted. | |
1022 | * | |
1023 | * Each char in the return string is interpret as an integer rather | |
1024 | * than a character. These numbers represent the number of digits in a | |
1025 | * group. The first char in the string represents the number of digits | |
1026 | * in the least significant group. If a char is negative, it indicates | |
1027 | * an unlimited number of digits for the group. If more chars from the | |
1028 | * string are required to group a number, the last char is used | |
1029 | * repeatedly. | |
1030 | * | |
2a60a9f6 BK |
1031 | * For example, if the grouping() returns <code>\003\002</code> |
1032 | * and is applied to the number 123456789, this corresponds to | |
1033 | * 12,34,56,789. Note that if the string was <code>32</code>, this would | |
1034 | * put more than 50 digits into the least significant group if | |
1035 | * the character set is ASCII. | |
f749a55b PC |
1036 | * |
1037 | * The string is returned by calling | |
1038 | * moneypunct<char_type>::do_grouping(). | |
1039 | * | |
1040 | * @return string representing grouping specification. | |
1041 | */ | |
1042 | string | |
1043 | grouping() const | |
1044 | { return this->do_grouping(); } | |
1045 | ||
1046 | /** | |
1047 | * @brief Return currency symbol string. | |
1048 | * | |
1049 | * This function returns a string_type to use as a currency symbol. It | |
1050 | * does so by returning returning | |
1051 | * moneypunct<char_type>::do_curr_symbol(). | |
1052 | * | |
1053 | * @return @a string_type representing a currency symbol. | |
1054 | */ | |
1055 | string_type | |
1056 | curr_symbol() const | |
1057 | { return this->do_curr_symbol(); } | |
1058 | ||
1059 | /** | |
1060 | * @brief Return positive sign string. | |
1061 | * | |
1062 | * This function returns a string_type to use as a sign for positive | |
1063 | * amounts. It does so by returning returning | |
1064 | * moneypunct<char_type>::do_positive_sign(). | |
1065 | * | |
1066 | * If the return value contains more than one character, the first | |
1067 | * character appears in the position indicated by pos_format() and the | |
1068 | * remainder appear at the end of the formatted string. | |
1069 | * | |
1070 | * @return @a string_type representing a positive sign. | |
1071 | */ | |
1072 | string_type | |
1073 | positive_sign() const | |
1074 | { return this->do_positive_sign(); } | |
1075 | ||
1076 | /** | |
1077 | * @brief Return negative sign string. | |
1078 | * | |
1079 | * This function returns a string_type to use as a sign for negative | |
1080 | * amounts. It does so by returning returning | |
1081 | * moneypunct<char_type>::do_negative_sign(). | |
1082 | * | |
1083 | * If the return value contains more than one character, the first | |
1084 | * character appears in the position indicated by neg_format() and the | |
1085 | * remainder appear at the end of the formatted string. | |
1086 | * | |
1087 | * @return @a string_type representing a negative sign. | |
1088 | */ | |
1089 | string_type | |
1090 | negative_sign() const | |
1091 | { return this->do_negative_sign(); } | |
1092 | ||
1093 | /** | |
1094 | * @brief Return number of digits in fraction. | |
1095 | * | |
1096 | * This function returns the exact number of digits that make up the | |
1097 | * fractional part of a money amount. It does so by returning | |
1098 | * returning moneypunct<char_type>::do_frac_digits(). | |
1099 | * | |
1100 | * The fractional part of a money amount is optional. But if it is | |
1101 | * present, there must be frac_digits() digits. | |
1102 | * | |
1103 | * @return Number of digits in amount fraction. | |
1104 | */ | |
1105 | int | |
1106 | frac_digits() const | |
1107 | { return this->do_frac_digits(); } | |
1108 | ||
1109 | //@{ | |
1110 | /** | |
1111 | * @brief Return pattern for money values. | |
1112 | * | |
1113 | * This function returns a pattern describing the formatting of a | |
1114 | * positive or negative valued money amount. It does so by returning | |
1115 | * returning moneypunct<char_type>::do_pos_format() or | |
1116 | * moneypunct<char_type>::do_neg_format(). | |
1117 | * | |
1118 | * The pattern has 4 fields describing the ordering of symbol, sign, | |
1119 | * value, and none or space. There must be one of each in the pattern. | |
1120 | * The none and space enums may not appear in the first field and space | |
1121 | * may not appear in the final field. | |
1122 | * | |
1123 | * The parts of a money string must appear in the order indicated by | |
1124 | * the fields of the pattern. The symbol field indicates that the | |
1125 | * value of curr_symbol() may be present. The sign field indicates | |
1126 | * that the value of positive_sign() or negative_sign() must be | |
1127 | * present. The value field indicates that the absolute value of the | |
1128 | * money amount is present. none indicates 0 or more whitespace | |
1129 | * characters, except at the end, where it permits no whitespace. | |
1130 | * space indicates that 1 or more whitespace characters must be | |
1131 | * present. | |
1132 | * | |
1133 | * For example, for the US locale and pos_format() pattern | |
2a60a9f6 BK |
1134 | * {symbol,sign,value,none}, curr_symbol() == '$' |
1135 | * positive_sign() == '+', and value 10.01, and | |
1136 | * options set to force the symbol, the corresponding string is | |
1137 | * <code>$+10.01</code>. | |
f749a55b PC |
1138 | * |
1139 | * @return Pattern for money values. | |
1140 | */ | |
1141 | pattern | |
1142 | pos_format() const | |
1143 | { return this->do_pos_format(); } | |
1144 | ||
1145 | pattern | |
1146 | neg_format() const | |
1147 | { return this->do_neg_format(); } | |
1148 | //@} | |
1149 | ||
1150 | protected: | |
1151 | /// Destructor. | |
1152 | virtual | |
1153 | ~moneypunct(); | |
1154 | ||
1155 | /** | |
1156 | * @brief Return decimal point character. | |
1157 | * | |
1158 | * Returns a char_type to use as a decimal point. This function is a | |
1159 | * hook for derived classes to change the value returned. | |
1160 | * | |
1161 | * @return @a char_type representing a decimal point. | |
1162 | */ | |
1163 | virtual char_type | |
1164 | do_decimal_point() const | |
1165 | { return _M_data->_M_decimal_point; } | |
1166 | ||
1167 | /** | |
1168 | * @brief Return thousands separator character. | |
1169 | * | |
1170 | * Returns a char_type to use as a thousands separator. This function | |
1171 | * is a hook for derived classes to change the value returned. | |
1172 | * | |
1173 | * @return @a char_type representing a thousands separator. | |
1174 | */ | |
1175 | virtual char_type | |
1176 | do_thousands_sep() const | |
1177 | { return _M_data->_M_thousands_sep; } | |
1178 | ||
1179 | /** | |
1180 | * @brief Return grouping specification. | |
1181 | * | |
1182 | * Returns a string representing groupings for the integer part of a | |
1183 | * number. This function is a hook for derived classes to change the | |
1184 | * value returned. @see grouping() for details. | |
1185 | * | |
1186 | * @return String representing grouping specification. | |
1187 | */ | |
1188 | virtual string | |
1189 | do_grouping() const | |
1190 | { return _M_data->_M_grouping; } | |
1191 | ||
1192 | /** | |
1193 | * @brief Return currency symbol string. | |
1194 | * | |
1195 | * This function returns a string_type to use as a currency symbol. | |
1196 | * This function is a hook for derived classes to change the value | |
1197 | * returned. @see curr_symbol() for details. | |
1198 | * | |
1199 | * @return @a string_type representing a currency symbol. | |
1200 | */ | |
1201 | virtual string_type | |
1202 | do_curr_symbol() const | |
1203 | { return _M_data->_M_curr_symbol; } | |
1204 | ||
1205 | /** | |
1206 | * @brief Return positive sign string. | |
1207 | * | |
1208 | * This function returns a string_type to use as a sign for positive | |
1209 | * amounts. This function is a hook for derived classes to change the | |
1210 | * value returned. @see positive_sign() for details. | |
1211 | * | |
1212 | * @return @a string_type representing a positive sign. | |
1213 | */ | |
1214 | virtual string_type | |
1215 | do_positive_sign() const | |
1216 | { return _M_data->_M_positive_sign; } | |
1217 | ||
1218 | /** | |
1219 | * @brief Return negative sign string. | |
1220 | * | |
1221 | * This function returns a string_type to use as a sign for negative | |
1222 | * amounts. This function is a hook for derived classes to change the | |
1223 | * value returned. @see negative_sign() for details. | |
1224 | * | |
1225 | * @return @a string_type representing a negative sign. | |
1226 | */ | |
1227 | virtual string_type | |
1228 | do_negative_sign() const | |
1229 | { return _M_data->_M_negative_sign; } | |
1230 | ||
1231 | /** | |
1232 | * @brief Return number of digits in fraction. | |
1233 | * | |
1234 | * This function returns the exact number of digits that make up the | |
1235 | * fractional part of a money amount. This function is a hook for | |
1236 | * derived classes to change the value returned. @see frac_digits() | |
1237 | * for details. | |
1238 | * | |
1239 | * @return Number of digits in amount fraction. | |
1240 | */ | |
1241 | virtual int | |
1242 | do_frac_digits() const | |
1243 | { return _M_data->_M_frac_digits; } | |
1244 | ||
1245 | /** | |
1246 | * @brief Return pattern for money values. | |
1247 | * | |
1248 | * This function returns a pattern describing the formatting of a | |
1249 | * positive valued money amount. This function is a hook for derived | |
1250 | * classes to change the value returned. @see pos_format() for | |
1251 | * details. | |
1252 | * | |
1253 | * @return Pattern for money values. | |
1254 | */ | |
1255 | virtual pattern | |
1256 | do_pos_format() const | |
1257 | { return _M_data->_M_pos_format; } | |
1258 | ||
1259 | /** | |
1260 | * @brief Return pattern for money values. | |
1261 | * | |
1262 | * This function returns a pattern describing the formatting of a | |
1263 | * negative valued money amount. This function is a hook for derived | |
1264 | * classes to change the value returned. @see neg_format() for | |
1265 | * details. | |
1266 | * | |
1267 | * @return Pattern for money values. | |
1268 | */ | |
1269 | virtual pattern | |
1270 | do_neg_format() const | |
1271 | { return _M_data->_M_neg_format; } | |
1272 | ||
1273 | // For use at construction time only. | |
1274 | void | |
8fc81078 PC |
1275 | _M_initialize_moneypunct(__c_locale __cloc = 0, |
1276 | const char* __name = 0); | |
f749a55b PC |
1277 | }; |
1278 | ||
1279 | template<typename _CharT, bool _Intl> | |
1280 | locale::id moneypunct<_CharT, _Intl>::id; | |
1281 | ||
1282 | template<typename _CharT, bool _Intl> | |
1283 | const bool moneypunct<_CharT, _Intl>::intl; | |
1284 | ||
1285 | template<> | |
1286 | moneypunct<char, true>::~moneypunct(); | |
1287 | ||
1288 | template<> | |
1289 | moneypunct<char, false>::~moneypunct(); | |
1290 | ||
1291 | template<> | |
1292 | void | |
1293 | moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); | |
1294 | ||
1295 | template<> | |
1296 | void | |
1297 | moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*); | |
1298 | ||
1299 | #ifdef _GLIBCXX_USE_WCHAR_T | |
1300 | template<> | |
1301 | moneypunct<wchar_t, true>::~moneypunct(); | |
1302 | ||
1303 | template<> | |
1304 | moneypunct<wchar_t, false>::~moneypunct(); | |
1305 | ||
1306 | template<> | |
1307 | void | |
1308 | moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, | |
1309 | const char*); | |
1310 | ||
1311 | template<> | |
1312 | void | |
1313 | moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, | |
1314 | const char*); | |
1315 | #endif | |
1316 | ||
939759fc | 1317 | /// class moneypunct_byname [22.2.6.4]. |
f749a55b PC |
1318 | template<typename _CharT, bool _Intl> |
1319 | class moneypunct_byname : public moneypunct<_CharT, _Intl> | |
1320 | { | |
1321 | public: | |
1322 | typedef _CharT char_type; | |
1323 | typedef basic_string<_CharT> string_type; | |
1324 | ||
1325 | static const bool intl = _Intl; | |
1326 | ||
1327 | explicit | |
1328 | moneypunct_byname(const char* __s, size_t __refs = 0) | |
1329 | : moneypunct<_CharT, _Intl>(__refs) | |
1330 | { | |
538075fe PC |
1331 | if (__builtin_strcmp(__s, "C") != 0 |
1332 | && __builtin_strcmp(__s, "POSIX") != 0) | |
f749a55b PC |
1333 | { |
1334 | __c_locale __tmp; | |
1335 | this->_S_create_c_locale(__tmp, __s); | |
1336 | this->_M_initialize_moneypunct(__tmp); | |
1337 | this->_S_destroy_c_locale(__tmp); | |
1338 | } | |
1339 | } | |
1340 | ||
1341 | protected: | |
1342 | virtual | |
1343 | ~moneypunct_byname() { } | |
1344 | }; | |
1345 | ||
1346 | template<typename _CharT, bool _Intl> | |
1347 | const bool moneypunct_byname<_CharT, _Intl>::intl; | |
1348 | ||
1349 | _GLIBCXX_BEGIN_LDBL_NAMESPACE | |
1350 | ||
1351 | /** | |
0eb95b0d BK |
1352 | * @brief Primary class template money_get. |
1353 | * @ingroup locales | |
f749a55b PC |
1354 | * |
1355 | * This facet encapsulates the code to parse and return a monetary | |
1356 | * amount from a string. | |
1357 | * | |
1358 | * The money_get template uses protected virtual functions to | |
1359 | * provide the actual results. The public accessors forward the | |
1360 | * call to the virtual functions. These virtual functions are | |
1361 | * hooks for developers to implement the behavior they require from | |
1362 | * the money_get facet. | |
1363 | */ | |
1364 | template<typename _CharT, typename _InIter> | |
1365 | class money_get : public locale::facet | |
1366 | { | |
1367 | public: | |
1368 | // Types: | |
1369 | //@{ | |
1370 | /// Public typedefs | |
1371 | typedef _CharT char_type; | |
1372 | typedef _InIter iter_type; | |
1373 | typedef basic_string<_CharT> string_type; | |
1374 | //@} | |
1375 | ||
1376 | /// Numpunct facet id. | |
1377 | static locale::id id; | |
1378 | ||
1379 | /** | |
1380 | * @brief Constructor performs initialization. | |
1381 | * | |
1382 | * This is the constructor provided by the standard. | |
1383 | * | |
1384 | * @param refs Passed to the base facet class. | |
1385 | */ | |
1386 | explicit | |
1387 | money_get(size_t __refs = 0) : facet(__refs) { } | |
1388 | ||
1389 | /** | |
1390 | * @brief Read and parse a monetary value. | |
1391 | * | |
1392 | * This function reads characters from @a s, interprets them as a | |
1393 | * monetary value according to moneypunct and ctype facets retrieved | |
1394 | * from io.getloc(), and returns the result in @a units as an integral | |
1395 | * value moneypunct::frac_digits() * the actual amount. For example, | |
1396 | * the string $10.01 in a US locale would store 1001 in @a units. | |
1397 | * | |
1398 | * Any characters not part of a valid money amount are not consumed. | |
1399 | * | |
1400 | * If a money value cannot be parsed from the input stream, sets | |
1401 | * err=(err|io.failbit). If the stream is consumed before finishing | |
1402 | * parsing, sets err=(err|io.failbit|io.eofbit). @a units is | |
1403 | * unchanged if parsing fails. | |
1404 | * | |
1405 | * This function works by returning the result of do_get(). | |
1406 | * | |
1407 | * @param s Start of characters to parse. | |
1408 | * @param end End of characters to parse. | |
1409 | * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. | |
1410 | * @param io Source of facets and io state. | |
1411 | * @param err Error field to set if parsing fails. | |
1412 | * @param units Place to store result of parsing. | |
1413 | * @return Iterator referencing first character beyond valid money | |
1414 | * amount. | |
1415 | */ | |
1416 | iter_type | |
1417 | get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, | |
1418 | ios_base::iostate& __err, long double& __units) const | |
1419 | { return this->do_get(__s, __end, __intl, __io, __err, __units); } | |
1420 | ||
1421 | /** | |
1422 | * @brief Read and parse a monetary value. | |
1423 | * | |
2a60a9f6 BK |
1424 | * This function reads characters from @a s, interprets them as |
1425 | * a monetary value according to moneypunct and ctype facets | |
1426 | * retrieved from io.getloc(), and returns the result in @a | |
1427 | * digits. For example, the string $10.01 in a US locale would | |
1428 | * store <code>1001</code> in @a digits. | |
f749a55b PC |
1429 | * |
1430 | * Any characters not part of a valid money amount are not consumed. | |
1431 | * | |
1432 | * If a money value cannot be parsed from the input stream, sets | |
1433 | * err=(err|io.failbit). If the stream is consumed before finishing | |
1434 | * parsing, sets err=(err|io.failbit|io.eofbit). | |
1435 | * | |
1436 | * This function works by returning the result of do_get(). | |
1437 | * | |
1438 | * @param s Start of characters to parse. | |
1439 | * @param end End of characters to parse. | |
1440 | * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. | |
1441 | * @param io Source of facets and io state. | |
1442 | * @param err Error field to set if parsing fails. | |
1443 | * @param digits Place to store result of parsing. | |
1444 | * @return Iterator referencing first character beyond valid money | |
1445 | * amount. | |
1446 | */ | |
1447 | iter_type | |
1448 | get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, | |
1449 | ios_base::iostate& __err, string_type& __digits) const | |
1450 | { return this->do_get(__s, __end, __intl, __io, __err, __digits); } | |
1451 | ||
1452 | protected: | |
1453 | /// Destructor. | |
1454 | virtual | |
1455 | ~money_get() { } | |
1456 | ||
1457 | /** | |
1458 | * @brief Read and parse a monetary value. | |
1459 | * | |
1460 | * This function reads and parses characters representing a monetary | |
1461 | * value. This function is a hook for derived classes to change the | |
1462 | * value returned. @see get() for details. | |
1463 | */ | |
1464 | // XXX GLIBCXX_ABI Deprecated | |
1465 | #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ | |
1466 | virtual iter_type | |
1467 | __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, | |
1468 | ios_base::iostate& __err, double& __units) const; | |
1469 | #else | |
1470 | virtual iter_type | |
1471 | do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, | |
1472 | ios_base::iostate& __err, long double& __units) const; | |
1473 | #endif | |
1474 | ||
1475 | /** | |
1476 | * @brief Read and parse a monetary value. | |
1477 | * | |
1478 | * This function reads and parses characters representing a monetary | |
1479 | * value. This function is a hook for derived classes to change the | |
1480 | * value returned. @see get() for details. | |
1481 | */ | |
1482 | virtual iter_type | |
1483 | do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, | |
1484 | ios_base::iostate& __err, string_type& __digits) const; | |
1485 | ||
1486 | // XXX GLIBCXX_ABI Deprecated | |
1487 | #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ | |
1488 | virtual iter_type | |
1489 | do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, | |
1490 | ios_base::iostate& __err, long double& __units) const; | |
1491 | #endif | |
1492 | ||
1493 | template<bool _Intl> | |
1494 | iter_type | |
1495 | _M_extract(iter_type __s, iter_type __end, ios_base& __io, | |
1496 | ios_base::iostate& __err, string& __digits) const; | |
1497 | }; | |
1498 | ||
1499 | template<typename _CharT, typename _InIter> | |
1500 | locale::id money_get<_CharT, _InIter>::id; | |
1501 | ||
1502 | /** | |
0eb95b0d BK |
1503 | * @brief Primary class template money_put. |
1504 | * @ingroup locales | |
f749a55b PC |
1505 | * |
1506 | * This facet encapsulates the code to format and output a monetary | |
1507 | * amount. | |
1508 | * | |
1509 | * The money_put template uses protected virtual functions to | |
1510 | * provide the actual results. The public accessors forward the | |
1511 | * call to the virtual functions. These virtual functions are | |
1512 | * hooks for developers to implement the behavior they require from | |
1513 | * the money_put facet. | |
1514 | */ | |
1515 | template<typename _CharT, typename _OutIter> | |
1516 | class money_put : public locale::facet | |
1517 | { | |
1518 | public: | |
1519 | //@{ | |
1520 | /// Public typedefs | |
1521 | typedef _CharT char_type; | |
1522 | typedef _OutIter iter_type; | |
1523 | typedef basic_string<_CharT> string_type; | |
1524 | //@} | |
1525 | ||
1526 | /// Numpunct facet id. | |
1527 | static locale::id id; | |
1528 | ||
1529 | /** | |
1530 | * @brief Constructor performs initialization. | |
1531 | * | |
1532 | * This is the constructor provided by the standard. | |
1533 | * | |
1534 | * @param refs Passed to the base facet class. | |
1535 | */ | |
1536 | explicit | |
1537 | money_put(size_t __refs = 0) : facet(__refs) { } | |
1538 | ||
1539 | /** | |
1540 | * @brief Format and output a monetary value. | |
1541 | * | |
1542 | * This function formats @a units as a monetary value according to | |
1543 | * moneypunct and ctype facets retrieved from io.getloc(), and writes | |
1544 | * the resulting characters to @a s. For example, the value 1001 in a | |
2a60a9f6 | 1545 | * US locale would write <code>$10.01</code> to @a s. |
f749a55b PC |
1546 | * |
1547 | * This function works by returning the result of do_put(). | |
1548 | * | |
1549 | * @param s The stream to write to. | |
1550 | * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. | |
1551 | * @param io Source of facets and io state. | |
1552 | * @param fill char_type to use for padding. | |
1553 | * @param units Place to store result of parsing. | |
1554 | * @return Iterator after writing. | |
1555 | */ | |
1556 | iter_type | |
1557 | put(iter_type __s, bool __intl, ios_base& __io, | |
1558 | char_type __fill, long double __units) const | |
1559 | { return this->do_put(__s, __intl, __io, __fill, __units); } | |
1560 | ||
1561 | /** | |
1562 | * @brief Format and output a monetary value. | |
1563 | * | |
2a60a9f6 BK |
1564 | * This function formats @a digits as a monetary value |
1565 | * according to moneypunct and ctype facets retrieved from | |
1566 | * io.getloc(), and writes the resulting characters to @a s. | |
1567 | * For example, the string <code>1001</code> in a US locale | |
1568 | * would write <code>$10.01</code> to @a s. | |
f749a55b PC |
1569 | * |
1570 | * This function works by returning the result of do_put(). | |
1571 | * | |
1572 | * @param s The stream to write to. | |
1573 | * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. | |
1574 | * @param io Source of facets and io state. | |
1575 | * @param fill char_type to use for padding. | |
1576 | * @param units Place to store result of parsing. | |
1577 | * @return Iterator after writing. | |
1578 | */ | |
1579 | iter_type | |
1580 | put(iter_type __s, bool __intl, ios_base& __io, | |
1581 | char_type __fill, const string_type& __digits) const | |
1582 | { return this->do_put(__s, __intl, __io, __fill, __digits); } | |
1583 | ||
1584 | protected: | |
1585 | /// Destructor. | |
1586 | virtual | |
1587 | ~money_put() { } | |
1588 | ||
1589 | /** | |
1590 | * @brief Format and output a monetary value. | |
1591 | * | |
1592 | * This function formats @a units as a monetary value according to | |
1593 | * moneypunct and ctype facets retrieved from io.getloc(), and writes | |
1594 | * the resulting characters to @a s. For example, the value 1001 in a | |
2a60a9f6 | 1595 | * US locale would write <code>$10.01</code> to @a s. |
f749a55b PC |
1596 | * |
1597 | * This function is a hook for derived classes to change the value | |
1598 | * returned. @see put(). | |
1599 | * | |
1600 | * @param s The stream to write to. | |
1601 | * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. | |
1602 | * @param io Source of facets and io state. | |
1603 | * @param fill char_type to use for padding. | |
1604 | * @param units Place to store result of parsing. | |
1605 | * @return Iterator after writing. | |
1606 | */ | |
1607 | // XXX GLIBCXX_ABI Deprecated | |
1608 | #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ | |
1609 | virtual iter_type | |
1610 | __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
1611 | double __units) const; | |
1612 | #else | |
1613 | virtual iter_type | |
1614 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
1615 | long double __units) const; | |
1616 | #endif | |
1617 | ||
1618 | /** | |
1619 | * @brief Format and output a monetary value. | |
1620 | * | |
2a60a9f6 BK |
1621 | * This function formats @a digits as a monetary value |
1622 | * according to moneypunct and ctype facets retrieved from | |
1623 | * io.getloc(), and writes the resulting characters to @a s. | |
1624 | * For example, the string <code>1001</code> in a US locale | |
1625 | * would write <code>$10.01</code> to @a s. | |
f749a55b PC |
1626 | * |
1627 | * This function is a hook for derived classes to change the value | |
1628 | * returned. @see put(). | |
1629 | * | |
1630 | * @param s The stream to write to. | |
1631 | * @param intl Parameter to use_facet<moneypunct<CharT,intl> >. | |
1632 | * @param io Source of facets and io state. | |
1633 | * @param fill char_type to use for padding. | |
1634 | * @param units Place to store result of parsing. | |
1635 | * @return Iterator after writing. | |
1636 | */ | |
1637 | virtual iter_type | |
1638 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
1639 | const string_type& __digits) const; | |
1640 | ||
1641 | // XXX GLIBCXX_ABI Deprecated | |
1642 | #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ | |
1643 | virtual iter_type | |
1644 | do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, | |
1645 | long double __units) const; | |
1646 | #endif | |
1647 | ||
1648 | template<bool _Intl> | |
1649 | iter_type | |
1650 | _M_insert(iter_type __s, ios_base& __io, char_type __fill, | |
1651 | const string_type& __digits) const; | |
1652 | }; | |
1653 | ||
1654 | template<typename _CharT, typename _OutIter> | |
1655 | locale::id money_put<_CharT, _OutIter>::id; | |
1656 | ||
1657 | _GLIBCXX_END_LDBL_NAMESPACE | |
1658 | ||
1659 | /** | |
1660 | * @brief Messages facet base class providing catalog typedef. | |
0eb95b0d | 1661 | * @ingroup locales |
f749a55b PC |
1662 | */ |
1663 | struct messages_base | |
1664 | { | |
1665 | typedef int catalog; | |
1666 | }; | |
1667 | ||
1668 | /** | |
0eb95b0d BK |
1669 | * @brief Primary class template messages. |
1670 | * @ingroup locales | |
f749a55b PC |
1671 | * |
1672 | * This facet encapsulates the code to retrieve messages from | |
1673 | * message catalogs. The only thing defined by the standard for this facet | |
1674 | * is the interface. All underlying functionality is | |
1675 | * implementation-defined. | |
1676 | * | |
1677 | * This library currently implements 3 versions of the message facet. The | |
1678 | * first version (gnu) is a wrapper around gettext, provided by libintl. | |
1679 | * The second version (ieee) is a wrapper around catgets. The final | |
1680 | * version (default) does no actual translation. These implementations are | |
1681 | * only provided for char and wchar_t instantiations. | |
1682 | * | |
1683 | * The messages template uses protected virtual functions to | |
1684 | * provide the actual results. The public accessors forward the | |
1685 | * call to the virtual functions. These virtual functions are | |
1686 | * hooks for developers to implement the behavior they require from | |
1687 | * the messages facet. | |
1688 | */ | |
1689 | template<typename _CharT> | |
1690 | class messages : public locale::facet, public messages_base | |
1691 | { | |
1692 | public: | |
1693 | // Types: | |
1694 | //@{ | |
1695 | /// Public typedefs | |
1696 | typedef _CharT char_type; | |
1697 | typedef basic_string<_CharT> string_type; | |
1698 | //@} | |
1699 | ||
1700 | protected: | |
1701 | // Underlying "C" library locale information saved from | |
1702 | // initialization, needed by messages_byname as well. | |
1703 | __c_locale _M_c_locale_messages; | |
1704 | const char* _M_name_messages; | |
1705 | ||
1706 | public: | |
1707 | /// Numpunct facet id. | |
1708 | static locale::id id; | |
1709 | ||
1710 | /** | |
1711 | * @brief Constructor performs initialization. | |
1712 | * | |
1713 | * This is the constructor provided by the standard. | |
1714 | * | |
1715 | * @param refs Passed to the base facet class. | |
1716 | */ | |
1717 | explicit | |
1718 | messages(size_t __refs = 0); | |
1719 | ||
1720 | // Non-standard. | |
1721 | /** | |
1722 | * @brief Internal constructor. Not for general use. | |
1723 | * | |
1724 | * This is a constructor for use by the library itself to set up new | |
1725 | * locales. | |
1726 | * | |
2a60a9f6 | 1727 | * @param cloc The C locale. |
f749a55b PC |
1728 | * @param s The name of a locale. |
1729 | * @param refs Refcount to pass to the base class. | |
1730 | */ | |
1731 | explicit | |
1732 | messages(__c_locale __cloc, const char* __s, size_t __refs = 0); | |
1733 | ||
1734 | /* | |
1735 | * @brief Open a message catalog. | |
1736 | * | |
1737 | * This function opens and returns a handle to a message catalog by | |
1738 | * returning do_open(s, loc). | |
1739 | * | |
1740 | * @param s The catalog to open. | |
1741 | * @param loc Locale to use for character set conversions. | |
1742 | * @return Handle to the catalog or value < 0 if open fails. | |
1743 | */ | |
1744 | catalog | |
1745 | open(const basic_string<char>& __s, const locale& __loc) const | |
1746 | { return this->do_open(__s, __loc); } | |
1747 | ||
1748 | // Non-standard and unorthodox, yet effective. | |
1749 | /* | |
1750 | * @brief Open a message catalog. | |
1751 | * | |
1752 | * This non-standard function opens and returns a handle to a message | |
1753 | * catalog by returning do_open(s, loc). The third argument provides a | |
1754 | * message catalog root directory for gnu gettext and is ignored | |
1755 | * otherwise. | |
1756 | * | |
1757 | * @param s The catalog to open. | |
1758 | * @param loc Locale to use for character set conversions. | |
1759 | * @param dir Message catalog root directory. | |
1760 | * @return Handle to the catalog or value < 0 if open fails. | |
1761 | */ | |
1762 | catalog | |
1763 | open(const basic_string<char>&, const locale&, const char*) const; | |
1764 | ||
1765 | /* | |
1766 | * @brief Look up a string in a message catalog. | |
1767 | * | |
1768 | * This function retrieves and returns a message from a catalog by | |
1769 | * returning do_get(c, set, msgid, s). | |
1770 | * | |
1771 | * For gnu, @a set and @a msgid are ignored. Returns gettext(s). | |
1772 | * For default, returns s. For ieee, returns catgets(c,set,msgid,s). | |
1773 | * | |
1774 | * @param c The catalog to access. | |
1775 | * @param set Implementation-defined. | |
1776 | * @param msgid Implementation-defined. | |
1777 | * @param s Default return value if retrieval fails. | |
1778 | * @return Retrieved message or @a s if get fails. | |
1779 | */ | |
1780 | string_type | |
1781 | get(catalog __c, int __set, int __msgid, const string_type& __s) const | |
1782 | { return this->do_get(__c, __set, __msgid, __s); } | |
1783 | ||
1784 | /* | |
1785 | * @brief Close a message catalog. | |
1786 | * | |
1787 | * Closes catalog @a c by calling do_close(c). | |
1788 | * | |
1789 | * @param c The catalog to close. | |
1790 | */ | |
1791 | void | |
1792 | close(catalog __c) const | |
1793 | { return this->do_close(__c); } | |
1794 | ||
1795 | protected: | |
1796 | /// Destructor. | |
1797 | virtual | |
1798 | ~messages(); | |
1799 | ||
1800 | /* | |
1801 | * @brief Open a message catalog. | |
1802 | * | |
1803 | * This function opens and returns a handle to a message catalog in an | |
1804 | * implementation-defined manner. This function is a hook for derived | |
1805 | * classes to change the value returned. | |
1806 | * | |
1807 | * @param s The catalog to open. | |
1808 | * @param loc Locale to use for character set conversions. | |
1809 | * @return Handle to the opened catalog, value < 0 if open failed. | |
1810 | */ | |
1811 | virtual catalog | |
1812 | do_open(const basic_string<char>&, const locale&) const; | |
1813 | ||
1814 | /* | |
1815 | * @brief Look up a string in a message catalog. | |
1816 | * | |
1817 | * This function retrieves and returns a message from a catalog in an | |
1818 | * implementation-defined manner. This function is a hook for derived | |
1819 | * classes to change the value returned. | |
1820 | * | |
1821 | * For gnu, @a set and @a msgid are ignored. Returns gettext(s). | |
1822 | * For default, returns s. For ieee, returns catgets(c,set,msgid,s). | |
1823 | * | |
1824 | * @param c The catalog to access. | |
1825 | * @param set Implementation-defined. | |
1826 | * @param msgid Implementation-defined. | |
1827 | * @param s Default return value if retrieval fails. | |
1828 | * @return Retrieved message or @a s if get fails. | |
1829 | */ | |
1830 | virtual string_type | |
1831 | do_get(catalog, int, int, const string_type& __dfault) const; | |
1832 | ||
1833 | /* | |
1834 | * @brief Close a message catalog. | |
1835 | * | |
1836 | * @param c The catalog to close. | |
1837 | */ | |
1838 | virtual void | |
1839 | do_close(catalog) const; | |
1840 | ||
1841 | // Returns a locale and codeset-converted string, given a char* message. | |
1842 | char* | |
1843 | _M_convert_to_char(const string_type& __msg) const | |
1844 | { | |
1845 | // XXX | |
1846 | return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str())); | |
1847 | } | |
1848 | ||
1849 | // Returns a locale and codeset-converted string, given a char* message. | |
1850 | string_type | |
1851 | _M_convert_from_char(char*) const | |
1852 | { | |
1853 | #if 0 | |
1854 | // Length of message string without terminating null. | |
1855 | size_t __len = char_traits<char>::length(__msg) - 1; | |
1856 | ||
1857 | // "everybody can easily convert the string using | |
1858 | // mbsrtowcs/wcsrtombs or with iconv()" | |
1859 | ||
1860 | // Convert char* to _CharT in locale used to open catalog. | |
1861 | // XXX need additional template parameter on messages class for this.. | |
1862 | // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type; | |
1863 | typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type; | |
1864 | ||
1865 | __codecvt_type::state_type __state; | |
1866 | // XXX may need to initialize state. | |
1867 | //initialize_state(__state._M_init()); | |
1868 | ||
1869 | char* __from_next; | |
1870 | // XXX what size for this string? | |
1871 | _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1)); | |
1872 | const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv); | |
1873 | __cvt.out(__state, __msg, __msg + __len, __from_next, | |
1874 | __to, __to + __len + 1, __to_next); | |
1875 | return string_type(__to); | |
1876 | #endif | |
1877 | #if 0 | |
1878 | typedef ctype<_CharT> __ctype_type; | |
1879 | // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg); | |
1880 | const __ctype_type& __cvt = use_facet<__ctype_type>(locale()); | |
1881 | // XXX Again, proper length of converted string an issue here. | |
1882 | // For now, assume the converted length is not larger. | |
1883 | _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1)); | |
1884 | __cvt.widen(__msg, __msg + __len, __dest); | |
1885 | return basic_string<_CharT>(__dest); | |
1886 | #endif | |
1887 | return string_type(); | |
1888 | } | |
1889 | }; | |
1890 | ||
1891 | template<typename _CharT> | |
1892 | locale::id messages<_CharT>::id; | |
1893 | ||
0eb95b0d | 1894 | /// Specializations for required instantiations. |
f749a55b PC |
1895 | template<> |
1896 | string | |
1897 | messages<char>::do_get(catalog, int, int, const string&) const; | |
1898 | ||
1899 | #ifdef _GLIBCXX_USE_WCHAR_T | |
1900 | template<> | |
1901 | wstring | |
1902 | messages<wchar_t>::do_get(catalog, int, int, const wstring&) const; | |
1903 | #endif | |
1904 | ||
939759fc | 1905 | /// class messages_byname [22.2.7.2]. |
f749a55b PC |
1906 | template<typename _CharT> |
1907 | class messages_byname : public messages<_CharT> | |
1908 | { | |
1909 | public: | |
1910 | typedef _CharT char_type; | |
1911 | typedef basic_string<_CharT> string_type; | |
1912 | ||
1913 | explicit | |
1914 | messages_byname(const char* __s, size_t __refs = 0); | |
1915 | ||
1916 | protected: | |
1917 | virtual | |
1918 | ~messages_byname() | |
1919 | { } | |
1920 | }; | |
1921 | ||
1922 | _GLIBCXX_END_NAMESPACE | |
1923 | ||
84b31797 | 1924 | // Include host and configuration specific messages functions. |
f749a55b PC |
1925 | #include <bits/messages_members.h> |
1926 | ||
84b31797 PC |
1927 | // 22.2.1.5 Template class codecvt |
1928 | #include <bits/codecvt.h> | |
1929 | ||
1930 | #ifndef _GLIBCXX_EXPORT_TEMPLATE | |
1931 | # include <bits/locale_facets_nonio.tcc> | |
1932 | #endif | |
1933 | ||
f749a55b | 1934 | #endif |