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