19#ifndef CPPREALM_MANAGED_PRIMARY_KEY_HPP
20#define CPPREALM_MANAGED_PRIMARY_KEY_HPP
22#include <cpprealm/macros.hpp>
23#include <cpprealm/rbool.hpp>
26 template <
typename,
typename>
36 using internal_type = T;
44 using internal_type = int64_t;
53 operator int64_t()
const {
73 using internal_type = std::string;
82 operator std::string()
const {
95 operator uuid()
const {
102 using internal_type = std::optional<int64_t>;
119 std::optional<int64_t> value;
120 operator std::optional<int64_t>()
const {
127 using internal_type = std::optional<internal::bridge::object_id>;
138 std::optional<object_id> value;
139 operator std::optional<object_id>()
const {
146 using internal_type = std::optional<std::string>;
160 std::optional<std::string> value;
161 operator std::optional<std::string>()
const {
168 using internal_type = std::optional<internal::bridge::uuid>;
179 std::optional<uuid> value;
180 operator std::optional<uuid>()
const {
188 return operator int64_t();
191 operator int64_t()
const {
192 return m_obj->template get<int64_t>(m_key);
195 rbool operator==(
const int64_t& rhs)
const noexcept;
196 rbool operator!=(
const int64_t& rhs)
const noexcept;
197 rbool operator>(
const int64_t& rhs)
const noexcept;
198 rbool operator>=(
const int64_t& rhs)
const noexcept;
199 rbool operator<(
const int64_t& rhs)
const noexcept;
200 rbool operator<=(
const int64_t& rhs)
const noexcept;
201 rbool operator==(
const int& rhs)
const noexcept;
202 rbool operator!=(
const int& rhs)
const noexcept;
203 rbool operator>(
const int& rhs)
const noexcept;
204 rbool operator>=(
const int& rhs)
const noexcept;
205 rbool operator<(
const int& rhs)
const noexcept;
206 rbool operator<=(
const int& rhs)
const noexcept;
214 template<
typename,
typename>
221 return operator std::string();
224 operator std::string()
const {
225 return m_obj->template get<std::string>(m_key);
228 rbool operator==(
const std::string& rhs)
const noexcept;
229 rbool operator!=(
const std::string& rhs)
const noexcept;
230 rbool operator==(
const char* rhs)
const noexcept;
231 rbool operator!=(
const char* rhs)
const noexcept;
239 template<
typename,
typename>
250 return m_obj->template get<internal::bridge::uuid>(m_key).operator ::realm::uuid();
262 template<
typename,
typename>
273 return m_obj->template get<internal::bridge::object_id>(m_key).operator ::realm::object_id();
285 template<
typename,
typename>
296 return static_cast<T
>(m_obj->template get<int64_t>(m_key));
299 rbool operator==(
const T& rhs)
const noexcept {
300 if (this->m_rbool_query) {
301 return this->m_rbool_query->equal(m_key, serialize(rhs));
303 return serialize(detach().value) == serialize(rhs);
305 rbool operator!=(
const T& rhs)
const noexcept {
306 if (this->m_rbool_query) {
307 return this->m_rbool_query->not_equal(m_key, serialize(rhs));
309 return serialize(detach().value) != serialize(rhs);
318 template<
typename,
typename>
325 return operator std::optional<int64_t>();
328 operator std::optional<int64_t>()
const {
329 return m_obj->get_optional<int64_t>(m_key);
332 rbool operator==(
const std::optional<int64_t>& rhs)
const noexcept;
333 rbool operator!=(
const std::optional<int64_t>& rhs)
const noexcept;
334 rbool operator>(
const int64_t& rhs)
const noexcept;
335 rbool operator>=(
const int64_t& rhs)
const noexcept;
336 rbool operator<(
const int64_t& rhs)
const noexcept;
337 rbool operator<=(
const int64_t& rhs)
const noexcept;
338 rbool operator>(
const int& rhs)
const noexcept;
339 rbool operator>=(
const int& rhs)
const noexcept;
340 rbool operator<(
const int& rhs)
const noexcept;
341 rbool operator<=(
const int& rhs)
const noexcept;
348 template<
typename,
typename>
353 struct managed<
primary_key<T>, std::enable_if_t<std::conjunction_v<typename internal::type_info::is_optional<T>,
354 std::is_enum<typename T::value_type> >>> final :
managed_base {
360 auto v = m_obj->get_optional<int64_t>(m_key);
362 return static_cast<typename T::value_type
>(*v);
368 rbool operator==(
const T& rhs)
const noexcept {
369 if (this->m_rbool_query) {
370 return this->m_rbool_query->equal(m_key, serialize(rhs));
372 return serialize(detach().value) == serialize(rhs);
374 rbool operator!=(
const T& rhs)
const noexcept {
375 if (this->m_rbool_query) {
376 return this->m_rbool_query->not_equal(m_key, serialize(rhs));
378 return serialize(detach().value) != serialize(rhs);
387 template<
typename,
typename>
394 return operator std::optional<std::string>();
397 operator std::optional<std::string>()
const {
398 return m_obj->get_optional<std::string>(m_key);
401 rbool operator==(
const std::optional<std::string>& rhs)
const noexcept;
402 rbool operator!=(
const std::optional<std::string>& rhs)
const noexcept;
403 rbool operator==(
const char* rhs)
const noexcept;
404 rbool operator!=(
const char* rhs)
const noexcept;
412 template<
typename,
typename>
419 return operator std::optional<realm::uuid>();
422 operator std::optional<realm::uuid>()
const {
425 return v->operator ::realm::uuid();
430 rbool operator==(
const std::optional<realm::uuid>& rhs)
const noexcept;
431 rbool operator!=(
const std::optional<realm::uuid>& rhs)
const noexcept;
439 template<
typename,
typename>
445 std::optional<realm::object_id> detach()
const {
446 return operator std::optional<realm::object_id>();
449 operator std::optional<realm::object_id>()
const {
452 return v->operator ::realm::object_id();
457 rbool operator==(
const std::optional<realm::object_id>& rhs)
const noexcept;
458 rbool operator!=(
const std::optional<realm::object_id>& rhs)
const noexcept;
466 template<
typename,
typename>
Definition: object_id.hpp:31
Definition: macros.hpp:286
Definition: managed_primary_key.hpp:43
Definition: managed_primary_key.hpp:72
Definition: managed_primary_key.hpp:30