⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _time.cc

📁 realview22.rar
💻 CC
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
 *
 * _time.cc - Definitions for the Standard Library time facets
 *
 * $Id: _time.cc,v 1.4 2003/05/06 14:32:35 helenj Exp $
 *
 ***************************************************************************
 *
 * 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.
 *
 **************************************************************************/

#include _RWSTD_CTIME

_RWSTD_NAMESPACE_BEGIN (__rw)

// -------------------------------------------
// Template __rw_time_reader member templates.
// -------------------------------------------

template <class _CharT, class _InputIter>
bool __rw_time_reader<_CharT, _InputIter>::
    _C_get_time_pattern (const string_type &__patt, tm *__tm) {

    enum {
        __edit_year    = 0x01, 
        __edit_month   = 0x02, 
        __edit_century = 0x04, 
        __edit_hour    = 0x08
    };
    

    int __post_edits = 0;

    const _CharT *__p = __patt.c_str (), *__patt_end = __p+__patt.length ();
    for ( ; __p<__patt_end; ++__p) {
        switch (this->_C_ctyp.narrow (*__p, ' ')) {
        case '%':
        {
            int *__iresult;
            int __ampm_dummy;  // scratch space for ampm value
            const __rw_keyword_map<_CharT> *__keywords = 0;
            
            switch (this->_C_ctyp.narrow (*++__p, ' ')) {
            case 'a':
            case 'A':
                // Day of week (abbreviated or not).
                __keywords = &this->_C_get_day_map (_C_timp);
                __iresult  = &__tm->tm_wday;
                break;
            case 'b':
            case 'B':
                // Month name (abbreviated or not).
                __keywords = &this->_C_get_month_map (_C_timp);
                __iresult  = &__tm->tm_mon;
                break;
            case 'm':
                // Numeric month, comes in 1 higher than the number we want.
                __post_edits |= __edit_month;
                __iresult     = &__tm->tm_mon;
                break;
            case 'c':
                // Full date, time and year in default format.
                return _C_get_time_pattern (this->_C_get_patt_string (_C_timp,
                                                                      2),
                                            __tm);
            case 'd':
                // Day of month.
                __iresult = &__tm->tm_mday;
                break;
            case 'I': // 12-hour clock
            case 'H': // 24-hour clock
                // Hours (12/24 distinction is made in the 'p' section)
                __iresult = &__tm->tm_hour;
                break;
            case 'p':
                // am/pm indicator
                __keywords = &this->_C_get_ampm_map (_C_timp);
                //  Assumes _CharT[0] are equal means entire string will be
                if (*this->_C_in == this->_C_get_ampm_string (_C_timp, true)[0])
                    __post_edits |= __edit_hour;
                __iresult = &__ampm_dummy;
                break;
            case 'M':
                // Minutes.
                __iresult = &__tm->tm_min;
                break;
            case 'S':
                // Seconds.
                __iresult = &__tm->tm_sec;
                break;
            case 'Y':
                // Year with Century.
                __post_edits |= __edit_year;
                __iresult = &__tm->tm_year;
                break;
            case 'y':
                // 2-digit Year without Century.
                __post_edits |= (__edit_year|__edit_century);
                __iresult = &__tm->tm_year;
                break;
            default:
                // All other format characters are not supported on input.
                return false;
            }
            
            if (__keywords) {
                if ((*__iresult = this->_C_get_keyword (*__keywords)) < 0)
                    return false;
            }
            else {
                this->_C_base = 10;
                *__iresult =
                    this->_C_parse (this->_C_get_digit_string (this->_C_digits),
                                    0UL);
            }
        }
        break;
        default:
            if (!this->eof () && *this->_C_in==*__p)
                ++(this->_C_in);
            else
                return false;
        }
        
        if (this->_C_error)
            return false;
    }
    
    if (__post_edits&__edit_year)
        if (__post_edits&__edit_century && __tm->tm_year<100)
            ; // 2-digit year is already relative to 1900
        else
            __tm->tm_year -= 1900;
    
    if (__post_edits&__edit_month)
        __tm->tm_mon--;
    
    if (__post_edits&__edit_hour)
        if (__tm->tm_hour < 12)
            __tm->tm_hour+=12;
    
    return true;
}

_RWSTD_NAMESPACE_END   // __rw

_RWSTD_NAMESPACE_BEGIN(std)

// ----------------------------------------------------------
// Facet time_get<_CharT, _InputIter> member templates.
// ---------------------------------------------------------

template <class _CharT, class _InputIter>
locale::id time_get<_CharT, _InputIter>::id;


template <class _CharT, class _InputIter>
time_base::dateorder time_get<_CharT, _InputIter>::do_date_order () const {

    _C_check_init (); 

    // We would prefer to return a value that matches the date format defined
    // in the timepunct facet in the caller's locale, but we can't get there
    // from here ...

    const _TYPENAME _RW::__rw_timepunct<_CharT>::string_type& __s =
        _RW::__rw_keyword_cracker<_CharT>::_C_get_patt_string (*_C_timp, 0);

    bool __haveYear = false;

    for (size_t __i = 0; __i < __s.length (); ++__i) {

        if (__s[__i] == _CharT ('y') || __s[__i] == _CharT ('Y'))
            __haveYear = true;

        if ( __s[__i] == _CharT ('d') || __s[__i] == _CharT ('a')
             || __s[__i] == _CharT ('A')) {

            if (__haveYear)
                return ydm;
            else
                return dmy;
        }
        if (__s[__i] == _CharT ('m') || __s[__i] == _CharT ('b')
            || __s[__i] == _CharT ('B')) {

            if (__haveYear)
                return ymd;
            else
                return mdy;
        }
    }

    return no_order;
}

template <class _CharT, class _InputIter>
_TYPENAME time_get<_CharT, _InputIter>::iter_type
time_get<_CharT, _InputIter>::do_get_time (_InputIter         __in,
                                           _InputIter         __end,
                                           ios_base&          __io,
                                           ios_base::iostate& __err,
                                           tm*                __tm) const {
    _C_check_init (); 

    _RW::__rw_time_reader<_CharT, _InputIter>
        __rdr (__in, __end, __io, *_C_timp);

    __err = ios_base::goodbit;

    // Parse according to pattern 1 (strftime '%X' -- default time pattern)
    if (!__rdr._C_get_time_pattern (__rdr._C_get_patt_string (__rdr._C_timp, 1),
                                    __tm))
        __err = ios_base::failbit;

    if (__rdr.eof ())
        __err |= ios_base::eofbit;
    
    return __in;
}

template <class _CharT, class _InputIter >
_TYPENAME time_get<_CharT, _InputIter>::iter_type
time_get<_CharT, _InputIter>::do_get_date (_InputIter         __in,
                                           _InputIter         __end,
                                           ios_base&          __io,
                                           ios_base::iostate& __err,
                                           tm*                __tm) const {

    _C_check_init (); 
    _RW::__rw_time_reader<_CharT, _InputIter>
        __rdr (__in, __end, __io, *_C_timp);

    __err = ios_base::goodbit;

    // Parse according to pattern 0 (strftime '%x' -- default date pattern)
    if (!__rdr._C_get_time_pattern (__rdr._C_get_patt_string (__rdr._C_timp, 0),
                                    __tm))
        __err = ios_base::failbit;

    if (__rdr.eof ())
        __err |= ios_base::eofbit;

    return __in;
}

template <class _CharT, class _InputIter >
_TYPENAME time_get<_CharT, _InputIter>::iter_type
time_get<_CharT, _InputIter>::do_get_weekday (_InputIter          __in,
                                              _InputIter         __end,
                                              ios_base&          __io,
                                              ios_base::iostate& __err,
                                              tm*                __tm) const {
    _C_check_init (); 

    _RW::__rw_time_reader<_CharT, _InputIter> 
        __rdr (__in, __end, __io, *_C_timp);

    int __wd = __rdr._C_get_keyword (__rdr._C_get_day_map (__rdr._C_timp));
    __err = ios_base::goodbit;

    if (__wd<0)
        __err = ios_base::failbit;
    else
        __tm->tm_wday = __wd;

    if (__rdr.eof ())
        __err |= ios_base::eofbit;

    return __in;
}

template <class _CharT, class _InputIter >
_TYPENAME time_get<_CharT, _InputIter>::iter_type
time_get<_CharT, _InputIter>::do_get_monthname (_InputIter         __in,
                                                _InputIter         __end,
                                                ios_base&          __io,
                                                ios_base::iostate& __err,
                                                tm*              __tm) const {
    _C_check_init (); 

    _RW::__rw_time_reader<_CharT, _InputIter>
        __rdr (__in, __end, __io, *_C_timp);

    int __mo = __rdr._C_get_keyword (__rdr._C_get_month_map (__rdr._C_timp));
    __err = ios_base::goodbit;

    if (__mo<0)
        __err = ios_base::failbit;
    else
        __tm->tm_mon = __mo;

    if (__rdr.eof ())
        __err |= ios_base::eofbit;

    return __in;
}

template <class _CharT, class _InputIter >
_TYPENAME time_get<_CharT, _InputIter>::iter_type
time_get<_CharT, _InputIter>::do_get_year (_InputIter         __in,
                                           _InputIter         __end,
                                           ios_base&          __io,
                                           ios_base::iostate& __err,
                                           tm*                __tm) const {

    _C_check_init (); 

    _RW::__rw_time_reader<_CharT, _InputIter> 
        __rdr (__in, __end, __io, *_C_timp);

    int __yr = __rdr._C_parse (__rdr._C_get_digits (int ()), int ());
    __err = ios_base::goodbit;

    // 2-digit year numbers are accepted, but are not treated specially, and so
    // end up in the 1st century C.E.
    if (__rdr._C_error)
        __err = ios_base::failbit;
    else
        __tm->tm_year = __yr-1900;

    if (__rdr.eof ())
        __err |= ios_base::eofbit;

    return __in;
}

// ----------------------------------------------------------
// Facet time_put<_CharT, _InputIter> member templates.
// ----------------------------------------------------------

template <class _CharT, class _OutputIter>
locale::id time_put<_CharT, _OutputIter>::id;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -