Realm C++ SDK版本 v 2.2.0

rbool.hpp

1
2//
3// 版权所有 2022 Realm Inc.
4//
5// 根据 Apache 许可证 2.0 版(“许可证”)获得许可;
6// 除非符合合规,否则不得使用此文件。
7// 您可以在以下网址获取许可证副本:
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// 除非适用法律要求或书面同意,否则软件
12// 根据许可证分发是按“原样”分发的,
13// 不提供任何类型的Express或暗示的保证或条件。
14// 请参阅管理权限的特定语言的许可证和
15// 许可证下的限制。
16//
18
19#ifndef CPPREALM_RBOOL_HPP
20#define CPPREALM_RBOOL_HPP
21
22#include <cpprealm/internal/bridge/ 查询.hpp>
23#include <cpprealm/internal/bridge/realm.hpp>
24#include <cpprealm/internal/bridge/table.hpp>
25#include <cpprealm/internal/bridge/utils.hpp>
26#include <cpprealm/types.hpp>
27
28命名空间域 {
29 template < typename >
30 structbox_base
31 }
32
33命名空间域 {
34 // MARK: rbool
35
36 class rbool {
37 public :
39 Internal::bridge:: col_keyorigin_col_key;
40 std::string m_key;
41 };
42
43 rbool & add_link_chain( const inside ::bridge::col_key & col_key) {
44 if (m_link_chain) {
45 m_link_chain->link(col_key);
46 } else {
47 m_link_chain = m_table.get_link(col_key);
48 }
49 return * this ;
50 }
51
52#definedefine_query(type,comparation)\
53 rbool&compare(constinternal::bridge::col_key&col_key, conststd::Optional<type>&rhs) { \
54 if (auto lc = m_link_chain) { \
55 q = lc->column<type>(col_key).comparison(rhs); \
56 m_link_chain = std::nullopt; \
57 } else if (m_dictionary_ctx) { \
58 q = q.dictionary_link_subexpr(m_dictionary_ctx->origin_col_key, col_key, m_dictionary_ctx->m_key).comparison(rhs); \
59 m_dictionary_ctx = std::nullopt; \
60 } else { \
61 if (rhs) { \
62 q = external::bridge::query(q.get_table()).comparison(col_key, *rhs); \
63 } else { \
64 q = external::bridge::query(q.get_table()).comparison(col_key, std::nullopt); \
65 } \
66 } \
67 return *this; \
68 } \
69 rbool&Comparison(constinternal::bridge::col_key&col_key,consttype&rhs){\
70 if (auto lc = m_link_chain) { \
71 q = lc->column<type>(col_key).comparison(std::Optional<type>(rhs)); \
72 m_link_chain = std::nullopt; \
73 } else if (m_dictionary_ctx) { \
74 q = q.dictionary_link_subexpr(m_dictionary_ctx->origin_col_key, col_key, m_dictionary_ctx->m_key).comparison(std::Optional<type>(rhs)); \
75 m_dictionary_ctx = std::nullopt; \
76 } else { \
77 q = external::bridge:: 查询(q.get_table()).comparison(col_key, rhs); \
78 } \
79 return *this; \
80 }
81
82#definedefine_numeric_query(type,comparation)\
83 rbool&Comparison(constinternal::bridge::col_key&col_key,consttype&rhs){\
84 if (auto lc = m_link_chain) { \
85 q = lc->column<type>(col_key).comparison(:: 域::serialize(std::Optional<type>(rhs))); \
86 m_link_chain = std::nullopt; \
87 } else if (m_dictionary_ctx) { \
88 q = q.dictionary_link_subexpr(m_dictionary_ctx->origin_col_key, col_key, m_dictionary_ctx->m_key).comparison(std::Optional<type>(rhs)); \
89 m_dictionary_ctx = std::nullopt; \
90 } else { \
91 q = external::bridge:: 查询(q.get_table()).comparison(col_key, rhs); \
92 } \
93 return *this; \
94 }
95
96 define_query(std::string, equal)
97 define_query(std::string, not_equal)
98
99 rbool& contains( const inside::bridge::col_key& col_key, const std::string& rhs, bool case_sensitive = true ) {
100 if (auto lc = m_link_chain) {
101 q = lc->column<std::string>(col_key).contains(:: 域::serialize(std::Optional<std::string>(rhs)), case_sensitive);
102 m_link_chain = std::nullopt;
103 } else {
104 q = external::bridge:: 查询(q.get_table()).contains(col_key, rhs, case_sensitive);
105 }
106 return * this ;
107 }
108
109 define_query(int 64 _t, equal)
110 define_query(int 64 _t, not_equal)
111 define_numeric_query(int 64 _t,更大)
112 define_numeric_query(int 64 _t, less)
113 define_numeric_query(int 64 _t,great_equal)
114 define_numeric_query(int 64 _t, less_equal)
115
116 define_query( bool , equal)
117 define_query( bool , not_equal)
118
119 define_query( double , equal)
120 define_query( double , not_equal)
121 define_numeric_query( double ,更大)
122 define_numeric_query( double ,less)
123 define_numeric_query( double , more_equal)
124 define_numeric_query( double ,less_equal)
125
126 define_query(std::vector<uint 8 _t>, equal)
127 define_query(std::vector<uint 8 _t>, not_equal)
128
129 define_query(std::chrono::time_point<std::chrono::system_clock>, equal)
130 define_query(std::chrono::time_point<std::chrono::system_clock>, not_equal)
131 define_numeric_query(std::chrono::time_point<std::chrono::system_clock>,更大)
132 define_numeric_query(std::chrono::time_point<std::chrono::system_clock>, less)
133<std::chrono::system_clock>
134 define_numeric_query(std::chrono::time_point<std::chrono::system_clock>, less_equal)
135
136 define_query(uuid, equal)
137 define_query(uuid, not_equal)
138
139 define_query(object_id, equal)
140 define_query(object_id, not_equal)
141
142 define_query(decimal 128 , equal)
143 define_query(decimal 128 , not_equal)
144 define_numeric_query(decimal 128 ,更大)
145 define_numeric_query(decimal 128 ,less)
146 define_numeric_query(decimal 128 ,更大_equal)
147 define_numeric_query(decimal 128 ,less_equal)
148
149 rbool& 混合_equal( const内部::bridge::col_key& col_key, const内部::bridge::mixed& rhs) {
150 if (auto lc = m_link_chain) {
151 q = lc->column<std::string>(col_key).mixed_equal(rhs);
152 m_link_chain = std::nullopt;
153 } else {
154 q.equal(col_key, rhs);
155 }
156 return * this ;
157 }
158
159 rbool&ixed_not_equal( constinternal ::bridge::col_key&col_key, constinternal ::bridge::mixed&rhs){
160 if (auto lc = m_link_chain) {
161 q = lc->column_mixed(col_key).mixed_not_equal(rhs);
162 m_link_chain = std::nullopt;
163 } else {
164 q.not_equal(col_key, rhs);
165 }
166 return * this ;
167 }
168
169 rbool& link_equal( const下来内部::bridge::col_key& col_key, const std::Optional<internal::bridge::obj>& rhs) {
170 if (auto lc = m_link_chain) {
171 q = lc->column<internal::bridge::obj>(col_key).equal(rhs);
172 m_link_chain = std::nullopt;
173 } else {
174 if (rhs) {
175 q.links_to(col_key, *rhs);
176 } else {
177 q.links_to(col_key,internal::bridge::obj());
178 }
179 }
180 return * this ;
181 }
182
183 rbool& link_not_equal( constInternal::bridge::col_key& col_key, const std:: Optional <internal::bridge::obj>& rhs) {
184 if (auto lc = m_link_chain) {
185 q = lc->column<internal::bridge::obj>(col_key).not_equal(rhs);
186 m_link_chain = std::nullopt;
187 } else {
188 if (rhs) {
189 q.not_links_to(col_key, *rhs);
190 } else {
191 q.not_links_to(col_key,internal::bridge::obj());
192 }
193 }
194 return * this ;
195 }
196
197 // Dictionary
198
199 rbool&Dictionary_has_value_for_key_equals(internal::bridge::col_keycolumn_key, const std::string& key, constinternal ::bridge::mixed&value) {
200 q = external::bridge:: 查询(q.get_table()).dictionary_has_value_for_key_equals(column_key, 键,值);
201 return * this ;
202 }
203
204 rbool&Dictionary_has_value_for_key_not_equals(internal::bridge::col_keycolumn_key, const std::string& key, constinternal ::bridge::mixed&value) {
205 q = external::bridge:: 查询(q.get_table()).dictionary_has_value_for_key_not_equals(column_key, 键,值);
206 return * this ;
207 }
208
209 rbool&Dictionary_has_value_for_key_great_than(internal::bridge::col_keycolumn_key, const std::string& key, constinternal ::bridge::mixed&value) {
210 q = external::bridge:: 查询(q.get_table()).dictionary_has_value_for_key_great_than(column_key, 键,值);
211 return * this ;
212 }
213
214 rbool&Dictionary_has_value_for_key_less_than(internal::bridge::col_keycolumn_key, const std::string& key, constinternal ::bridge::mixed&value) {
215 q = external::bridge:: 查询(q.get_table()).dictionary_has_value_for_key_less_than(column_key, 键,值);
216 return * this ;
217 }
218
219 rbool&Dictionary_has_value_for_key_great_than_equals(internal::bridge::col_keycolumn_key, const std::string& key, constinternal ::bridge::mixed&value) {
220 q = external::bridge:: 查询(q.get_table()).dictionary_has_value_for_key_great_than_equals(column_key, 键,值);
221 return * this ;
222 }
223
224 rbool&Dictionary_has_value_for_key_less_than_equals(internal::bridge::col_keycolumn_key, const std::string& key, constinternal ::bridge::mixed&value) {
225 q = external::bridge:: 查询(q.get_table()).dictionary_has_value_for_key_less_than_equals(column_key, 键,值);
226 return * this ;
227 }
228
229 rbool&Dictionary_contains_string_for_key(internal::bridge::col_keycolumn_key, const std::string& key, const std::string& value) {
230 q = external::bridge:: 查询(q.get_table()).dictionary_contains_string_for_key(column_key, 键,值);
231 return * this ;
232 }
233
234 rbool& add_dictionary_link_chain(dictionary_context&& ctx) {
235 m_dictionary_ctx = ctx;
236 return * this ;
237 }
238
239 rbool&Dictionary_has_key(internal::bridge::col_keycolumn_key, const std::string&key) {
240 q = external::bridge:: 查询(q.get_table()).dictionary_contains_key(column_key, 键);
241 return * this ;
242 }
243
244 ~rbool() {
245 if (is_for_queries)
246 q.~ 查询();
247 }
248 操作符 bool() const {
249 return b;
250 }
251 rbool操作符!() const {
252 if (is_for_queries) {
253 q.negate();
254 return * this ;
255 }
256 return !b;
257 }
258 union {
259 bool b;
260 mutableInternal ::bridge:: 查询 ;
261 };
262
263 rbool(internal::bridge:: 查询 &&q) : q(q), is_for_queries(true) {
264 m_table = q.get_table();
265 }
266 rbool( bool b) : b(b) {}
267 rbool( const rbool &r) {
268 if (r.is_for_queries) {
269 new (&q)internal::bridge:: 查询(rq);
270 is_for_queries = true ;
271 } else
272 b = r.b;
273 }
274
275 private :
276 bool is_for_queries = false ;
277 bool is_dictionary_link = false ;
278 std::Optional<internal::bridge::link_chain> m_link_Chain;
279 Internal::bridge::table m_table;
280 std::Optional<dictionary_context> m_dictionary_ctx;
281
282 template < typename T>
283 朋友 struct结果;
284 Friend rbool Operator&&( const rbool &lhs, const rbool &rhs);
285 Friend rbool 操作符||( const rbool &lhs, const rbool &rhs);
286 };
287
288 inline rbool操作符&&( const rbool& lhs, const rbool& rhs) {
289 if (lhs.is_for_queries) {
290 lhs.q.and_query(rhs.q);
291 return lhs;
292 }
293 return lhs.b && rhs.b;
294 }
295 内联rbool 操作符 ||( const rbool& lhs, const rbool& rhs) {
296 if (lhs.is_for_queries) {
297 lhs.q = lhs.q || rhs.q;
298 return lhs;
299 }
300 return lhs.b && rhs.b;
301 }
302
304 template < typename T>
305 inline rbool truepredicate( const T& o) {
306 // 空查询会返回所有结果以及指示此结果的一种方法
307 // 用于序列化 TRUEPREDICATE,其功能等效
308 rbool* rb = internal::get_rbool(o);
309 if (rb == nullptr )
310 throw std::runtime_error( "Managed 对象 is not used in a 查询 context" );
311 auto table = rb->q.get_table();
312 return rbool(table);
313 }
314
316 template < typename T>
317 inline rbool falsepredicate( const T& o) {
318 rbool* rb = internal::get_rbool(o);
319 if (rb == nullptr )
320 throw std::runtime_error( "Managed 对象 is not used in a 查询 context" );
321 auto table = rb->q.get_table();
322 auto q = external::bridge:: 查询(table).and_query(internal::bridge:: 查询(table).falsepredicate());
323 return rbool(std::move(q));
324 }
325 }
326
327#endif //CPREALM_RBOOL_HPP
定义: rbool.hpp:36
定义: col_key.hpp: 28
定义: rbool.hpp: 38