.\" ident @(#)money_get.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH money_get 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2money_get\fP \ - Monetary formatting facet for input. .SH SYNOPSIS .br #include .br template > .RE .RS 0 class money_get; .SH DESCRIPTION The money_get_facet interprets formatted monetary string values. .SH INTERFACE .br template > .RE .RS 0 class money_get : public locale::facet { .br public: .RE .RS 1 typedef charT char_type; .br typedef InputIterator iter_type; .br typedef basic_string string_type; .br explicit money_get(size_t = 0); .br iter_type get(iter_type, iter_type, bool, ios_base&, .RE .RS 15 ios_base::iostate&, long double&) const; .RE .RS 1 iter_type get(iter_type, iter_type, bool, ios_base&, .RE .RS 15 ios_base::iostate&, string_type&) const; .RE .RS 1 static locale::id id; .RE .RS 0 protected: .RE .RS 2 ~money_get(); // virtual .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, .RE .RS 26 bool, ios_base&, .br ios_base::iostate&, .br long double&) const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, .RE .RS 26 bool, ios_base&, .br ios_base::iostate&, .br string_type&) const; .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of character upon which the facet is instantiated. .RE .br iter_type .RE .RS 3 Type of iterator used to scan the character buffer. .RE .br string_type .RE .RS 3 Type of character string passed to member functions. .RE .SH CONSTRUCTORS .br explicit money_get(size_t refs = 0) .RE .RS 3 Construct a money_get facet. If the \f2refs\fP argument is \f20\fP, then destruction of the object is delegated to the locale, or locales, containing it. This allows the user to ignore lifetime management issues. On the other hand, if \f2refs\fP is \f21\fP, then the object must be explicitly deleted; the locale does not do so. .RE .SH DESTRUCTORS .br ~money_get(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH STATIC MEMBERS .br static locale::id id; .RE .RS 3 Unique identifier for this type of facet. .RE .SH PUBLIC MEMBER FUNCTIONS The public members of the money_get facet include an interface to protected members. Each public member \f2get\fP has a corresponding virtual protected member \f2do_get\fP. .br iter_type .br get(iter_type s, iter_type end, bool intl, ios_base& f, .RE .RS 3 ios_base::iostate& err, long double& units) const; .RE .RS 0 iter_type .br get(iter_type s, iter_type end, bool intl, ios_base& f, .RE .RS 3 ios_base::iostate& err, string_type& digits) const; .RE .RS 3 Each of these two overloads of the public member function \f2get\fP calls the corresponding protected \f2do_get\fP function. .RE .SH PROTECTED MEMBER FUNCTIONS .RE .RS 0 virtual iter_type .br do_get(iter_type s, iter_type end, .RE .RS 6 bool intl, ios_base& f, .br ios_base::iostate& err, .br long double& units) const; .RE .RS 0 virtual iter_type .br do_get(iter_type s, iter_type end, .RE .RS 6 bool intl, ios_base& f, .br ios_base::iostate& err, .br string_type& digits) const; .RE .RS 3 Reads in a localized character representation of a monetary value and generates a generic representation, either as a sequence of digits or as a \f2long double \fPvalue. In either case \f2do_get\fP uses the smallest possible unit of currency. Both overloads of \f2do_get\fP read characters from the range \f2[s,end)\fP until one of three things occurs: .RS .5i .HP .5i - A monetary value is assembled .HP .5i - An error occurs .HP .5i - No more characters are available. .RE The functions use \f2f.flags()\fP and the \f2moneypunct\fP or \f2moneypunct\fP facet (depending on the \f2intl\fP argument) from \f2f.getloc()\fP for formatting information to use in interpreting the sequence of characters. \f2do_get\fP, then places a pure sequence of digits representing the monetary value in the smallest possible unit of currency into the string argument \f2digits\fP, or it calculates a \f2long double\fP value based on those digits and returns that value in \f2units\fP. The following specifics apply to formatting: .RS .5i .HP .5i - Digit group separators are optional. If no grouping is specified, then any thousands separator characters are treated as delimiters. .HP .5i - If \f2space\fP or \f2none\fP are part of the format pattern in \f2moneypunct\fP, then optional whitespace is consumed, except at the end. See the \f2moneypunct\fP reference section for a description of money-specific formatting flags. .HP .5i - If \f2iosbase::showbase\fP is set in \f2f.flags()\fP, then the currency symbol is optional, and if it appears after all other elements, then it is not consumed. Otherwise the currency symbol is required, and is consumed wherever it occurs. .HP .5i - \f2digits\fP are preceded by a \f2`-'\fP or \f2units\fP are negated, if the monetary value is negative. .HP .5i - See the \f2moneypunct\fP reference section for a description of money specific \f2formatting\fP flags. .RE The \f2err\fP argument is set to \f2iosbase::failbit\fP if an error occurs during parsing. Returns an iterator pointing one past the last character that is part of a valid monetary sequence. .RE .SH EXAMPLE .RE .RS 0 // .br // moneyget.cpp .br // .br .br #include .br #include .br using namespace std; .br .br int main () .br { .RE .RS 1 using namespace std; .br typedef istreambuf_iterator > .RE .RS 9 iter_type; .RE .RS 0 .RE .RS 1 locale loc; .br string buffer("$100.02"); .br string dest; .br long double ldest; .br ios_base::iostate state; .br iter_type end; .RE .RS 0 .RE .RS 2 // Get a money_get facet .RE .RS 1 const money_get& mgf = .RE .RS 0 #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE .RE .RS 3 use_facet >(loc); .RE .RS 0 #else .RE .RS 3 use_facet(loc,(money_get*)0); .RE .RS 0 #endif .br .RE .RS 2 { .RE .RS 4 // Build an istringstream from the buffer and construct .br // a beginning iterator on it. .RE .RS 3 istringstream ins(buffer); .br iter_type begin(ins); .RE .RS 0 .RE .RS 4 // Get a string representation of the monetary value .RE .RS 3 mgf.get(begin,end,false,ins,state,dest); .RE .RS 2 } .br { .RE .RS 4 // Build another istringstream from the buffer, etc. .br // so we have an iterator pointing to the beginning .RE .RS 3 istringstream ins(buffer); .br iter_type begin(ins); .RE .RS 0 .RE .RS 4 // Get a long double representation .br // of the monetary value .RE .RS 3 mgf.get(begin,end,false,ins,state,ldest); .RE .RS 2 } .RE .RS 1 cout << buffer << " --> " << dest .RE .RS 7 << " --> " << ldest << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .SH SEE ALSO locale, facets, money_put, moneypunct