_monetary.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers. You should not attempt to use this header
  20. // file directly.
  21. #ifndef _STLP_INTERNAL_MONETARY_H
  22. #define _STLP_INTERNAL_MONETARY_H
  23. #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
  24. # include <stl/_ostreambuf_iterator.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
  27. # include <stl/_istreambuf_iterator.h>
  28. #endif
  29. #ifndef _STLP_FACETS_FWD_H
  30. # include <stl/_facets_fwd.h>
  31. #endif
  32. _STLP_BEGIN_NAMESPACE
  33. class money_base {
  34. public:
  35. enum part {none, space, symbol, sign, value};
  36. struct pattern {
  37. char field[4];
  38. };
  39. };
  40. // moneypunct facets: forward declaration
  41. template <class _charT, _STLP_DFL_NON_TYPE_PARAM(bool, _International, false) > class moneypunct {};
  42. // money_get facets
  43. template <class _CharT, class _InputIter>
  44. class money_get : public locale::facet {
  45. public:
  46. typedef _CharT char_type;
  47. typedef _InputIter iter_type;
  48. typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type;
  49. explicit money_get(size_t __refs = 0) : locale::facet(__refs) {}
  50. iter_type get(iter_type __s, iter_type __end, bool __intl,
  51. ios_base& __str, ios_base::iostate& __err,
  52. _STLP_LONGEST_FLOAT_TYPE& __units) const
  53. { return do_get(__s, __end, __intl, __str, __err, __units); }
  54. iter_type get(iter_type __s, iter_type __end, bool __intl,
  55. ios_base& __str, ios_base::iostate& __err,
  56. string_type& __digits) const
  57. { return do_get(__s, __end, __intl, __str, __err, __digits); }
  58. static locale::id id;
  59. protected:
  60. ~money_get() {}
  61. virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl,
  62. ios_base& __str, ios_base::iostate& __err,
  63. _STLP_LONGEST_FLOAT_TYPE& __units) const;
  64. virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl,
  65. ios_base& __str, ios_base::iostate& __err,
  66. string_type& __digits) const;
  67. };
  68. // moneypunct facets: definition of specializations
  69. _STLP_TEMPLATE_NULL
  70. class _STLP_CLASS_DECLSPEC moneypunct<char, true> : public locale::facet, public money_base {
  71. public:
  72. typedef char char_type;
  73. typedef string string_type;
  74. explicit moneypunct _STLP_PSPEC2(char, true) (size_t __refs = 0);
  75. char decimal_point() const { return do_decimal_point(); }
  76. char thousands_sep() const { return do_thousands_sep(); }
  77. string grouping() const { return do_grouping(); }
  78. string_type curr_symbol() const { return do_curr_symbol(); }
  79. string_type positive_sign() const { return do_positive_sign(); }
  80. string_type negative_sign() const { return do_negative_sign(); }
  81. int frac_digits() const { return do_frac_digits(); }
  82. pattern pos_format() const { return do_pos_format(); }
  83. pattern neg_format() const { return do_neg_format(); }
  84. static _STLP_STATIC_DECLSPEC locale::id id;
  85. _STLP_STATIC_CONSTANT(bool, intl = true);
  86. protected:
  87. pattern _M_pos_format;
  88. pattern _M_neg_format;
  89. ~moneypunct _STLP_PSPEC2(char, true) ();
  90. virtual char do_decimal_point() const;
  91. virtual char do_thousands_sep() const;
  92. virtual string do_grouping() const;
  93. virtual string do_curr_symbol() const;
  94. virtual string do_positive_sign() const;
  95. virtual string do_negative_sign() const;
  96. virtual int do_frac_digits() const;
  97. virtual pattern do_pos_format() const;
  98. virtual pattern do_neg_format() const;
  99. };
  100. _STLP_TEMPLATE_NULL
  101. class _STLP_CLASS_DECLSPEC moneypunct<char, false> : public locale::facet, public money_base {
  102. public:
  103. typedef char char_type;
  104. typedef string string_type;
  105. explicit moneypunct _STLP_PSPEC2(char, false) (size_t __refs = 0);
  106. char decimal_point() const { return do_decimal_point(); }
  107. char thousands_sep() const { return do_thousands_sep(); }
  108. string grouping() const { return do_grouping(); }
  109. string_type curr_symbol() const { return do_curr_symbol(); }
  110. string_type positive_sign() const { return do_positive_sign(); }
  111. string_type negative_sign() const { return do_negative_sign(); }
  112. int frac_digits() const { return do_frac_digits(); }
  113. pattern pos_format() const { return do_pos_format(); }
  114. pattern neg_format() const { return do_neg_format(); }
  115. static _STLP_STATIC_DECLSPEC locale::id id;
  116. _STLP_STATIC_CONSTANT(bool, intl = false);
  117. protected:
  118. pattern _M_pos_format;
  119. pattern _M_neg_format;
  120. ~moneypunct _STLP_PSPEC2(char, false) ();
  121. virtual char do_decimal_point() const;
  122. virtual char do_thousands_sep() const;
  123. virtual string do_grouping() const;
  124. virtual string do_curr_symbol() const;
  125. virtual string do_positive_sign() const;
  126. virtual string do_negative_sign() const;
  127. virtual int do_frac_digits() const;
  128. virtual pattern do_pos_format() const;
  129. virtual pattern do_neg_format() const;
  130. };
  131. #ifndef _STLP_NO_WCHAR_T
  132. _STLP_TEMPLATE_NULL
  133. class _STLP_CLASS_DECLSPEC moneypunct<wchar_t, true> : public locale::facet, public money_base {
  134. public:
  135. typedef wchar_t char_type;
  136. typedef wstring string_type;
  137. explicit moneypunct _STLP_PSPEC2(wchar_t, true) (size_t __refs = 0);
  138. wchar_t decimal_point() const { return do_decimal_point(); }
  139. wchar_t thousands_sep() const { return do_thousands_sep(); }
  140. string grouping() const { return do_grouping(); }
  141. string_type curr_symbol() const { return do_curr_symbol(); }
  142. string_type positive_sign() const { return do_positive_sign(); }
  143. string_type negative_sign() const { return do_negative_sign(); }
  144. int frac_digits() const { return do_frac_digits(); }
  145. pattern pos_format() const { return do_pos_format(); }
  146. pattern neg_format() const { return do_neg_format(); }
  147. static _STLP_STATIC_DECLSPEC locale::id id;
  148. _STLP_STATIC_CONSTANT(bool, intl = true);
  149. protected:
  150. pattern _M_pos_format;
  151. pattern _M_neg_format;
  152. ~moneypunct _STLP_PSPEC2(wchar_t, true) ();
  153. virtual wchar_t do_decimal_point() const;
  154. virtual wchar_t do_thousands_sep() const;
  155. virtual string do_grouping() const;
  156. virtual string_type do_curr_symbol() const;
  157. virtual string_type do_positive_sign() const;
  158. virtual string_type do_negative_sign() const;
  159. virtual int do_frac_digits() const;
  160. virtual pattern do_pos_format() const;
  161. virtual pattern do_neg_format() const;
  162. };
  163. _STLP_TEMPLATE_NULL
  164. class _STLP_CLASS_DECLSPEC moneypunct<wchar_t, false> : public locale::facet, public money_base {
  165. public:
  166. typedef wchar_t char_type;
  167. typedef wstring string_type;
  168. explicit moneypunct _STLP_PSPEC2(wchar_t, false) (size_t __refs = 0);
  169. wchar_t decimal_point() const { return do_decimal_point(); }
  170. wchar_t thousands_sep() const { return do_thousands_sep(); }
  171. string grouping() const { return do_grouping(); }
  172. string_type curr_symbol() const { return do_curr_symbol(); }
  173. string_type positive_sign() const { return do_positive_sign(); }
  174. string_type negative_sign() const { return do_negative_sign(); }
  175. int frac_digits() const { return do_frac_digits(); }
  176. pattern pos_format() const { return do_pos_format(); }
  177. pattern neg_format() const { return do_neg_format(); }
  178. static _STLP_STATIC_DECLSPEC locale::id id;
  179. _STLP_STATIC_CONSTANT(bool, intl = false);
  180. protected:
  181. pattern _M_pos_format;
  182. pattern _M_neg_format;
  183. ~moneypunct _STLP_PSPEC2(wchar_t, false) ();
  184. virtual wchar_t do_decimal_point() const;
  185. virtual wchar_t do_thousands_sep() const;
  186. virtual string do_grouping() const;
  187. virtual string_type do_curr_symbol() const;
  188. virtual string_type do_positive_sign() const;
  189. virtual string_type do_negative_sign() const;
  190. virtual int do_frac_digits() const;
  191. virtual pattern do_pos_format() const;
  192. virtual pattern do_neg_format() const;
  193. };
  194. # endif
  195. template <class _charT, _STLP_DFL_NON_TYPE_PARAM(bool , _International , false) > class moneypunct_byname {};
  196. _STLP_TEMPLATE_NULL
  197. class _STLP_CLASS_DECLSPEC moneypunct_byname<char, true> : public moneypunct<char, true> {
  198. friend class _Locale_impl;
  199. public:
  200. typedef money_base::pattern pattern;
  201. typedef char char_type;
  202. typedef string string_type;
  203. explicit moneypunct_byname _STLP_PSPEC2(char, true) (const char * __name, size_t __refs = 0);
  204. protected:
  205. ~moneypunct_byname _STLP_PSPEC2(char, true) ();
  206. virtual char do_decimal_point() const;
  207. virtual char do_thousands_sep() const;
  208. virtual string do_grouping() const;
  209. virtual string_type do_curr_symbol() const;
  210. virtual string_type do_positive_sign() const;
  211. virtual string_type do_negative_sign() const;
  212. virtual int do_frac_digits() const;
  213. private:
  214. moneypunct_byname _STLP_PSPEC2(char, true) (_Locale_monetary *__monetary);
  215. typedef moneypunct_byname<char, true> _Self;
  216. //explicitely defined as private to avoid warnings:
  217. moneypunct_byname(_Self const&);
  218. _Self& operator = (_Self const&);
  219. _Locale_monetary* _M_monetary;
  220. };
  221. _STLP_TEMPLATE_NULL
  222. class _STLP_CLASS_DECLSPEC moneypunct_byname<char, false> : public moneypunct<char, false> {
  223. friend class _Locale_impl;
  224. public:
  225. typedef money_base::pattern pattern;
  226. typedef char char_type;
  227. typedef string string_type;
  228. explicit moneypunct_byname _STLP_PSPEC2(char, false) (const char * __name, size_t __refs = 0);
  229. protected:
  230. ~moneypunct_byname _STLP_PSPEC2(char, false) ();
  231. virtual char do_decimal_point() const;
  232. virtual char do_thousands_sep() const;
  233. virtual string do_grouping() const;
  234. virtual string_type do_curr_symbol() const;
  235. virtual string_type do_positive_sign() const;
  236. virtual string_type do_negative_sign() const;
  237. virtual int do_frac_digits() const;
  238. private:
  239. moneypunct_byname _STLP_PSPEC2(char, false) (_Locale_monetary *__monetary);
  240. typedef moneypunct_byname<char, false> _Self;
  241. //explicitely defined as private to avoid warnings:
  242. moneypunct_byname(_Self const&);
  243. _Self& operator = (_Self const&);
  244. _Locale_monetary* _M_monetary;
  245. };
  246. #if !defined (_STLP_NO_WCHAR_T)
  247. _STLP_TEMPLATE_NULL
  248. class _STLP_CLASS_DECLSPEC moneypunct_byname<wchar_t, true> : public moneypunct<wchar_t, true> {
  249. friend class _Locale_impl;
  250. public:
  251. typedef money_base::pattern pattern;
  252. typedef wchar_t char_type;
  253. typedef wstring string_type;
  254. explicit moneypunct_byname _STLP_PSPEC2(wchar_t, true) (const char * __name, size_t __refs = 0);
  255. protected:
  256. ~moneypunct_byname _STLP_PSPEC2(wchar_t, true) ();
  257. virtual wchar_t do_decimal_point() const;
  258. virtual wchar_t do_thousands_sep() const;
  259. virtual string do_grouping() const;
  260. virtual string_type do_curr_symbol() const;
  261. virtual string_type do_positive_sign() const;
  262. virtual string_type do_negative_sign() const;
  263. virtual int do_frac_digits() const;
  264. private:
  265. moneypunct_byname _STLP_PSPEC2(wchar_t, true) (_Locale_monetary *__monetary);
  266. typedef moneypunct_byname<wchar_t, true> _Self;
  267. //explicitely defined as private to avoid warnings:
  268. moneypunct_byname(_Self const&);
  269. _Self& operator = (_Self const&);
  270. _Locale_monetary* _M_monetary;
  271. };
  272. _STLP_TEMPLATE_NULL
  273. class _STLP_CLASS_DECLSPEC moneypunct_byname<wchar_t, false> : public moneypunct<wchar_t, false> {
  274. friend class _Locale_impl;
  275. public:
  276. typedef money_base::pattern pattern;
  277. typedef wchar_t char_type;
  278. typedef wstring string_type;
  279. explicit moneypunct_byname _STLP_PSPEC2(wchar_t, false) (const char * __name, size_t __refs = 0);
  280. protected:
  281. ~moneypunct_byname _STLP_PSPEC2(wchar_t, false) ();
  282. virtual wchar_t do_decimal_point() const;
  283. virtual wchar_t do_thousands_sep() const;
  284. virtual string do_grouping() const;
  285. virtual string_type do_curr_symbol() const;
  286. virtual string_type do_positive_sign() const;
  287. virtual string_type do_negative_sign() const;
  288. virtual int do_frac_digits() const;
  289. private:
  290. moneypunct_byname _STLP_PSPEC2(wchar_t, false) (_Locale_monetary *__monetary);
  291. typedef moneypunct_byname<wchar_t, false> _Self;
  292. //explicitely defined as private to avoid warnings:
  293. moneypunct_byname(_Self const&);
  294. _Self& operator = (_Self const&);
  295. _Locale_monetary* _M_monetary;
  296. };
  297. #endif
  298. //===== methods ======
  299. // money_put facets
  300. template <class _CharT, class _OutputIter>
  301. class money_put : public locale::facet {
  302. public:
  303. typedef _CharT char_type;
  304. typedef _OutputIter iter_type;
  305. typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type;
  306. explicit money_put(size_t __refs = 0) : locale::facet(__refs) {}
  307. iter_type put(iter_type __s, bool __intl, ios_base& __str,
  308. char_type __fill, _STLP_LONGEST_FLOAT_TYPE __units) const
  309. { return do_put(__s, __intl, __str, __fill, __units); }
  310. iter_type put(iter_type __s, bool __intl, ios_base& __str,
  311. char_type __fill,
  312. const string_type& __digits) const
  313. { return do_put(__s, __intl, __str, __fill, __digits); }
  314. static locale::id id;
  315. protected:
  316. ~money_put() {}
  317. virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __str,
  318. char_type __fill, _STLP_LONGEST_FLOAT_TYPE __units) const;
  319. virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __str,
  320. char_type __fill,
  321. const string_type& __digits) const;
  322. };
  323. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  324. _STLP_EXPORT_TEMPLATE_CLASS money_get<char, istreambuf_iterator<char, char_traits<char> > >;
  325. _STLP_EXPORT_TEMPLATE_CLASS money_put<char, ostreambuf_iterator<char, char_traits<char> > >;
  326. # if ! defined (_STLP_NO_WCHAR_T)
  327. _STLP_EXPORT_TEMPLATE_CLASS money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  328. _STLP_EXPORT_TEMPLATE_CLASS money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
  329. # endif
  330. #endif
  331. _STLP_END_NAMESPACE
  332. #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
  333. # include <stl/_monetary.c>
  334. #endif
  335. #endif /* _STLP_INTERNAL_MONETARY_H */
  336. // Local Variables:
  337. // mode:C++
  338. // End: