1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/src/message_facets.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,168 @@
1.4 +/*
1.5 + * Copyright (c) 1999
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +#ifndef MESSAGE_FACETS_H
1.22 +#define MESSAGE_FACETS_H
1.23 +
1.24 +#include <string>
1.25 +#include <locale>
1.26 +#include <typeinfo>
1.27 +#include <hash_map>
1.28 +
1.29 +#include "c_locale.h"
1.30 +#include "acquire_release.h"
1.31 +
1.32 +_STLP_BEGIN_NAMESPACE
1.33 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.34 +
1.35 +// Class _Catalog_locale_map. The reason for this is that, internally,
1.36 +// a message string is always a char*. We need a ctype facet to convert
1.37 +// a string to and from wchar_t, and the user is permitted to provide such
1.38 +// a facet when calling open().
1.39 +
1.40 +struct _Catalog_locale_map {
1.41 + _Catalog_locale_map() : M(0) {}
1.42 + ~_Catalog_locale_map() { if (M) delete M; }
1.43 +
1.44 + void insert(nl_catd_type key, const locale& L);
1.45 + locale lookup(nl_catd_type key) const;
1.46 + void erase(nl_catd_type key);
1.47 +
1.48 + typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type> > map_type;
1.49 + map_type *M;
1.50 +
1.51 +private: // Invalidate copy constructor and assignment
1.52 + _Catalog_locale_map(const _Catalog_locale_map&);
1.53 + void operator=(const _Catalog_locale_map&);
1.54 +};
1.55 +
1.56 +/*
1.57 + * In glibc nl_catd type is void *, but messages_base::catalog is defined as int
1.58 + * by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms;
1.59 + * Another problem, is that do_open() may return negative value to indicate that no
1.60 + * catalog open---this case can't be represented with pointers.
1.61 + * The class _Catalog_nl_catd_map intended to make relation between
1.62 + * messages_base::catalog and nl_catd handler.
1.63 + *
1.64 + */
1.65 +
1.66 +#if defined (_STLP_REAL_LOCALE_IMPLEMENTED) && (defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__))
1.67 +# define _STLP_USE_NL_CATD_MAPPING
1.68 +#else
1.69 +/* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1,
1.70 + * has to be large enough to contain a nl_catd_type value.
1.71 + */
1.72 +_STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int))
1.73 +#endif
1.74 +
1.75 +class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map {
1.76 +public:
1.77 + _Catalog_nl_catd_map()
1.78 + {}
1.79 + ~_Catalog_nl_catd_map()
1.80 + {}
1.81 +
1.82 + typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog> > map_type;
1.83 + typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type> > rmap_type;
1.84 + // typedef map<messages_base::catalog,nl_catd_type> map_type;
1.85 + // typedef map<nl_catd_type,messages_base::catalog> rmap_type;
1.86 +
1.87 + messages_base::catalog insert(nl_catd_type cat)
1.88 +#if !defined (_STLP_USE_NL_CATD_MAPPING)
1.89 + { return (messages_base::catalog)cat; }
1.90 +#else
1.91 + ;
1.92 +#endif
1.93 +
1.94 + void erase(messages_base::catalog)
1.95 +#if !defined (_STLP_USE_NL_CATD_MAPPING)
1.96 + {}
1.97 +#else
1.98 + ;
1.99 +#endif
1.100 +
1.101 + nl_catd_type operator [] ( messages_base::catalog cat ) const
1.102 +#if !defined (_STLP_USE_NL_CATD_MAPPING)
1.103 + { return cat; }
1.104 +#else
1.105 + { return cat < 0 ? 0 : M[cat]; }
1.106 +#endif
1.107 +
1.108 +private:
1.109 + _Catalog_nl_catd_map(const _Catalog_nl_catd_map&);
1.110 + _Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&);
1.111 +
1.112 +#if defined (_STLP_USE_NL_CATD_MAPPING)
1.113 + mutable map_type M;
1.114 + mutable rmap_type Mr;
1.115 + static _STLP_VOLATILE __stl_atomic_t _count;
1.116 +#endif
1.117 +};
1.118 +
1.119 +class _STLP_CLASS_DECLSPEC _Messages {
1.120 +public:
1.121 + typedef messages_base::catalog catalog;
1.122 +
1.123 + _Messages();
1.124 +
1.125 + virtual catalog do_open(const string& __fn, const locale& __loc) const;
1.126 + virtual string do_get(catalog __c, int __set, int __msgid,
1.127 + const string& __dfault) const;
1.128 +#if !defined (_STLP_NO_WCHAR_T)
1.129 + virtual wstring do_get(catalog __c, int __set, int __msgid,
1.130 + const wstring& __dfault) const;
1.131 +#endif
1.132 + virtual void do_close(catalog __c) const;
1.133 + virtual ~_Messages();
1.134 + bool _M_delete;
1.135 +};
1.136 +
1.137 +class _STLP_CLASS_DECLSPEC _Messages_impl : public _Messages {
1.138 +public:
1.139 + _Messages_impl(bool, _Locale_name_hint* hint = 0);
1.140 + _Messages_impl(bool, _Locale_messages*);
1.141 +
1.142 + catalog do_open(const string& __fn, const locale& __loc) const;
1.143 + string do_get(catalog __c, int __set, int __msgid,
1.144 + const string& __dfault) const;
1.145 +#if !defined (_STLP_NO_WCHAR_T)
1.146 + wstring do_get(catalog __c, int __set, int __msgid,
1.147 + const wstring& __dfault) const;
1.148 +#endif
1.149 + void do_close(catalog __c) const;
1.150 +
1.151 + ~_Messages_impl();
1.152 +
1.153 +private:
1.154 + _Locale_messages* _M_message_obj;
1.155 + _Catalog_locale_map* _M_map;
1.156 + mutable _Catalog_nl_catd_map _M_cat;
1.157 +
1.158 + //private definition to avoid warning (with ICL)
1.159 + _Messages_impl(const _Messages_impl&);
1.160 + _Messages_impl& operator=(const _Messages_impl&);
1.161 +};
1.162 +
1.163 +_STLP_MOVE_TO_STD_NAMESPACE
1.164 +
1.165 +_STLP_END_NAMESPACE
1.166 +
1.167 +#endif
1.168 +
1.169 +// Local Variables:
1.170 +// mode:C++
1.171 +// End: