STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Types | Private Member Functions | List of all members
money_get< _Elem, _InIt > Class Template Reference
Inheritance diagram for money_get< _Elem, _InIt >:
locale::facet _Facet_base _Crt_new_delete

Public Types

typedef _Elem char_type
 
typedef _InIt iter_type
 
typedef basic_string< _Elem, char_traits< _Elem >, allocator< _Elem > > string_type
 

Public Member Functions

_InIt get (_InIt _First, _InIt _Last, bool _Intl, ios_base &_Iosbase, ios_base::iostate &_State, long double &_Val) const
 
_InIt get (_InIt _First, _InIt _Last, bool _Intl, ios_base &_Iosbase, ios_base::iostate &_State, string_type &_Val) const
 
 money_get (size_t _Refs=0)
 
 money_get (const _Locinfo &_Lobj, size_t _Refs=0)
 
- Public Member Functions inherited from locale::facet
virtual void __CLR_OR_THIS_CALL _Incref ()
 
virtual _Facet_base *__CLR_OR_THIS_CALL _Decref ()
 
__CLR_OR_THIS_CALL facet (const facet &)=delete
 
facet &__CLR_OR_THIS_CALL operator= (const facet &)=delete
 
- Public Member Functions inherited from _Facet_base
virtual __CLR_OR_THIS_CALL ~_Facet_base () _NOEXCEPT
 

Static Public Member Functions

static size_t _Getcat (const locale::facet **_Ppf=0, const locale *_Ploc=0)
 
- Static Public Member Functions inherited from locale::facet
static size_t __CLRCALL_OR_CDECL _Getcat (const facet **=0, const locale *=0)
 

Static Public Attributes

__PURE_APPDOMAIN_GLOBAL static _CRTIMP2_PURE locale::id id
 

Protected Member Functions

virtual __CLR_OR_THIS_CALL ~money_get () _NOEXCEPT
 
void _Init (const _Locinfo &)
 
virtual _InIt __CLR_OR_THIS_CALL do_get (_InIt _First, _InIt _Last, bool _Intl, ios_base &_Iosbase, ios_base::iostate &_State, long double &_Val) const
 
virtual _InIt __CLR_OR_THIS_CALL do_get (_InIt _First, _InIt _Last, bool _Intl, ios_base &_Iosbase, ios_base::iostate &_State, string_type &_Val) const
 
- Protected Member Functions inherited from locale::facet
__CLR_OR_THIS_CALL facet (size_t _Initrefs=0)
 
virtual __CLR_OR_THIS_CALL ~facet () _NOEXCEPT
 

Private Types

typedef moneypunct< _Elem, false_Mypunct0
 
typedef moneypunct< _Elem, true_Mypunct1
 

Private Member Functions

string _Getmfld (_InIt &_First, _InIt &_Last, bool _Intl, ios_base &_Iosbase, _Elem *_Atoms) const
 

Member Typedef Documentation

template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
typedef moneypunct<_Elem, false> money_get< _Elem, _InIt >::_Mypunct0
private
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
typedef moneypunct<_Elem, true> money_get< _Elem, _InIt >::_Mypunct1
private
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
typedef _Elem money_get< _Elem, _InIt >::char_type
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
typedef _InIt money_get< _Elem, _InIt >::iter_type
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
typedef basic_string<_Elem, char_traits<_Elem>, allocator<_Elem> > money_get< _Elem, _InIt >::string_type

Constructor & Destructor Documentation

template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
money_get< _Elem, _InIt >::money_get ( size_t  _Refs = 0)
inlineexplicit
378  : locale::facet(_Refs)
379  { // construct from current locale
380  _BEGIN_LOCINFO(_Lobj)
381  _Init(_Lobj);
382  _END_LOCINFO()
383  }
Definition: xlocale:137
void _Init(const _Locinfo &)
Definition: xlocmon:405
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
money_get< _Elem, _InIt >::money_get ( const _Locinfo _Lobj,
size_t  _Refs = 0 
)
inline
386  : locale::facet(_Refs)
387  { // construct from specified locale
388  _Init(_Lobj);
389  }
Definition: xlocale:137
void _Init(const _Locinfo &)
Definition: xlocmon:405
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
virtual __CLR_OR_THIS_CALL money_get< _Elem, _InIt >::~money_get ( )
inlineprotectedvirtual
402  { // destroy the object
403  }

Member Function Documentation

template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
static size_t money_get< _Elem, _InIt >::_Getcat ( const locale::facet **  _Ppf = 0,
const locale _Ploc = 0 
)
inlinestatic
393  { // return locale category mask and construct standard facet
394  if (_Ppf != 0 && *_Ppf == 0)
395  *_Ppf = new money_get<_Elem, _InIt>(
396  _Locinfo(_Ploc->c_str()));
397  return (_X_MONETARY);
398  }
Definition: xlocinfo:53
_Ret_z_ const char * c_str() const
Definition: xlocale:424
Definition: xlocmon:349
#define _X_MONETARY
Definition: xlocinfo.h:40
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
string money_get< _Elem, _InIt >::_Getmfld ( _InIt &  _First,
_InIt &  _Last,
bool  _Intl,
ios_base _Iosbase,
_Elem *  _Atoms 
) const
inlineprivate
463  { // get monetary field from [_First, _Last) into string_type
464  _DEBUG_RANGE(_First, _Last);
465  const _Mpunct<_Elem> *_Ppunct_fac;
466  if (_Intl)
467  _Ppunct_fac =
468  &_USE(_Iosbase.getloc(), _Mypunct1); // international
469  else
470  _Ppunct_fac =
471  &_USE(_Iosbase.getloc(), _Mypunct0); // local
472 
473  bool _Bad = false, _Neg = false;
474  string_type _Sign;
475  const money_base::pattern _Pattern = _Ppunct_fac->neg_format();
476  string _Val;
477  size_t _Idx;
478  static constexpr char _Src[] = {"0123456789-"};
479  const ctype<_Elem>& _Ctype_fac =
480  _USE(_Iosbase.getloc(), ctype<_Elem>);
481  _Ctype_fac.widen(&_Src[0], &_Src[sizeof (_Src)], _Atoms);
482 
483  for (size_t _Off = 0; !_Bad && _Off < 4; ++_Off)
484  switch (_Pattern.field[_Off])
485  { // parse a format component
486  case money_base::symbol:
487  { // parse currency symbol
488  string_type _Symbol = _Ppunct_fac->curr_symbol();
490 
491  if (!(_Iosbase.flags() & ios_base::showbase)
492  && _First != _Last && *_First != *_Symbol.c_str())
493  _Symbol.erase(); // showbase ==> mandatory symbol
494  else if (_Off == 3 && _Sign.size() <= 1
495  && (_First == _Last || *_First != *_Symbol.c_str()))
496  _Symbol.erase(); // currency symbol optional at end
497 
498  for (_Source = _Symbol.begin();
499  _First != _Last && _Source != _Symbol.end()
500  && *_First == *_Source; ++_Source, (void)++_First)
501  ; // still matching currency symbol
502 
503  if (_Source != _Symbol.end())
504  _Bad = true; // currency symbol match failed
505  break;
506  }
507 
508  case money_base::sign: // parse sign
509  if (_First == _Last)
510  ; // assume no sign
511  else if (0 < (_Ppunct_fac->positive_sign()).size()
512  && _Ppunct_fac->positive_sign()[0] == *_First)
513  { // match positive sign
514  ++_First;
515  _Sign = _Ppunct_fac->positive_sign();
516  }
517  else if (0 < (_Ppunct_fac->negative_sign()).size()
518  && _Ppunct_fac->negative_sign()[0] == *_First)
519  { // match negative sign
520  ++_First;
521  _Sign = _Ppunct_fac->negative_sign();
522  _Neg = true;
523  }
524  else if (0 == (_Ppunct_fac->positive_sign()).size())
525  ;
526  else if (0 == (_Ppunct_fac->negative_sign()).size())
527  _Neg = true;
528  break; // sign match can't fail
529 
530  case money_base::value:
531  { // parse value field
532  int _Fracdigseen = 0;
533  int _Fracdigits = _Ppunct_fac->frac_digits();
534  const string _Grouping = _Ppunct_fac->grouping();
535  const _Elem _Kseparator = _Grouping.size() == 0
536  ? (_Elem)0 : _Ppunct_fac->thousands_sep();
537 
538  if (_Kseparator == (_Elem)0
539  || CHAR_MAX <= (unsigned char)*_Grouping.c_str())
540  for (; _First != _Last
541  && (_Idx = _Find_elem(_Atoms, *_First)) < 10;
542  ++_First)
543  _Val += _Src[_Idx]; // no grouping, just gather digits
544  else
545  { // grouping specified, gather digits and group sizes
546  string _Groups((size_t)1, '\0');
547  size_t _Group = 0;
548 
549  for (; _First != _Last; ++_First)
550  if ((_Idx = _Find_elem(_Atoms, *_First)) < 10)
551  { // got a digit, add to group size
552  _Val += _Src[_Idx];
553  if (_Groups[_Group] != CHAR_MAX)
554  ++_Groups[_Group];
555  }
556  else if (_Groups[_Group] == '\0'
557  || *_First != _Kseparator)
558  break; // not a group separator, done
559  else
560  { // add a new group to _Groups string
561  _Groups.append((size_t)1, '\0');
562  ++_Group;
563  }
564 
565  if (_Group == 0)
566  ; // no thousands separators seen
567  else if ('\0' < _Groups[_Group])
568  ++_Group; // add trailing group to group count
569  else
570  _Bad = true; // trailing separator, fail
571 
572  for (const char *_Pg = _Grouping.c_str();
573  !_Bad && 0 < _Group; )
574  if (*_Pg == CHAR_MAX)
575  break; // end of grouping constraints to check
576  else if ((0 < --_Group && *_Pg != _Groups[_Group])
577  || (0 == _Group && *_Pg < _Groups[_Group]))
578  _Bad = true; // bad group size, fail
579  else if ('\0' < _Pg[1])
580  ++_Pg; // group size okay, advance to next test
581  if (_Bad)
582  break; // bad grouping, give up
583  }
584 
585  const _Elem _Point = _Ppunct_fac->decimal_point();
586  if (_First != _Last
587  && _Point != (_Elem)0
588  && *_First == _Point)
589  { // seen decimal point, gather fraction digits
590  while (++_First != _Last
591  && _Fracdigseen < _Fracdigits
592  && (_Idx = _Find_elem(_Atoms, *_First)) < 10)
593  {
594  _Val += _Src[_Idx];
595  ++_Fracdigseen;
596  }
597 
598  if (_Fracdigseen < _Fracdigits)
599  _Bad = true; // short fraction
600  }
601 
602  if (_Val.size() == 0)
603  _Bad = true; // fail if no elements parsed
604  else
605  for (; _Fracdigseen < _Fracdigits; ++_Fracdigseen)
606  _Val += '0'; // pad out fraction with zeros
607  break;
608  }
609 
610  case money_base::space:
611  case money_base::none:
612  { // parse optional space
613  if (_Off == 3)
614  break; // ignore space at end
615 
616  bool _Seen = false;
617 
618  for (; _First != _Last
619  && _Ctype_fac.is(ctype_base::space, *_First); ++_First)
620  _Seen = true; // skip any space
621  if (_Pattern.field[_Off] == money_base::space && !_Seen)
622  _Bad = true; // fail if no space seen
623  }
624  }
625 
626  if (!_Bad && 1 < _Sign.size())
627  { // match rest of sign string
629 
630  for (_Source = _Sign.begin(); ++_Source != _Sign.end()
631  && _First != _Last && *_First == *_Source; ++_First)
632  ;
633  if (_Source != _Sign.end())
634  _Bad = true; // rest of sign doesn't match, fail
635  }
636 
637  if (_Bad)
638  _Val.erase(); // bad input, return empty string
639  else if (_Neg)
640  _Val.insert((size_t)0, (size_t)1, '-'); // minus sign
641  return (_Val);
642  }
Definition: xlocmon:23
_Mybase::const_iterator const_iterator
Definition: xstring:1887
Definition: xlocale:2061
moneypunct< _Elem, true > _Mypunct1
Definition: xlocmon:353
constexpr auto size(const _Container &_Cont) -> decltype(_Cont.size())
Definition: xutility:1477
Definition: xlocmon:23
_Ret_z_ const _Elem * c_str() const _NOEXCEPT
Definition: xstring:3001
#define _DEBUG_RANGE(first, last)
Definition: xutility:902
bool __CLR_OR_THIS_CALL is(mask _Maskval, _Elem _Ch) const
Definition: xlocale:2083
#define _USE(loc, fac)
Definition: xlocale:499
iterator insert(const const_iterator _Where, const initializer_list< _Elem > _Ilist)
Definition: xstring:2204
moneypunct< _Elem, false > _Mypunct0
Definition: xlocmon:352
Definition: xlocmon:23
locale __CLR_OR_THIS_CALL getloc() const
Definition: xiosbase:432
_Source
Definition: corecrt_wstring.h:187
fmtflags __CLR_OR_THIS_CALL flags() const
Definition: xiosbase:375
_Myt & append(initializer_list< _Elem > _Ilist)
Definition: xstring:2199
Definition: xlocale:2077
basic_string< _Elem, char_traits< _Elem >, allocator< _Elem > > string_type
Definition: xlocmon:359
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *terminate_handler)()
_In_ size_t _Out_opt_ int _In_z_ unsigned char const * _Src
Definition: mbstring.h:1039
size_t _Find_elem(_Elem *_Base, _Elem _Ch)
Definition: xlocnum:88
_Myt & erase(const size_type _Off=0)
Definition: xstring:2584
static constexpr _Fmtflags showbase
Definition: xiosbase:58
Definition: xlocmon:26
_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
Definition: xlocale:2126
Definition: xlocmon:23
char field[4]
Definition: xlocmon:28
#define CHAR_MAX
Definition: limits.h:24
size_type size() const _NOEXCEPT
Definition: xstring:3023
Definition: xlocmon:23
_FwdIt const _Ty _Val
Definition: algorithm:1938
_FwdIt _Last
Definition: algorithm:1936
Definition: xlocmon:39
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
void money_get< _Elem, _InIt >::_Init ( const _Locinfo )
inlineprotected
406  { // initialize from _Locinfo object
407  }
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
virtual _InIt __CLR_OR_THIS_CALL money_get< _Elem, _InIt >::do_get ( _InIt  _First,
_InIt  _Last,
bool  _Intl,
ios_base _Iosbase,
ios_base::iostate &  _State,
long double &  _Val 
) const
inlineprotectedvirtual
412  { // get long double from [_First, _Last) into _Val
413  _Elem _Atoms[sizeof ("0123456789-")];
414  string _Str = _Getmfld(_First, _Last, _Intl, _Iosbase, _Atoms);
415 
416  if (_First == _Last)
418  if (_Str.size() == 0)
419  _State |= ios_base::failbit; // _Getmfld failed
420  else
421  { // convert to long double
422  const char *_Eb = _Str.c_str();
423  char *_Ep;
424  int _Errno = 0;
425  const long double _Ans =
426  _Stodx_v2(_Eb, &_Ep, 0, &_Errno); // convert and "widen" double to long double
427 
428  if (_Ep == _Eb || _Errno != 0)
430  else
431  _Val = _Ans; // deliver value
432  }
433  return (_First);
434  }
static constexpr _Iostate failbit
Definition: xiosbase:88
string _Getmfld(_InIt &_First, _InIt &_Last, bool _Intl, ios_base &_Iosbase, _Elem *_Atoms) const
Definition: xlocmon:461
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
_FwdIt const _Ty _Val
Definition: algorithm:1938
_END_EXTERN_C _STD_BEGIN double _Stodx_v2(const char *_Str, char **_Endptr, int _Pten, int *_Perr)
Definition: xlocnum:53
_FwdIt _Last
Definition: algorithm:1936
static constexpr _Iostate eofbit
Definition: xiosbase:87
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
virtual _InIt __CLR_OR_THIS_CALL money_get< _Elem, _InIt >::do_get ( _InIt  _First,
_InIt  _Last,
bool  _Intl,
ios_base _Iosbase,
ios_base::iostate &  _State,
string_type _Val 
) const
inlineprotectedvirtual
439  { // get string_type from [_First, _Last) into _Val
440  _Elem _Atoms[sizeof ("0123456789-")];
441  string _Str = _Getmfld(_First, _Last, _Intl, _Iosbase, _Atoms);
442  size_t _Len = _Str.size();
443 
444  if (_First == _Last)
446  if (_Len == 0)
447  _State |= ios_base::failbit; // _Getmfld failed
448  else
449  { // deliver value
450  size_t _Idx = 0;
451  _Val.resize(_Len);
452  if (_Str[0] == '-')
453  _Val[_Idx++] = _Atoms[10];
454  for (; _Idx < _Len; ++_Idx)
455  _Val[_Idx] = _Atoms[_Str[_Idx] - '0']; // map digits
456  }
457  return (_First);
458  }
static constexpr _Iostate failbit
Definition: xiosbase:88
string _Getmfld(_InIt &_First, _InIt &_Last, bool _Intl, ios_base &_Iosbase, _Elem *_Atoms) const
Definition: xlocmon:461
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
_FwdIt const _Ty _Val
Definition: algorithm:1938
_FwdIt _Last
Definition: algorithm:1936
static constexpr _Iostate eofbit
Definition: xiosbase:87
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
_InIt money_get< _Elem, _InIt >::get ( _InIt  _First,
_InIt  _Last,
bool  _Intl,
ios_base _Iosbase,
ios_base::iostate &  _State,
long double &  _Val 
) const
inline
364  { // get long double from [_First, _Last) into _Val
365  return (do_get(_First, _Last, _Intl, _Iosbase, _State, _Val));
366  }
virtual _InIt __CLR_OR_THIS_CALL do_get(_InIt _First, _InIt _Last, bool _Intl, ios_base &_Iosbase, ios_base::iostate &_State, long double &_Val) const
Definition: xlocmon:409
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
_FwdIt const _Ty _Val
Definition: algorithm:1938
_FwdIt _Last
Definition: algorithm:1936
template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
_InIt money_get< _Elem, _InIt >::get ( _InIt  _First,
_InIt  _Last,
bool  _Intl,
ios_base _Iosbase,
ios_base::iostate &  _State,
string_type _Val 
) const
inline
371  { // get string_type from [_First, _Last) into _Val
372  return (do_get(_First, _Last, _Intl, _Iosbase, _State, _Val));
373  }
virtual _InIt __CLR_OR_THIS_CALL do_get(_InIt _First, _InIt _Last, bool _Intl, ios_base &_Iosbase, ios_base::iostate &_State, long double &_Val) const
Definition: xlocmon:409
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
_FwdIt const _Ty _Val
Definition: algorithm:1938
_FwdIt _Last
Definition: algorithm:1936

Member Data Documentation

template<class _Elem , class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem> >>
__PURE_APPDOMAIN_GLOBAL locale::id money_get< _Elem, _InIt >::id
static

The documentation for this class was generated from the following file: