• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / github_pull_request_281750

30 Oct 2023 03:37PM UTC coverage: 90.528% (-1.0%) from 91.571%
github_pull_request_281750

Pull #6073

Evergreen

jedelbo
Log free space and history sizes when opening file
Pull Request #6073: Merge next-major

95488 of 175952 branches covered (0.0%)

8973 of 12277 new or added lines in 149 files covered. (73.09%)

622 existing lines in 51 files now uncovered.

233503 of 257934 relevant lines covered (90.53%)

6533720.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.23
/src/realm/object-store/c_api/list.cpp
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 utilied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#include <realm/object-store/c_api/types.hpp>
20
#include <realm/object-store/c_api/util.hpp>
21

22
namespace realm::c_api {
23

24
RLM_API bool realm_list_size(const realm_list_t* list, size_t* out_size)
25
{
38✔
26
    return wrap_err([&]() {
38✔
27
        size_t size = list->size();
38✔
28
        if (out_size)
38✔
29
            *out_size = size;
36✔
30
        return true;
38✔
31
    });
38✔
32
}
38✔
33

34
RLM_API bool realm_list_get_property(const realm_list_t* list, realm_property_info_t* out_property_info)
35
{
×
36
    static_cast<void>(list);
×
37
    static_cast<void>(out_property_info);
×
38
    REALM_TERMINATE("Not implemented yet.");
×
39
}
×
40

41
RLM_API bool realm_list_get(const realm_list_t* list, size_t index, realm_value_t* out_value)
42
{
132✔
43
    return wrap_err([&]() {
132✔
44
        list->verify_attached();
132✔
45
        auto mixed = list->get_any(index);
132✔
46

66✔
47
        if (out_value) {
132✔
48
            *out_value = to_capi(mixed);
130✔
49
        }
130✔
50
        return true;
132✔
51
    });
132✔
52
}
132✔
53

54
RLM_API bool realm_list_find(const realm_list_t* list, const realm_value_t* value, size_t* out_index, bool* out_found)
55
{
64✔
56
    if (out_index)
64✔
57
        *out_index = realm::not_found;
64✔
58
    if (out_found)
64✔
59
        *out_found = false;
64✔
60

32✔
61
    return wrap_err([&] {
64✔
62
        list->verify_attached();
64✔
63
        auto val = from_capi(*value);
64✔
64
        check_value_assignable(*list, val);
64✔
65
        auto index = list->find_any(val);
64✔
66
        if (out_index)
64✔
67
            *out_index = index;
64✔
68
        if (out_found)
64✔
69
            *out_found = index < list->size();
64✔
70
        return true;
64✔
71
    });
64✔
72
}
64✔
73

74

75
RLM_API bool realm_list_insert(realm_list_t* list, size_t index, realm_value_t value)
76
{
202✔
77
    return wrap_err([&]() {
202✔
78
        auto val = from_capi(value);
202✔
79
        check_value_assignable(*list, val);
202✔
80

101✔
81
        list->insert_any(index, val);
202✔
82
        return true;
202✔
83
    });
202✔
84
}
202✔
85

86
RLM_API realm_list_t* realm_list_insert_list(realm_list_t* list, size_t index)
87
{
6✔
88
    return wrap_err([&]() {
6✔
89
        list->insert_collection(index, CollectionType::List);
6✔
90
        return new realm_list_t{list->get_list(index)};
6✔
91
    });
6✔
92
}
6✔
93

94
RLM_API realm_set_t* realm_list_insert_set(realm_list_t* list, size_t index)
95
{
4✔
96
    return wrap_err([&]() {
4✔
97
        list->insert_collection(index, CollectionType::Set);
4✔
98
        return new realm_set_t{list->get_set(index)};
4✔
99
    });
4✔
100
}
4✔
101

102
RLM_API realm_dictionary_t* realm_list_insert_dictionary(realm_list_t* list, size_t index)
103
{
4✔
104
    return wrap_err([&]() {
4✔
105
        list->insert_collection(index, CollectionType::Dictionary);
4✔
106
        return new realm_dictionary_t{list->get_dictionary(index)};
4✔
107
    });
4✔
108
}
4✔
109

110
RLM_API realm_list_t* realm_list_set_list(realm_list_t* list, size_t index)
111
{
4✔
112
    return wrap_err([&]() {
4✔
113
        list->set_collection(index, CollectionType::List);
4✔
114
        return new realm_list_t{list->get_list(index)};
4✔
115
    });
4✔
116
}
4✔
117

118
RLM_API realm_set_t* realm_list_set_set(realm_list_t* list, size_t index)
119
{
2✔
120
    return wrap_err([&]() {
2✔
121
        list->set_collection(index, CollectionType::Set);
2✔
122
        return new realm_set_t{list->get_set(index)};
2✔
123
    });
2✔
124
}
2✔
125

126
RLM_API realm_dictionary_t* realm_list_set_dictionary(realm_list_t* list, size_t index)
127
{
2✔
128
    return wrap_err([&]() {
2✔
129
        list->set_collection(index, CollectionType::Dictionary);
2✔
130
        return new realm_dictionary_t{list->get_dictionary(index)};
2✔
131
        ;
1✔
NEW
132
    });
×
133
}
2✔
134

135

136
RLM_API realm_list_t* realm_list_get_list(realm_list_t* list, size_t index)
137
{
2✔
138
    return wrap_err([&]() {
2✔
139
        return new realm_list_t{list->get_list(index)};
2✔
140
    });
2✔
141
}
2✔
142

143
RLM_API realm_set_t* realm_list_get_set(realm_list_t* list, size_t index)
144
{
2✔
145
    return wrap_err([&]() {
2✔
146
        return new realm_set_t{list->get_set(index)};
2✔
147
    });
2✔
148
}
2✔
149

150
RLM_API realm_dictionary_t* realm_list_get_dictionary(realm_list_t* list, size_t index)
151
{
2✔
152
    return wrap_err([&]() {
2✔
153
        return new realm_dictionary_t{list->get_dictionary(index)};
2✔
154
    });
2✔
155
}
2✔
156

157
RLM_API bool realm_list_move(realm_list_t* list, size_t from_index, size_t to_index)
158
{
4✔
159
    return wrap_err([&]() {
4✔
160
        list->move(from_index, to_index);
4✔
161
        return true;
4✔
162
    });
4✔
163
}
4✔
164

165

166
RLM_API bool realm_list_set(realm_list_t* list, size_t index, realm_value_t value)
167
{
6✔
168
    return wrap_err([&]() {
6✔
169
        auto val = from_capi(value);
6✔
170
        check_value_assignable(*list, val);
6✔
171

3✔
172
        list->set_any(index, val);
6✔
173
        return true;
6✔
174
    });
6✔
175
}
6✔
176

177
RLM_API realm_object_t* realm_list_insert_embedded(realm_list_t* list, size_t index)
178
{
2✔
179
    return wrap_err([&]() {
2✔
180
        return new realm_object_t({list->get_realm(), list->insert_embedded(index)});
2✔
181
    });
2✔
182
}
2✔
183

184
RLM_API realm_object_t* realm_list_set_embedded(realm_list_t* list, size_t index)
185
{
×
186
    return wrap_err([&]() {
×
187
        list->verify_attached();
×
188
        return new realm_object_t({list->get_realm(), list->set_embedded(index)});
×
189
    });
×
190
}
×
191

192
RLM_API realm_object_t* realm_list_get_linked_object(realm_list_t* list, size_t index)
193
{
4✔
194
    return wrap_err([&]() {
4✔
195
        list->verify_attached();
4✔
196
        auto o = list->get_object(index);
4✔
197
        return o ? new realm_object_t({list->get_realm(), o}) : nullptr;
3✔
198
    });
4✔
199
}
4✔
200

201
RLM_API bool realm_list_erase(realm_list_t* list, size_t index)
202
{
2✔
203
    return wrap_err([&]() {
2✔
204
        list->remove(index);
2✔
205
        return true;
2✔
206
    });
2✔
207
}
2✔
208

209
RLM_API bool realm_list_clear(realm_list_t* list)
210
{
14✔
211
    return wrap_err([&]() {
14✔
212
        // Note: Confusing naming.
7✔
213
        list->remove_all();
14✔
214
        return true;
14✔
215
    });
14✔
216
}
14✔
217

218
RLM_API bool realm_list_remove_all(realm_list_t* list)
219
{
2✔
220
    return wrap_err([&]() {
2✔
221
        // Note: Confusing naming.
1✔
222
        list->delete_all();
2✔
223
        return true;
2✔
224
    });
2✔
225
}
2✔
226

227
RLM_API realm_list_t* realm_list_from_thread_safe_reference(const realm_t* realm, realm_thread_safe_reference_t* tsr)
228
{
4✔
229
    return wrap_err([&]() {
4✔
230
        auto ltsr = dynamic_cast<realm_list::thread_safe_reference*>(tsr);
4✔
231
        if (!ltsr) {
4✔
232
            throw LogicError{ErrorCodes::IllegalOperation, "Thread safe reference type mismatch"};
2✔
233
        }
2✔
234

1✔
235
        auto list = ltsr->resolve<List>(*realm);
2✔
236
        return new realm_list_t{std::move(list)};
2✔
237
    });
2✔
238
}
4✔
239

240
RLM_API bool realm_list_resolve_in(const realm_list_t* from_list, const realm_t* target_realm,
241
                                   realm_list_t** resolved)
242
{
8✔
243
    return wrap_err([&]() {
8✔
244
        try {
8✔
245
            const auto& realm = *target_realm;
8✔
246
            auto frozen_list = from_list->freeze(realm);
8✔
247
            if (frozen_list.is_valid()) {
8✔
248
                *resolved = new realm_list_t{std::move(frozen_list)};
6✔
249
            }
6✔
250
            else {
2✔
251
                *resolved = nullptr;
2✔
252
            }
2✔
253
            return true;
8✔
254
        }
8✔
255
        catch (NoSuchTable&) {
×
256
            *resolved = nullptr;
×
257
            return true;
×
258
        }
×
259
        catch (KeyNotFound&) {
×
260
            *resolved = nullptr;
×
261
            return true;
×
262
        }
×
263
    });
8✔
264
}
8✔
265

266
RLM_API bool realm_list_is_valid(const realm_list_t* list)
267
{
6✔
268
    if (!list)
6✔
269
        return false;
×
270
    return list->is_valid();
6✔
271
}
6✔
272

273
} // namespace realm::c_api
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc