sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1999
|
sl@0
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* Copyright (c) 1999
|
sl@0
|
6 |
* Boris Fomitchev
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* This material is provided "as is", with absolutely no warranty expressed
|
sl@0
|
9 |
* or implied. Any use is at your own risk.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* Permission to use or copy this software for any purpose is hereby granted
|
sl@0
|
12 |
* without fee, provided the above notices are retained on all copies.
|
sl@0
|
13 |
* Permission to modify the code and to distribute modified code is granted,
|
sl@0
|
14 |
* provided the above notices are retained, and a notice that the code was
|
sl@0
|
15 |
* modified is included with the above copyright notice.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
#ifndef MESSAGE_FACETS_H
|
sl@0
|
19 |
#define MESSAGE_FACETS_H
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <string>
|
sl@0
|
22 |
#include <locale>
|
sl@0
|
23 |
#include <typeinfo>
|
sl@0
|
24 |
#include <hash_map>
|
sl@0
|
25 |
|
sl@0
|
26 |
#include "c_locale.h"
|
sl@0
|
27 |
#include "acquire_release.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
_STLP_BEGIN_NAMESPACE
|
sl@0
|
30 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
sl@0
|
31 |
|
sl@0
|
32 |
// Class _Catalog_locale_map. The reason for this is that, internally,
|
sl@0
|
33 |
// a message string is always a char*. We need a ctype facet to convert
|
sl@0
|
34 |
// a string to and from wchar_t, and the user is permitted to provide such
|
sl@0
|
35 |
// a facet when calling open().
|
sl@0
|
36 |
|
sl@0
|
37 |
struct _Catalog_locale_map {
|
sl@0
|
38 |
_Catalog_locale_map() : M(0) {}
|
sl@0
|
39 |
~_Catalog_locale_map() { if (M) delete M; }
|
sl@0
|
40 |
|
sl@0
|
41 |
void insert(nl_catd_type key, const locale& L);
|
sl@0
|
42 |
locale lookup(nl_catd_type key) const;
|
sl@0
|
43 |
void erase(nl_catd_type key);
|
sl@0
|
44 |
|
sl@0
|
45 |
typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type> > map_type;
|
sl@0
|
46 |
map_type *M;
|
sl@0
|
47 |
|
sl@0
|
48 |
private: // Invalidate copy constructor and assignment
|
sl@0
|
49 |
_Catalog_locale_map(const _Catalog_locale_map&);
|
sl@0
|
50 |
void operator=(const _Catalog_locale_map&);
|
sl@0
|
51 |
};
|
sl@0
|
52 |
|
sl@0
|
53 |
/*
|
sl@0
|
54 |
* In glibc nl_catd type is void *, but messages_base::catalog is defined as int
|
sl@0
|
55 |
* by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms;
|
sl@0
|
56 |
* Another problem, is that do_open() may return negative value to indicate that no
|
sl@0
|
57 |
* catalog open---this case can't be represented with pointers.
|
sl@0
|
58 |
* The class _Catalog_nl_catd_map intended to make relation between
|
sl@0
|
59 |
* messages_base::catalog and nl_catd handler.
|
sl@0
|
60 |
*
|
sl@0
|
61 |
*/
|
sl@0
|
62 |
|
sl@0
|
63 |
#if defined (_STLP_REAL_LOCALE_IMPLEMENTED) && (defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__))
|
sl@0
|
64 |
# define _STLP_USE_NL_CATD_MAPPING
|
sl@0
|
65 |
#else
|
sl@0
|
66 |
/* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1,
|
sl@0
|
67 |
* has to be large enough to contain a nl_catd_type value.
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
_STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int))
|
sl@0
|
70 |
#endif
|
sl@0
|
71 |
|
sl@0
|
72 |
class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map {
|
sl@0
|
73 |
public:
|
sl@0
|
74 |
_Catalog_nl_catd_map()
|
sl@0
|
75 |
{}
|
sl@0
|
76 |
~_Catalog_nl_catd_map()
|
sl@0
|
77 |
{}
|
sl@0
|
78 |
|
sl@0
|
79 |
typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog> > map_type;
|
sl@0
|
80 |
typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type> > rmap_type;
|
sl@0
|
81 |
// typedef map<messages_base::catalog,nl_catd_type> map_type;
|
sl@0
|
82 |
// typedef map<nl_catd_type,messages_base::catalog> rmap_type;
|
sl@0
|
83 |
|
sl@0
|
84 |
messages_base::catalog insert(nl_catd_type cat)
|
sl@0
|
85 |
#if !defined (_STLP_USE_NL_CATD_MAPPING)
|
sl@0
|
86 |
{ return (messages_base::catalog)cat; }
|
sl@0
|
87 |
#else
|
sl@0
|
88 |
;
|
sl@0
|
89 |
#endif
|
sl@0
|
90 |
|
sl@0
|
91 |
void erase(messages_base::catalog)
|
sl@0
|
92 |
#if !defined (_STLP_USE_NL_CATD_MAPPING)
|
sl@0
|
93 |
{}
|
sl@0
|
94 |
#else
|
sl@0
|
95 |
;
|
sl@0
|
96 |
#endif
|
sl@0
|
97 |
|
sl@0
|
98 |
nl_catd_type operator [] ( messages_base::catalog cat ) const
|
sl@0
|
99 |
#if !defined (_STLP_USE_NL_CATD_MAPPING)
|
sl@0
|
100 |
{ return cat; }
|
sl@0
|
101 |
#else
|
sl@0
|
102 |
{ return cat < 0 ? 0 : M[cat]; }
|
sl@0
|
103 |
#endif
|
sl@0
|
104 |
|
sl@0
|
105 |
private:
|
sl@0
|
106 |
_Catalog_nl_catd_map(const _Catalog_nl_catd_map&);
|
sl@0
|
107 |
_Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&);
|
sl@0
|
108 |
|
sl@0
|
109 |
#if defined (_STLP_USE_NL_CATD_MAPPING)
|
sl@0
|
110 |
mutable map_type M;
|
sl@0
|
111 |
mutable rmap_type Mr;
|
sl@0
|
112 |
static _STLP_VOLATILE __stl_atomic_t _count;
|
sl@0
|
113 |
#endif
|
sl@0
|
114 |
};
|
sl@0
|
115 |
|
sl@0
|
116 |
class _STLP_CLASS_DECLSPEC _Messages {
|
sl@0
|
117 |
public:
|
sl@0
|
118 |
typedef messages_base::catalog catalog;
|
sl@0
|
119 |
|
sl@0
|
120 |
_Messages();
|
sl@0
|
121 |
|
sl@0
|
122 |
virtual catalog do_open(const string& __fn, const locale& __loc) const;
|
sl@0
|
123 |
virtual string do_get(catalog __c, int __set, int __msgid,
|
sl@0
|
124 |
const string& __dfault) const;
|
sl@0
|
125 |
#if !defined (_STLP_NO_WCHAR_T)
|
sl@0
|
126 |
virtual wstring do_get(catalog __c, int __set, int __msgid,
|
sl@0
|
127 |
const wstring& __dfault) const;
|
sl@0
|
128 |
#endif
|
sl@0
|
129 |
virtual void do_close(catalog __c) const;
|
sl@0
|
130 |
virtual ~_Messages();
|
sl@0
|
131 |
bool _M_delete;
|
sl@0
|
132 |
};
|
sl@0
|
133 |
|
sl@0
|
134 |
class _STLP_CLASS_DECLSPEC _Messages_impl : public _Messages {
|
sl@0
|
135 |
public:
|
sl@0
|
136 |
_Messages_impl(bool, _Locale_name_hint* hint = 0);
|
sl@0
|
137 |
_Messages_impl(bool, _Locale_messages*);
|
sl@0
|
138 |
|
sl@0
|
139 |
catalog do_open(const string& __fn, const locale& __loc) const;
|
sl@0
|
140 |
string do_get(catalog __c, int __set, int __msgid,
|
sl@0
|
141 |
const string& __dfault) const;
|
sl@0
|
142 |
#if !defined (_STLP_NO_WCHAR_T)
|
sl@0
|
143 |
wstring do_get(catalog __c, int __set, int __msgid,
|
sl@0
|
144 |
const wstring& __dfault) const;
|
sl@0
|
145 |
#endif
|
sl@0
|
146 |
void do_close(catalog __c) const;
|
sl@0
|
147 |
|
sl@0
|
148 |
~_Messages_impl();
|
sl@0
|
149 |
|
sl@0
|
150 |
private:
|
sl@0
|
151 |
_Locale_messages* _M_message_obj;
|
sl@0
|
152 |
_Catalog_locale_map* _M_map;
|
sl@0
|
153 |
mutable _Catalog_nl_catd_map _M_cat;
|
sl@0
|
154 |
|
sl@0
|
155 |
//private definition to avoid warning (with ICL)
|
sl@0
|
156 |
_Messages_impl(const _Messages_impl&);
|
sl@0
|
157 |
_Messages_impl& operator=(const _Messages_impl&);
|
sl@0
|
158 |
};
|
sl@0
|
159 |
|
sl@0
|
160 |
_STLP_MOVE_TO_STD_NAMESPACE
|
sl@0
|
161 |
|
sl@0
|
162 |
_STLP_END_NAMESPACE
|
sl@0
|
163 |
|
sl@0
|
164 |
#endif
|
sl@0
|
165 |
|
sl@0
|
166 |
// Local Variables:
|
sl@0
|
167 |
// mode:C++
|
sl@0
|
168 |
// End:
|