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

📄 _locimp.h

📁 realview22.rar
💻 H
📖 第 1 页 / 共 2 页
字号:

        _C_name = _RWSTD_STATIC_CAST (char*,
                                      _RWSTD_C::memcpy (new char [__size],
                                                        __name, __size));
    }

    _C_facet_names.resize (_C_n_categories, _STD::string ());
}


inline __rw_locale_imp::__rw_locale_imp (const __rw_locale_imp &__rhs,
                                         const char *__name, size_type __ref)
    : _C_facet_names (__rhs._C_facet_names), 
      _C_facets (__rhs._C_facets), 
      _C_native (__rhs._C_native), 
      _C_named (__rhs._C_named), 
      _C_name (0),
      _C_ref_count (__ref) {

    
    if (__name) {
        size_type __size = _RWSTD_C::strlen (__name) + 1;
        _C_name =
            _RWSTD_STATIC_CAST (char*,
                                _RWSTD_C::memcpy (new char [__size], __name,
                                                  __size));
    }

    for (size_type __i = _C_facets.size (); __i--; ) {
        if (_C_facets [__i])
            _RWSTD_ATOMIC_PREINCREMENT (_C_facets [__i]->_C_ref_count,
                                        _C_facets [__i]->_C_mutex);
    }
}


inline const char*
__rw_locale_imp::_C_category_name (int __cat) const {

    int __mask = _C_first_category;

    for (size_type __i = 0;
         __i < size_type (_C_n_categories); ++__i, __mask <<= 1)

        if (__cat & __mask)
            return _C_facet_names[__i].c_str();

    return "";
}

// --------------------------------------------
// Implementation class -- __rw_digit_map_base.
// --------------------------------------------

// A place to stash some static constants, so that each instantiation of the
// derived class rwstd::__rw_digit_map does not have to have a separate copy.

struct _RWSTD_EXPORT __rw_digit_map_base
{
    enum { _C_zero, _C_minus, _C_plus, _C_X, _C_x, _C_E, _C_e };
    static const char _C_punct_chars[7];   // "0-+XxEe"
    static const char _C_digit_chars[22];  // "0123456789ABCDEFabcdef"
    static const char _C_char_values[22];  // values in range 0-15
};

// -------------------------------------------------------
// Implementation class template -- __rw_digit_map<_CharT>.
// -------------------------------------------------------

// Maps digits into their corresponding numeric values, and caches widened
// equivalents of some number-related punctuation characters that don't depend
// on the numpunct facet.  A private instance of this class is hidden in
// ctype<_CharT> for use by numeric conversion facets.  A call to init must
// precede the first call to _C_eval if _C_is_inited() is false.  Eval returns 0-15
// if argument is a valid digit, a negative value otherwise.
//
// Specialized for char for performance.  The specialization assumes digits
// fit into the char code-set in an ASCII-like manner ('0'..'9' contiguous,
// 'A'..'F' contiguous, 'a'..'f' contiguous, '0' < 'A' < 'a').

_RWSTD_SPECIALIZED_CLASS
class _RWSTD_EXPORT __rw_digit_map<char>
    : public __rw_digit_map_base
{
 public:
  typedef char char_type;

  bool        _C_is_inited (void) const {
      return true;
  }
  const char *_C_get_punct (void) const {
      return _C_punct_chars;
  }
  inline int  _C_eval (char) const;

  static inline const __rw_digit_map<char>&
  _C_get_digit_map (const _STD::ctype<char>&);
};

// Inline members of __rw_digit_map<char>:
//
// (Note that the definition of _C_get_digit_map is in <rw/_ctype.h> because it
//  has to come after the definition of ctype<char>.)

inline int __rw_digit_map<char>::_C_eval (char __c) const
{
    int __n =__c;
    if ((__n -= '0') > 9) {
        if ((   (__n -= ('A' - '0')) > 5
             && (__n -= ('a' - 'A')) > 5) || (__n += 10) < 10)
            __n = -1;
    }
    return __n;
}

template <class _CharT>
class __rw_digit_map
    : public __rw_digit_map_base
{
  bool _C_inited;
  _CharT _C_punct_array[7];
  _CharT _C_digit_array[22];
  char _C_value_array[22];
 public:
  typedef _CharT char_type;

  __rw_digit_map (void): _C_inited(false)
        { }
  bool          _C_is_inited (void) const {
      return _C_inited;
  }
  void          _C_init (const _STD::ctype<_CharT>& ct);

  const _CharT *_C_get_punct (void) const {
      return _C_punct_array;
  }
  int           _C_eval (_CharT) const;

    // Can-opener for getting the __rw_digit_map out of a ctype.
    // (Works because of the friend declaration in
    // __rw_ctype_helper<_CharT> below.)
  static const __rw_digit_map<char_type>&
  _C_get_digit_map (const _STD::ctype<char_type>& __ctp) {
      if (!__ctp._C_digit_map._C_inited) {
          __rw_digit_map<char_type> &__map = 
              _RWSTD_CONST_CAST (__rw_digit_map<char_type>&,
                                 __ctp._C_digit_map);

          __map._C_init (__ctp);
      }
      return __ctp._C_digit_map;
  }
};


template <class _CharT>
inline void 
__rw_digit_map<_CharT>::_C_init (const _STD::ctype<_CharT> &__ctp) {

    __ctp.widen (_C_punct_chars, _C_punct_chars + sizeof _C_punct_chars,
                _C_punct_array);

    __ctp.widen (_C_digit_chars, _C_digit_chars + sizeof _C_digit_chars,
                _C_digit_array);

    _RWSTD_C::memcpy (_C_value_array, _C_char_values, sizeof _C_value_array);
    _C_inited = true;
}


template <class _CharT>
inline int __rw_digit_map<_CharT>::_C_eval (_CharT __c) const {

    const _CharT *__end = _C_digit_array + sizeof _C_value_array;

    for (const _CharT *__p = _C_digit_array; __p != __end; ++__p)
        if (*__p == __c)
            return _C_value_array [__p - _C_digit_array];

    return -1;
}


// ------------------------------------------------------
// Implementation function templates -- create_xxx_facet.
// ------------------------------------------------------

// The __rw_facet_maker<Facet>::_C_maker_func functions described above delegate
// actual construction of facets to three inline function templates named
// create_xxx_facet, where xxx is 'classic' or 'native' or 'named'.  The
// default (template) versions of these functions construct facets as follows:
//
//   classic -- default constructor for the facet with only the refs argument.
//   native -- calls create_named_facet with a name of "".
//   named -- calls create_classic_facet, ignoring the passed name.
//
// This default behavior is overridden (specialized) for certain facet types.
// In particular, create_named_facet is specialized for all facet types that
// have a derived _byname version, to construct that version with the passed
// name (see <rw/_locale.h>) and create_native_facet is specialized for all
// facet types whose "native" behavior (as determined by the vendor) differs
// from the byname facet with a name of "" (see <rw/vendor>).

template <class _Facet>
inline _Facet*
__rw_create_named_facet (_Facet*, const char*, _RWSTD_C::size_t);

template <class _Facet>
inline _Facet*
__rw_create_native_facet (_Facet*);

template <class _Facet>
inline _Facet*
__rw_create_classic_facet (_Facet*)
{
    return new _Facet ();
}

// ---------------------------------------------------------
// Implementation class template -- __rw_facet_maker<Facet>.
// ---------------------------------------------------------

// When use_facet (inline) finds that a locale does not contain an explicit
// facet of the requested type, it calls locale::_C_make_facet
// (non-template) to create or find the facet in a cache, and install it
// in the locale.  As a parameter to __make_explicit, use_facet passes
// a call-back function which _C_make_facet can call to construct
// a facet of the requested type if needed.  The call-back functions are
// obtained by instantiating the following helper class template:

template <class _Facet>
struct __rw_facet_maker
{
    static __rw_facet_base* _C_maker_func (int, const char*, _RWSTD_C::size_t);
};


template <class _Facet>
inline
__rw_facet_base* __rw_facet_maker<_Facet>::
_C_maker_func (int __t, const char* __name, _RWSTD_C::size_t __ref)
{
    switch (__t) {
    case 0:  return __rw_create_classic_facet ((_Facet*)0);
    case 1:  return __rw_create_native_facet ((_Facet*)0);
    }
    return __rw_create_named_facet ((_Facet*)0, __name, __ref);
}


// Typedef for the above __rw_facet_maker functions, for use in the declaration
// of locale::_C_make_facet.

typedef __rw_facet_base*
__rw_facet_maker_func (int, const char*, _RWSTD_C::size_t);


_RWSTD_NAMESPACE_END   // __rw


#endif   //_RWSTD_LOCIMP_H_INCLUDED

⌨️ 快捷键说明

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