19#ifndef CPPREALM_BRIDGE_OBJ_HPP
20#define CPPREALM_BRIDGE_OBJ_HPP
29#include <cpprealm/types.hpp>
30#include <cpprealm/internal/bridge/binary.hpp>
31#include <cpprealm/internal/bridge/col_key.hpp>
32#include <cpprealm/internal/bridge/decimal128.hpp>
33#include <cpprealm/internal/bridge/dictionary.hpp>
34#include <cpprealm/internal/bridge/object.hpp>
35#include <cpprealm/internal/bridge/object_id.hpp>
36#include <cpprealm/internal/bridge/table.hpp>
37#include <cpprealm/internal/bridge/utils.hpp>
50 struct NotificationToken;
52 namespace internal::bridge {
56 namespace internal::type_info {
57 template <
typename,
typename>
61 template <
typename,
typename>
63 template <
typename,
typename>
67namespace realm::internal::bridge {
88 struct is_optional : std::false_type {
93 struct is_optional<std::optional<T>> : std::true_type {
99 [[nodiscard]] T get(
const obj&,
const col_key& col_key);
101 [[nodiscard]] std::string get(
const obj&,
const col_key& col_key);
103 [[nodiscard]] uuid get(
const obj&,
const col_key& col_key);
105 [[nodiscard]] object_id get(
const obj&,
const col_key& col_key);
107 [[nodiscard]] decimal128 get(
const obj&,
const col_key& col_key);
109 [[nodiscard]] binary get(
const obj&,
const col_key& col_key);
111 [[nodiscard]] timestamp get(
const obj&,
const col_key& col_key);
113 [[nodiscard]] int64_t get(
const obj&,
const col_key& col_key);
115 [[nodiscard]]
double get(
const obj&,
const col_key& col_key);
117 [[nodiscard]]
bool get(
const obj&,
const col_key& col_key);
119 [[nodiscard]] mixed get(
const obj&,
const col_key& col_key);
121 [[nodiscard]] core_dictionary get(
const obj&,
const col_key& col_key);
126 obj& operator=(
const obj& other) ;
128 obj& operator=(
obj&& other);
131 operator Obj()
const;
132 [[nodiscard]]
table get_table()
const noexcept;
133 [[nodiscard]]
table get_target_table(
col_key)
const noexcept;
135 [[nodiscard]]
bool is_valid()
const;
137 template <
typename T>
139 return internal::bridge::get<T>(*
this,
col_key);
142 template <
typename T>
147 return internal::bridge::get<T>(*
this,
col_key);
161 void set(
const col_key&
col_key,
const std::chrono::time_point<std::chrono::system_clock>& value);
163 std::enable_if_t<std::is_enum_v<T>>
set(
const col_key&
col_key,
const T& value) {
175 void set_list_values(
const col_key&
col_key,
const std::vector<obj_key>& values);
176 void set_list_values(
const col_key&
col_key,
const std::vector<std::string>& values);
177 void set_list_values(
const col_key&
col_key,
const std::vector<bool>& values);
178 void set_list_values(
const col_key&
col_key,
const std::vector<int64_t>& values);
179 void set_list_values(
const col_key&
col_key,
const std::vector<double>& values);
180 void set_list_values(
const col_key&
col_key,
const std::vector<internal::bridge::uuid>& values);
181 void set_list_values(
const col_key&
col_key,
const std::vector<internal::bridge::object_id>& values);
182 void set_list_values(
const col_key&
col_key,
const std::vector<internal::bridge::decimal128>& values);
183 void set_list_values(
const col_key&
col_key,
const std::vector<binary>& values);
184 void set_list_values(
const col_key&
col_key,
const std::vector<mixed>& values);
185 void set_list_values(
const col_key&
col_key,
const std::vector<timestamp>& values);
187 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<int64_t>>& values);
188 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<bool>>& values);
189 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<double>>& values);
190 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<std::string>>& values);
191 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<obj_key>>& values);
192 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<internal::bridge::uuid>>& values);
193 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<internal::bridge::object_id>>& values);
194 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<binary>>& values);
195 void set_list_values(
const col_key&
col_key,
const std::vector<std::optional<timestamp>>& values);
197 template <
typename ValueType>
198 void set_list_values(
const col_key&
col_key,
const std::vector<ValueType>& values) {
199 std::vector<typename internal::type_info::type_info<ValueType, void>::internal_type> v2;
200 for (
auto v : values) {
201 if constexpr (std::is_pointer_v<ValueType>) {
207 m_obj = m_obj = this->get_table().create_object();
209 std::apply([&m_obj, &v](
auto && ...p) {
210 (
accessor<
typename std::decay_t<
decltype(p)>::Result,
void>::set(
211 m_obj, m_obj.get_table().get_column_key(p.name),
212 (*v).*(std::decay_t<
decltype(p)>::ptr)), ...);
214 v2.push_back(m_obj.get_key());
216 v2.push_back(::realm::serialize(v));
222 [[nodiscard]]
obj_key get_key()
const;
223 [[nodiscard]]
obj_link get_link()
const;
227 obj create_and_set_linked_object(
const col_key&);
229 void to_json(std::ostream& out)
const noexcept;
231 inline const Obj* get_obj()
const;
232 inline Obj* get_obj();
233 friend inline const Obj* get_obj(
const obj&);
234 friend inline Obj* get_obj(
obj&);
235 template <
typename T>
237#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
238 storage::Obj m_obj[1];
240 std::shared_ptr<Obj> m_obj;
246 table get_table(uint32_t table_key);
247 table get_table(
const std::string& table_key);
249 std::reference_wrapper<realm> m_realm;
252 std::string table_name_for_object_type(
const std::string&);
Definition: accessors.hpp:33
Definition: binary.hpp:30
Definition: col_key.hpp:28
Definition: dictionary.hpp:106
Definition: decimal128.hpp:30
Definition: lnklst.hpp:33
Definition: obj_key.hpp:33
Definition: obj_key.hpp:53
Definition: object_id.hpp:31
Definition: timestamp.hpp:30