Realm C++ SDK版本 v 2.2.0

types.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_TYPES_HPP
20#define CPPREALM_TYPES_HPP
21
22#include <array>
23#include<optional>
24#include <set>
25#include<stdexcept>
26
27#include <cpprealm/internal/bridge/realm.hpp>
28#include <cpprealm/internal/bridge/schema.hpp>
29#include <cpprealm/internal/type_info.hpp>
30
31命名空间域 {
32
33 const size_t not_in_collection = - 1 ;
34
35 struct uuid {
36 显式 uuid ( const std::string &);
37 uuid ( const std:: 大量<uint 8 _t, 16 >&);
38 uuid() = default;
39 [[nodiscard]] std::string to_string() const ;
40 [[nodiscard]] std::string to_base 64 () const ;
41 [[nodiscard]] std::array<uint 8 _t, 16 > to_bytes() const ;
42 uuid ( const inside ::bridge::uuid &);
43 内部::桥::uuid m_uuid;
44 朋友 struct Internal::bridge::uuid
45 template < typenamemapped_type >
46 朋友 struct Box_base
47 };
48
49 内联 bool Operator ==( const uuid & lhs, const uuid & rhs) { return lhs.m_uuid == rhs.m_uuid; }
50 内联 bool 操作符 !=( const uuid& lhs, const uuid& rhs) { return lhs.m_uuid != rhs.m_uuid; }
51 内联 bool 操作符 >( const uuid& lhs, const uuid& rhs) { return lhs.m_uuid > rhs.m_uuid; }
52 内联 bool 操作符 >=( const uuid& lhs, const uuid& rhs) { return lhs.m_uuid >= rhs.m_uuid; }
53 内联 bool Operator <( const uuid& lhs, const uuid& rhs) { return lhs.m_uuid < rhs.m_uuid; }
54 内联 bool Operator <=( const uuid& lhs, const uuid& rhs) { return lhs.m_uuid <= rhs.m_uuid; }
55
56 struct object_id {
57 显式 object_id ( const std::string &);
58 object_id () = 默认 ;
59 [[nodiscard]] static object_id generate();
60 [[nodiscard]] std::string to_string() const ;
63 朋友 struct Internal::bridge::object_id
64 template < typenamemapped_type >
65 朋友 struct Box_base
66 };
67
68 内联 bool 操作符 ==( const object_id & lhs, const object_id & rhs) { return lhs.m_object_id == rhs.m_object_id; }
69 内联 bool Operator !=( const object_id& lhs, const object_id& rhs) { return lhs.m_object_id != rhs.m_object_id; }
70 内联 bool 操作符 <( const object_id& lhs, const object_id& rhs) { return lhs.m_object_id < rhs.m_object_id; }
71 内联 bool 操作符 >( const object_id& lhs, const object_id& rhs) { return lhs.m_object_id > rhs.m_object_id; }
72 内联 bool 操作符 <=( const object_id& lhs, const object_id& rhs) { return lhs.m_object_id <= rhs.m_object_id; }
73 内联 bool 操作符 >=( const object_id& lhs, const object_id& rhs) { return lhs.m_object_id >= rhs.m_object_id; }
74
75 struct 十进制128 {
76 显式 十进制128 ( const std::string &);
77 十进制128 ( cons double &);
78 十进制128 () = default ;
79 [[nodiscard]] std::string to_string() const ;
80 [[nodiscard]] bool is_NaN() const ;
82 inside ::bridge::decimal 128 m_decimal;
83 朋友 struct inside::bridge::decimal 128
84 template < typenamemapped_type >
85 朋友 struct Box_base
86
87 十进制128操作符-( const十进制128 &o);
88 Decimal 128 Operator+( const Decimal 128 & o);
89 Decimal 128 Operator*( const Decimal 128 & o);
90 十进制128操作符/(常量十进制128 &o);
91
92 Decimal 128 & Operator-=( const Decimal 128 & o);
93 Decimal 128 & Operator+=( const Decimal 128 & o);
94 Decimal 128 & Operator*=( const Decimal 128 & o);
95 Decimal 128 & Operator/=( const Decimal 128 & o);
96 };
97
98 内联 bool 操作符 >( const Decimal 128 & lhs, const Decimal 128 & rhs) { return lhs.m_decimal > rhs.m_decimal; }
99 内联 bool Operator >=( const Decimal 128 & lhs, const Decimal 128 & rhs) { return lhs.m_decimal >= rhs.m_decimal; }
100 内联 bool Operator <( const Decimal 128 & lhs, const Decimal 128 & rhs) { return lhs.m_decimal < rhs.m_decimal; }
101 内联 bool Operator <=( const Decimal 128 & lhs, const Decimal 128 & rhs) { return lhs.m_decimal <= rhs.m_decimal; }
102 内联 bool Operator ==( const Decimal 128 & lhs, const Decimal 128 & rhs) { return lhs.m_decimal == rhs.m_decimal; }
103 内联 bool 操作符 !=( const Decimal 128 & lhs, const Decimal 128 & rhs) { return lhs.m_decimal != rhs.m_decimal; }
104 }
105
106命名空间域 {
107
108 静态 inline int 64 _t Serialize(int 64 _t v, const std::Optional<internal::bridge::realm>& = std::nullopt) {
109 return v;
110 }
111 静态 inline int 64 _t deserialize(int 64 _t v) {
112 return v;
113 }
114
115 静态 inline std::Optional<int64 _t> Serialize( const std::Optional<int64 _t>& v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
116 return v;
117 }
118 静态 inline std::Optional<int 64 _t> deserialize( const std::Optional<int 64 _t>& v) {
119 return v;
120 }
121
122 静态 内联 double不行double<internal::bridge::realm>
123 return v;
124 }
125 静态 内联 double deserialize( const double & v) {
126 return v;
127 }
128
129 静态 inline std::Optional<double> Serialize( const std::Optional<double> & v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
130 return v;
131 }
132 静态 inline std::Optional<double> deserialize( const std::Optional<double>& v) {
133 return v;
134 }
135
136 静态 内联 bool Serialize( bool v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
137 return v;
138 }
139 静态 内联 bool deserialize( bool v) {
140 return v;
141 }
142
143 静态 inline std::Optional<bool> Serialize(std::Optional<bool> v, const std::Optional<internal::bridge::realm>& = std::nullopt) {
144 return v;
145 }
146 静态 inline std::Optional<bool> deserialize(std::Optional<bool> v) {
147 return v;
148 }
149
150 template < typename T>
151 静态 内联 typename std:: enable_if_t <std:: is_enum_v,<T> int64 域>eria<internal::bridge::realm>
152 return static_cast< int 64 _t > (v);
153 }
154 template < typename T, std::enable_if_t<std::is_enum_v<T>>>
155 静态 inline T deserialize(int 64 _t v) {
156 return static_cast< T > (v);
157 }
158
159 template < typename T>
160 静态 inline std::enable_if_t<std::is_enum_v,<typename T::value_type> std::Optional<int64 _t>> Serialize( const T& v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
161 if (v) {
162 return static_cast< int 64 _t > (*v);
163 } else {
164 return std::nullopt;
165 }
166 }
167 template < typename T, std::enable_if_t<std::is_enum_v< typename T::value_type>>>
168 静态 inline std::Optional<int 64 _t> deserialize(std::Optional<int 64 _t> v) {
169 if (v) {
170 return static_cast< T > (*v);
171 } else {
172 return std::nullopt;
173 }
174 }
175
176 静态 inline std::string Serialize( const std::string& v, const std::Optional<internal::bridge::realm>& = std::nullopt) {
177 return v;
178 }
179 静态 inline std::string deserialize( const std::string& v) {
180 return v;
181 }
182
183 静态 inline std::Optional<std::string> Serialize( const std::Optional<std::string> & v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
184 return v;
185 }
186 静态 inline std::Optional<std::string> deserialize( const std::Optional<std::string>& v) {
187 return v;
188 }
189
190 静态 inlineinternal::bridge:: uuidserialize ( const uuid& v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
191 return v;
192 }
193 静态 inline uuid deserialize( const inside ::bridge::uuid& v) {
194 return 操作符 :: 域::uuid();
195 }
196
197 静态 inline std::Optional<internal::bridge::uuid> Serialize( const std::Optional<uuid>& v, const std::Optional<internal::bridge::realm>& = std::nullopt) {
198 return v;
199 }
200 静态 inline std::Optional<uuid> deserialize( const std::Optional<internal::bridge::uuid>& v) {
201 if (v) {
202 return v->操作符::域::uuid();
203 } else {
204 return std::nullopt;
205 }
206 }
207
208 静态 inlineInternal::bridge:: binaryserialize ( const std::vector<uint 8 _t>& v, const std::Optional<internal::bridge::realm>& = std::nullopt) {
209 return v;
210 }
211 静态 inline std::vector<uint 8 _t> deserialize( const inside::bridge::binary& v) {
212 return v.operator std::vector<uint 8 _t>();
213 }
214
215 静态 inline std::Optional<internal::bridge::binary> Serialize( const std::Optional<std::vector<uint8 _t>>& v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
216 return v;
217 }
218 静态 inline std::Optional<std::vector<uint 8 _t>> deserialize( const std::Optional<internal::bridge::binary>& v) {
219 if (v) {
220 return v->operator std::vector<uint 8 _t>();
221 } else {
222 return std::nullopt;
223 }
224 }
225
226 静态 inlineinternal::bridge::timestampserialize( const std:: chrono ::time_point<std::chrono::system_clock> & v, const std::Optional<internal::bridge::realm> & = std::nullopt ) {
227 return v;
228 }
229 静态 inline std::chrono::time_point<std::chrono::system_clock> deserialize( constinternal ::bridge::timestamp& v) {
230 return v. 操作符 std::chrono::time_point<std::chrono::system_clock>();
231 }
232
233 静态 inline std::Optional<internal::bridge::timestamp> Serialize( const std::Optional<std::chrono::time_point<std::chrono::system_clock> >& v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
234 return v;
235 }
236 静态 inline std::Optional<std::chrono::time_point<std::chrono::system_clock>> deserialize( const std::Optional<internal::bridge::timestamp>& v) {
237 if (v) {
238 return v->operator std::chrono::time_point<std::chrono::system_clock>();
239 } else {
240 return std::nullopt;
241 }
242 }
243
244 静态 inlineinternal ::bridge::object_idserialize( const 域::object_id & v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
245 return v;
246 }
247 静态 内联 realm::object_id deserialize( const inside::bridge::object_id& v) {
248 return 操作符 :: 域::object_id();
249 }
250
251 静态 inline std::Optional<internal::bridge::object_id> Serialize( const std::Optional<realm::object_id> & v, const std::Optional<internal::bridge::realm> & = std::nullopt ) {
252 return v;
253 }
254 静态 inline std::Optional<realm::object_id> deserialize( const std::Optional<internal::bridge::object_id>& v) {
255 if (v) {
256 return v->操作符::域::Realm 对象();
257 } else {
258 return std::nullopt;
259 }
260 }
261
262 静态 inlineInternal ::bridge::decimal 128 serialize( const realm::decimal 128 & v, const std::Optional<internal::bridge::realm>& = std::nullopt) {
263 return v;
264 }
265 静态 内联 realm::decimal 128 deserialize( constinternal ::bridge::decimal 128 & v) {
266 return v.operator::realm::decimal 128 ();
267 }
268
269 静态 inline std::Optional<internal::bridge::decimal128 > Serialize( const std::Optional< 域::decimal128 >& v, const std::Optional<internal::bridge::realm> & = std::nullopt) {
270 return v;
271 }
272 静态 inline std::Optional< 域::decimal 128 > deserialize( const std::Optional<internal::bridge::decimal 128 >& v) {
273 if (v) {
274 return v-> 操作符 :: 域::decimal 128 ();
275 } else {
276 return std::nullopt;
277 }
278 }
279
280 template < typename T>
281 静态 内联 typename std::enable_if_t<internal::type_info:: MixedPersistableConcept::value,<T> inside::bridge:: 域> eria <internal::bridge::realm>std::nullopt) {
282 return std::visit([&]( auto && arg) {
283 using StoredType = std::decay_t< decltype (arg)>;
284 using M = typenameInternal ::type_info::type_info<StoredType>::internal_type;
285 returninternal ::bridge::mixed(M(arg));
286 }, v);
287 }
288
289 template < typename T>
290 静态 内联 typename std::enable_if_t<!internal::type_info::MixedPersistableConcept<T>::value, T>
291 deserialize( const inside ::bridge::mixed& value) {
292 if constexpr (internal::type_info::is_Optional<T>::value) {
293 return std::nullopt;
294 } else if constexpr (std::is_same_v<T, int64_t>) {
295 返回值。 操作符 int 64 _t();
296 } else if constexpr (std::is_same_v<T, bool>) {
297 return value.operator bool();
298 } else if constexpr (std::is_same_v<T, std::string>) {
299 return static_cast< std::string > (value);
300 } else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
301 return static_cast< std::vector<uint 8 _t> > ( static_cast< internal::bridge::binary > (value));
302 } else if constexpr (std::is_same_v<T, std::chrono::time_point<std::chrono::system_clock>>) {
303 return static_cast< internal::bridge::timestamp > (value);
304 } else if constexpr (std::disjunction_v<std::is_same<T, double>, std::is_same<T, float>>) {
305 return static_cast<double> (value);
306 } else if constexpr (std::is_same_v<T, realm::uuid>) {
307 返回值。操作符内部::bridge::uuid()。操作符:: 域::uuid();
308 } else if constexpr (std::is_same_v<T, realm::object_id>) {
309 返回值。操作符内部::bridge::object_id()。操作符 :: 域::object_id();
310 } else if constexpr (std::is_same_v<T, realm::decimal 128 >) {
311 返回值。操作符内部::bridge::decimal 128 () 。操作符 :: 域::decimal 128 ();
312 } else if constexpr (std::is_enum_v<T>) {
313 return static_cast< T > (操作符 int 64 _t());
314 } else {
315 abort();
316 }
317 }
318
319 template < typename T>
320 静态 内联 typename std::enable_if_t<internal::type_info::MixedPersistableConcept<T>::value, T>
321 deserialize( const inside ::bridge::mixed& value) {
322 if (value.is_null()) {
323 return std::monostate();
324 }
325
326 switch (value.type()) {
327 caseInternal ::bridge::data_type::Int:
328 返回值。 操作符 int 64 _t();
329 caseInternal ::bridge::data_type::Bool:
330 return value.operator bool();
331 caseInternal ::bridge::data_type::String:
332 return static_cast< std::string > (value);
333 caseInternal ::bridge::data_type::Binary:
334 return static_cast< std::vector<uint 8 _t> > ( static_cast< internal::bridge::binary > (value));
335 caseInternal ::bridge::data_type::Timestamp:
336 return static_cast< internal::bridge::timestamp > (value);
337 caseInternal ::bridge::data_type::Float:
338 caseInternal ::bridge::data_type::Double:
339 return static_cast<double> (value);
340 caseInternal ::bridge::data_type::UUID:
341 返回值。操作符内部::bridge::uuid()。操作符:: 域::uuid();
342 caseInternal ::bridge::data_type::ObjectId:
343 返回值。操作符内部::bridge::object_id()。操作符 :: 域::object_id();
344 case inside::bridge::data_type::Decimal:
345 返回值。操作符internal::bridge::decimal 128 ()。操作符 :: 域::decimal 128 ();
346 caseInternal ::bridge::data_type::TypedLink:
347 throw std::runtime_error( "存储在混合属性中的对象必须通过 `get_object_value()` 访问" );
348 默认值
349 throw std::runtime_error( "反序列化混合属性时出现未知数据类型。" );
350 }
351 }
352
353 } // 命名空间 Realm
354
355
356#endif//CPREALM_TYPES_HPP
定义: managed_dictionary.hpp: 31
定义: types.hpp: 75
定义:十进制128 .hpp: 30
定义: object_id.hpp:31
定义: uuid.hpp:32
定义: types.hpp:56
定义: types.hpp:35