acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
property_set.h
1#pragma once
2
3
4// Include payload.h
5// Don`t include this file directly
6
7
8#include "acme/prototype/prototype/property.h"
9#include "acme/prototype/collection/atom_array.h"
10#include "acme/prototype/string/_character_range.h"
11//#include "payload_reference.h"
12enum enum_network_header
13{
14 e_network_header_unknown,
15 e_network_header_request,
16 e_network_header_response,
17 e_network_header_raw
18};
19
20// ::property set key is case insensitive
21// PROPERTY_ARRAY Property set ordered
22class CLASS_DECL_ACME property_set_base :
23 public ::property_holder_array_base
24{
25public:
26
27
28 //__declare_iterator(name_iterator, &(*this->m_pelement)->id());
29 //__declare_iterator(value_iterator, &(*this->m_pelement)->m_var);
30
31 using property_holder_array_base::property_holder_array_base;
32 using property_holder_array_base::operator =;
33
34 property_set_base(::std::initializer_list < ::payload > list_base);
35 // property_set() {}
36 // property_set(const ::property_set & set);
37 // property_set(::property_set && set);
38 ~property_set_base();
39
40
41 ::collection::count erase_by_name(const ::atom & atom);
42 ::collection::count erase_by_name(string_array_base & straName);
43
44 virtual ::particle * source_channel();
45
46 //::payload operator()(const ::atom & atom, const ::payload & payloadDefault = ::error_not_found) const;
47
48 string _001Replace(const ::scoped_string & scopedstr) const;
49
50 inline string format(const ::scoped_string & scopedstr) const { return _001Replace(scopedstr); }
51
52
53 string as_string(const ::scoped_string& scopedstrSeparator1, const ::scoped_string& scopedstrSeparator2);
54
55 //::collection::index index_of(const ::atom & atom, ::collection::index iStart = 0) const;
56
57 //::property* find_by_text(const ::scoped_string & scopedstr, ::collection::index iStart = 0) const;
58
59 ::collection::index index_of(const ::atom& atom, ::collection::index iStart = 0) const;// { return atom.is_text() ? find_text_key((const ::scoped_string &)atom.m_str, iStart) : find_index(atom.m_i32)
60 ::collection::index index_of_name(const ::scoped_string &scopedstr, ::collection::index iStart = 0) const;
61 ::property * find(const ::atom & atom, ::collection::index iStart = 0) const;// { return atom.is_text() ? find_text_key((const ::scoped_string &)atom.m_str, iStart) : find_index(atom.m_i32)
62 ::property & property(const ::atom & atom); // { return atom.is_text() ? get_text_key((const ::scoped_string &)atom.m_str, iStart) : get_index(atom.m_i32); }
63 const ::property& property(const ::atom& atom) const
64 {
65
66 return ((::property_set_base*)this)->property(atom);
67
68 }
69
70
71 //::collection::index find(const ::atom_array_base& atoma) const;// { return atom.is_text() ? find_text_key((const ::scoped_string &)atom.m_str, iStart) : find_index(atom.m_i32); }
72 ::property * find(const ::atom_array_base & atoma) const;// { return atom.is_text() ? find_text_key((const ::scoped_string &)atom.m_str, iStart) : find_index(atom.m_i32); }
73 ::property & property(const ::atom_array_base & atoma); // { return atom.is_text() ? get_text_key((const ::scoped_string &)atom.m_str, iStart) : get_index(atom.m_i32); }
74 const ::property& property(const ::atom_array_base& atoma) const
75 {
76
77 return ((::property_set_base*)this)->property(atoma);
78
79 }
80
81
82 //::property * find_index(::iptr i) const;
83 //::property & get_index(::iptr i);
84
85
86 //::property * find_text_key(const scoped_string & scopedstr, ::collection::index iStart = 0) const;
87 //::property & get_text_key(const scoped_string & scopedstr, ::collection::index iStart = 0);
88
89
90 //inline ::property * find_property_index(::collection::index iIndex, ::collection::index iStart = 0) const { return find_index(iIndex); }
91 //inline ::property & get_property_index(::collection::index iIndex, ::collection::index iStart = 0) { return get_index(iIndex); }
92
93
94 //inline ::property * find_property_text_key(const scoped_string & scopedstr, ::collection::index iStart = 0) const { return find_text_key(scopedstr, iStart); }
95 //inline ::property & get_property_text_key(const scoped_string & scopedstr, ::collection::index iStart = 0) { return get_text_key(scopedstr, iStart); }
96
97
98 //inline ::property * payload_index(::iptr iIndex, ::collection::index iStart = 0) const { return find_property_index(iIndex); }
99 //inline ::property & payload_index(::iptr iIndex, ::collection::index iStart = 0) { return get_property_index(iIndex); }
100
101
102 //inline ::property * payload_text_key(const scoped_string & scopedstr, ::collection::index iStart = 0) const { return find_property_text_key(scopedstr, iStart); }
103 //inline ::property & payload_text_key(const scoped_string & scopedstr, ::collection::index iStart = 0) { return get_property_text_key(scopedstr, iStart); }
104
105 inline const ::property& operator[](const ::atom_array_base& atoma) const { return property(atoma); }
106 inline const ::property& operator[](const ::atom& atom) const { return property(atom); }
107
108 inline ::property & operator[](const ::atom_array_base & atoma) { return property(atoma); }
109 inline ::property & operator[](const ::atom & atom) { return property(atom); }
110
111 template < prototype_integral INTEGRAL >
112 inline const ::property & property_at(INTEGRAL i) const { return *this->element_at(i); }
113 template < prototype_integral INTEGRAL >
114 inline ::property & property_at(INTEGRAL i) { return *this->element_at(i); }
115
116
117
118 //template < prototype_character_range RANGE >
119 //inline ::property & operator[](const RANGE & range) { return property(range); }
120 //template < prototype_character_range RANGE >
121 //inline const ::property & operator[](const RANGE & range) const { return property(range); }
122
123 //template < has_get_string HAS_GET_STRING >
124 //inline ::property & operator[](const HAS_GET_STRING & has_get_string) { return payload((const ::scoped_string_base &)has_get_string.get_string()); }
125 //template < has_get_string HAS_GET_STRING >
126 //inline const ::property & operator[](const HAS_GET_STRING & has_get_string) const { return payload((const ::scoped_string_base &)has_get_string.get_string()); }
127
128 //template < has_as_string HAS_AS_STRING >
129 //inline ::property & operator[](const HAS_AS_STRING & has_as_string) { return payload((const ::scoped_string_base &)has_as_string.as_string()); }
130 //template < has_as_string HAS_AS_STRING >
131 //inline const ::property & operator[](const HAS_AS_STRING & has_as_string) const { return payload((const ::scoped_string_base &)has_as_string.as_string()); }
132
133 //inline ::property & operator[](const ::atom & atom) { return payload(atom); }
134 //inline const ::property & operator[](const ::atom & atom) const { return payload(atom); }
135
136 //inline ::property & operator[](const ::scoped_string & scopedstrName) { return payload(scopedstrName); }
137 //inline const ::property & operator[](const ::scoped_string & scopedstrName) const { return payload(scopedstrName); }
138
139 //inline ::property & operator[](const ::scoped_string & scopedstrName) { return payload(strName); }
140 //inline const ::property & operator[](const ::scoped_string & scopedstrName) const { return payload(strName); }
141
142 //inline ::property & operator[](::collection::index iIndex) { return payload(iIndex); }
143 //inline const ::property & operator[](::collection::index iIndex) const { return payload(iIndex); }
144
145 //inline ::property & operator[](const ::payload & payloadKey) { return payload(payloadKey); }
146 //inline const ::property & operator[](const ::payload & payloadKey) const { return payload(payloadKey); }
147
148//#ifdef OS64BIT
149//
150// inline ::property & operator[](::i32 iIndex) { return payload(iIndex); }
151// inline const ::property & operator[](::i32 iIndex) const { return payload(iIndex); }
152//
153//#endif
154
155 //::payload & topic(const ::atom & atom);
156
157 //::payload_reference reference(const atom& atom); { return topic(atom); }
158
159 ::payload_reference reference(const atom& atom);
160 ::payload_reference reference(const atom_array_base & atom);
161
162 //::payload & set(const ::atom & atom);
163
164 //::property & at(::collection::index iId);
165 //const ::property & at(::collection::index iId) const;
166
167 ::collection::index index_of_case_insensitive_payload(const ::payload & payload, ::collection::index iStart = 0) const;
168 ::collection::index index_of_case_insensitive_string(const ::scoped_string & scopedstr, ::collection::index iStart = 0) const;
169
170 ::collection::index index_of_payload(const ::payload & payload, ::collection::index iStart = 0) const;
171 ::collection::index index_of_string(const ::scoped_string & scopedstr, ::collection::index iStart = 0) const;
172
173 //::property * str_find(const ::property & property) const;
174
175 bool case_insensitive_contains_payload(const ::payload& payload, ::collection::index iStart = 0) const { return index_of_case_insensitive_payload(payload, iStart)>= 0; }
176 bool case_insensitive_contains_string(const ::scoped_string & scopedstr, ::collection::index iStart = 0) const { return index_of_case_insensitive_string(scopedstr, iStart) >= 0; }
177
178 bool contains_payload(const ::payload & payload, ::collection::index iStart = 0) const { return index_of_payload(payload, iStart) >= 0; }
179 bool contains_string(const ::scoped_string & scopedstr, ::collection::index iStart = 0) const { return index_of_string(scopedstr, iStart) >= 0; }
180
181 bool case_insensitive_contains_payload_count(const ::payload & payload, ::collection::count countMin = 1, ::collection::count countMax = -1) const;
182 bool case_insensitive_contains_string_count(const ::scoped_string & scopedstr, ::collection::count countMin = 1, ::collection::count countMax = -1) const;
183
184 bool contains_payload_count(const ::payload & payload, ::collection::count countMin = 1, ::collection::count countMax = -1) const;
185 bool contains_string_count(const ::scoped_string & scopedstr, ::collection::count countMin = 1, ::collection::count countMax = -1) const;
186
187 bool payload_contains(const ::property_set_base & set) const;
188 bool string_contains(const ::property_set_base & set) const;
189 bool contains_keys(const ::property_set_base & set) const;
190 bool contains(const ::property_set_base & set) const;
191
192 bool case_insensitive_erase_first_payload(const ::payload & payload, ::collection::index iStart = 0);
193 bool case_insensitive_erase_first_string(const ::scoped_string & scopedstr, ::collection::index iStart = 0);
194
195 bool erase_first_payload(const ::payload & payload, ::collection::index iStart = 0);
196 bool erase_first_string(const ::scoped_string & scopedstr, ::collection::index iStart = 0);
197
198 ::collection::count case_insensitive_erase_payload_count(const ::payload & payload, ::collection::count countMin = 0, ::collection::count countMax = -1);
199 ::collection::count case_insensitive_erase_string_count(const ::scoped_string & scopedstr, ::collection::count countMin = 0, ::collection::count countMax = -1);
200
201 ::collection::count erase_payload_count(const ::payload & payload, ::collection::count countMin = 0, ::collection::count countMax = -1);
202 ::collection::count erase_string_count(const ::scoped_string & scopedstr, ::collection::count countMin = 0, ::collection::count countMax = -1);
203
204 bool has_property(const ::atom & atom) const;
205
206 bool has_replace(const ::atom& atom, const ::payload & payload);
207
208 bool is_true(const ::atom & atom) const;
209
210 bool is_true_or_empty(const ::atom & atom) const;
211
212 bool is_false(const ::atom & atom) const { auto p = find(atom); return !p || p->is_false(); }
213
214 bool is_set_false(const ::atom & atom) const { auto p = find(atom); return p && p->is_set_false(); }
215
216 bool is_set_empty(::collection::count countMinimum = 1) const;
217
218 bool has_properties(::collection::count countMinimum = 1) const;
219
220
221 //inline auto names(::collection::index iStart = 0, ::collection::index iEnd = -1) const { return name_iterator(iStart, iEnd, this); }
222
223
224 inline ::property& set_at(const ::atom& atom, const ::payload& payload);
225
226 bool _get_string(string& strResult, const ::atom & atom) const;
227
228 ::payload get_payload(const ::atom & atom);
229
230 const ::payload & get(const ::atom & atom) const;
231
232 ::f32_array_base get(const ::atom & atom, const ::f32_array_base & f32a) const;
233 ::f64_array_base get(const ::atom& atom, const ::f64_array_base& f64a) const;
234 ::string get(const ::atom& atom, const ::scoped_string & scopedstr) const;
235 ::i32 get(const ::atom& atom, const ::i32 & i) const;
236 ::i64 get(const ::atom& atom, const ::i64 & ll) const;
237 ::f32 get(const ::atom& atom, const ::f32 & f) const;
238 ::f64 get(const ::atom& atom, const ::f64 & d) const;
239
240 bool get_bool(const ::atom & atom, bool bDefault = false) const;
241 ::i32 get_int(const ::atom & atom, ::i32 iDefault = 0) const;
242 ::u32 get_u32(const ::atom & atom, ::u32 uDefault = 0) const;
243 ::string get_string(const ::atom & atom, const ::scoped_string & scopedstrDefault = nullptr) const;
244 ::file::path get_file_path(const ::atom & atom, const ::file::path & pathDefault ={}) const;
245
246 //template < typename TYPE >
247 //inline void exchange(const ::atom & atom, TYPE & t)
248 //{
249
250 // if (is_storing())
251 // {
252
253 // operator[](atom) = t;
254
255 // }
256 // else
257 // {
258
259 // t = operator[](atom);
260
261 // }
262
263 //}
264
265 //template < typename TYPE >
266 //inline void exchange(const ::atom & atom, const TYPE & t)
267 //{
268
269 // if (is_storing())
270 // {
271
272 // operator[](atom) = t;
273
274 // }
275 // else
276 // {
277
278 // throw ::exception(error_bad_argument);
279
280 // }
281
282 //}
283
284 //inline void exchange( const ::atom & atom, bool & b)
285 //{
286
287 // if (is_storing())
288 // {
289
290 // if (b)
291 // {
292
293 // operator[](atom) = true;
294
295 // }
296 // else
297 // {
298
299 // erase_by_name(atom);
300
301 // }
302
303 // }
304 // else
305 // {
306
307 // b = is_true(atom);
308
309 // }
310
311 //}
312
313 ::collection::count unset(const ::atom & atom);
314
315 bool is_new(const ::atom & atom) const;
316
317 bool is_null(const ::atom & atom) const;
318
319 bool is_new_or_null(const ::atom & atom) const;
320
321
322 //using property_ptra::is_empty;
323
324 bool is_empty(const ::atom & atom) const;
325 bool is_empty() const { return ::property_holder_array_base::is_empty(); }
326 bool has_property() const { return this->has_element(); }
327 ::collection::count property_count() const { return this->get_count(); }
328
329
330 ::collection::index add_property(const ::atom & atom) { return this->add_item(new ::property(atom)); }
331 ::property * add_property(const ::atom_array_base & atoma);
332 ::collection::index add_property(const ::property & property) { return this->add_item(new ::property(property)); }
333
334
335 inline const ::property & property_at(::collection::index nIndex) const { return *this->element_at(nIndex); }
336 inline ::property & property_at(::collection::index nIndex) { return *this->element_at(nIndex); }
337
338 inline ::collection::index erase_property_at(::collection::index iIndex) { return this->erase_at(iIndex); }
339
340 inline ::collection::count erase_all_properties() { return this->erase_all(); }
341
342 //auto begin() { return propertyptra().begin(); }
343 //auto begin() const { return propertyptra().begin(); }
344 //auto end() { return propertyptra().end(); }
345 //auto end() const { return propertyptra().end(); }
346
347 //auto is_end(property_arraytra::const_iterator iterator) const { return propertyptra().is_end(iterator); }
348
349 template < typename TYPE >
350 bool _get(const ::atom & atom, TYPE & t)
351 {
352
353 auto pproperty = find(atom);
354
355 if (!pproperty)
356 {
357
358 return false;
359
360 }
361
362 pproperty->_as(t);
363
364 return true;
365
366 }
367
368
369 void _008ParseCommandLine(const ::scoped_string & scopedstrCmdLine, ::payload & payloadFile);
370 void _008ParseCommandFork(const ::scoped_string & scopedstrCmdLine, ::payload & payloadFile, string & strApp);
371 void _008Parse(bool bApp, const ::scoped_string & scopedstrCmdLine, ::payload & payloadFile, string & strApp);
372 void _008AddArgumentPairs(::string_array_base & straArguments);
373 void _008AddArgumentOrFile(::payload & payloadFile, const ::scoped_string & scopedstrArgument);
374 void _008AddArgument(const ::scoped_string & scopedstrArgument);
375 void _008Add(const ::scoped_string & scopedstrKey, const ::scoped_string & scopedstrValue);
376
377 void _008ParseCommandArguments(string_array_base & straArguments, ::payload & payloadFile, string & strApp);
378 void _008ParseArguments(bool bApp, string_array_base & straArguments, ::payload & payloadFile, string & strApp);
379
380
381 void clear();
382
383 //virtual string eval(const ::scoped_string & scopedstr);
384
385 //virtual string gen_eval(const ::scoped_string & scopedstr);
386
387 //virtual string gen_string(const ::scoped_string & scopedstr);
388
389
390 string evaluate(const ::scoped_string & scopedstr) const;
391
392 bool get_evaluation(::string & str, const ::scoped_string & scopedstrExpression) const;
393
394
395 void parse_ini(const ::scoped_string & scopedstrIni);
396 ::string get_ini() const;
397 ::string_array_base get_ini_lines() const;
398 void parse_standard_configuration(const ::scoped_string & scopedstrStandardConfiguration);
399 //void parse_ini_file(const ::file::path& path);
400 //void parse_ini_folder(const ::file::path& path);
401
402 void parse_network_payload(const ::scoped_string & scopedstrNetworkPayload);
403 void parse_network_payload(::ansi_range & range);
404 void parse_network_arguments(const ::scoped_string & scopedstrUrl);
405 void _parse_network_arguments(const ::scoped_string & scopedstrUrlQuery);
406 enum_network_header parse_network_headers(const ::scoped_string & scopedstrHeaders);
407 enum_network_header parse_network_headers(const string_array_base & straHeaders, ::collection::index i = 0);
408 void _parse_network_headers(const string_array_base & straHeaders, ::collection::index i = 0);
409
410
411 string & get_network_arguments(string & str) const;
412 string & get_network_payload(string & str, bool bNewLine = true) const;
413 string get_network_arguments() const { string str; return get_network_arguments(str); }
414 string get_network_payload() const { string str; return get_network_payload(str); }
415 string get_command_line(const string_array_base & straKeys) const;
416 string get_command_line() const;
417
418
419
420 //virtual stream & write(::stream & stream) const override;
421 //virtual stream & read(::stream & stream) override;
422
423
424 virtual string implode(const ::scoped_string & scopedstrGlue) const;
425 //::collection::count get_count() const;
426
427
428 ::property_set_base & operator = (const ::payload & payload);
429 //::property_set_base & operator = (const ::property_set_base & set);
430// ::property_set_base & operator = (const pair_set_interface & set);
431// ::property_set_base & operator = (const str_str_interface & set);
432
433 ::property_set_base & operator += (const ::property_set_base & set);
434 ::property_set_base & operator |= (const ::property_set_base & set);
435
436
437 ::property_set_base & append(const ::property_set_base & set);
438 ::property_set_base & merge(const ::property_set_base & set);
439
440 ::property_set_base & merge(const ::property & property);
441
442
443
444
445 template < prototype_subparticle T >
446 T * cast(const ::atom & atom, T * pDefault = nullptr)
447 {
448
449 if (!has_property(atom))
450 {
451
452 return pDefault;
453
454 }
455
456 return operator[](atom).cast < T > (pDefault);
457
458 }
459
460
461 template < prototype_subparticle T >
462 T * cast(const ::atom & atom, T * pDefault = nullptr) const
463 {
464
465 return ((::property_set_base *) this)->cast < T >(atom, pDefault);
466
467 }
468
469
470 void parse_environment_variable(const string_array_base & straEnvironment);
471
472 ::string id_payload_listing() const;
473
474
475};
476
477
478//CLASS_DECL_ACME void property_set_skip_network_payload(const_char_pointer &pszJson);
479CLASS_DECL_ACME void property_set_skip_network_payload(::ansi_range & range);
480
481
482//inline ::pointer<::handle::ini>operator ""_pini(const ::scoped_string & scopedstr, size_t s);
483
484
485//inline ::handle::ini operator ""_ini(const ::scoped_string & scopedstr, size_t s);
486
487
488//inline ::pointer<::property_set_base>localconfigini();
489
490
491inline bool ::property_set_base::_get_string(string & strResult, const ::atom & atom) const
492{
493
494 auto pproperty = find(atom);
495
496 if (::is_null(pproperty))
497 {
498
499 return false;
500
501 }
502
503 strResult = pproperty->as_string();
504
505 return true;
506
507}
508
509
510class CLASS_DECL_ACME property_set :
511 public ::array_particle < ::property_set_base >
512{
513public:
514
515
516 using BASE_CLASS = ::array_particle < ::property_set_base >;
517
518
519 using BASE_CLASS::BASE_CLASS;
520 using BASE_CLASS::operator =;
521
522
523 using ::property_set_base::cast;
524
525 using ::property_set_base::as_string;
526
527
528};
529
530
531
532CLASS_DECL_ACME ::pointer < ::property_set > create_network_arguments_property_set(const ::scoped_string& scopedstrNetworkArguments);
533
534
535
Definition atom_array.h:12
Definition atom.h:237
::collection::index erase_at(::collection::index nIndex, ::collection::count nCount=1)
Definition aaa__array_base_impl.h:62
Definition path.h:52
Definition list.h:33
Definition __payload_reference.h:6
Definition payload.h:54
void parse_standard_configuration(const ::scoped_string &scopedstrStandardConfiguration)
Definition property_set.cpp:1000
Definition property_set.h:512
Definition range.h:223