locale_facets_nonio.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033
  1. // Locale support -*- C++ -*-
  2. // Copyright (C) 2007-2021 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 || defined __LONG_DOUBLE_IEEE128__)
  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_ALT128_COMPAT \
  1429. && defined __LONG_DOUBLE_IEEE128__
  1430. virtual iter_type
  1431. __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
  1432. ios_base::iostate& __err, __ibm128& __units) const;
  1433. #endif
  1434. // XXX GLIBCXX_ABI Deprecated
  1435. #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
  1436. && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__)
  1437. virtual iter_type
  1438. do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io,
  1439. ios_base::iostate& __err, long double& __units) const;
  1440. #endif
  1441. template<bool _Intl>
  1442. iter_type
  1443. _M_extract(iter_type __s, iter_type __end, ios_base& __io,
  1444. ios_base::iostate& __err, string& __digits) const;
  1445. };
  1446. template<typename _CharT, typename _InIter>
  1447. locale::id money_get<_CharT, _InIter>::id;
  1448. /**
  1449. * @brief Primary class template money_put.
  1450. * @ingroup locales
  1451. *
  1452. * This facet encapsulates the code to format and output a monetary
  1453. * amount.
  1454. *
  1455. * The money_put template uses protected virtual functions to
  1456. * provide the actual results. The public accessors forward the
  1457. * call to the virtual functions. These virtual functions are
  1458. * hooks for developers to implement the behavior they require from
  1459. * the money_put facet.
  1460. */
  1461. template<typename _CharT, typename _OutIter>
  1462. class money_put : public locale::facet
  1463. {
  1464. public:
  1465. ///@{
  1466. /// Public typedefs
  1467. typedef _CharT char_type;
  1468. typedef _OutIter iter_type;
  1469. typedef basic_string<_CharT> string_type;
  1470. ///@}
  1471. /// Numpunct facet id.
  1472. static locale::id id;
  1473. /**
  1474. * @brief Constructor performs initialization.
  1475. *
  1476. * This is the constructor provided by the standard.
  1477. *
  1478. * @param __refs Passed to the base facet class.
  1479. */
  1480. explicit
  1481. money_put(size_t __refs = 0) : facet(__refs) { }
  1482. /**
  1483. * @brief Format and output a monetary value.
  1484. *
  1485. * This function formats @a units as a monetary value according to
  1486. * moneypunct and ctype facets retrieved from io.getloc(), and writes
  1487. * the resulting characters to @a __s. For example, the value 1001 in a
  1488. * US locale would write <code>$10.01</code> to @a __s.
  1489. *
  1490. * This function works by returning the result of do_put().
  1491. *
  1492. * @param __s The stream to write to.
  1493. * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
  1494. * @param __io Source of facets and io state.
  1495. * @param __fill char_type to use for padding.
  1496. * @param __units Place to store result of parsing.
  1497. * @return Iterator after writing.
  1498. */
  1499. iter_type
  1500. put(iter_type __s, bool __intl, ios_base& __io,
  1501. char_type __fill, long double __units) const
  1502. { return this->do_put(__s, __intl, __io, __fill, __units); }
  1503. /**
  1504. * @brief Format and output a monetary value.
  1505. *
  1506. * This function formats @a digits as a monetary value
  1507. * according to moneypunct and ctype facets retrieved from
  1508. * io.getloc(), and writes the resulting characters to @a __s.
  1509. * For example, the string <code>1001</code> in a US locale
  1510. * would write <code>$10.01</code> to @a __s.
  1511. *
  1512. * This function works by returning the result of do_put().
  1513. *
  1514. * @param __s The stream to write to.
  1515. * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
  1516. * @param __io Source of facets and io state.
  1517. * @param __fill char_type to use for padding.
  1518. * @param __digits Place to store result of parsing.
  1519. * @return Iterator after writing.
  1520. */
  1521. iter_type
  1522. put(iter_type __s, bool __intl, ios_base& __io,
  1523. char_type __fill, const string_type& __digits) const
  1524. { return this->do_put(__s, __intl, __io, __fill, __digits); }
  1525. protected:
  1526. /// Destructor.
  1527. virtual
  1528. ~money_put() { }
  1529. /**
  1530. * @brief Format and output a monetary value.
  1531. *
  1532. * This function formats @a units as a monetary value according to
  1533. * moneypunct and ctype facets retrieved from io.getloc(), and writes
  1534. * the resulting characters to @a __s. For example, the value 1001 in a
  1535. * US locale would write <code>$10.01</code> to @a __s.
  1536. *
  1537. * This function is a hook for derived classes to change the value
  1538. * returned. @see put().
  1539. *
  1540. * @param __s The stream to write to.
  1541. * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
  1542. * @param __io Source of facets and io state.
  1543. * @param __fill char_type to use for padding.
  1544. * @param __units Place to store result of parsing.
  1545. * @return Iterator after writing.
  1546. */
  1547. // XXX GLIBCXX_ABI Deprecated
  1548. #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
  1549. && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__)
  1550. virtual iter_type
  1551. __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
  1552. double __units) const;
  1553. #else
  1554. virtual iter_type
  1555. do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
  1556. long double __units) const;
  1557. #endif
  1558. /**
  1559. * @brief Format and output a monetary value.
  1560. *
  1561. * This function formats @a digits as a monetary value
  1562. * according to moneypunct and ctype facets retrieved from
  1563. * io.getloc(), and writes the resulting characters to @a __s.
  1564. * For example, the string <code>1001</code> in a US locale
  1565. * would write <code>$10.01</code> to @a __s.
  1566. *
  1567. * This function is a hook for derived classes to change the value
  1568. * returned. @see put().
  1569. *
  1570. * @param __s The stream to write to.
  1571. * @param __intl Parameter to use_facet<moneypunct<CharT,intl> >.
  1572. * @param __io Source of facets and io state.
  1573. * @param __fill char_type to use for padding.
  1574. * @param __digits Place to store result of parsing.
  1575. * @return Iterator after writing.
  1576. */
  1577. virtual iter_type
  1578. do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
  1579. const string_type& __digits) const;
  1580. // XXX GLIBCXX_ABI Deprecated
  1581. #if defined _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT \
  1582. && defined __LONG_DOUBLE_IEEE128__
  1583. virtual iter_type
  1584. __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
  1585. __ibm128 __units) const;
  1586. #endif
  1587. // XXX GLIBCXX_ABI Deprecated
  1588. #if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ \
  1589. && (_GLIBCXX_USE_CXX11_ABI == 0 || defined __LONG_DOUBLE_IEEE128__)
  1590. virtual iter_type
  1591. do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
  1592. long double __units) const;
  1593. #endif
  1594. template<bool _Intl>
  1595. iter_type
  1596. _M_insert(iter_type __s, ios_base& __io, char_type __fill,
  1597. const string_type& __digits) const;
  1598. };
  1599. template<typename _CharT, typename _OutIter>
  1600. locale::id money_put<_CharT, _OutIter>::id;
  1601. _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
  1602. /**
  1603. * @brief Messages facet base class providing catalog typedef.
  1604. * @ingroup locales
  1605. */
  1606. struct messages_base
  1607. {
  1608. typedef int catalog;
  1609. };
  1610. _GLIBCXX_BEGIN_NAMESPACE_CXX11
  1611. /**
  1612. * @brief Primary class template messages.
  1613. * @ingroup locales
  1614. *
  1615. * This facet encapsulates the code to retrieve messages from
  1616. * message catalogs. The only thing defined by the standard for this facet
  1617. * is the interface. All underlying functionality is
  1618. * implementation-defined.
  1619. *
  1620. * This library currently implements 3 versions of the message facet. The
  1621. * first version (gnu) is a wrapper around gettext, provided by libintl.
  1622. * The second version (ieee) is a wrapper around catgets. The final
  1623. * version (default) does no actual translation. These implementations are
  1624. * only provided for char and wchar_t instantiations.
  1625. *
  1626. * The messages template uses protected virtual functions to
  1627. * provide the actual results. The public accessors forward the
  1628. * call to the virtual functions. These virtual functions are
  1629. * hooks for developers to implement the behavior they require from
  1630. * the messages facet.
  1631. */
  1632. template<typename _CharT>
  1633. class messages : public locale::facet, public messages_base
  1634. {
  1635. public:
  1636. // Types:
  1637. ///@{
  1638. /// Public typedefs
  1639. typedef _CharT char_type;
  1640. typedef basic_string<_CharT> string_type;
  1641. ///@}
  1642. protected:
  1643. // Underlying "C" library locale information saved from
  1644. // initialization, needed by messages_byname as well.
  1645. __c_locale _M_c_locale_messages;
  1646. const char* _M_name_messages;
  1647. public:
  1648. /// Numpunct facet id.
  1649. static locale::id id;
  1650. /**
  1651. * @brief Constructor performs initialization.
  1652. *
  1653. * This is the constructor provided by the standard.
  1654. *
  1655. * @param __refs Passed to the base facet class.
  1656. */
  1657. explicit
  1658. messages(size_t __refs = 0);
  1659. // Non-standard.
  1660. /**
  1661. * @brief Internal constructor. Not for general use.
  1662. *
  1663. * This is a constructor for use by the library itself to set up new
  1664. * locales.
  1665. *
  1666. * @param __cloc The C locale.
  1667. * @param __s The name of a locale.
  1668. * @param __refs Refcount to pass to the base class.
  1669. */
  1670. explicit
  1671. messages(__c_locale __cloc, const char* __s, size_t __refs = 0);
  1672. /*
  1673. * @brief Open a message catalog.
  1674. *
  1675. * This function opens and returns a handle to a message catalog by
  1676. * returning do_open(__s, __loc).
  1677. *
  1678. * @param __s The catalog to open.
  1679. * @param __loc Locale to use for character set conversions.
  1680. * @return Handle to the catalog or value < 0 if open fails.
  1681. */
  1682. catalog
  1683. open(const basic_string<char>& __s, const locale& __loc) const
  1684. { return this->do_open(__s, __loc); }
  1685. // Non-standard and unorthodox, yet effective.
  1686. /*
  1687. * @brief Open a message catalog.
  1688. *
  1689. * This non-standard function opens and returns a handle to a message
  1690. * catalog by returning do_open(s, loc). The third argument provides a
  1691. * message catalog root directory for gnu gettext and is ignored
  1692. * otherwise.
  1693. *
  1694. * @param __s The catalog to open.
  1695. * @param __loc Locale to use for character set conversions.
  1696. * @param __dir Message catalog root directory.
  1697. * @return Handle to the catalog or value < 0 if open fails.
  1698. */
  1699. catalog
  1700. open(const basic_string<char>&, const locale&, const char*) const;
  1701. /*
  1702. * @brief Look up a string in a message catalog.
  1703. *
  1704. * This function retrieves and returns a message from a catalog by
  1705. * returning do_get(c, set, msgid, s).
  1706. *
  1707. * For gnu, @a __set and @a msgid are ignored. Returns gettext(s).
  1708. * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
  1709. *
  1710. * @param __c The catalog to access.
  1711. * @param __set Implementation-defined.
  1712. * @param __msgid Implementation-defined.
  1713. * @param __s Default return value if retrieval fails.
  1714. * @return Retrieved message or @a __s if get fails.
  1715. */
  1716. string_type
  1717. get(catalog __c, int __set, int __msgid, const string_type& __s) const
  1718. { return this->do_get(__c, __set, __msgid, __s); }
  1719. /*
  1720. * @brief Close a message catalog.
  1721. *
  1722. * Closes catalog @a c by calling do_close(c).
  1723. *
  1724. * @param __c The catalog to close.
  1725. */
  1726. void
  1727. close(catalog __c) const
  1728. { return this->do_close(__c); }
  1729. protected:
  1730. /// Destructor.
  1731. virtual
  1732. ~messages();
  1733. /*
  1734. * @brief Open a message catalog.
  1735. *
  1736. * This function opens and returns a handle to a message catalog in an
  1737. * implementation-defined manner. This function is a hook for derived
  1738. * classes to change the value returned.
  1739. *
  1740. * @param __s The catalog to open.
  1741. * @param __loc Locale to use for character set conversions.
  1742. * @return Handle to the opened catalog, value < 0 if open failed.
  1743. */
  1744. virtual catalog
  1745. do_open(const basic_string<char>&, const locale&) const;
  1746. /*
  1747. * @brief Look up a string in a message catalog.
  1748. *
  1749. * This function retrieves and returns a message from a catalog in an
  1750. * implementation-defined manner. This function is a hook for derived
  1751. * classes to change the value returned.
  1752. *
  1753. * For gnu, @a __set and @a __msgid are ignored. Returns gettext(s).
  1754. * For default, returns s. For ieee, returns catgets(c,set,msgid,s).
  1755. *
  1756. * @param __c The catalog to access.
  1757. * @param __set Implementation-defined.
  1758. * @param __msgid Implementation-defined.
  1759. * @param __s Default return value if retrieval fails.
  1760. * @return Retrieved message or @a __s if get fails.
  1761. */
  1762. virtual string_type
  1763. do_get(catalog, int, int, const string_type& __dfault) const;
  1764. /*
  1765. * @brief Close a message catalog.
  1766. *
  1767. * @param __c The catalog to close.
  1768. */
  1769. virtual void
  1770. do_close(catalog) const;
  1771. // Returns a locale and codeset-converted string, given a char* message.
  1772. char*
  1773. _M_convert_to_char(const string_type& __msg) const
  1774. {
  1775. // XXX
  1776. return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str()));
  1777. }
  1778. // Returns a locale and codeset-converted string, given a char* message.
  1779. string_type
  1780. _M_convert_from_char(char*) const
  1781. {
  1782. // XXX
  1783. return string_type();
  1784. }
  1785. };
  1786. template<typename _CharT>
  1787. locale::id messages<_CharT>::id;
  1788. /// Specializations for required instantiations.
  1789. template<>
  1790. string
  1791. messages<char>::do_get(catalog, int, int, const string&) const;
  1792. #ifdef _GLIBCXX_USE_WCHAR_T
  1793. template<>
  1794. wstring
  1795. messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;
  1796. #endif
  1797. /// class messages_byname [22.2.7.2].
  1798. template<typename _CharT>
  1799. class messages_byname : public messages<_CharT>
  1800. {
  1801. public:
  1802. typedef _CharT char_type;
  1803. typedef basic_string<_CharT> string_type;
  1804. explicit
  1805. messages_byname(const char* __s, size_t __refs = 0);
  1806. #if __cplusplus >= 201103L
  1807. explicit
  1808. messages_byname(const string& __s, size_t __refs = 0)
  1809. : messages_byname(__s.c_str(), __refs) { }
  1810. #endif
  1811. protected:
  1812. virtual
  1813. ~messages_byname()
  1814. { }
  1815. };
  1816. _GLIBCXX_END_NAMESPACE_CXX11
  1817. _GLIBCXX_END_NAMESPACE_VERSION
  1818. } // namespace
  1819. // Include host and configuration specific messages functions.
  1820. #include <bits/messages_members.h>
  1821. // 22.2.1.5 Template class codecvt
  1822. #include <bits/codecvt.h>
  1823. #include <bits/locale_facets_nonio.tcc>
  1824. #endif