Realm C++ SDK Version v2.2.0

mixed.hpp

1
2//
3// Copyright 2024 Realm Inc.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
18
19#ifndef CPPREALM_BRIDGE_MIXED_HPP
20#define CPPREALM_BRIDGE_MIXED_HPP
21
22#include <string>
23#include <optional>
24#include <variant>
25#include <cpprealm/internal/bridge/property.hpp>
26#include <cpprealm/internal/bridge/binary.hpp>
27#include <cpprealm/internal/bridge/uuid.hpp>
28#include <cpprealm/internal/bridge/timestamp.hpp>
29#include <cpprealm/internal/bridge/obj_key.hpp>
30#include <cpprealm/internal/bridge/object_id.hpp>
31#include <cpprealm/internal/bridge/decimal128.hpp>
32
33namespace realm {
34 class Mixed;
35
36 using mixed = std::variant<
37 std::monostate,
38 int64_t,
39 bool,
40 std::string,
41 double,
42 std::vector<uint8_t>,
43 std::chrono::time_point<std::chrono::system_clock>,
44 uuid,
45 object_id,
46 decimal128>;
47}
48
49namespace realm::internal::bridge {
50 enum class data_type {
51 // Note: Value assignments must be kept in sync with <realm/column_type.h>
52 // Note: Any change to this enum is a file-format breaking change.
53 Int = 0,
54 Bool = 1,
55 String = 2,
56 Binary = 4,
57 Mixed = 6,
58 Timestamp = 8,
59 Float = 9,
60 Double = 10,
61 Decimal = 11,
62 Link = 12,
63 LinkList = 13,
64 ObjectId = 15,
65 TypedLink = 16,
66 UUID = 17,
67 };
68
69 struct mixed {
70 mixed();
71 mixed(const mixed& other) ;
72 mixed& operator=(const mixed& other) ;
73 mixed(mixed&& other);
74 mixed& operator=(mixed&& other);
75 ~mixed();
76
77 explicit mixed(const std::string&);
78 mixed(const std::monostate&); //NOLINT(google-explicit-constructor)
79 mixed(const int&); //NOLINT(google-explicit-constructor)
80 mixed(const int64_t&); //NOLINT(google-explicit-constructor)
81 mixed(const double&); //NOLINT(google-explicit-constructor)
82 mixed(const bool&); //NOLINT(google-explicit-constructor)
83 mixed(const struct uuid&); //NOLINT(google-explicit-constructor)
84 mixed(const struct object_id&); //NOLINT(google-explicit-constructor)
85 mixed(const struct decimal128&); //NOLINT(google-explicit-constructor)
86 mixed(const struct timestamp&); //NOLINT(google-explicit-constructor)
87 mixed(const struct obj_link&); //NOLINT(google-explicit-constructor)
88 mixed(const struct obj_key&); //NOLINT(google-explicit-constructor)
89 mixed(const struct binary&); //NOLINT(google-explicit-constructor)
90 mixed(const Mixed&); //NOLINT(google-explicit-constructor)
91 template<typename T>
92 mixed(const std::optional<T>& o); //NOLINT(google-explicit-constructor)
93 operator std::string() const; //NOLINT(google-explicit-constructor)
94 operator int64_t() const; //NOLINT(google-explicit-constructor)
95 operator double() const; //NOLINT(google-explicit-constructor)
96 operator bool() const; //NOLINT(google-explicit-constructor)
97 operator bridge::uuid() const; //NOLINT(google-explicit-constructor)
98 operator bridge::object_id() const; //NOLINT(google-explicit-constructor)
99 operator bridge::decimal128() const; //NOLINT(google-explicit-constructor)
100 operator bridge::timestamp() const; //NOLINT(google-explicit-constructor)
101 operator bridge::obj_link() const; //NOLINT(google-explicit-constructor)
102 operator bridge::obj_key() const; //NOLINT(google-explicit-constructor)
103 operator bridge::binary() const; //NOLINT(google-explicit-constructor)
104
105 explicit operator Mixed() const;
106
107 [[nodiscard]] data_type type() const noexcept;
108 [[nodiscard]] bool is_null() const noexcept;
109 private:
110 std::string m_owned_string;
111 binary m_owned_data;
112#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
113 storage::Mixed m_mixed[1];
114#else
115 std::shared_ptr<Mixed> m_mixed;
116#endif
117 friend bool operator ==(const mixed&, const mixed&);
118 friend bool operator !=(const mixed&, const mixed&);
119 friend bool operator >(const mixed&, const mixed&);
120 friend bool operator <(const mixed&, const mixed&);
121 friend bool operator >=(const mixed&, const mixed&);
122 friend bool operator <=(const mixed&, const mixed&);
123 };
124
125 bool operator ==(const mixed&, const mixed&);
126 bool operator !=(const mixed&, const mixed&);
127 bool operator >(const mixed&, const mixed&);
128 bool operator <(const mixed&, const mixed&);
129 bool operator >=(const mixed&, const mixed&);
130 bool operator <=(const mixed&, const mixed&);
131}
132
133
134#endif //CPPREALM_BRIDGE_MIXED_HPP
Definition: binary.hpp:30
Definition: decimal128.hpp:30
Definition: mixed.hpp:69
Definition: obj_key.hpp:33
Definition: object_id.hpp:31
Definition: timestamp.hpp:30
Definition: uuid.hpp:32