📄 locale_classes.h
字号:
// collate, ctype, monetary, numeric, time, and messages. These // directly correspond to ISO C99 macros LC_COLLATE, LC_CTYPE, // LC_MONETARY, LC_NUMERIC, and LC_TIME. In addition, POSIX (IEEE // 1003.1-2001) specifies LC_MESSAGES. // In addition to the standard categories, the underlying // operating system is allowed to define extra LC_* // macros. For GNU systems, the following are also valid: // LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, // and LC_IDENTIFICATION. static const size_t _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES;#ifdef __GTHREADS static __gthread_once_t _S_once;#endif explicit locale(_Impl*) throw(); static void _S_initialize(); static void _S_initialize_once(); static category _S_normalize_category(category); void _M_coalesce(const locale& __base, const locale& __add, category __cat); }; // 22.1.1.1.2 Class locale::facet /** * @brief Localization functionality base class. * * The facet class is the base class for a localization feature, such as * money, time, and number printing. It provides common support for facets * and reference management. * * Facets may not be copied or assigned. */ class locale::facet { private: friend class locale; friend class locale::_Impl; mutable _Atomic_word _M_refcount; // Contains data from the underlying "C" library for the classic locale. static __c_locale _S_c_locale; // String literal for the name of the classic locale. static const char _S_c_name[2];#ifdef __GTHREADS static __gthread_once_t _S_once;#endif static void _S_initialize_once(); protected: /** * @brief Facet constructor. * * This is the constructor provided by the standard. If refs is 0, the * facet is destroyed when the last referencing locale is destroyed. * Otherwise the facet will never be destroyed. * * @param refs The initial value for reference count. */ explicit facet(size_t __refs = 0) throw() : _M_refcount(__refs ? 1 : 0) { } /// Facet destructor. virtual ~facet(); static void _S_create_c_locale(__c_locale& __cloc, const char* __s, __c_locale __old = 0); static __c_locale _S_clone_c_locale(__c_locale& __cloc); static void _S_destroy_c_locale(__c_locale& __cloc); // Returns data from the underlying "C" library data for the // classic locale. static __c_locale _S_get_c_locale(); static const char* _S_get_c_name(); private: inline void _M_add_reference() const throw() { __gnu_cxx::__atomic_add(&_M_refcount, 1); } inline void _M_remove_reference() const throw() { if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1) { try { delete this; } catch (...) { } } } facet(const facet&); // Not defined. facet& operator=(const facet&); // Not defined. }; // 22.1.1.1.3 Class locale::id /** * @brief Facet ID class. * * The ID class provides facets with an index used to identify them. * Every facet class must define a public static member locale::id, or be * derived from a facet that provides this member, otherwise the facet * cannot be used in a locale. The locale::id ensures that each class * type gets a unique identifier. */ class locale::id { private: friend class locale; friend class locale::_Impl; template<typename _Facet> friend const _Facet& use_facet(const locale&); template<typename _Facet> friend bool has_facet(const locale&) throw (); // NB: There is no accessor for _M_index because it may be used // before the constructor is run; the effect of calling a member // function (even an inline) would be undefined. mutable size_t _M_index; // Last id number assigned. static _Atomic_word _S_refcount; void operator=(const id&); // Not defined. id(const id&); // Not defined. public: // NB: This class is always a static data member, and thus can be // counted on to be zero-initialized. /// Constructor. id() { } size_t _M_id() const; }; // Implementation object for locale. class locale::_Impl { public: // Friends. friend class locale; friend class locale::facet; template<typename _Facet> friend bool has_facet(const locale&) throw(); template<typename _Facet> friend const _Facet& use_facet(const locale&); template<typename _Cache> friend struct __use_cache; private: // Data Members. _Atomic_word _M_refcount; const facet** _M_facets; size_t _M_facets_size; const facet** _M_caches; char** _M_names; static const locale::id* const _S_id_ctype[]; static const locale::id* const _S_id_numeric[]; static const locale::id* const _S_id_collate[]; static const locale::id* const _S_id_time[]; static const locale::id* const _S_id_monetary[]; static const locale::id* const _S_id_messages[]; static const locale::id* const* const _S_facet_categories[]; inline void _M_add_reference() throw() { __gnu_cxx::__atomic_add(&_M_refcount, 1); } inline void _M_remove_reference() throw() { if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1) { try { delete this; } catch(...) { } } } _Impl(const _Impl&, size_t); _Impl(const char*, size_t); _Impl(size_t) throw(); ~_Impl() throw(); _Impl(const _Impl&); // Not defined. void operator=(const _Impl&); // Not defined. inline bool _M_check_same_name() { bool __ret = true; for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i) __ret = std::strcmp(_M_names[__i], _M_names[__i + 1]) == 0; return __ret; } void _M_replace_categories(const _Impl*, category); void _M_replace_category(const _Impl*, const locale::id* const*); void _M_replace_facet(const _Impl*, const locale::id*); void _M_install_facet(const locale::id*, const facet*); template<typename _Facet> inline void _M_init_facet(_Facet* __facet) { _M_install_facet(&_Facet::id, __facet); } void _M_install_cache(const facet* __cache, size_t __index) throw() { __cache->_M_add_reference(); _M_caches[__index] = __cache; } }; template<typename _Facet> locale::locale(const locale& __other, _Facet* __f) { _M_impl = new _Impl(*__other._M_impl, 1); char* _M_tmp_names[_S_categories_size]; size_t __i = 0; try { for (; __i < _S_categories_size; ++__i) { _M_tmp_names[__i] = new char[2]; std::strcpy(_M_tmp_names[__i], "*"); } _M_impl->_M_install_facet(&_Facet::id, __f); } catch(...) { _M_impl->_M_remove_reference(); for (size_t __j = 0; __j < __i; ++__j) delete [] _M_tmp_names[__j]; __throw_exception_again; } for (size_t __k = 0; __k < _S_categories_size; ++__k) { delete [] _M_impl->_M_names[__k]; _M_impl->_M_names[__k] = _M_tmp_names[__k]; } }} // namespace std#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -