|
1 /* |
|
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. |
|
3 * Copyright (c) 1999 |
|
4 * Silicon Graphics Computer Systems, Inc. |
|
5 * |
|
6 * Copyright (c) 1999 |
|
7 * Boris Fomitchev |
|
8 * |
|
9 * This material is provided "as is", with absolutely no warranty expressed |
|
10 * or implied. Any use is at your own risk. |
|
11 * |
|
12 * Permission to use or copy this software for any purpose is hereby granted |
|
13 * without fee, provided the above notices are retained on all copies. |
|
14 * Permission to modify the code and to distribute modified code is granted, |
|
15 * provided the above notices are retained, and a notice that the code was |
|
16 * modified is included with the above copyright notice. |
|
17 * |
|
18 */ |
|
19 #ifndef MESSAGE_FACETS_H |
|
20 # define MESSAGE_FACETS_H |
|
21 |
|
22 #include <string> |
|
23 #include <stl/_messages_facets.h> |
|
24 #include <stl/_ctype.h> |
|
25 // #include <istream> |
|
26 #include <typeinfo> |
|
27 #include <hash_map> |
|
28 #include "c_locale.h" |
|
29 |
|
30 _STLP_BEGIN_NAMESPACE |
|
31 |
|
32 // Forward declaration of an opaque type. |
|
33 struct _Catalog_locale_map; |
|
34 |
|
35 _Locale_messages* __acquire_messages(const char* name); |
|
36 void __release_messages(_Locale_messages* cat); |
|
37 |
|
38 // Class _Catalog_locale_map. The reason for this is that, internally, |
|
39 // a message string is always a char*. We need a ctype facet to convert |
|
40 // a string to and from wchar_t, and the user is permitted to provide such |
|
41 // a facet when calling open(). |
|
42 |
|
43 struct _Catalog_locale_map |
|
44 { |
|
45 _Catalog_locale_map() : M(0) {} |
|
46 ~_Catalog_locale_map() { if (M) delete M; } |
|
47 |
|
48 void insert(int key, const locale& L); |
|
49 locale lookup(int key) const; |
|
50 void erase(int key); |
|
51 |
|
52 hash_map<int, locale, hash<int>, equal_to<int> >* M; |
|
53 |
|
54 private: // Invalidate copy constructor and assignment |
|
55 _Catalog_locale_map(const _Catalog_locale_map&); |
|
56 void operator=(const _Catalog_locale_map&); |
|
57 }; |
|
58 |
|
59 |
|
60 class _Messages { |
|
61 public: |
|
62 typedef messages_base::catalog catalog; |
|
63 |
|
64 _STLP_DECLSPEC _Messages(); |
|
65 |
|
66 virtual catalog do_open(const string& __fn, const locale& __loc) const; |
|
67 virtual string do_get(catalog __c, int __set, int __msgid, |
|
68 const string& __dfault) const; |
|
69 # ifndef _STLP_NO_WCHAR_T |
|
70 virtual wstring do_get(catalog __c, int __set, int __msgid, |
|
71 const wstring& __dfault) const; |
|
72 # endif |
|
73 virtual void do_close(catalog __c) const; |
|
74 virtual _STLP_DECLSPEC ~_Messages(); |
|
75 bool _M_delete; |
|
76 }; |
|
77 |
|
78 class _Messages_impl : public _Messages { |
|
79 public: |
|
80 |
|
81 _Messages_impl(bool); |
|
82 |
|
83 _Messages_impl(bool, _Locale_messages*); |
|
84 |
|
85 catalog do_open(const string& __fn, const locale& __loc) const; |
|
86 string do_get(catalog __c, int __set, int __msgid, |
|
87 const string& __dfault) const; |
|
88 # ifndef _STLP_NO_WCHAR_T |
|
89 wstring do_get(catalog __c, int __set, int __msgid, |
|
90 const wstring& __dfault) const; |
|
91 # endif |
|
92 void do_close(catalog __c) const; |
|
93 |
|
94 ~_Messages_impl(); |
|
95 |
|
96 private: |
|
97 _Locale_messages* _M_message_obj; |
|
98 _Catalog_locale_map* _M_map; |
|
99 }; |
|
100 |
|
101 _STLP_END_NAMESPACE |
|
102 |
|
103 #endif |