/home/ntakagi/work/STLport-5.1.5/src/message_facets.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 #ifndef MESSAGE_FACETS_H 00019 #define MESSAGE_FACETS_H 00020 00021 #include <string> 00022 #include <locale> 00023 #include <typeinfo> 00024 #include <hash_map> 00025 00026 #include "c_locale.h" 00027 #include "acquire_release.h" 00028 00029 _STLP_BEGIN_NAMESPACE 00030 _STLP_MOVE_TO_PRIV_NAMESPACE 00031 00032 // Class _Catalog_locale_map. The reason for this is that, internally, 00033 // a message string is always a char*. We need a ctype facet to convert 00034 // a string to and from wchar_t, and the user is permitted to provide such 00035 // a facet when calling open(). 00036 00037 struct _Catalog_locale_map { 00038 _Catalog_locale_map() : M(0) {} 00039 ~_Catalog_locale_map() { if (M) delete M; } 00040 00041 void insert(nl_catd_type key, const locale& L); 00042 locale lookup(nl_catd_type key) const; 00043 void erase(nl_catd_type key); 00044 00045 typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type> > map_type; 00046 map_type *M; 00047 00048 private: // Invalidate copy constructor and assignment 00049 _Catalog_locale_map(const _Catalog_locale_map&); 00050 void operator=(const _Catalog_locale_map&); 00051 }; 00052 00053 /* 00054 * In glibc nl_catd type is void *, but messages_base::catalog is defined as int 00055 * by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms; 00056 * Another problem, is that do_open() may return negative value to indicate that no 00057 * catalog open---this case can't be represented with pointers. 00058 * The class _Catalog_nl_catd_map intended to make relation between 00059 * messages_base::catalog and nl_catd handler. 00060 * 00061 */ 00062 00063 #if defined (_STLP_REAL_LOCALE_IMPLEMENTED) && (defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__)) 00064 # define _STLP_USE_NL_CATD_MAPPING 00065 #else 00066 /* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1, 00067 * has to be large enough to contain a nl_catd_type value. 00068 */ 00069 _STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int)) 00070 #endif 00071 00072 class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map { 00073 public: 00074 _Catalog_nl_catd_map() 00075 {} 00076 ~_Catalog_nl_catd_map() 00077 {} 00078 00079 typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog> > map_type; 00080 typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type> > rmap_type; 00081 // typedef map<messages_base::catalog,nl_catd_type> map_type; 00082 // typedef map<nl_catd_type,messages_base::catalog> rmap_type; 00083 00084 messages_base::catalog insert(nl_catd_type cat) 00085 #if !defined (_STLP_USE_NL_CATD_MAPPING) 00086 { return (messages_base::catalog)cat; } 00087 #else 00088 ; 00089 #endif 00090 00091 void erase(messages_base::catalog) 00092 #if !defined (_STLP_USE_NL_CATD_MAPPING) 00093 {} 00094 #else 00095 ; 00096 #endif 00097 00098 nl_catd_type operator [] ( messages_base::catalog cat ) const 00099 #if !defined (_STLP_USE_NL_CATD_MAPPING) 00100 { return cat; } 00101 #else 00102 { return cat < 0 ? 0 : M[cat]; } 00103 #endif 00104 00105 private: 00106 _Catalog_nl_catd_map(const _Catalog_nl_catd_map&); 00107 _Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&); 00108 00109 #if defined (_STLP_USE_NL_CATD_MAPPING) 00110 mutable map_type M; 00111 mutable rmap_type Mr; 00112 static _STLP_VOLATILE __stl_atomic_t _count; 00113 #endif 00114 }; 00115 00116 class _STLP_CLASS_DECLSPEC _Messages { 00117 public: 00118 typedef messages_base::catalog catalog; 00119 00120 _Messages(); 00121 00122 virtual catalog do_open(const string& __fn, const locale& __loc) const; 00123 virtual string do_get(catalog __c, int __set, int __msgid, 00124 const string& __dfault) const; 00125 #if !defined (_STLP_NO_WCHAR_T) 00126 virtual wstring do_get(catalog __c, int __set, int __msgid, 00127 const wstring& __dfault) const; 00128 #endif 00129 virtual void do_close(catalog __c) const; 00130 virtual ~_Messages(); 00131 bool _M_delete; 00132 }; 00133 00134 class _STLP_CLASS_DECLSPEC _Messages_impl : public _Messages { 00135 public: 00136 _Messages_impl(bool, _Locale_name_hint* hint = 0); 00137 _Messages_impl(bool, _Locale_messages*); 00138 00139 catalog do_open(const string& __fn, const locale& __loc) const; 00140 string do_get(catalog __c, int __set, int __msgid, 00141 const string& __dfault) const; 00142 #if !defined (_STLP_NO_WCHAR_T) 00143 wstring do_get(catalog __c, int __set, int __msgid, 00144 const wstring& __dfault) const; 00145 #endif 00146 void do_close(catalog __c) const; 00147 00148 ~_Messages_impl(); 00149 00150 private: 00151 _Locale_messages* _M_message_obj; 00152 _Catalog_locale_map* _M_map; 00153 mutable _Catalog_nl_catd_map _M_cat; 00154 00155 //private definition to avoid warning (with ICL) 00156 _Messages_impl(const _Messages_impl&); 00157 _Messages_impl& operator=(const _Messages_impl&); 00158 }; 00159 00160 _STLP_MOVE_TO_STD_NAMESPACE 00161 00162 _STLP_END_NAMESPACE 00163 00164 #endif 00165 00166 // Local Variables: 00167 // mode:C++ 00168 // End:
Generated on Mon Mar 10 15:32:17 2008 by ![]() |