acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
context.h
1#pragma once
2
3
4#include "acme/prototype/collection/atom_map.h"
5//#include "acme/prototype/collection/pointer_array.h"
6#include "acme/prototype/text/international_locale_schema.h"
7
8
9namespace text
10{
11
12
13 class context;
14
15
16 class schema :
17 public map_particle < atom_map_base < string > >
18 {
19 public:
20
21
22 ::atom m_atomSchema;
23
24
25 schema() { InitHashTable(4 * 1024 -1); };
26
27
28 };
29
30 class CLASS_DECL_ACME locale :
31 public map_particle < atom_map_base < schema > >
32 {
33 public:
34
35
36 ::atom m_atomLocale;
37
38 inline const schema * get_schema(const ::atom & idSchema) const
39 {
40
41 return this->defer_get(idSchema);
42
43 }
44
45
46 locale() { InitHashTable(256 - 1); };
47
48
49 };
50
51
52 class CLASS_DECL_ACME table :
53 virtual public ::particle
54 {
55 public:
56
57
58 schema * m_pschemaEn;
59 schema * m_pschemaStd;
60 atom_map_base < locale > m_map;
61
62
63 table();
64 ~table() override;
65
66
67 inline const locale * get_locale(const ::atom & idLocale) const
68 {
69
70 return m_map.defer_get(idLocale);
71
72 }
73
74
75 virtual void initialize(::particle * pparticle) override;
76
77
78 inline auto& operator[](const ::atom& atom) { return m_map[atom]; }
79 inline auto& operator[](const ::atom& atom)const { return m_map[atom]; }
80
81 void set(const ::atom & atom, const ::atom & idLocale, const ::atom & idSchema, const ::scoped_string & scopedstr);
82 bool _get(::string & str, const ::text::context* pcontext, const ::atom& atom) const;
83 string get(const ::text::context * pcontext, const ::atom & atom, bool bIdAsDefaultValue = true) const;
84 string get(const ::text::context * pcontext,const ::atom & atom,const ::scoped_string & scopedstrLocale,const ::scoped_string & scopedstrSchema,bool bIdAsDefaultValue = true) const;
85 void get(string_array_base & stra, const ::text::context * pcontext, const ::atom & atom) const;
86 void _get(string_array_base & stra, const ::text::context * pcontext, const ::atom & atom) const ;
87
88 bool load(const ::scoped_string & scopedstrBaseDir);
89 bool load_uistr_file(const ::atom & idLocale, const ::atom & idSchema, ::file::file * pfile);
90
91 string body(const ::scoped_string & scopedstr);
92
93 bool matches(const ::text::context * pcontext, const ::atom & atom, const ::scoped_string & scopedstr) const;
94 bool begins(const ::text::context * pcontext, const ::scoped_string & scopedstr, const ::atom & atom) const;
95 bool begins_eat(const ::text::context * pcontext, string & str, const ::atom & atom) const;
96
97
98 };
99
100
101 class CLASS_DECL_ACME context :
102 virtual public ::particle
103 {
104 protected:
105
106
107 friend class table;
108
109 ::pointer<::text::international::locale_schema> m_plocaleschema;
110
111 ::pointer<table> m_ptable;
112
113 ::pointer<locale> m_plocale;
114
115 ::pointer<schema> m_pschema;
116 ::pointer<schema> m_pschemaLocale;
117 ::pointer<schema> m_pschemaSchemaEn;
118 ::pointer<schema> m_pschemaSchemaStd;
119
120
121
122 pointer_array < schema > m_schemaptra;
123
124
125 public:
126
127
128 context();
129 ~context() override;
130
131#ifdef _DEBUG
132
133 ::i64 increment_reference_count() override
134 {
135
136 return ::particle::increment_reference_count();
137
138 }
139
140
141 ::i64 decrement_reference_count() override
142 {
143
144 return ::particle::decrement_reference_count();
145
146 }
147
148#endif
149
150
151 inline void defer_ok(table * ptable)
152 {
153
154 if (ptable != m_ptable)
155 {
156
157 m_ptable = ptable;
158
159 prepare();
160
161 }
162
163 }
164
165
166 void set_table(table* ptable);
167
168 void prepare();
169
170
171 const string_array_base & locale_ex() const;
172
173 const string_array_base & schema_ex() const;
174
175
176 inline ::text::international::locale_schema * localeschema()
177 {
178
179 return m_plocaleschema;
180
181 }
182
183
184 inline const ::text::international::locale_schema & localeschema() const
185 {
186
187 return *m_plocaleschema;
188
189 }
190
191
192 inline bool matches(const ::atom & atom, const ::scoped_string & scopedstr) const
193 {
194
195 return m_ptable->matches(this, atom, scopedstr);
196
197 }
198
199
200 inline bool begins(const ::atom & atom, const ::scoped_string & scopedstr) const
201 {
202
203 return m_ptable->begins(this, scopedstr, atom);
204
205 }
206
207
208 inline bool begins_eat(string & str, const ::atom & atom) const
209 {
210
211 return m_ptable->begins_eat(this, str, atom);
212
213 }
214
215
216 inline void get(string_array_base & stra, const ::atom & atom) const
217 {
218
219 return m_ptable->get(stra, this, atom);
220
221
222 }
223
224
225 inline string get(const ::atom& atom) const
226 {
227
228 if (m_ptable == nullptr)
229 {
230
231 return atom.as_string();
232
233 }
234
235 return m_ptable->get(this, atom);
236
237 }
238
239 //virtual bool match(const regex * pregexp, string_array_base & stra, const ::scoped_string & scopedstr, atom pszExp, atom pszRoot);
240
241 //virtual bool match(string_array_base & stra, const ::scoped_string & scopedstr, ::atom pszExp, ::atom pszRoot) const;
242
243
244 };
245
246
247} // namespace acme
248
249
250
Definition atom.h:237
Definition file.h:33
Definition map.h:1084
Definition context.h:103
Definition context.h:32
Definition context.h:18