acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_container.h
1// Created by camilo on 2022-11-08 17:25 <3ThomasBorregaardSorensen!!
2// Created by camilo on 2023-01-20 22:25 <3ThomasBorregaardSorensen!!
3// 2023-01-20 22:25 - Mummi, Lucinho, Bilbo, Blue, Carol e Zibia contribution through ca2 HQ!!
4// 2023-01-20 22:25 - lowluds, shegotmad, mrsteinbergplease and octaelliptical contribution through Twitch.TV!!
5#pragma once
6
7
8CLASS_DECL_ACME void copy(::string & str, const ::payload & payload);
9CLASS_DECL_ACME void copy(::payload & payload, const ::i32 & i);
10CLASS_DECL_ACME void copy(::payload & payload, const ::scoped_string & scopedstr);
11
12namespace generic
13{
14
15
16 namespace container
17 {
18
19
20 template < prototype_container CONTAINER1, prototype_container CONTAINER2 >
21 CONTAINER1& append(CONTAINER1& container1, const CONTAINER2& container2)
22 {
23
24 for (auto& item : container2)
25 {
26
27 ::copy(container1.add_new(), item);
28
29 }
30
31 return container1;
32
33 }
34
35
36 template < prototype_container CONTAINER1, prototype_container CONTAINER2 >
37 CONTAINER1& copy(CONTAINER1& container1, const CONTAINER2& container2)
38 {
39
40 container1.clear();
41
42 return append(container1, container2);
43
44 }
45
46
47 } // namespace container
48
49
50} // namespace generic
51
52
53template < prototype_container CONTAINER >
54inline ::string as_string(const CONTAINER& container, const ::scoped_string& scopedstrSeparator = "|")
55{
56
57 ::string str;
58
59 for (const auto& item : container)
60 {
61
62 if (str.has_character())
63 {
64
65 str += scopedstrSeparator;
66
67 }
68
69 str += ::as_string(item);
70
71 }
72
73 return str;
74
75}
76
77template < typename ITEM >
78inline ::string as_string(const ::set < ITEM > & set, const ::scoped_string& scopedstrSeparator = "|")
79{
80
81 ::string str;
82
83 for (const auto& item : set)
84 {
85
86 if (str.has_character())
87 {
88
89 str += scopedstrSeparator;
90
91 }
92
93 str += ::as_string(item.item());
94
95 }
96
97 return str;
98
99}
100
101
102template < prototype_container CONTAINER >
103inline void from_string(CONTAINER & container, const ::scoped_string & scopedstr, const ::scoped_string & scopedstrSeparator = "|")
104{
105
106 ::tokenizer tokenizer(scopedstr);
107
108 ::string strToken;
109
110 while(tokenizer.get_next_token(strToken, scopedstrSeparator))
111 {
112
113 typename CONTAINER::BASE_TYPE t;
114
115 ::from_string(t, strToken);
116
117 container.add(t);
118
119 }
120
121}
122
123
124template < typename ITEM >
125inline void from_string(::set < ITEM > & set, const ::scoped_string& scopedstr, const ::scoped_string& scopedstrSeparator = "|")
126{
127
128 ::tokenizer tokenizer(scopedstr);
129
130 ::string strToken;
131
132 while (tokenizer.get_next_token(strToken, scopedstrSeparator))
133 {
134
135 ITEM item;
136
137 ::from_string(item, strToken);
138
139 set.set_key(item);
140
141 }
142
143}
144
145
146
Definition item.h:93
Definition payload.h:54
Definition tokenizer.h:6