locale_facets_nonio.h 67 KB

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