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