.\" ident @(#)num_get.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH num_get 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2num_get\fP \ - A numeric formatting facet for input. .SH SYNOPSIS .RE .RS 0 #include .br template class num_get; .SH DESCRIPTION The num_get facet allows for formatted input of numbers. basic_istream_and all other input-oriented streams use this facet to implement formatted numeric input. .SH INTERFACE .br template > .RE .RS 0 class num_get : public locale::facet { .br public: .RE .RS 1 typedef charT char_type; .br typedef InputIterator iter_type; .br explicit num_get(size_t refs = 0); .br iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, bool&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base& , .RE .RS 15 ios_base::iostate&, long&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, unsigned short&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, unsigned int&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, unsigned long&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, float&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, double&) const; .RE .RS 1 iter_type get(iter_type, iter_type, ios_base&, .RE .RS 15 ios_base::iostate&, long double&) const; .RE .RS 1 static locale::id id; .RE .RS 0 .br protected: .RE .RS 2 ~num_get(); // virtual .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, bool&) const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, long&) const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, .br unsigned short&) const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, .br unsigned int&) const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, .br unsigned long&) const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, float&) .br const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, double&) .br const; .RE .RS 1 virtual iter_type do_get(iter_type, iter_type, ios_base&, .RE .RS 26 ios_base::iostate&, .br long double&) const; .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 Type of character the facet is instantiated on. .RE .br iter_type .RE .RS 3 Type of iterator used to scan the character buffer. .RE .SH CONSTRUCTORS .br explicit num_get(size_t refs = 0) .RE .RS 3 Construct a num_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. In this case, the object can be maintained across the lifetime of multiple locales. .RE .SH DESTRUCTORS .br ~num_get(); // virtual and protected .RE .RS 3 Destroys the facet. .RE .SH FACET ID .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 num_get facet include an interface to protected members. Each public member \f2xxx\fP has a corresponding virtual protected member \f2do_xxx\fP. All work is delegated to these protected members. For instance, the long version of the public \f2get\fP function simply calls its protected cousin \f2do_get\fP. .br iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, bool& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, long& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, unsigned short& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, unsigned int& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, unsigned long& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, float& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, double& v) const; .RE .RS 0 iter_type .br get(iter_type in, iter_type end, ios_base& io, .RE .RS 3 ios_base::iostate& err, long double& v) const; .RE .RS 3 Each of the eight overloads of the \f2get\fP function simply call the corresponding \f2do_get\fP function. .RE .SH PROTECTED MEMBER FUNCTIONS .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, bool& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, long& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, .br unsigned short& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, .br unsigned int& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, .br unsigned long& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, float& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& err, double& v) const; .RE .RS 0 virtual iter_type .br do_get(iter_type in, iter_type end, ios_base& io, .RE .RS 6 ios_base::iostate& long double& v) const; .RE .RS 3 The eight overloads of the \f2do_get\fP member function all take a sequence of characters\f2 [int,end)\fP, and extract a numeric value. The numeric value is returned in \f2v\fP. The \f2io \fPargument is used to obtain formatting information and the \f2err\fP argument is used to set error conditions in a calling stream. .RE .SH EXAMPLE .RE .RS 0 // .br // numget.cpp .br // .br .br #include .br .br int main () .br { .RE .RS 1 using namespace std; .RE .RS 0 .br typedef istreambuf_iterator > .RE .RS 1 iter_type; .RE .RS 2 .RE .RS 1 locale loc; .br ios_base::iostate state; .br bool bval = false; .br long lval = 0L; .br long double ldval = 0.0; .br iter_type end; .RE .RS 0 .RE .RS 2 // Get a num_get facet .RE .RS 1 const num_get& tg = .RE .RS 0 #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE .RE .RS 1 use_facet >(loc); .RE .RS 0 #else .RE .RS 1 use_facet(loc,(num_get*)0); .RE .RS 0 #endif .br .RE .RS 2 { .RE .RS 4 // Build an istringstream from the buffer and construct .br // beginning and ending iterators on it. .RE .RS 3 istringstream ins("true"); .br iter_type begin(ins); .RE .RS 0 .RE .RS 4 // Get a bool value .RE .RS 3 tg.get(begin,end,ins,state,bval); .RE .RS 2 } .RE .RS 1 cout << bval << endl; .RE .RS 2 { .RE .RS 4 // Get a long value .RE .RS 3 istringstream ins("2422235"); .br iter_type begin(ins); .br tg.get(begin,end,ins,state,lval); .RE .RS 2 } .RE .RS 1 cout << lval << endl; .RE .RS 2 { .RE .RS 4 // Get a long double value .RE .RS 3 istringstream ins("32324342.98908"); .br iter_type begin(ins); .br tg.get(begin,end,ins,state,ldval); .RE .RS 2 } .RE .RS 1 cout << ldval << endl; .br return 0; .RE .RS 0 } .SH SEE ALSO locale, facets, num_put, numpunct, ctype