Realm C++ SDK Version v2.2.0

object.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_OBJECT_HPP
20#define CPPREALM_BRIDGE_OBJECT_HPP
21
22#include <any>
23#include <functional>
24#include <memory>
25#include <unordered_map>
26
27#include <cpprealm/internal/bridge/utils.hpp>
28
29namespace realm {
30 class Object;
31 class IndexSet;
32 class CollectionChangeCallback;
33 struct CollectionChangeSet;
34 struct NotificationToken;
35}
36namespace realm::internal::bridge {
37 struct realm;
38 struct obj;
39 struct obj_link;
40 struct object_schema;
41 struct list;
42 struct col_key;
43 struct dictionary;
44
47 notification_token(const notification_token &other) = delete;
48 notification_token &operator=(const notification_token &other) = delete;
50 notification_token &operator=(notification_token &&other);
51 notification_token(NotificationToken&&);
53 operator NotificationToken() const;
54 void unregister();
55 private:
56#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
57 storage::NotificationToken m_token[1];
58#else
59 std::shared_ptr<NotificationToken> m_token;
60#endif
61 };
62
63 struct index_set {
64 index_set(); //NOLINT(google-explicit-constructor)
65 index_set(const index_set& other) ;
66 index_set& operator=(const index_set& other);
67 index_set(index_set&& other);
68 index_set& operator=(index_set&& other);
69 ~index_set();
70 index_set(const IndexSet&); //NOLINT(google-explicit-constructor)
71 [[nodiscard]] bool empty() const;
73 // An iterator over the individual indices in the set rather than the ranges
75 public:
76 index_iterator() = default;
77 index_iterator(const index_iterator& other) ;
78 index_iterator& operator=(const index_iterator& other);
80 index_iterator& operator=(index_iterator&& other);
82 size_t operator*() const noexcept;
83 bool operator==(index_iterator const& it) const noexcept;
84 bool operator!=(index_iterator const& it) const noexcept;
85
86 index_iterator& operator++() noexcept;
87
88 index_iterator operator++(int) noexcept;
89
90 private:
91 friend struct index_iterable_adaptor;
92#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
93 storage::IndexSet_IndexIterator m_iterator[1];
94#else
95 std::shared_ptr<std::any> m_iterator;
96#endif
97 };
98
100 index_iterable_adaptor() = default;
102 index_iterable_adaptor& operator=(const index_iterable_adaptor& other);
107
108 const_iterator begin() const noexcept;
109 const_iterator end() const noexcept;
110 private:
111 friend struct index_set;
112#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
113 storage::IndexSet_IndexIteratableAdaptor m_index_iterable_adaptor[1];
114#else
115 std::shared_ptr<std::any> m_index_iterable_adaptor;
116#endif
117 };
118 index_iterable_adaptor as_indexes() const;
119 private:
120#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
121 storage::IndexSet m_idx_set[1];
122#else
123 std::shared_ptr<IndexSet> m_idx_set;
124#endif
125 };
127 collection_change_set(); //NOLINT(google-explicit-constructor)
129 collection_change_set& operator=(const collection_change_set& other);
133 collection_change_set(const CollectionChangeSet&);
134 operator CollectionChangeSet() const;
135 [[nodiscard]] index_set deletions() const;
136 [[nodiscard]] index_set modifications() const;
137 [[nodiscard]] index_set insertions() const;
138 [[nodiscard]] std::unordered_map<int64_t, index_set> columns() const;
139 [[nodiscard]] bool empty() const;
140 [[nodiscard]] bool collection_root_was_deleted() const;
141 private:
142#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
143 storage::CollectionChangeSet m_change_set[1];
144#else
145 std::shared_ptr<CollectionChangeSet> m_change_set;
146#endif
147 };
149 virtual ~collection_change_callback() {}
150 virtual void before(collection_change_set const& c) = 0;
151 virtual void after(collection_change_set const& c) = 0;
152 };
153
154 struct object {
155 object(); //NOLINT(google-explicit-constructor)
156 object(const object& other) ;
157 object& operator=(const object& other);
158 object(object&& other);
159 object& operator=(object&& other);
160 ~object();
161 object(const Object&); //NOLINT(google-explicit-constructor)
162 object(const realm &realm, const obj &obj); //NOLINT(google-explicit-constructor)
163 object(const realm &realm, const obj_link& link);
164
165 operator Object() const; //NOLINT(google-explicit-constructor)
166
167 [[nodiscard]] obj get_obj() const;
168
169 [[nodiscard]] realm get_realm() const;
170
171 [[nodiscard]] bool is_valid() const;
172
173 notification_token add_notification_callback(std::shared_ptr<collection_change_callback>&& cb);
174
175 [[nodiscard]] object_schema get_object_schema() const;
176
177 [[nodiscard]] list get_list(const col_key&) const;
178 [[nodiscard]] dictionary get_dictionary(const col_key&) const;
179 private:
180#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
181 storage::Object m_object[1];
182#else
183 std::shared_ptr<Object> m_object;
184#endif
185 };
186}
187
188#endif //CPPREALM_BRIDGE_OBJECT_HPP
Definition: col_key.hpp:28
Definition: dictionary.hpp:138
Definition: object.hpp:63
Definition: list.hpp:49
Definition: obj.hpp:123
Definition: object_schema.hpp:33
Definition: object.hpp:154
Definition: realm.hpp:67