ReactOS 0.4.15-dev-7924-g5949c20
locale_catalog.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 <hash_map>
21#include <string>
22
23#include <locale>
24#include <istream>
25
26#include "c_locale.h"
27#include "locale_impl.h"
28#include "acquire_release.h"
29
32
33// Those wrappers are needed to use locale functions in __acquire_category,
34// all functions have to present the same prototype.
35
36static void* _Loc_ctype_create(const char * s, _Locale_name_hint* hint, int *__err_code)
37{ return _Locale_ctype_create(s, hint, __err_code); }
38static void* _Loc_codecvt_create(const char * s, _Locale_name_hint* hint, int *__err_code)
39{ return _Locale_codecvt_create(s, hint, __err_code); }
40static void* _Loc_numeric_create(const char * s, _Locale_name_hint* hint, int *__err_code)
41{ return _Locale_numeric_create(s, hint, __err_code); }
42static void* _Loc_time_create(const char * s, _Locale_name_hint* hint, int *__err_code)
43{ return _Locale_time_create(s, hint, __err_code); }
44static void* _Loc_collate_create(const char * s, _Locale_name_hint* hint, int *__err_code)
45{ return _Locale_collate_create(s, hint, __err_code); }
46static void* _Loc_monetary_create(const char * s, _Locale_name_hint* hint, int *__err_code)
47{ return _Locale_monetary_create(s, hint, __err_code); }
48static void* _Loc_messages_create(const char * s, _Locale_name_hint* hint, int *__err_code)
49{ return _Locale_messages_create(s, hint, __err_code); }
50
51static char const* _Loc_ctype_name(void* l, char* s)
52{ return _Locale_ctype_name((_Locale_ctype*)l, s); }
53static char const* _Loc_codecvt_name(void* l, char* s)
55static char const* _Loc_numeric_name(void* l, char* s)
57static char const* _Loc_time_name(void* l, char* s)
58{ return _Locale_time_name((_Locale_time*)l, s); }
59static char const* _Loc_collate_name(void* l, char* s)
61static char const* _Loc_monetary_name(void* l, char* s)
63static char const* _Loc_messages_name(void* l, char* s)
64{ return _Locale_messages_name((_Locale_messages*)l, s); }
65
66static const char* _Loc_ctype_default(char* p)
67{ return _Locale_ctype_default(p); }
68static const char* _Loc_numeric_default(char * p)
69{ return _Locale_numeric_default(p); }
70static const char* _Loc_time_default(char* p)
71{ return _Locale_time_default(p); }
72static const char* _Loc_collate_default(char* p)
73{ return _Locale_collate_default(p); }
74static const char* _Loc_monetary_default(char* p)
75{ return _Locale_monetary_default(p); }
76static const char* _Loc_messages_default(char* p)
77{ return _Locale_messages_default(p); }
78
85static void _Loc_messages_destroy(void* p) {_Locale_messages_destroy((_Locale_messages*)p);}
86
87typedef void* (*loc_create_func_t)(const char *, _Locale_name_hint*, int *__err_code);
88typedef char const* (*loc_name_func_t)(void* l, char* s);
89typedef void (*loc_destroy_func_t)(void* l);
90typedef const char* (*loc_default_name_func_t)(char* s);
91typedef char const* (*loc_extract_name_func_t)(const char*, char*, _Locale_name_hint*, int *__err_code);
92
93//----------------------------------------------------------------------
94// Acquire and release low-level category objects. The whole point of
95// this is so that we don't allocate (say) four different _Locale_ctype
96// objects for a single locale.
97
98// Global hash tables for category objects.
100
101// Look up a category by name
103 static Category_Map *_S_ctype_hash = 0;
104 return &_S_ctype_hash;
105}
107 static Category_Map *_S_codecvt_hash = 0;
108 return &_S_codecvt_hash;
109}
111 static Category_Map *_S_numeric_hash = 0;
112 return &_S_numeric_hash;
113}
115 static Category_Map *_S_time_hash = 0;
116 return &_S_time_hash;
117}
119 static Category_Map *_S_collate_hash = 0;
120 return &_S_collate_hash;
121}
123 static Category_Map *_S_monetary_hash = 0;
124 return &_S_monetary_hash;
125}
127 static Category_Map *_S_messages_hash;
128 return &_S_messages_hash;
129}
130
131// We have a single lock for all of the hash tables. We may wish to
132// replace it with six different locks.
133/* REFERENCED */
136 return lock;
137}
138
139static void*
141 loc_extract_name_func_t extract_name,
142 loc_create_func_t create_obj, loc_default_name_func_t default_name,
143 Category_Map ** M, int *__err_code) {
144#if !defined (__BORLANDC__) || (__BORLANDC__ >= 0x564)
145 typedef Category_Map::iterator Category_iterator;
147#else
148# if !defined(_STLP_DEBUG)
149 pair<_Ht_iterator<_Slist_iterator<pair<const string,pair<void *,unsigned int> >,_Nonconst_traits<pair<const string,pair<void *,unsigned int> > > >,_NonLocalHashMapTraitsT<pair<const string,pair<void *,unsigned int> > > >, bool> result;
150# else
151 pair<_DBG_iter<_NonDbg_hashtable<pair<const string,pair<void *,unsigned int> >,string,hash<string>,_HashMapTraitsT<pair<const string,pair<void *,unsigned int> > >,_Select1st<pair<const string,pair<void *,unsigned int> > >,_DbgEqual<string,equal_to<string> >,allocator<pair<const string,pair<void *,unsigned int> > > >,_DbgTraits<_NonLocalHashMapTraitsT<pair<const string,pair<void *,unsigned int> > > > >, bool> result;
152# endif
153#endif
154
155 *__err_code = _STLP_LOC_UNDEFINED;
156
157 // Find what name to look for. Be careful if user requests the default.
158 if (name[0] == 0) {
159 name = default_name(buf);
160 if (name == 0 || name[0] == 0)
161 name = "C";
162 }
163 else {
164 const char* cname = extract_name(name, buf, hint, __err_code);
165 if (cname == 0) {
166 return 0;
167 }
168 name = cname;
169 }
170
171 Category_Map::value_type __e(name, pair<void*,size_t>((void*)0,size_t(0)));
172
174
175 if (!*M)
176 *M = new Category_Map();
177
178 // Look for an existing entry with that name.
179 result = (*M)->insert_noresize(__e);
180
181 if (result.second) {
182 // There was no entry in the map already. Create the category.
183 (*result.first).second.first = create_obj(name, hint, __err_code);
184 if (!(*result.first).second.first) {
185 (*M)->erase(result.first);
186#if defined (_STLP_LEAKS_PEDANTIC)
187 if ((*M)->empty()) {
188 delete *M;
189 *M = 0;
190 }
191#endif
192 return 0;
193 }
194 }
195
196 // Increment the reference count.
197 ++((*result.first).second.second);
198
199 return (*result.first).second.first;
200}
201
202static void
204 loc_destroy_func_t destroy_fun,
206 Category_Map** M) {
207 Category_Map *pM = *M;
208
209 if (cat && pM) {
210 // Find the name of the category object.
212 char const* name = get_name(cat, buf);
213
214 if (name != 0) {
217 if (it != pM->end()) {
218 // Decrement the ref count. If it goes to zero, delete this category
219 // from the map.
220 if (--((*it).second.second) == 0) {
221 void* cat1 = (*it).second.first;
222 destroy_fun(cat1);
223 pM->erase(it);
224#if defined (_STLP_LEAKS_PEDANTIC)
225 if (pM->empty()) {
226 delete pM;
227 *M = 0;
228 }
229#endif
230 }
231 }
232 }
233 }
234}
235
236_Locale_ctype* _STLP_CALL __acquire_ctype(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
239 ctype_hash(), __err_code));
240}
244 codecvt_hash(), __err_code));
245}
249 numeric_hash(), __err_code));
250}
251_Locale_time* _STLP_CALL __acquire_time(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
254 time_hash(), __err_code));
255}
259 collate_hash(), __err_code));
260}
264 monetary_hash(), __err_code));
265}
266_Locale_messages* _STLP_CALL __acquire_messages(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
267 return __REINTERPRET_CAST(_Locale_messages*, __acquire_category(name, buf, hint,
269 messages_hash(), __err_code));
270}
271
284void _STLP_CALL __release_messages(_Locale_messages* cat)
286
#define _STLP_CALL
Definition: _bc.h:131
#define _STLP_MUTEX_INITIALIZER
Definition: _threads.h:241
int get_name(unsigned char **pos, uint32_t *remaining, const char **out_name)
Definition: util.c:55
r l[0]
Definition: byte_order.h:168
_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::iterator iterator
Definition: _hash_map.h:75
bool empty() const
Definition: _hash_map.h:168
#define M(row, col)
#define __REINTERPRET_CAST(__x, __y)
Definition: features.h:586
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define _STLP_STATIC_MUTEX
Definition: features.h:267
#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 s
Definition: gl.h:2039
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLuint64EXT * result
Definition: glext.h:11304
struct _Locale_collate * _Locale_collate_create(const char *, struct _Locale_name_hint *, int *)
char const * _Locale_codecvt_name(const struct _Locale_codecvt *, char *__buf)
void _Locale_monetary_destroy(struct _Locale_monetary *)
void _Locale_codecvt_destroy(struct _Locale_codecvt *)
struct _Locale_ctype * _Locale_ctype_create(const char *, struct _Locale_name_hint *, int *)
const char * _Locale_messages_default(char *__buf)
const char * _Locale_ctype_default(char *__buf)
struct _Locale_monetary * _Locale_monetary_create(const char *, struct _Locale_name_hint *, int *)
struct _Locale_codecvt * _Locale_codecvt_create(const char *, struct _Locale_name_hint *, int *)
char const * _Locale_monetary_name(const struct _Locale_monetary *, char *__buf)
char const * _Locale_time_name(const struct _Locale_time *, char *__buf)
void _Locale_time_destroy(struct _Locale_time *)
void _Locale_ctype_destroy(struct _Locale_ctype *)
#define _STLP_LOC_UNDEFINED
Definition: c_locale.h:99
char const * _Locale_collate_name(const struct _Locale_collate *, char *__buf)
char const * _Locale_messages_name(const struct _Locale_messages *, char *__buf)
#define _Locale_MAX_SIMPLE_NAME
Definition: c_locale.h:54
void _Locale_numeric_destroy(struct _Locale_numeric *)
char const * _Locale_numeric_name(const struct _Locale_numeric *, char *__buf)
const char * _Locale_collate_default(char *__buf)
char const * _Locale_extract_numeric_name(const char *cname, char *__buf, struct _Locale_name_hint *__hint, int *__err_code)
char const * _Locale_extract_monetary_name(const char *cname, char *__buf, struct _Locale_name_hint *__hint, int *__err_code)
char const * _Locale_extract_time_name(const char *cname, char *__buf, struct _Locale_name_hint *__hint, int *__err_code)
const char * _Locale_numeric_default(char *__buf)
char const * _Locale_extract_collate_name(const char *cname, char *__buf, struct _Locale_name_hint *__hint, int *__err_code)
void _Locale_collate_destroy(struct _Locale_collate *)
struct _Locale_time * _Locale_time_create(const char *, struct _Locale_name_hint *, int *)
struct _Locale_messages * _Locale_messages_create(const char *, struct _Locale_name_hint *, int *)
void _Locale_messages_destroy(struct _Locale_messages *)
const char * _Locale_monetary_default(char *__buf)
char const * _Locale_extract_ctype_name(const char *cname, char *__buf, struct _Locale_name_hint *__hint, int *__err_code)
char const * _Locale_ctype_name(const struct _Locale_ctype *, char *__buf)
const char * _Locale_time_default(char *__buf)
char const * _Locale_extract_messages_name(const char *cname, char *__buf, struct _Locale_name_hint *__hint, int *__err_code)
struct _Locale_numeric * _Locale_numeric_create(const char *, struct _Locale_name_hint *, int *)
static void __release_category(void *cat, loc_destroy_func_t destroy_fun, loc_name_func_t get_name, Category_Map **M)
static void _Loc_numeric_destroy(void *p)
const char *(* loc_default_name_func_t)(char *s)
void _STLP_CALL __release_time(_Locale_time *cat)
static Category_Map ** monetary_hash()
static void * _Loc_time_create(const char *s, _Locale_name_hint *hint, int *__err_code)
void _STLP_CALL __release_codecvt(_Locale_codecvt *cat)
static void * _Loc_collate_create(const char *s, _Locale_name_hint *hint, int *__err_code)
_Locale_ctype *_STLP_CALL __acquire_ctype(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
static char const * _Loc_collate_name(void *l, char *s)
_Locale_monetary *_STLP_CALL __acquire_monetary(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
static char const * _Loc_numeric_name(void *l, char *s)
static void _Loc_messages_destroy(void *p)
static char const * _Loc_monetary_name(void *l, char *s)
static Category_Map ** time_hash()
static void _Loc_monetary_destroy(void *p)
static const char * _Loc_time_default(char *p)
static void * __acquire_category(const char *&name, char *buf, _Locale_name_hint *hint, loc_extract_name_func_t extract_name, loc_create_func_t create_obj, loc_default_name_func_t default_name, Category_Map **M, int *__err_code)
static char const * _Loc_messages_name(void *l, char *s)
_Locale_codecvt *_STLP_CALL __acquire_codecvt(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
_Locale_collate *_STLP_CALL __acquire_collate(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
static Category_Map ** collate_hash()
void _STLP_CALL __release_ctype(_Locale_ctype *cat)
_Locale_numeric *_STLP_CALL __acquire_numeric(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
static Category_Map ** messages_hash()
static void _Loc_collate_destroy(void *p)
static void _Loc_time_destroy(void *p)
_STLP_BEGIN_NAMESPACE static _STLP_MOVE_TO_PRIV_NAMESPACE void * _Loc_ctype_create(const char *s, _Locale_name_hint *hint, int *__err_code)
static const char * _Loc_collate_default(char *p)
static Category_Map ** numeric_hash()
static void _Loc_codecvt_destroy(void *p)
char const *(* loc_extract_name_func_t)(const char *, char *, _Locale_name_hint *, int *__err_code)
void(* loc_destroy_func_t)(void *l)
void _STLP_CALL __release_numeric(_Locale_numeric *cat)
static void * _Loc_messages_create(const char *s, _Locale_name_hint *hint, int *__err_code)
static const char * _Loc_ctype_default(char *p)
void *(* loc_create_func_t)(const char *, _Locale_name_hint *, int *__err_code)
static char const * _Loc_ctype_name(void *l, char *s)
static void * _Loc_monetary_create(const char *s, _Locale_name_hint *hint, int *__err_code)
static const char * _Loc_monetary_default(char *p)
static Category_Map ** codecvt_hash()
static void * _Loc_numeric_create(const char *s, _Locale_name_hint *hint, int *__err_code)
static _STLP_STATIC_MUTEX & category_hash_mutex()
static void * _Loc_codecvt_create(const char *s, _Locale_name_hint *hint, int *__err_code)
static Category_Map ** ctype_hash()
void _STLP_CALL __release_messages(_Locale_messages *cat)
static void _Loc_ctype_destroy(void *p)
hash_map< string, pair< void *, size_t >, hash< string >, equal_to< string > > Category_Map
void _STLP_CALL __release_collate(_Locale_collate *cat)
_Locale_time *_STLP_CALL __acquire_time(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
void _STLP_CALL __release_monetary(_Locale_monetary *cat)
static const char * _Loc_numeric_default(char *p)
char const *(* loc_name_func_t)(void *l, char *s)
static const char * _Loc_messages_default(char *p)
static char const * _Loc_codecvt_name(void *l, char *s)
static char const * _Loc_time_name(void *l, char *s)
_Locale_messages *_STLP_CALL __acquire_messages(const char *&name, char *buf, _Locale_name_hint *hint, int *__err_code)
char string[160]
Definition: util.h:11
Definition: _hash_fun.h:40
Definition: name.c:39
Definition: _pair.h:47
rwlock_t lock
Definition: tcpcore.h:0
DWORD hint
Definition: vfdcmd.c:88