Realm C++ SDK Version v2.2.0

managed_uuid.hpp

1
2//
3// Copyright 2022 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_MANAGED_UUID_HPP
20#define CPPREALM_MANAGED_UUID_HPP
21
22#include <cpprealm/macros.hpp>
23#include <cpprealm/types.hpp>
24
25namespace realm {
26 class rbool;
27}
28namespace realm {
29
30 template<>
31 struct managed<realm::uuid> : managed_base {
32 using value_type = realm::uuid;
33 using managed<realm::uuid>::managed_base::operator=;
34
35 [[nodiscard]] realm::uuid detach() const {
36 return m_obj->template get<realm::internal::bridge::uuid>(m_key).operator ::realm::uuid();
37 }
38
39 [[nodiscard]] realm::uuid operator *() const {
40 return detach();
41 }
42
43 [[nodiscard]] operator realm::uuid() const {
44 return detach();
45 }
46
47 //MARK: - comparison operators
48 rbool operator==(const realm::uuid& rhs) const noexcept;
49 rbool operator!=(const realm::uuid& rhs) const noexcept;
50
51 private:
52 managed() = default;
53 managed(const managed&) = delete;
54 managed(managed &&) = delete;
55 managed& operator=(const managed&) = delete;
56 managed& operator=(managed&&) = delete;
57 template<typename, typename>
58 friend struct managed;
59 };
60
61 template<>
62 struct managed<std::optional<realm::uuid>> : managed_base {
63 using value_type = std::optional<realm::uuid>;
64 using managed<std::optional<realm::uuid>>::managed_base::operator=;
65
66 [[nodiscard]] std::optional<realm::uuid> detach() const {
67 auto v = m_obj->template get_optional<realm::internal::bridge::uuid>(m_key);
68 if (v) {
69 return v.value().operator ::realm::uuid();
70 } else {
71 return std::nullopt;
72 }
73 }
74
75 [[nodiscard]] std::optional<realm::uuid> operator *() const {
76 return detach();
77 }
78
79 [[nodiscard]] operator std::optional<realm::uuid>() const {
80 return detach();
81 }
82
83 //MARK: - comparison operators
84 rbool operator==(const std::optional<realm::uuid>& rhs) const noexcept;
85 rbool operator!=(const std::optional<realm::uuid>& rhs) const noexcept;
86
87 private:
88 managed() = default;
89 managed(const managed&) = delete;
90 managed(managed &&) = delete;
91 managed& operator=(const managed&) = delete;
92 managed& operator=(managed&&) = delete;
93 template<typename, typename>
94 friend struct managed;
95 };
96
97} // namespace realm
98
99
100#endif//CPPREALM_MANAGED_UUID_HPP
Definition: rbool.hpp:36
Definition: macros.hpp:286
Definition: obj.hpp:62
Definition: types.hpp:35