michael@0: /* michael@0: * Copyright (c) 1999 michael@0: * Silicon Graphics Computer Systems, Inc. michael@0: * michael@0: * Copyright (c) 1999 michael@0: * Boris Fomitchev michael@0: * michael@0: * This material is provided "as is", with absolutely no warranty expressed michael@0: * or implied. Any use is at your own risk. michael@0: * michael@0: * Permission to use or copy this software for any purpose is hereby granted michael@0: * without fee, provided the above notices are retained on all copies. michael@0: * Permission to modify the code and to distribute modified code is granted, michael@0: * provided the above notices are retained, and a notice that the code was michael@0: * modified is included with the above copyright notice. michael@0: * michael@0: */ michael@0: #ifndef MESSAGE_FACETS_H michael@0: #define MESSAGE_FACETS_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "c_locale.h" michael@0: michael@0: _STLP_BEGIN_NAMESPACE michael@0: _STLP_MOVE_TO_PRIV_NAMESPACE michael@0: michael@0: // Class _Catalog_locale_map. The reason for this is that, internally, michael@0: // a message string is always a char*. We need a ctype facet to convert michael@0: // a string to and from wchar_t, and the user is permitted to provide such michael@0: // a facet when calling open(). michael@0: michael@0: struct _Catalog_locale_map { michael@0: _Catalog_locale_map() : M(0) {} michael@0: ~_Catalog_locale_map() { if (M) delete M; } michael@0: michael@0: void insert(nl_catd_type key, const locale& L); michael@0: locale lookup(nl_catd_type key) const; michael@0: void erase(nl_catd_type key); michael@0: michael@0: typedef hash_map, equal_to, michael@0: allocator > > map_type; michael@0: map_type *M; michael@0: michael@0: private: // Invalidate copy constructor and assignment michael@0: _Catalog_locale_map(const _Catalog_locale_map&); michael@0: void operator=(const _Catalog_locale_map&); michael@0: }; michael@0: michael@0: /* michael@0: * In glibc nl_catd type is void *, but messages_base::catalog is defined as int michael@0: * by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms; michael@0: * Another problem, is that do_open() may return negative value to indicate that no michael@0: * catalog open---this case can't be represented with pointers. michael@0: * The class _Catalog_nl_catd_map intended to make relation between michael@0: * messages_base::catalog and nl_catd handler. michael@0: * michael@0: */ michael@0: michael@0: #if defined (_STLP_USE_GLIBC2_LOCALIZATION) michael@0: # define _STLP_USE_NL_CATD_MAPPING michael@0: #else michael@0: /* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1, michael@0: * has to be large enough to contain a nl_catd_type value. michael@0: */ michael@0: _STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int)) michael@0: #endif michael@0: michael@0: class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map { michael@0: public: michael@0: _Catalog_nl_catd_map() michael@0: {} michael@0: ~_Catalog_nl_catd_map() michael@0: {} michael@0: michael@0: typedef hash_map, equal_to, michael@0: allocator > > map_type; michael@0: typedef hash_map, equal_to, michael@0: allocator > > rmap_type; michael@0: // typedef map map_type; michael@0: // typedef map rmap_type; michael@0: michael@0: messages_base::catalog insert(nl_catd_type cat) michael@0: #if !defined (_STLP_USE_NL_CATD_MAPPING) michael@0: { return (messages_base::catalog)cat; } michael@0: #else michael@0: ; michael@0: #endif michael@0: michael@0: void erase(messages_base::catalog) michael@0: #if !defined (_STLP_USE_NL_CATD_MAPPING) michael@0: {} michael@0: #else michael@0: ; michael@0: #endif michael@0: michael@0: nl_catd_type operator [] ( messages_base::catalog cat ) michael@0: #if !defined (_STLP_USE_NL_CATD_MAPPING) michael@0: { return cat; } michael@0: #else michael@0: { return cat < 0 ? 0 : M[cat]; } michael@0: #endif michael@0: michael@0: private: michael@0: _Catalog_nl_catd_map(const _Catalog_nl_catd_map&); michael@0: _Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&); michael@0: michael@0: #if defined (_STLP_USE_NL_CATD_MAPPING) michael@0: map_type M; michael@0: rmap_type Mr; michael@0: static _STLP_VOLATILE __stl_atomic_t _count; michael@0: #endif michael@0: }; michael@0: michael@0: class _Messages { michael@0: public: michael@0: typedef messages_base::catalog catalog; michael@0: michael@0: _Messages(bool, const char *name); michael@0: _Messages(bool, _Locale_messages*); michael@0: michael@0: catalog do_open(const string& __fn, const locale& __loc) const; michael@0: string do_get(catalog __c, int __set, int __msgid, michael@0: const string& __dfault) const; michael@0: #if !defined (_STLP_NO_WCHAR_T) michael@0: wstring do_get(catalog __c, int __set, int __msgid, michael@0: const wstring& __dfault) const; michael@0: #endif michael@0: void do_close(catalog __c) const; michael@0: ~_Messages(); michael@0: michael@0: private: michael@0: _Locale_messages* _M_message_obj; michael@0: _Catalog_locale_map* _M_map; michael@0: mutable _Catalog_nl_catd_map _M_cat; michael@0: michael@0: //private definition to avoid warning (with ICL) michael@0: _Messages(const _Messages&); michael@0: _Messages& operator=(const _Messages&); michael@0: }; michael@0: michael@0: _STLP_MOVE_TO_STD_NAMESPACE michael@0: michael@0: _STLP_END_NAMESPACE michael@0: michael@0: #endif michael@0: michael@0: // Local Variables: michael@0: // mode:C++ michael@0: // End: