Realm C++ SDK Version v2.2.0

managed_binary.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_BINARY_HPP
20#define CPPREALM_MANAGED_BINARY_HPP
21
22#include <cpprealm/macros.hpp>
23#include <cpprealm/types.hpp>
24
25namespace realm {
26 class rbool;
27}
28
29namespace realm {
30
31 template<>
32 struct managed<std::vector<uint8_t>> : managed_base {
33 using managed<std::vector<uint8_t>>::managed_base::operator=;
34
35 [[nodiscard]] std::vector<uint8_t> detach() const;
36 [[nodiscard]] operator std::vector<uint8_t>() const;
37
38 std::vector<uint8_t> operator*() const;
39 void push_back(uint8_t v);
40 uint8_t operator[](uint8_t idx) const;
41 size_t size() const;
42
43 //MARK: - comparison operators
44 rbool operator==(const std::vector<uint8_t>& rhs) const noexcept;
45 rbool operator!=(const std::vector<uint8_t>& rhs) const noexcept;
46
47 private:
48 managed() = default;
49 managed(const managed&) = delete;
50 managed(managed &&) = delete;
51 managed& operator=(const managed&) = delete;
52 managed& operator=(managed&&) = delete;
53 template<typename, typename>
54 friend struct managed;
55 };
56
57 template<>
58 struct managed<std::optional<std::vector<uint8_t>>> : managed_base {
59 using managed<std::optional<std::vector<uint8_t>>>::managed_base::operator=;
60
61 [[nodiscard]] std::optional<std::vector<uint8_t>> detach() const;
62 [[nodiscard]] operator std::optional<std::vector<uint8_t>>() const;
63
64 struct box {
65 std::optional<std::vector<uint8_t>> operator*() const;
66 void push_back(uint8_t v);
67 uint8_t operator[](uint8_t idx) const;
68 size_t size() const;
69 private:
70 box(managed& parent) : m_parent(parent) { }
71 std::reference_wrapper<managed<std::optional<std::vector<uint8_t>>>> m_parent;
72 friend struct managed<std::optional<std::vector<uint8_t>>>;
73 };
74
75 std::unique_ptr<box> operator->()
76 {
77 return std::make_unique<box>(box(*this));
78 }
79 [[nodiscard]] box operator*() {
80 return box(*this);
81 }
82
83 //MARK: - comparison operators
84 rbool operator==(const std::optional<std::vector<uint8_t>>& rhs) const noexcept;
85 rbool operator!=(const std::optional<std::vector<uint8_t>>& 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
98
99#endif//CPPREALM_MANAGED_BINARY_HPP
Definition: rbool.hpp:36
Definition: managed_dictionary.hpp:129
Definition: macros.hpp:286
Definition: obj.hpp:62