📄 _punct.h
字号:
return _C_tinit._C_dt_tm_pats[__i];
}
};
// -------------------------------------------------------------
// Implementation class template -- __rw_timepunct_impl_data<_CharT>.
// -------------------------------------------------------------
// __rw_timepunct<_CharT> derives from this (via rwstd::__rw_timepunct_impl)
// to get its private data members.
template <class _CharT>
class __rw_timepunct_impl_data
{
friend class __rw_timepunct<_CharT>;
friend class __rw_keyword_cracker<_CharT>;
public:
typedef _STD::char_traits<_CharT> traits_type;
typedef _STD::basic_string<_CharT, traits_type, _STD::allocator<_CharT> >
string_type;
private:
string_type _C_day_nms[7][2];
string_type _C_month_nms[12][2];
string_type _C_ampm_nms[2];
string_type _C_bad_nm;
string_type _C_ord_nms[100];
string_type _C_dt_tm_pats[6];
__rw_keyword_def<_CharT> _C_dn_defs[7][2];
__rw_keyword_map<_CharT> _C_dn_defsmap;
__rw_keyword_def<_CharT> _C_mn_defs[12][2];
__rw_keyword_map<_CharT> _C_mn_defsmap;
__rw_keyword_def<_CharT> _C_ampm_defs[2];
__rw_keyword_map<_CharT> _C_ampm_defsmap;
protected:
__rw_timepunct_impl_data (const __rw_timepunct_init<_CharT>&);
void _C_initpat (const _STD::locale&);
void _C_initfacet (const _STD::locale&);
};
_RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_timepunct_impl_data<char>);
#ifndef _RWSTD_NO_WCHAR_TYPE
_RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_timepunct_impl_data<wchar_t>);
#endif // _RWSTD_NO_WCHAR_TYPE
// -------------------------------------------------------------
// Implementation class template -- __rw_timepunct_impl<_CharT>.
// -------------------------------------------------------------
// __rw_timepunct<_CharT> derives from this to get the parts of its behavior that
// must be specialized on the character type. Currently the only specialized
// behavior is the initialization logic in the constructor.
template <class _CharT>
class __rw_timepunct_impl
: public __rw_timepunct_impl_data<_CharT>
{
protected:
__rw_timepunct_impl(void);
};
_RWSTD_SPECIALIZED_CLASS
class _RWSTD_EXPORT __rw_timepunct_impl<char>
: public __rw_timepunct_impl_data<char>
{
static const __rw_timepunct_init_data<char> _C_ivals;
protected:
__rw_timepunct_impl (void):
__rw_timepunct_impl_data<char>(__rw_timepunct_init<char>(_C_ivals)) { }
};
#ifndef _RWSTD_NO_WCHAR_T
_RWSTD_SPECIALIZED_CLASS
class _RWSTD_EXPORT __rw_timepunct_impl<wchar_t>
: public __rw_timepunct_impl_data<wchar_t>
{
static const __rw_timepunct_init_data<wchar_t> _C_ivals;
protected:
__rw_timepunct_impl(void):
__rw_timepunct_impl_data<wchar_t>(__rw_timepunct_init<wchar_t>(_C_ivals)) { }
};
#endif // _RWSTD_NO_WCHAR_T
// ----------------------------------------------------------
// Time and date punctuation facet -- __rw_timepunct<_CharT>.
// ----------------------------------------------------------
template <class _CharT>
class __rw_timepunct : public locale::facet,
public __rw_timepunct_impl<_CharT>
{
public:
typedef _CharT char_type;
typedef _STD::char_traits<char_type> traits_type;
typedef _STD::basic_string<char_type, traits_type,
_STD::allocator<char_type> >
string_type;
_EXPLICIT __rw_timepunct (size_t __refs=0):
locale::facet(__refs, locale::time) { }
string_type dayname (int __day, bool __abbreviated) const
{ return do_dayname(__day, __abbreviated); }
string_type monthname (int __month, bool __abbreviated) const
{ return do_monthname(__month, __abbreviated); }
string_type ordinal (int __number) const
{ return do_ordinal(__number); }
static _STD::locale::id id;
// Implementation:
enum { _C_facet_cat = locale::time, _C_ok_implicit = 1 };
protected:
virtual string_type do_dayname (int day, bool abbreviated) const;
virtual string_type do_monthname (int month, bool abbreviated) const;
virtual string_type do_ordinal (int number) const;
private:
virtual void _C_initfacet (const _STD::locale&);
#ifdef _RWSTD_NO_MEMBER_TEMPLATES
_STD::locale::id &_C_get_id (void) const { return id; }
#endif
};
_RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_timepunct<char>);
#ifndef _RWSTD_NO_WCHAR_TYPE
_RWSTD_INSTANTIATE_1 (class _RWSTD_EXPORT __rw_timepunct<wchar_t>);
#endif // _RWSTD_NO_WCHAR_TYPE
// --------------------------------------------------------------
// Implementation class template -- __rw_keyword_cracker<_CharT>.
// --------------------------------------------------------------
// Gives derived classes a backdoor way to get the private
// __rw_keyword_map and other members out of numpunct and __rw_timepunct facets.
template <class _CharT>
class __rw_keyword_cracker
{
public:
static const __rw_keyword_map<_CharT>&
_C_get_tf_map (const numpunct<_CharT> &__np) {
return __np.tf_map_;
}
static const __rw_keyword_map<_CharT>&
_C_get_day_map (const __rw_timepunct<_CharT>& __p) {
return __p._C_dn_defsmap;
}
static const __rw_keyword_map<_CharT>&
_C_get_month_map (const __rw_timepunct<_CharT>& __p) {
return __p._C_mn_defsmap;
}
static const __rw_keyword_map<_CharT>&
_C_get_ampm_map (const __rw_timepunct<_CharT>& __p) {
return __p._C_ampm_defsmap;
}
static const _TYPENAME __rw_numpunct_impl_data<_CharT>::string_type&
_C_get_tf_string (const __rw_numpunct_impl_data<_CharT>& __np, bool __val) {
return __val ? __np._C_tn : __np._C_fn;
}
static const _TYPENAME __rw_timepunct<_CharT>::string_type&
_C_get_day_string (const __rw_timepunct<_CharT>& __p, unsigned __val, bool __abr) {
return __val < 7 ? __p._C_day_nms[__val][__abr] : __p._C_bad_nm;
}
static const _TYPENAME __rw_timepunct<_CharT>::string_type&
_C_get_month_string (const __rw_timepunct<_CharT>& __p, unsigned __val, bool __abr)
{
return __val < 12 ? __p._C_month_nms[__val][__abr] : __p._C_bad_nm;
}
static const _TYPENAME __rw_timepunct<_CharT>::string_type&
_C_get_ampm_string (const __rw_timepunct<_CharT>& __p, bool __pm) {
return __p._C_ampm_nms[__pm];
}
static const _TYPENAME __rw_timepunct<_CharT>::string_type&
_C_get_ord_string (const __rw_timepunct<_CharT>& __p, unsigned __val) {
return __val < 99 ? __p._C_ord_nms[__val] : __p._C_bad_nm;
}
static const _TYPENAME __rw_timepunct<_CharT>::string_type&
_C_get_patt_string (const __rw_timepunct<_CharT>& __p, unsigned __val) {
return __val < 6 ? __p._C_dt_tm_pats[__val] : __p._C_bad_nm;
}
};
// -------------------------------------------------------------------
// Implementation class template -- __rw_digit_handler_base_1<_CharT>.
// -------------------------------------------------------------------
// Contains _CharT-dependent functionality that is common to the digit_reader
// and __rw_digit_writer classes, particularly related to getting access
// to ctype and punct facets they both use.
template <class _CharT>
class __rw_digit_handler_base_1
: public __rw_keyword_cracker<_CharT>
{
public:
const _STD::ctype<_CharT> &_C_ctyp;
const __rw_digit_map<_CharT> &_C_dmap;
const __rw_punct_data<_CharT> &_C_punct;
// ctor for general numerics, gets punct from loc's numpunct facet
inline __rw_digit_handler_base_1 (const _STD::locale&);
// ctor for money, passed __rw_punct_data is in fact a moneypunct facet
__rw_digit_handler_base_1 (const _STD::locale &__loc,
const __rw_punct_data<_CharT> &__pun)
: _C_ctyp (_USE_FACET (_STD::ctype<_CharT>, __loc)),
_C_dmap (__rw_digit_map<_CharT>::_C_get_digit_map (_C_ctyp)),
_C_punct (__pun)
{ }
_CharT _C_get_decimal_point () const {
return _C_punct._C_dp;
}
_CharT _C_get_thousands_sep () const {
return _C_punct._C_ts;
}
const char* _C_get_grouping () const {
return _C_punct._C_gr.c_str();
}
};
#ifndef _RWSTD_INLINE_INSTANTIATION_HACK
template <class _CharT>
inline __rw_digit_handler_base_1<_CharT>::
__rw_digit_handler_base_1 (const locale& __loc)
: _C_ctyp (_USE_FACET (_STD::ctype<_CharT>, __loc)),
_C_dmap (__rw_digit_map<_CharT>::_C_get_digit_map (_C_ctyp)),
_C_punct (_USE_FACET (_STD::numpunct<_CharT>, __loc))
{ }
#endif // _RWSTD_INLINE_INSTANTIATION_HACK
// ------------------------------------------------
// Implementation class -- __rw_digit_reader_base.
// ------------------------------------------------
// Contains digit_reader members that do not depend on the digit_reader
// template parameters, particularly for converting strings of char digits
// to long and floating-point binary values.
class _RWSTD_EXPORT __rw_digit_reader_base : public __rw_digit_map_base
{
public:
enum {
_C_good = 0x0000,
_C_no_digits = 0x0001,
_C_too_many_groups = 0x0004,
_C_group_too_long = 0x0008,
_C_group_is_empty = 0x0010,
_C_bad_grouping = 0x0020,
_C_bad_exponent = 0x0040,
_C_overflow = 0x0080,
_C_bad_curr_symbol = 0x0100,
_C_bad_sign = 0x0200,
// state bits
_C_signed = 0x01000, // sign allowed in input
_C_negative = 0x02000, // minus sign was present
_C_exp_negative = 0x04000, // minus sign was present on exponent
_C_advanced = 0x08000, // iterator was advanced
_C_infinity = 0x10000, // inf/infinity
_C_nan = 0x20000, // NaN - Not a Number
_C_DEF_BUFSIZE = 64 // room for at most this many digits
};
// Fields defining digits to be converted, usually filled in by derived
// class before calling one of the conversion methods below.
int _C_error; // Bit-field
int _C_base; // 2, 8, 10, or 16, 0=not yet determined
int _C_state; // bitmap of state bits
char *_C_frac_beg; // Start of fractional part of digits
char *_C_exp_beg; // Start of exponent in digits
size_t _C_bufsize; // actual size of buffer
// Binary digits (i.e. 0, 1, 2, not '0', '1', '2')
char _C_buffer [_C_DEF_BUFSIZE]; // sufficient in most cases
char *_C_digits; // may be dynamically allocated
__rw_digit_reader_base (int __radix = 0)
: _C_error (_C_good), _C_base (__radix), _C_state (_C_signed),
_C_frac_beg (0), _C_exp_beg (0), _C_bufsize (_C_DEF_BUFSIZE),
_C_digits (_C_buffer) { }
~__rw_digit_reader_base () {
if (_C_digits != _C_buffer)
delete[] _C_digits;
}
// parse a string of digits into a long
long _C_parse (const char *__end, long) {
return _RWSTD_STATIC_CAST (unsigned long, _C_parse (__end, 0UL));
}
// parse a string of digits into an unsigned long
unsigned long _C_parse (const char *__end, unsigned long = 0);
// overloads provided for genericity
short _C_parse (const char *__end, short) {
return _RWSTD_STATIC_CAST (short, _C_parse (__end, 0L));
}
unsigned short _C_parse (const char *__end, unsigned short) {
return _RWSTD_STATIC_CAST (unsigned short, _C_parse (__end, 0UL));
}
int _C_parse (const char *__end, int) {
return _RWSTD_STATIC_CAST (int, _C_parse (__end, 0L));
}
unsigned int _C_parse (const char *__end, unsigned int) {
return _RWSTD_STATIC_CAST (unsigned int, _C_parse (__end, 0UL));
}
#ifdef _RWSTD_LONG_LONG
unsigned _RWSTD_LONG_LONG _C_parse (const char *__end,
unsigned _RWSTD_LONG_LONG);
_RWSTD_LONG_LONG _C_parse (const char *__end, _RWSTD_LONG_LONG) {
return _RWSTD_STATIC_CAST (unsigned _RWSTD_LONG_LONG,
_C_parse (__end, (unsigned _RWSTD_LONG_LONG)0));
}
#endif // _RWSTD_LONG_LONG
// _C_parse a string of digits and interpret it as a pointer
void *_C_parse (const char *__end, void* __val);
float _C_parse (const char *__end, float __val, const char *__fmt = "%g")
__softfp {
return _C_parse_float (__end, __fmt, &__val), __val;
}
double _C_parse (const char *__end, double __val,
const char *__fmt = "%lg") __softfp {
return _C_parse_float (__end, __fmt, &__val), __val;
}
long double _C_parse (const char *__end, long double __val,
const char *__fmt =
"%" _RWSTD_LDBL_SCANF_PREFIX "g") __softfp {
// careful with format specifier on platform where
// sizeof (double) == sizeof (long double)
return _C_parse_float (__end, __fmt, &__val), __val;
}
protected:
// reallocates a buffer when the existing one fills up
static char* _C_realloc (char*&, char*, _RWSTD_C::size_t&);
// reallocates digit buffer when the existing one fills up
char* _C_realloc ();
private:
// parse a string of decimal only digits into an unsigned long
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -