ReactOS 0.4.15-dev-7924-g5949c20
messages.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 1999
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Copyright (c) 1999
6 * Boris Fomitchev
7 *
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
10 *
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
16 *
17 */
18#include "stlport_prefix.h"
19
20#include <typeinfo>
21
22#include "message_facets.h"
23#include "acquire_release.h"
24
26
28
30 _STLP_TRY {
31#if !defined (_STLP_NO_TYPEINFO) && !defined (_STLP_NO_RTTI)
32 // Don't bother to do anything unless we're using a non-default ctype facet
33# ifdef _STLP_NO_WCHAR_T
34 typedef char _Char;
35# else
36 typedef wchar_t _Char;
37# endif
38
39 typedef ctype<_Char> wctype;
40 wctype const& wct = use_facet<wctype>(L);
41 if (typeid(wct) != typeid(wctype)) {
42#endif
43 if (!M)
44 M = new map_type;
45
47#if !defined (_STLP_NO_TYPEINFO) && !defined (_STLP_NO_RTTI)
48 }
49#endif
50 }
52}
53
55 if (M)
56 M->erase(key);
57}
58
60 if (M) {
62 return i != M->end() ? (*i).second : locale::classic();
63 }
64 else
65 return locale::classic();
66}
67
68
69#if defined (_STLP_USE_NL_CATD_MAPPING)
70_STLP_VOLATILE __stl_atomic_t _Catalog_nl_catd_map::_count = 0;
71
72messages_base::catalog _Catalog_nl_catd_map::insert(nl_catd_type cat) {
73 messages_base::catalog &res = Mr[cat];
74 if ( res == 0 ) {
75#if defined (_STLP_ATOMIC_INCREMENT)
77#else
79 {
80 _STLP_auto_lock sentry(_Count_lock);
81 res = __STATIC_CAST(int, ++_count);
82 }
83#endif
84 M[res] = cat;
85 }
86 return res;
87}
88
89void _Catalog_nl_catd_map::erase(messages_base::catalog cat) {
90 map_type::iterator mit(M.find(cat));
91 if (mit != M.end()) {
92 Mr.erase((*mit).second);
93 M.erase(mit);
94 }
95}
96#endif
97
98//----------------------------------------------------------------------
99//
100_Messages::_Messages(bool is_wide, const char *name) :
101 _M_message_obj(0), _M_map(0) {
102 if (!name)
104
105 int __err_code;
108 if (!_M_message_obj)
109 locale::_M_throw_on_creation_failure(__err_code, name, "messages");
110
111 if (is_wide)
113}
114
115_Messages::_Messages(bool is_wide, _Locale_messages* msg) :
116 _M_message_obj(msg), _M_map(is_wide ? new _Catalog_locale_map() : 0)
117{}
118
121 delete _M_map;
122}
123
126 : (nl_catd_type)(-1);
127
128 if ( result != (nl_catd_type)(-1) ) {
129 if ( _M_map != 0 ) {
131 }
132 return _STLP_MUTABLE(_Messages_impl, _M_cat).insert( result );
133 }
134
135 return -1;
136}
137
139 int set, int p_id, const string& dfault) const {
140 return _M_message_obj != 0 && cat >= 0
142 set, p_id, dfault.c_str()))
143 : dfault;
144}
145
146#if !defined (_STLP_NO_WCHAR_T)
147
148wstring
150 int set, int p_id, const wstring& dfault) const {
151 typedef ctype<wchar_t> wctype;
152 const wctype& ct = use_facet<wctype>(_M_map->lookup(_STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]));
153
154 const char* str = _Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat], set, p_id, "");
155
156 // Verify that the lookup failed; an empty string might represent success.
157 if (!str)
158 return dfault;
159 else if (str[0] == '\0') {
160 const char* str2 = _Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat], set, p_id, "*");
161 if (!str2 || ((str2[0] == '*') && (str2[1] == '\0')))
162 return dfault;
163 }
164
165 // str is correct. Now we must widen it to get a wstring.
166 size_t n = strlen(str);
167
168 // NOT PORTABLE. What we're doing relies on internal details of the
169 // string implementation. (Contiguity of string elements.)
170 wstring result(n, wchar_t(0));
171 ct.widen(str, str + n, &*result.begin());
172 return result;
173}
174
175#endif
176
177void _Messages::do_close(catalog thecat) const {
178 if (_M_message_obj)
179 _Locale_catclose(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]);
180 if (_M_map) _M_map->erase(_STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]);
181 _STLP_MUTABLE(_Messages_impl, _M_cat).erase( thecat );
182}
183
185
186//----------------------------------------------------------------------
187// messages<char>
189 : locale::facet(refs) {}
190
192 : messages<char>(refs), _M_impl(new _STLP_PRIV _Messages(false, name)) {}
193
195 : messages<char>(0), _M_impl(new _STLP_PRIV _Messages(false, msg)) {}
196
198{ delete _M_impl; }
199
202{ return _M_impl->do_open(filename, l); }
203
204string
206 const string& dfault) const
207{ return _M_impl->do_get(cat, set, p_id, dfault); }
208
210{ _M_impl->do_close(cat); }
211
212#if !defined (_STLP_NO_WCHAR_T)
213
214//----------------------------------------------------------------------
215// messages<wchar_t>
216
218 : locale::facet(refs) {}
219
221 : messages<wchar_t>(refs), _M_impl(new _STLP_PRIV _Messages(true, name)) {}
222
224 : messages<wchar_t>(0), _M_impl(new _STLP_PRIV _Messages(true, msg)) {}
225
227{ delete _M_impl; }
228
231{ return _M_impl->do_open(filename, L); }
232
233wstring
235 int set, int p_id, const wstring& dfault) const
236{ return _M_impl->do_get(thecat, set, p_id, dfault); }
237
239{ _M_impl->do_close(cat); }
240
241#endif
242
244
245// Local Variables:
246// mode:C++
247// End:
#define _STLP_PRIV
Definition: _dm.h:70
#define _STLP_ATOMIC_INCREMENT(__x)
Definition: _sparc_atomic.h:57
size_t __stl_atomic_t
Definition: _threads.h:232
#define _STLP_MUTEX_INITIALIZER
Definition: _threads.h:241
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void _STLP_CALL __release_messages(_Locale_messages *cat)
_Locale_messages *_STLP_CALL __acquire_messages(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
#define msg(x)
Definition: auth_time.c:54
r l[0]
Definition: byte_order.h:168
messages_base::catalog catalog
_Catalog_locale_map * _M_map
void do_close(catalog __c) const
Definition: messages.cpp:177
_Locale_messages * _M_message_obj
catalog do_open(const string &__fn, const locale &__loc) const
Definition: messages.cpp:124
_Messages(bool, const char *name)
Definition: messages.cpp:100
_Catalog_nl_catd_map _M_cat
string do_get(catalog __c, int __set, int __msgid, const string &__dfault) const
Definition: messages.cpp:138
const _CharT * c_str() const
Definition: _string.h:949
Definition: _ctype.h:58
_STLP_TEMPLATE_FOR_CONT_EXT iterator find(const _KT &__key)
Definition: _hash_map.h:195
iterator end()
Definition: _hash_map.h:174
_STLP_TEMPLATE_FOR_CONT_EXT size_type erase(const _KT &__key)
Definition: _hash_map.h:218
_Ht::const_iterator const_iterator
Definition: _hash_map.h:76
pair< iterator, bool > insert(const value_type &__obj)
Definition: _hash_map.h:179
Definition: _locale.h:75
static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_null_name()
Definition: locale.cpp:57
static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_creation_failure(int __err_code, const char *name, const char *facet)
Definition: locale.cpp:68
static const locale &_STLP_CALL classic()
Definition: locale.cpp:404
messages_base::catalog catalog
messages_base::catalog catalog
Definition: _set.h:50
unsigned short wchar_t
Definition: crtdefs.h:345
#define M(row, col)
unsigned char
Definition: typeof.h:29
#define _STLP_MUTABLE(type, x)
Definition: features.h:634
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define _STLP_VOLATILE
Definition: features.h:277
#define _STLP_STATIC_MUTEX
Definition: features.h:267
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
#define _STLP_TRY
Definition: features.h:817
#define _STLP_CATCH_ALL
Definition: features.h:818
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
GLdouble n
Definition: glext.h:7729
GLuint res
Definition: glext.h:9613
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
wctype_t __cdecl wctype(const char *)
const char * filename
Definition: ioapi.h:137
#define _Locale_MAX_SIMPLE_NAME
Definition: c_locale.h:54
void _Locale_catclose(struct _Locale_messages *, nl_catd_type)
nl_catd_type _Locale_catopen(struct _Locale_messages *, const char *)
const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type, int, int, const char *)
int nl_catd_type
Definition: c_locale.h:47
char string[160]
Definition: util.h:11
#define L(x)
Definition: ntvdm.h:50
const WCHAR * str
#define true
Definition: stdbool.h:36
#define false
Definition: stdbool.h:37
void insert(nl_catd_type key, const locale &L)
Definition: messages.cpp:29
locale lookup(nl_catd_type key) const
Definition: messages.cpp:59
void erase(nl_catd_type key)
Definition: messages.cpp:54
hash_map< nl_catd_type, locale, hash< nl_catd_type >, equal_to< nl_catd_type >, allocator< pair< _STLP_CONST nl_catd_type, locale > > > map_type
Definition: copy.c:22
Definition: name.c:39
Definition: _pair.h:47
#define new(TYPE, numElems)
Definition: treelist.c:54