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 22 23 #ifndef _STLP_INTERNAL_MONETARY_H 24 #define _STLP_INTERNAL_MONETARY_H 25 26 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H 27 # include <stl/_ostreambuf_iterator.h> 28 #endif 29 30 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H 31 # include <stl/_istreambuf_iterator.h> 32 #endif 33 34 #ifndef _STLP_FACETS_FWD_H 35 # include <stl/_facets_fwd.h> 36 #endif 37 38 _STLP_BEGIN_NAMESPACE 39 40 class money_base { 41 public: 42 enum part {none, space, symbol, sign, value}; 43 struct pattern { 44 char field[4]; 45 }; 46 }; 47 48 // moneypunct facets: forward declaration 49 template <class _charT, _STLP_DFL_NON_TYPE_PARAM(bool, _International, false) > class moneypunct {}; 50 51 // money_get facets 52 53 template <class _CharT, class _InputIter> 54 class money_get : public locale::facet { 55 public: 56 typedef _CharT char_type; 57 typedef _InputIter iter_type; 58 typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type; 59 facet(__refs)60 explicit money_get(size_t __refs = 0) : locale::facet(__refs) {} get(iter_type __s,iter_type __end,bool __intl,ios_base & __str,ios_base::iostate & __err,_STLP_LONGEST_FLOAT_TYPE & __units)61 iter_type 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 { return do_get(__s, __end, __intl, __str, __err, __units); } get(iter_type __s,iter_type __end,bool __intl,ios_base & __str,ios_base::iostate & __err,string_type & __digits)65 iter_type get(iter_type __s, iter_type __end, bool __intl, 66 ios_base& __str, ios_base::iostate& __err, 67 string_type& __digits) const 68 { return do_get(__s, __end, __intl, __str, __err, __digits); } 69 70 static locale::id id; 71 72 protected: ~money_get()73 ~money_get() {} 74 virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl, 75 ios_base& __str, ios_base::iostate& __err, 76 _STLP_LONGEST_FLOAT_TYPE& __units) const; 77 virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl, 78 ios_base& __str, ios_base::iostate& __err, 79 string_type& __digits) const; 80 }; 81 82 83 // moneypunct facets: definition of specializations 84 85 _STLP_TEMPLATE_NULL 86 class _STLP_CLASS_DECLSPEC moneypunct<char, true> : public locale::facet, public money_base { 87 public: 88 typedef char char_type; 89 typedef string string_type; 90 explicit moneypunct _STLP_PSPEC2(char, true) (size_t __refs = 0); 91 decimal_point()92 char decimal_point() const { return do_decimal_point(); } thousands_sep()93 char thousands_sep() const { return do_thousands_sep(); } grouping()94 string grouping() const { return do_grouping(); } curr_symbol()95 string_type curr_symbol() const { return do_curr_symbol(); } positive_sign()96 string_type positive_sign() const { return do_positive_sign(); } negative_sign()97 string_type negative_sign() const { return do_negative_sign(); } frac_digits()98 int frac_digits() const { return do_frac_digits(); } pos_format()99 pattern pos_format() const { return do_pos_format(); } neg_format()100 pattern neg_format() const { return do_neg_format(); } 101 102 static _STLP_STATIC_DECLSPEC locale::id id; 103 _STLP_STATIC_CONSTANT(bool, intl = true); 104 105 protected: 106 pattern _M_pos_format; 107 pattern _M_neg_format; 108 109 ~moneypunct _STLP_PSPEC2(char, true) (); 110 111 virtual char do_decimal_point() const; 112 virtual char do_thousands_sep() const; 113 virtual string do_grouping() const; 114 115 virtual string do_curr_symbol() const; 116 117 virtual string do_positive_sign() const; 118 virtual string do_negative_sign() const; 119 virtual int do_frac_digits() const; 120 virtual pattern do_pos_format() const; 121 virtual pattern do_neg_format() const; 122 }; 123 124 _STLP_TEMPLATE_NULL 125 class _STLP_CLASS_DECLSPEC moneypunct<char, false> : public locale::facet, public money_base { 126 public: 127 typedef char char_type; 128 typedef string string_type; 129 130 explicit moneypunct _STLP_PSPEC2(char, false) (size_t __refs = 0); 131 decimal_point()132 char decimal_point() const { return do_decimal_point(); } thousands_sep()133 char thousands_sep() const { return do_thousands_sep(); } grouping()134 string grouping() const { return do_grouping(); } curr_symbol()135 string_type curr_symbol() const { return do_curr_symbol(); } positive_sign()136 string_type positive_sign() const { return do_positive_sign(); } negative_sign()137 string_type negative_sign() const { return do_negative_sign(); } frac_digits()138 int frac_digits() const { return do_frac_digits(); } pos_format()139 pattern pos_format() const { return do_pos_format(); } neg_format()140 pattern neg_format() const { return do_neg_format(); } 141 142 static _STLP_STATIC_DECLSPEC locale::id id; 143 _STLP_STATIC_CONSTANT(bool, intl = false); 144 145 protected: 146 pattern _M_pos_format; 147 pattern _M_neg_format; 148 149 ~moneypunct _STLP_PSPEC2(char, false) (); 150 151 virtual char do_decimal_point() const; 152 virtual char do_thousands_sep() const; 153 virtual string do_grouping() const; 154 155 virtual string do_curr_symbol() const; 156 157 virtual string do_positive_sign() const; 158 virtual string 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 164 165 #ifndef _STLP_NO_WCHAR_T 166 167 _STLP_TEMPLATE_NULL 168 class _STLP_CLASS_DECLSPEC moneypunct<wchar_t, true> : public locale::facet, public money_base { 169 public: 170 typedef wchar_t char_type; 171 typedef wstring string_type; 172 explicit moneypunct _STLP_PSPEC2(wchar_t, true) (size_t __refs = 0); decimal_point()173 wchar_t decimal_point() const { return do_decimal_point(); } thousands_sep()174 wchar_t thousands_sep() const { return do_thousands_sep(); } grouping()175 string grouping() const { return do_grouping(); } curr_symbol()176 string_type curr_symbol() const { return do_curr_symbol(); } positive_sign()177 string_type positive_sign() const { return do_positive_sign(); } negative_sign()178 string_type negative_sign() const { return do_negative_sign(); } frac_digits()179 int frac_digits() const { return do_frac_digits(); } pos_format()180 pattern pos_format() const { return do_pos_format(); } neg_format()181 pattern neg_format() const { return do_neg_format(); } 182 183 static _STLP_STATIC_DECLSPEC locale::id id; 184 _STLP_STATIC_CONSTANT(bool, intl = true); 185 186 protected: 187 pattern _M_pos_format; 188 pattern _M_neg_format; 189 190 ~moneypunct _STLP_PSPEC2(wchar_t, true) (); 191 192 virtual wchar_t do_decimal_point() const; 193 virtual wchar_t do_thousands_sep() const; 194 virtual string do_grouping() const; 195 196 virtual string_type do_curr_symbol() const; 197 198 virtual string_type do_positive_sign() const; 199 virtual string_type do_negative_sign() const; 200 virtual int do_frac_digits() const; 201 virtual pattern do_pos_format() const; 202 virtual pattern do_neg_format() const; 203 }; 204 205 206 _STLP_TEMPLATE_NULL 207 class _STLP_CLASS_DECLSPEC moneypunct<wchar_t, false> : public locale::facet, public money_base { 208 public: 209 typedef wchar_t char_type; 210 typedef wstring string_type; 211 explicit moneypunct _STLP_PSPEC2(wchar_t, false) (size_t __refs = 0); decimal_point()212 wchar_t decimal_point() const { return do_decimal_point(); } thousands_sep()213 wchar_t thousands_sep() const { return do_thousands_sep(); } grouping()214 string grouping() const { return do_grouping(); } curr_symbol()215 string_type curr_symbol() const { return do_curr_symbol(); } positive_sign()216 string_type positive_sign() const { return do_positive_sign(); } negative_sign()217 string_type negative_sign() const { return do_negative_sign(); } frac_digits()218 int frac_digits() const { return do_frac_digits(); } pos_format()219 pattern pos_format() const { return do_pos_format(); } neg_format()220 pattern neg_format() const { return do_neg_format(); } 221 222 static _STLP_STATIC_DECLSPEC locale::id id; 223 _STLP_STATIC_CONSTANT(bool, intl = false); 224 225 protected: 226 pattern _M_pos_format; 227 pattern _M_neg_format; 228 229 ~moneypunct _STLP_PSPEC2(wchar_t, false) (); 230 231 virtual wchar_t do_decimal_point() const; 232 virtual wchar_t do_thousands_sep() const; 233 virtual string do_grouping() const; 234 235 virtual string_type do_curr_symbol() const; 236 237 virtual string_type do_positive_sign() const; 238 virtual string_type do_negative_sign() const; 239 virtual int do_frac_digits() const; 240 virtual pattern do_pos_format() const; 241 virtual pattern do_neg_format() const; 242 }; 243 244 # endif 245 246 template <class _charT, _STLP_DFL_NON_TYPE_PARAM(bool , _International , false) > class moneypunct_byname {}; 247 248 _STLP_TEMPLATE_NULL 249 class _STLP_CLASS_DECLSPEC moneypunct_byname<char, true> : public moneypunct<char, true> { 250 friend class _Locale_impl; 251 public: 252 typedef money_base::pattern pattern; 253 typedef char char_type; 254 typedef string string_type; 255 256 explicit moneypunct_byname _STLP_PSPEC2(char, true) (const char * __name, size_t __refs = 0); 257 258 protected: 259 ~moneypunct_byname _STLP_PSPEC2(char, true) (); 260 virtual char do_decimal_point() const; 261 virtual char do_thousands_sep() const; 262 virtual string do_grouping() const; 263 264 virtual string_type do_curr_symbol() const; 265 266 virtual string_type do_positive_sign() const; 267 virtual string_type do_negative_sign() const; 268 virtual int do_frac_digits() const; 269 270 private: 271 moneypunct_byname _STLP_PSPEC2(char, true) (_Locale_monetary *__monetary); 272 273 typedef moneypunct_byname<char, true> _Self; 274 //explicitely defined as private to avoid warnings: 275 moneypunct_byname(_Self const&); 276 _Self& operator = (_Self const&); 277 278 _Locale_monetary* _M_monetary; 279 }; 280 281 _STLP_TEMPLATE_NULL 282 class _STLP_CLASS_DECLSPEC moneypunct_byname<char, false> : public moneypunct<char, false> { 283 friend class _Locale_impl; 284 public: 285 typedef money_base::pattern pattern; 286 typedef char char_type; 287 typedef string string_type; 288 289 explicit moneypunct_byname _STLP_PSPEC2(char, false) (const char * __name, size_t __refs = 0); 290 291 protected: 292 ~moneypunct_byname _STLP_PSPEC2(char, false) (); 293 virtual char do_decimal_point() const; 294 virtual char do_thousands_sep() const; 295 virtual string do_grouping() const; 296 297 virtual string_type do_curr_symbol() const; 298 299 virtual string_type do_positive_sign() const; 300 virtual string_type do_negative_sign() const; 301 virtual int do_frac_digits() const; 302 303 private: 304 moneypunct_byname _STLP_PSPEC2(char, false) (_Locale_monetary *__monetary); 305 306 typedef moneypunct_byname<char, false> _Self; 307 //explicitely defined as private to avoid warnings: 308 moneypunct_byname(_Self const&); 309 _Self& operator = (_Self const&); 310 311 _Locale_monetary* _M_monetary; 312 }; 313 314 #if !defined (_STLP_NO_WCHAR_T) 315 _STLP_TEMPLATE_NULL 316 class _STLP_CLASS_DECLSPEC moneypunct_byname<wchar_t, true> : public moneypunct<wchar_t, true> { 317 friend class _Locale_impl; 318 public: 319 typedef money_base::pattern pattern; 320 typedef wchar_t char_type; 321 typedef wstring string_type; 322 323 explicit moneypunct_byname _STLP_PSPEC2(wchar_t, true) (const char * __name, size_t __refs = 0); 324 325 protected: 326 ~moneypunct_byname _STLP_PSPEC2(wchar_t, true) (); 327 virtual wchar_t do_decimal_point() const; 328 virtual wchar_t do_thousands_sep() const; 329 virtual string do_grouping() const; 330 331 virtual string_type do_curr_symbol() const; 332 333 virtual string_type do_positive_sign() const; 334 virtual string_type do_negative_sign() const; 335 virtual int do_frac_digits() const; 336 337 private: 338 moneypunct_byname _STLP_PSPEC2(wchar_t, true) (_Locale_monetary *__monetary); 339 340 typedef moneypunct_byname<wchar_t, true> _Self; 341 //explicitely defined as private to avoid warnings: 342 moneypunct_byname(_Self const&); 343 _Self& operator = (_Self const&); 344 345 _Locale_monetary* _M_monetary; 346 }; 347 348 _STLP_TEMPLATE_NULL 349 class _STLP_CLASS_DECLSPEC moneypunct_byname<wchar_t, false> : public moneypunct<wchar_t, false> { 350 friend class _Locale_impl; 351 public: 352 typedef money_base::pattern pattern; 353 typedef wchar_t char_type; 354 typedef wstring string_type; 355 356 explicit moneypunct_byname _STLP_PSPEC2(wchar_t, false) (const char * __name, size_t __refs = 0); 357 358 protected: 359 ~moneypunct_byname _STLP_PSPEC2(wchar_t, false) (); 360 virtual wchar_t do_decimal_point() const; 361 virtual wchar_t do_thousands_sep() const; 362 virtual string do_grouping() const; 363 364 virtual string_type do_curr_symbol() const; 365 366 virtual string_type do_positive_sign() const; 367 virtual string_type do_negative_sign() const; 368 virtual int do_frac_digits() const; 369 370 private: 371 moneypunct_byname _STLP_PSPEC2(wchar_t, false) (_Locale_monetary *__monetary); 372 373 typedef moneypunct_byname<wchar_t, false> _Self; 374 //explicitely defined as private to avoid warnings: 375 moneypunct_byname(_Self const&); 376 _Self& operator = (_Self const&); 377 378 _Locale_monetary* _M_monetary; 379 }; 380 #endif 381 382 //===== methods ====== 383 384 385 // money_put facets 386 387 template <class _CharT, class _OutputIter> 388 class money_put : public locale::facet { 389 public: 390 typedef _CharT char_type; 391 typedef _OutputIter iter_type; 392 typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type; 393 facet(__refs)394 explicit money_put(size_t __refs = 0) : locale::facet(__refs) {} put(iter_type __s,bool __intl,ios_base & __str,char_type __fill,_STLP_LONGEST_FLOAT_TYPE __units)395 iter_type put(iter_type __s, bool __intl, ios_base& __str, 396 char_type __fill, _STLP_LONGEST_FLOAT_TYPE __units) const 397 { return do_put(__s, __intl, __str, __fill, __units); } put(iter_type __s,bool __intl,ios_base & __str,char_type __fill,const string_type & __digits)398 iter_type put(iter_type __s, bool __intl, ios_base& __str, 399 char_type __fill, 400 const string_type& __digits) const 401 { return do_put(__s, __intl, __str, __fill, __digits); } 402 403 static locale::id id; 404 405 protected: ~money_put()406 ~money_put() {} 407 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __str, 408 char_type __fill, _STLP_LONGEST_FLOAT_TYPE __units) const; 409 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __str, 410 char_type __fill, 411 const string_type& __digits) const; 412 }; 413 414 #if defined (_STLP_USE_TEMPLATE_EXPORT) 415 _STLP_EXPORT_TEMPLATE_CLASS money_get<char, istreambuf_iterator<char, char_traits<char> > >; 416 _STLP_EXPORT_TEMPLATE_CLASS money_put<char, ostreambuf_iterator<char, char_traits<char> > >; 417 # if ! defined (_STLP_NO_WCHAR_T) 418 _STLP_EXPORT_TEMPLATE_CLASS money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >; 419 _STLP_EXPORT_TEMPLATE_CLASS money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >; 420 # endif 421 #endif 422 423 _STLP_END_NAMESPACE 424 425 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) 426 # include <stl/_monetary.c> 427 #endif 428 429 #endif /* _STLP_INTERNAL_MONETARY_H */ 430 431 // Local Variables: 432 // mode:C++ 433 // End: 434 435 436