Realm C++ SDK Version v2.2.0

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