/*************************************************************************** * * _money.h - Definitions of the money facets * * This is an internal header file used to implement the C++ Standard * Library. It should never be #included directly by a program. * * $Id: _money.h 186353 2014-07-29 16:30:44Z ransin01 $ * *************************************************************************** * * Copyright (c) 1994-2001 Rogue Wave Software, Inc. All Rights Reserved. * * This computer software is owned by Rogue Wave Software, Inc. and is * protected by U.S. copyright laws and other laws and by international * treaties. This computer software is furnished by Rogue Wave Software, * Inc. pursuant to a written license agreement and may be used, copied, * transmitted, and stored only in accordance with the terms of such * license and with the inclusion of the above copyright notice. This * computer software or any other copies thereof may not be provided or * otherwise made available to any other person. * * U.S. Government Restricted Rights. This computer software is provided * with Restricted Rights. Use, duplication, or disclosure by the * Government is subject to restrictions as set forth in subparagraph (c) * (1) (ii) of The Rights in Technical Data and Computer Software clause * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the * Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19, * as applicable. Manufacturer is Rogue Wave Software, Inc., 5500 * Flatiron Parkway, Boulder, Colorado 80301 USA. * **************************************************************************/ #ifndef _RWSTD_MONEY_H_INCLUDED #define _RWSTD_MONEY_H_INCLUDED #include #include #include #include _RWSTD_NAMESPACE_BEGIN (std) struct money_base { enum part { none, space, symbol, sign, value }; struct pattern { char field[4]; }; }; _RWSTD_NAMESPACE_END // std _RWSTD_NAMESPACE_BEGIN (__rw) template class __rw_money_handler_base_1; template class __rw_money_reader_base_1; template class __rw_money_writer_base_1; template class __rw_money_reader_base_2; template class __rw_money_writer_base_2; // -------------------------------------------------------------- // Implementation class template -- __rw_moneypunct_init_data<_CharT>. // -------------------------------------------------------------- // Structure used to initialize a rwstd::__rw_moneypunct_impl_data<_CharT>. template class __rw_moneypunct_init_data { public: bool _C_del; // Delete when initialization is done _CharT _C_dp, _C_ts; // Decimal point and thousands separator const char *_C_gr; // Grouping pattern const _CharT *_C_cs; // Currency symbol string const _CharT *_C_ps, *_C_ns; // Positive and negative sign strings int _C_fd; // Number of fractional digits _STD::money_base::pattern _C_pf; // Positive format pattern _STD::money_base::pattern _C_nf; // Negative format pattern }; // --------------------------------------------- // Implementation class -- __rw_moneypunct_impl_base. // --------------------------------------------- // Contains parts of __rw_moneypunct_impl_data<_CharT> that // do not depend on the template parameter. class _RWSTD_EXPORT __rw_moneypunct_impl_base { public: static const _RW::__rw_moneypunct_init_data* _C_get_named_init (const char*, bool); }; // ------------------------------------------------------------- // Implementation class template -- __rw_moneypunct_impl_data<_CharT>. // ------------------------------------------------------------- // moneypunct<_CharT, _Intl> derives from this (via // __rw_moneypunct_impl<_CharT, _Intl>) to get its private data members. template class __rw_moneypunct_impl_data : public __rw_moneypunct_impl_base, public __rw_punct_data<_CharT> { friend class __rw_money_handler_base_1<_CharT>; friend class _STD::moneypunct<_CharT, false>; friend class _STD::moneypunct<_CharT, true>; typedef _STD::char_traits<_CharT> traits_type; typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> > string_type; string_type _C_cs; // Currency symbol string_type _C_ps, // Positive and negative sign strings _C_ns; int _C_fd; // Number of fractional digits // Positive and negative format patterns _STD::money_base::pattern _C_pf, _C_nf; protected: __rw_moneypunct_impl_data (const __rw_moneypunct_init_data<_CharT>*); const __rw_moneypunct_init_data<_CharT>* _C_get_init_by_name_ (const char*, bool); }; _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_moneypunct_impl_data); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_moneypunct_impl_data); #endif // _RWSTD_NO_WCHAR_T // ------------------------------------------------------------------ // Implementation class template -- __rw_money_handler_base_1<_CharT>. // ------------------------------------------------------------------ // Contains common __rw_money_reader and __rw_money_writer functionality that depends // only on the _CharT template parameter. template class __rw_money_handler_base_1 { const __rw_moneypunct_impl_data<_CharT> &_C_mpunct; protected: typedef _STD::char_traits<_CharT> traits_type; typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> > string_type; __rw_money_handler_base_1 (const __rw_moneypunct_impl_data<_CharT> &__p) : _C_mpunct(__p) { } static const __rw_moneypunct_impl_data<_CharT>& _C_get_punct_data (const locale &__loc, bool __intl); const _STD::money_base::pattern& _C_get_pos_format() const { return _C_mpunct._C_pf; } const _STD::money_base::pattern& _C_get_neg_format() const { return _C_mpunct._C_nf; } const string_type &_C_get_positive_sign () const { return _C_mpunct._C_ps; } const string_type &_C_get_negative_sign () const { return _C_mpunct._C_ns; } const string_type &_C_get_curr_symbol () const { return _C_mpunct._C_cs; } int _C_get_frac_digits () const { return _C_mpunct._C_fd; } }; _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_money_handler_base_1); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_money_handler_base_1); #endif // _RWSTD_NO_WCHAR_T // ----------------------------------------------------------------- // Implementation class template -- __rw_money_reader_base_1<_CharT>. // ----------------------------------------------------------------- // Contains parts of __rw_money_reader<_CharT, _InputIter> // that depend only on the _CharT template parameter. template class __rw_money_reader_base_1 : public __rw_money_handler_base_1<_CharT> { protected: typedef _STD::char_traits<_CharT> traits_type; typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> > string_type; __rw_digit_reader_base_1<_CharT> &reader; __rw_money_reader_base_1 (__rw_digit_reader_base_1<_CharT> &__r, const __rw_moneypunct_impl_data<_CharT> &mp) : __rw_money_handler_base_1<_CharT>(mp), reader(__r) {} public: void _C_get_money_string (string_type&, const char*); }; _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_money_reader_base_1); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_money_reader_base_1); #endif // _RWSTD_NO_WCHAR_T // --------------------------------------------------------------------------- // Implementation class template - __rw_money_reader_base_2<_CharT, _InputIter> // --------------------------------------------------------------------------- // Contains parts of __rw_money_reader<_CharT, _InputIter> that do not depend // on the intl constructor parameter. template class __rw_money_reader_base_2 : public __rw_digit_reader<_CharT, _InputIter>, public __rw_money_reader_base_1<_CharT> { protected: typedef _STD::char_traits<_CharT> traits_type; typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> > string_type; __rw_money_reader_base_2 (_InputIter&, _InputIter&, ios_base&, const __rw_moneypunct_impl_data<_CharT>&); __rw_digit_reader_base_1<_CharT> &_C_this_as_digit_reader () { return *this; } public: char *_C_get_money_digits (void); // Get monetary-format digits }; _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT __rw_money_reader_base_2 > > ); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT __rw_money_reader_base_2 > > ); #endif // _RWSTD_NO_WCHAR_T // ------------------------------------------------------------------------ // Implementation class template -- __rw_money_reader<_CharT, _InputIter>. // ------------------------------------------------------------------------ template class __rw_money_reader : public __rw_money_reader_base_2<_CharT, _InputIter> { public: __rw_money_reader (_InputIter &__begin, _InputIter &__end, _STD::ios_base &__flags, bool __intl) : __rw_money_reader_base_2<_CharT, _InputIter> (__begin, __end, __flags, __rw_money_handler_base_1<_CharT>::_C_get_punct_data(__flags.getloc(), __intl)) { } }; // ----------------------------------------------------------------- // Implementation class template -- __rw_money_writer_base_1<_CharT>. // ----------------------------------------------------------------- // Contains parts of __rw_money_writer<_CharT, _Intl, _OutputIter> // that depend only on the _CharT template parameter. template class __rw_money_writer_base_1 : public __rw_money_handler_base_1<_CharT> { public: typedef _STD::char_traits<_CharT> traits_type; typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> > string_type; void _C_put_money (_CharT __fill); void _C_put_money (const string_type&, _CharT __fill); protected: __rw_digit_writer_base_1<_CharT> &writer; __rw_money_writer_base_1 (__rw_digit_writer_base_1<_CharT> &__w, const __rw_moneypunct_impl_data<_CharT> &__mp) : __rw_money_handler_base_1<_CharT>(__mp), writer(__w) { } virtual void _C_put_money_sub (const _CharT*, const _CharT*, bool, _CharT) = 0; }; _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_money_writer_base_1); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_money_writer_base_1); #endif // _RWSTD_NO_WCHAR_T // --------------------------------------------------------------------------- // Implementation class template __rw_money_writer_base_2<_CharT, _OutputIter> // --------------------------------------------------------------------------- // Contains parts of __rw_money_writer<_CharT, _OutputIter> // that do not depend on the intl constructor parameter. template class __rw_money_writer_base_2 : public __rw_digit_writer<_CharT, _OutputIter>, public __rw_money_writer_base_1<_CharT> { protected: typedef _STD::char_traits<_CharT> traits_type; typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> > string_type; __rw_money_writer_base_2 (_OutputIter &__it, _STD::ios_base &__flags, const __rw_moneypunct_impl_data<_CharT> &__mp) : __rw_digit_writer<_CharT, _OutputIter> (__it, __flags, __mp), __rw_money_writer_base_1<_CharT> (this_as_digit_writer(), __mp) { } __rw_digit_writer_base_1<_CharT> &this_as_digit_writer () { return *this; } virtual void _C_put_money_sub (const _CharT*, const _CharT*, bool, _CharT); }; _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT __rw_money_writer_base_2 > > ); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT __rw_money_writer_base_2 > > ); #endif // _RWSTD_NO_WCHAR_T // ------------------------------------------------------------------------- // Implementation class template -- __rw_money_writer<_CharT, _OutputIter>. // ------------------------------------------------------------------------- template class __rw_money_writer : public __rw_money_writer_base_2<_CharT, _OutputIter> { public: __rw_money_writer (_OutputIter &__it, _STD::ios_base &__flags, bool __intl) : __rw_money_writer_base_2<_CharT, _OutputIter> (__it, __flags, __rw_money_handler_base_1<_CharT>::_C_get_punct_data(__flags.getloc(), __intl)) { } }; template const __rw_moneypunct_init_data<_CharT>* __rw_fixup_moneypunct_init (const __rw_moneypunct_init_data*, _CharT*); _RWSTD_SPECIALIZED_FUNCTION inline const __rw_moneypunct_init_data* __rw_fixup_moneypunct_init (const __rw_moneypunct_init_data *__mp, char*) { return __mp; } // ------------------------------------------------------------------ // Implementation class template -- __rw_moneypunct_impl<_CharT, _Intl>. // ------------------------------------------------------------------ // moneypunct<_CharT, _Intl> derives from this to get the parts of its behavior // that are specialized for the character type and the _Intl format selection. template class __rw_moneypunct_impl : public __rw_moneypunct_impl_data<_CharT> { protected: __rw_moneypunct_impl (); }; _RWSTD_SPECIALIZED_CLASS class _RWSTD_EXPORT __rw_moneypunct_impl : public __rw_moneypunct_impl_data { friend class __rw_moneypunct_impl_base; protected: typedef __rw_moneypunct_impl_data parent_type; static const __rw_moneypunct_init_data _C_ivals; __rw_moneypunct_impl (const __rw_moneypunct_init_data *__mp = &_C_ivals) : parent_type (__mp) { } }; _RWSTD_SPECIALIZED_CLASS class _RWSTD_EXPORT __rw_moneypunct_impl : public __rw_moneypunct_impl_data { friend class __rw_moneypunct_impl_base; protected: typedef __rw_moneypunct_impl_data parent_type; static const __rw_moneypunct_init_data _C_ivals; __rw_moneypunct_impl (const __rw_moneypunct_init_data *__mp = &_C_ivals) : parent_type(__mp) { } }; #ifndef _RWSTD_NO_WCHAR_T _RWSTD_SPECIALIZED_CLASS class _RWSTD_EXPORT __rw_moneypunct_impl : public __rw_moneypunct_impl_data { protected: typedef __rw_moneypunct_impl_data parent_type; static const __rw_moneypunct_init_data _C_ivals; __rw_moneypunct_impl (const __rw_moneypunct_init_data *__mp = &_C_ivals) : parent_type(__mp) { } }; _RWSTD_SPECIALIZED_CLASS class _RWSTD_EXPORT __rw_moneypunct_impl : public __rw_moneypunct_impl_data { protected: typedef __rw_moneypunct_impl_data parent_type; static const __rw_moneypunct_init_data _C_ivals; __rw_moneypunct_impl (const __rw_moneypunct_init_data *__mp = &_C_ivals) : parent_type(__mp) { } }; #endif // _RWSTD_NO_WCHAR_T _RWSTD_NAMESPACE_END // __rw _RWSTD_NAMESPACE_BEGIN (std) // --------------------------------------------------------------- // Standard money parsing facet -- money_get<_CharT, _InputIter>. // --------------------------------------------------------------- template ) > class money_get: public locale::facet { public: typedef _CharT char_type; typedef _InputIter iter_type; typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type; _EXPLICIT money_get (size_t __ref=0) : locale::facet(__ref, locale::monetary) { } iter_type get (iter_type __begin, iter_type __end, bool __intl, ios_base& __flags, ios_base::iostate& __err, long double& __units) const { return do_get(__begin, __end, __intl, __flags, __err, __units); } iter_type get (iter_type __begin, iter_type __end, bool __intl, ios_base& __flags, ios_base::iostate& __err, string_type &__digits) const { return do_get (__begin, __end, __intl, __flags, __err, __digits); } static locale::id id; // Implementation: enum { _C_facet_cat = locale::monetary, _C_ok_implicit = 1 }; protected: virtual iter_type do_get (iter_type, iter_type, bool, ios_base&, ios_base::iostate&, long double&) const; virtual iter_type do_get (iter_type, iter_type, bool, ios_base&, ios_base::iostate&, string_type&) const; private: #ifdef _RWSTD_NO_MEMBER_TEMPLATES locale::id &_C_get_id () const { return id; } #endif }; _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT money_get > > ); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT money_get > > ); #endif // _RWSTD_NO_WCHAR_T // ------------------------------------------------------------------- // Standard money formatting facet -- money_put<_CharT, _OutputIter>. // ------------------------------------------------------------------- template ) > class money_put: public locale::facet { public: typedef _CharT char_type; typedef _OutputIter iter_type; typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type; _EXPLICIT money_put (size_t __ref=0) : locale::facet(__ref, locale::monetary) { } #ifndef _RWSTD_NO_LONG_DOUBLE iter_type put (iter_type __it, bool __intl, ios_base& __flags, char_type __fill, long double __quant) const #else iter_type put (iter_type __it, bool __intl, ios_base& __flags, char_type __fill, double __quant) const #endif { return do_put (__it, __intl, __flags, __fill, __quant); } iter_type put (iter_type __it, bool __intl, ios_base& __flags, char_type __fill, const string_type& __digits) const { return do_put(__it, __intl, __flags, __fill, __digits); } static locale::id id; // Implementation: enum { _C_facet_cat = locale::monetary, _C_ok_implicit = 1 }; protected: #ifndef __SOFTFP #ifdef __TARGET_ARCH_AARCH64 #define __SOFTFP #else #ifdef __EDG__ #define __SOFTFP __softfp #else #define __SOFTFP __attribute__((pcs("aapcs"))) #endif #endif #endif #ifndef _RWSTD_NO_LONG_DOUBLE virtual iter_type do_put (iter_type, bool, ios_base&, char_type, long double) const __SOFTFP; #else virtual iter_type do_put (iter_type, bool, ios_base&, char_type, double) const __SOFTFP; #endif virtual iter_type do_put (iter_type, bool, ios_base&, char_type, const string_type&) const; private: #ifdef _RWSTD_NO_MEMBER_TEMPLATES locale::id &_C_get_id (void) const { return id; } #endif }; _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT money_put > > ); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_3 ( class _RWSTD_EXPORT money_put > > ); #endif // _RWSTD_NO_WCHAR_T // ----------------------------------------------------------- // Standard money punctuation facet -- moneypunct<_CharT, bool>. // ----------------------------------------------------------- template class moneypunct: public locale::facet, public money_base, public _RW::__rw_moneypunct_impl<_CharT, _Intl> { public: typedef _CharT char_type; typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type; _RWSTD_STATIC_CONST (bool, intl = _Intl); // The second parameter (i) to the constructor is implementation specific. // For portable code, always let it default as shown. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE _EXPLICIT moneypunct (size_t __ref = 0, const _RW::__rw_moneypunct_init_data<_CharT>* = moneypunct::_C_get_ivals()); #else _EXPLICIT moneypunct (size_t = 0); moneypunct (size_t __ref, const _RW::__rw_moneypunct_init_data<_CharT>*); #endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE char_type decimal_point() const { return do_decimal_point(); } char_type thousands_sep() const { return do_thousands_sep(); } string grouping() const { return do_grouping(); } string_type curr_symbol() const { return do_curr_symbol(); }; string_type positive_sign() const { return do_positive_sign(); } string_type negative_sign() const { return do_negative_sign(); } int frac_digits() const { return do_frac_digits(); } pattern pos_format() const { return do_pos_format(); } pattern neg_format() const { return do_neg_format(); } static locale::id id; // Implementation: enum { _C_facet_cat = locale::monetary, _C_ok_implicit = 1 }; protected: virtual char_type do_decimal_point() const; virtual char_type do_thousands_sep() const; virtual string do_grouping() const; virtual string_type do_curr_symbol() const; virtual string_type do_positive_sign() const; virtual string_type do_negative_sign() const; virtual int do_frac_digits() const; virtual pattern do_pos_format() const; virtual pattern do_neg_format() const; private: virtual void _C_initfacet (const locale&); #ifdef _RWSTD_NO_MEMBER_TEMPLATES locale::id &_C_get_id (void) const { return id; } #endif public: static const _RW::__rw_moneypunct_init_data<_CharT> *_C_get_ivals () { return &_RW::__rw_moneypunct_impl<_CharT, _Intl>::_C_ivals; } }; #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE template inline moneypunct<_CharT, _Intl>:: moneypunct (size_t __ref, const _RW::__rw_moneypunct_init_data<_CharT> *__mp) : locale::facet(__ref, locale::monetary), _RW::__rw_moneypunct_impl<_CharT, _Intl>(__mp) { } #else // if defined (_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE) template inline moneypunct<_CharT, _Intl>::moneypunct (size_t __ref) : locale::facet(__ref, locale::monetary), _RW::__rw_moneypunct_impl<_CharT, _Intl> ((_RW::__rw_moneypunct_init_data<_CharT>*)&_RW:: __rw_moneypunct_impl<_CharT, _Intl>::_C_ivals) { } template inline moneypunct<_CharT, _Intl>:: moneypunct (size_t __ref, const _RW::__rw_moneypunct_init_data<_CharT> *__mp) : locale::facet(__ref, locale::monetary), _RW::__rw_moneypunct_impl<_CharT, _Intl>(__mp) { } #endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE _RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT moneypunct); _RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT moneypunct); #ifndef _RWSTD_NO_WCHAR_T _RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT moneypunct); _RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT moneypunct); #endif // _RWSTD_NO_WCHAR_T // -------------------------------------------------------- // Standard derived facet -- moneypunct_byname<_CharT, _Intl>. // -------------------------------------------------------- template class moneypunct_byname: public moneypunct<_CharT, _Intl> { typedef moneypunct<_CharT, _Intl> _Punct; public: _EXPLICIT moneypunct_byname (const char* __name, size_t __ref = 0) : moneypunct<_CharT, _Intl>(__ref, _Punct::_C_get_init_by_name_ (__name, moneypunct<_CharT, _Intl>::intl)) { } }; _RWSTD_NAMESPACE_END // std _RWSTD_NAMESPACE_BEGIN (__rw) _USING (_RWSTD_C::size_t); #ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC template inline _STD::moneypunct<_CharT, _Intl>* __rw_create_named_facet (_STD::moneypunct<_CharT, _Intl>*, const char *__name, size_t __ref) { return new _STD::moneypunct_byname<_CharT, _Intl>(__name, __ref); } #else // if defined (_RWSTD_NO_FUNC_PARTIAL_SPEC) _RWSTD_SPECIALIZED_FUNCTION inline _STD::moneypunct* __rw_create_named_facet (_STD::moneypunct*, const char *__name, size_t __ref) { return new _STD::moneypunct_byname(__name, __ref); } _RWSTD_SPECIALIZED_FUNCTION inline _STD::moneypunct* __rw_create_named_facet (_STD::moneypunct*, const char *__name, size_t __ref) { return new _STD::moneypunct_byname(__name, __ref); } #ifndef _RWSTD_NO_WCHAR_T _RWSTD_SPECIALIZED_FUNCTION inline _STD::moneypunct* __rw_create_named_facet (_STD::moneypunct*, const char *__name, size_t __ref) { return new _STD::moneypunct_byname(__name, __ref); } _RWSTD_SPECIALIZED_FUNCTION inline _STD::moneypunct* __rw_create_named_facet (_STD::moneypunct*, const char *__name, size_t __ref) { return new _STD::moneypunct_byname(__name, __ref); } #endif // _RWSTD_NO_WCHAR_T #endif // _RWSTD_NO_FUNC_PARTIAL_SPEC _RWSTD_NAMESPACE_END // __rw #if _RWSTD_DEFINE_TEMPLATE (MONEY) # include #endif #endif // _RWSTD_MONEY_H_INCLUDED