19#ifndef CPPREALM_FLEXIBLE_SYNC_HPP
20#define CPPREALM_FLEXIBLE_SYNC_HPP
25#include <cpprealm/internal/bridge/obj.hpp>
26#include <cpprealm/internal/bridge/query.hpp>
27#include <cpprealm/internal/bridge/schema.hpp>
28#include <cpprealm/internal/bridge/realm.hpp>
29#include <cpprealm/internal/bridge/utils.hpp>
31#include <cpprealm/macros.hpp>
32#include <cpprealm/results.hpp>
33#include <cpprealm/rbool.hpp>
41 class MutableSubscriptionSet;
42 class SubscriptionSet;
43 class SubscriptionStore;
51 std::string identifier;
53 std::optional<std::string> name;
55 std::chrono::time_point<std::chrono::system_clock> created_at;
57 std::chrono::time_point<std::chrono::system_clock> updated_at;
59 std::string query_string;
61 std::string object_class_name;
86 void add(
const std::string &name ,
87 std::optional<std::function<
rbool(
managed<T> &)>> &&query_fn = std::nullopt) {
88 static_assert(
sizeof(
managed<T>),
"Must declare schema for T");
91 auto group = m_realm.get().read_group();
92 auto table_ref = group.get_table(schema.table_key());
98 auto full_query = (*query_fn)(query_object).q;
99 insert_or_assign(name, full_query);
101 insert_or_assign(name, root_query);
107 void remove(
const std::string& name);
111 std::optional<sync_subscription> find(
const std::string& name);
117 template <
typename T>
118 std::enable_if_t<std::is_base_of_v<object<T>, T>>
119 update_subscription(
const std::string& name, std::optional<std::function<
rbool(T&)>>&& query_fn = std::nullopt) {
121 add(name, std::move(query_fn));
128 template <
typename T>
129 void update_subscription(
const std::string& name,
130 std::optional<std::function<
rbool(
managed<T>&)>>&& query_fn = std::nullopt) {
132 add(name, std::move(query_fn));
140#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
141 internal::bridge::storage::MutableSyncSubscriptionSet m_subscription_set[1];
143 std::shared_ptr<sync::MutableSubscriptionSet> m_subscription_set;
145 std::reference_wrapper<internal::bridge::realm> m_realm;
147 sync::MutableSubscriptionSet get_subscription_set();
160 [[nodiscard]]
size_t size()
const;
164 std::optional<sync_subscription> find(
const std::string& name);
171#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
172 internal::bridge::storage::SyncSubscriptionSet m_subscription_set[1];
174 std::shared_ptr<sync::SubscriptionSet> m_subscription_set;
176 std::reference_wrapper<internal::bridge::realm> m_realm;
Definition: query.hpp:131
Definition: flex_sync.hpp:71
Definition: flex_sync.hpp:37
Definition: flex_sync.hpp:150
size_t size() const
The total number of subscriptions in the set.
Definition: flex_sync.cpp:134
Definition: flex_sync.hpp:49