Realm C++ SDK Version v2.2.0

list.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_BRIDGE_LIST_HPP
20#define CPPREALM_BRIDGE_LIST_HPP
21
22#include <cstdlib>
23#include <string>
24#include <memory>
25#include <optional>
26#include <cpprealm/internal/bridge/utils.hpp>
27
28namespace realm {
29 class List;
30}
31
32namespace realm::internal::bridge {
33 struct realm;
34 struct obj;
35 struct obj_key;
36 struct mixed;
37 struct binary;
38 struct uuid;
39 struct object_id;
40 struct decimal128;
41 struct col_key;
42 struct timestamp;
43 struct table;
44 struct notification_token;
45 struct collection_change_callback;
46 struct results;
47 struct sort_descriptor;
48
49 struct list {
50 list();
51 list(const list& other) ;
52 list& operator=(const list& other) ;
53 list(list&& other);
54 list& operator=(list&& other);
55 ~list();
56 list(const List&); //NOLINT(google-explicit-constructor)
57 operator List() const; //NOLINT(google-explicit-constructor)
58 list(const realm& realm, const obj& obj, const col_key&);
59
60 [[nodiscard]] size_t size() const;
61 void remove(size_t idx);
62 void remove_all();
63
64 table get_table() const;
65
66 void add(const std::string&);
67 void add(const int64_t &);
68 void add(const double &);
69 void add(const bool &);
70 void add(const binary &);
71 void add(const uuid &);
72 void add(const object_id &);
73 void add(const decimal128 &);
74 void add(const mixed &);
75 void add(const obj_key &);
76 void add(const timestamp &);
77 obj add_embedded();
78
79 void set(size_t pos, const int64_t &);
80 void set(size_t pos, const double &);
81 void set(size_t pos, const bool &);
82 void set(size_t pos, const std::string &);
83 void set(size_t pos, const uuid &);
84 void set(size_t pos, const object_id &);
85 void set(size_t pos, const decimal128 &);
86 void set(size_t pos, const mixed &);
87 void set(size_t pos, const timestamp &);
88 void set(size_t pos, const binary &);
89
90 size_t find(const int64_t &);
91 size_t find(const bool &);
92 size_t find(const double &);
93 size_t find(const std::string &);
94 size_t find(const uuid &);
95 size_t find(const object_id &);
96 size_t find(const decimal128 &);
97 size_t find(const mixed &);
98 size_t find(const timestamp &);
99 size_t find(const binary&);
100 size_t find(const obj_key&);
101
102 results sort(const std::vector<sort_descriptor>&);
103 [[nodiscard]] results as_results() const;
104
105 notification_token add_notification_callback(std::shared_ptr<collection_change_callback>);
106 private:
107 template <typename ValueType>
108 friend ValueType get(const list&, size_t idx);
109 friend inline List* get_list(list& lst);
110 friend inline const List* get_list(const list& lst);
111 inline ::realm::List* get_list();
112 inline const ::realm::List* get_list() const;
113#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
114 storage::List m_list[1];
115#else
116 std::shared_ptr<::realm::List> m_list;
117#endif
118 };
119
120 template <typename ValueType>
121 [[nodiscard]] ValueType get(const list&, size_t idx);
122 template <>
123 [[nodiscard]] std::string get(const list&, size_t idx);
124 template <>
125 [[nodiscard]] int64_t get(const list&, size_t idx);
126 template <>
127 [[nodiscard]] double get(const list&, size_t idx);
128 template <>
129 [[nodiscard]] binary get(const list&, size_t idx);
130 template <>
131 [[nodiscard]] uuid get(const list&, size_t idx);
132 template <>
133 [[nodiscard]] object_id get(const list&, size_t idx);
134 template <>
135 [[nodiscard]] decimal128 get(const list&, size_t idx);
136 template <>
137 [[nodiscard]] mixed get(const list&, size_t idx);
138 template <>
139 [[nodiscard]] obj get(const list&, size_t idx);
140
141 template <>
142 [[nodiscard]] std::optional<int64_t> get(const list& lst, size_t idx);
143 template <>
144 [[nodiscard]] std::optional<double> get(const list& lst, size_t idx);
145 template <>
146 [[nodiscard]] std::optional<bool> get(const list& lst, size_t idx);
147 template <>
148 [[nodiscard]] std::optional<uuid> get(const list& lst, size_t idx);
149 template <>
150 [[nodiscard]] std::optional<object_id> get(const list& lst, size_t idx);
151 template <>
152 [[nodiscard]] std::optional<std::string> get(const list& lst, size_t idx);
153 template <>
154 [[nodiscard]] std::optional<binary> get(const list& lst, size_t idx);
155 template <>
156 [[nodiscard]] std::optional<timestamp> get(const list& lst, size_t idx);
157}
158
159#endif //CPPREALM_BRIDGE_LIST_HPP
Definition: binary.hpp:30
Definition: col_key.hpp:28
Definition: decimal128.hpp:30
Definition: list.hpp:49
Definition: mixed.hpp:69
Definition: obj_key.hpp:33
Definition: obj.hpp:123
Definition: object_id.hpp:31
Definition: realm.hpp:67
Definition: results.hpp:46
Definition: set.hpp:48
Definition: table.hpp:40
Definition: timestamp.hpp:30
Definition: uuid.hpp:32