ReactOS  0.4.14-dev-368-gfa26425
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 
73  messages_base::catalog &res = Mr[cat];
74  if ( res == 0 ) {
75 #if defined (_STLP_ATOMIC_INCREMENT)
76  res = __STATIC_CAST(int, _STLP_ATOMIC_INCREMENT(&_count));
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 
89 void _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 
124 _Messages::catalog _Messages::do_open(const string& filename, const locale& L) const {
126  : (nl_catd_type)(-1);
127 
128  if ( result != (nl_catd_type)(-1) ) {
129  if ( _M_map != 0 ) {
130  _M_map->insert(result, L);
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
141  ? string(_Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[cat],
142  set, p_id, dfault.c_str()))
143  : dfault;
144 }
145 
146 #if !defined (_STLP_NO_WCHAR_T)
147 
148 wstring
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 
177 void _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 
201 messages_byname<char>::do_open(const string& filename, const locale& l) const
202 { return _M_impl->do_open(filename, l); }
203 
204 string
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 
233 wstring
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 true
Definition: stdbool.h:37
#define _STLP_STATIC_MUTEX
Definition: features.h:267
#define new(TYPE, numElems)
Definition: treelist.c:54
void do_close(catalog __c) const
Definition: messages.cpp:177
iterator end()
Definition: _hash_map.h:174
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
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
void insert(nl_catd_type key, const locale &L)
Definition: messages.cpp:29
#define M(row, col)
GLdouble n
Definition: glext.h:7729
int nl_catd_type
Definition: c_locale.h:39
static int insert
Definition: xmllint.c:144
const char * filename
Definition: ioapi.h:135
locale lookup(nl_catd_type key) const
Definition: messages.cpp:59
#define _STLP_VOLATILE
Definition: features.h:277
_STLP_TEMPLATE_FOR_CONT_EXT iterator find(const _KT &__key)
Definition: _hash_map.h:195
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
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
_Locale_messages *_STLP_CALL __acquire_messages(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
void _STLP_CALL __release_messages(_Locale_messages *cat)
Definition: _locale.h:75
static const locale &_STLP_CALL classic()
Definition: locale.cpp:404
const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type, int, int, const char *)
_Catalog_nl_catd_map _M_cat
static void do_close(SOCKET)
messages_base::catalog catalog
const WCHAR * str
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
unsigned char
Definition: typeof.h:29
#define _STLP_CATCH_ALL
Definition: features.h:818
unsigned short wchar_t
Definition: crtdefs.h:324
void erase(nl_catd_type key)
Definition: messages.cpp:54
#define _STLP_MUTABLE(type, x)
Definition: features.h:634
_STLP_TEMPLATE_FOR_CONT_EXT size_type erase(const _KT &__key)
Definition: _hash_map.h:218
r l[0]
Definition: byte_order.h:167
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
_Catalog_locale_map * _M_map
Definition: _ctype.h:58
static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_on_null_name()
Definition: locale.cpp:57
static const WCHAR L[]
Definition: oid.c:1250
catalog do_open(const string &__fn, const locale &__loc) const
Definition: messages.cpp:124
nl_catd_type _Locale_catopen(struct _Locale_messages *, const char *)
#define _STLP_PRIV
Definition: _dm.h:70
#define false
Definition: stdbool.h:38
#define _Locale_MAX_SIMPLE_NAME
Definition: c_locale.h:54
char string[160]
Definition: util.h:11
_Ht::const_iterator const_iterator
Definition: _hash_map.h:76
#define _STLP_MUTEX_INITIALIZER
Definition: _threads.h:241
wctype_t __cdecl wctype(const char *)
void _Locale_catclose(struct _Locale_messages *, nl_catd_type)
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_TRY
Definition: features.h:817
Definition: _pair.h:47
#define msg(x)
Definition: auth_time.c:54
Definition: name.c:36
GLuint res
Definition: glext.h:9613
string do_get(catalog __c, int __set, int __msgid, const string &__dfault) const
Definition: messages.cpp:138
pair< iterator, bool > insert(const value_type &__obj)
Definition: _hash_map.h:179
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
_Locale_messages * _M_message_obj
size_t __stl_atomic_t
Definition: _threads.h:232
Definition: _set.h:46
GLuint64EXT * result
Definition: glext.h:11304
static int do_open(IN OUT nfs41_open_state *state, IN uint32_t create, IN uint32_t createhow, IN nfs41_file_info *createattrs, IN bool_t try_recovery, OUT nfs41_file_info *info)
Definition: open.c:189
_Messages(bool, const char *name)
Definition: messages.cpp:100
Definition: path.c:42
#define _STLP_ATOMIC_INCREMENT(__x)
Definition: _sparc_atomic.h:57