• 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

79.37
/src/realm/object-store/c_api/conversion.hpp
1
#ifndef REALM_OBJECT_STORE_C_API_CONVERSION_HPP
2
#define REALM_OBJECT_STORE_C_API_CONVERSION_HPP
3

4
#include <realm.h>
5

6
#include <realm/object-store/property.hpp>
7
#include <realm/object-store/schema.hpp>
8
#include <realm/object-store/object_schema.hpp>
9
#include <realm/object-store/shared_realm.hpp>
10

11
#include <realm/string_data.hpp>
12
#include <realm/binary_data.hpp>
13
#include <realm/timestamp.hpp>
14
#include <realm/decimal128.hpp>
15
#include <realm/object_id.hpp>
16
#include <realm/mixed.hpp>
17
#include <realm/uuid.hpp>
18

19
#include <string>
20

21
namespace realm::c_api {
22

23
static inline realm_string_t to_capi(StringData data)
24
{
104✔
25
    return realm_string_t{data.data(), data.size()};
104✔
26
}
104✔
27

28
// Because this is often used as `return to_capi(...);` it is dangerous to pass a temporary string here. If you really
29
// need to and know it is correct (eg passing to a C callback), you can explicitly create the StringData wrapper.
30
realm_string_t to_capi(const std::string&& str) = delete; // temporary std::string would dangle.
31

32
static inline realm_string_t to_capi(const std::string& str)
33
{
×
34
    return to_capi(StringData{str});
×
35
}
×
36

37
static inline realm_string_t to_capi(std::string_view str_view)
38
{
×
39
    return realm_string_t{str_view.data(), str_view.size()};
×
40
}
×
41

42
static inline StringData from_capi(realm_string_t str)
43
{
706✔
44
    return StringData{str.data, str.size};
706✔
45
}
706✔
46

47
static inline realm_binary_t to_capi(BinaryData bin)
48
{
20✔
49
    return realm_binary_t{reinterpret_cast<const unsigned char*>(bin.data()), bin.size()};
20✔
50
}
20✔
51

52
static inline BinaryData from_capi(realm_binary_t bin)
53
{
26✔
54
    return BinaryData{reinterpret_cast<const char*>(bin.data), bin.size};
26✔
55
}
26✔
56

57
static inline realm_timestamp_t to_capi(Timestamp ts)
58
{
24✔
59
    return realm_timestamp_t{ts.get_seconds(), ts.get_nanoseconds()};
24✔
60
}
24✔
61

62
static inline Timestamp from_capi(realm_timestamp_t ts)
63
{
26✔
64
    return Timestamp{ts.seconds, ts.nanoseconds};
26✔
65
}
26✔
66

67
static inline realm_decimal128_t to_capi(const Decimal128& dec)
68
{
20✔
69
    auto raw = dec.raw();
20✔
70
    return realm_decimal128_t{{raw->w[0], raw->w[1]}};
20✔
71
}
20✔
72

73
static inline Decimal128 from_capi(realm_decimal128_t dec)
74
{
34✔
75
    return Decimal128{Decimal128::Bid128{{dec.w[0], dec.w[1]}}};
34✔
76
}
34✔
77

78
static inline realm_object_id_t to_capi(ObjectId object_id)
79
{
30✔
80
    realm_object_id_t result;
30✔
81
    auto bytes = object_id.to_bytes();
30✔
82
    std::copy(bytes.begin(), bytes.end(), result.bytes);
30✔
83
    return result;
30✔
84
}
30✔
85

86
static inline ObjectId from_capi(realm_object_id_t object_id)
87
{
34✔
88
    static_assert(ObjectId::num_bytes == 12);
34✔
89
    ObjectId::ObjectIdBytes bytes;
34✔
90
    std::copy(object_id.bytes, object_id.bytes + 12, bytes.begin());
34✔
91
    return ObjectId(bytes);
34✔
92
}
34✔
93

94
static inline ObjLink from_capi(realm_link_t val)
95
{
4✔
96
    return ObjLink{TableKey(val.target_table), ObjKey(val.target)};
4✔
97
}
4✔
98

99
static inline realm_link_t to_capi(ObjLink link)
100
{
8✔
101
    return realm_link_t{link.get_table_key().value, link.get_obj_key().value};
8✔
102
}
8✔
103

104
static inline UUID from_capi(realm_uuid_t val)
105
{
26✔
106
    static_assert(sizeof(val.bytes) == UUID::num_bytes);
26✔
107
    UUID::UUIDBytes bytes;
26✔
108
    std::copy(val.bytes, val.bytes + UUID::num_bytes, bytes.data());
26✔
109
    return UUID{bytes};
26✔
110
}
26✔
111

112
static inline realm_uuid_t to_capi(UUID val)
113
{
20✔
114
    realm_uuid_t uuid;
20✔
115
    auto bytes = val.to_bytes();
20✔
116
    std::copy(bytes.data(), bytes.data() + UUID::num_bytes, uuid.bytes);
20✔
117
    return uuid;
20✔
118
}
20✔
119

120
static inline Mixed from_capi(realm_value_t val)
121
{
2,682✔
122
    switch (val.type) {
2,682✔
123
        case RLM_TYPE_NULL:
204✔
124
            return Mixed{};
204✔
125
        case RLM_TYPE_INT:
1,574✔
126
            return Mixed{val.integer};
1,574✔
127
        case RLM_TYPE_BOOL:
24✔
128
            return Mixed{val.boolean};
24✔
129
        case RLM_TYPE_STRING:
596✔
130
            return Mixed{from_capi(val.string)};
596✔
131
        case RLM_TYPE_BINARY:
24✔
132
            return Mixed{from_capi(val.binary)};
24✔
133
        case RLM_TYPE_TIMESTAMP:
24✔
134
            return Mixed{from_capi(val.timestamp)};
24✔
135
        case RLM_TYPE_FLOAT:
24✔
136
            return Mixed{val.fnum};
24✔
137
        case RLM_TYPE_DOUBLE:
30✔
138
            return Mixed{val.dnum};
30✔
139
        case RLM_TYPE_DECIMAL128:
28✔
140
            return Mixed{from_capi(val.decimal128)};
28✔
141
        case RLM_TYPE_OBJECT_ID:
28✔
142
            return Mixed{from_capi(val.object_id)};
28✔
143
        case RLM_TYPE_LINK:
102✔
144
            return Mixed{ObjLink{TableKey(val.link.target_table), ObjKey(val.link.target)}};
102✔
145
        case RLM_TYPE_UUID:
24✔
146
            return Mixed{UUID{from_capi(val.uuid)}};
24✔
NEW
147
        case RLM_TYPE_LIST:
✔
NEW
148
            return Mixed{0, CollectionType::List};
×
NEW
149
        case RLM_TYPE_SET:
✔
NEW
150
            return Mixed{0, CollectionType::Set};
×
NEW
151
        case RLM_TYPE_DICTIONARY:
✔
NEW
152
            return Mixed{0, CollectionType::Dictionary};
×
153
    }
×
154
    REALM_TERMINATE("Invalid realm_value_t"); // LCOV_EXCL_LINE
×
155
}
×
156

157
static inline realm_value_t to_capi(Mixed value)
158
{
466✔
159
    realm_value_t val;
466✔
160
    if (value.is_null()) {
466✔
161
        val.type = RLM_TYPE_NULL;
90✔
162
    }
90✔
163
    else {
376✔
164
        auto type = value.get_type();
376✔
165
        switch (type) {
376✔
166
            case type_Int: {
110✔
167
                val.type = RLM_TYPE_INT;
110✔
168
                val.integer = value.get<int64_t>();
110✔
169
                break;
110✔
170
            }
×
171
            case type_Bool: {
20✔
172
                val.type = RLM_TYPE_BOOL;
20✔
173
                val.boolean = value.get<bool>();
20✔
174
                break;
20✔
175
            }
×
176
            case type_String: {
60✔
177
                val.type = RLM_TYPE_STRING;
60✔
178
                val.string = to_capi(value.get<StringData>());
60✔
179
                break;
60✔
180
            }
×
181
            case type_Binary: {
20✔
182
                val.type = RLM_TYPE_BINARY;
20✔
183
                val.binary = to_capi(value.get<BinaryData>());
20✔
184
                break;
20✔
185
            }
×
186
            case type_Timestamp: {
20✔
187
                val.type = RLM_TYPE_TIMESTAMP;
20✔
188
                val.timestamp = to_capi(value.get<Timestamp>());
20✔
189
                break;
20✔
190
            }
×
191
            case type_Float: {
20✔
192
                val.type = RLM_TYPE_FLOAT;
20✔
193
                val.fnum = value.get<float>();
20✔
194
                break;
20✔
195
            }
×
196
            case type_Double: {
22✔
197
                val.type = RLM_TYPE_DOUBLE;
22✔
198
                val.dnum = value.get<double>();
22✔
199
                break;
22✔
200
            }
×
201
            case type_Decimal: {
20✔
202
                val.type = RLM_TYPE_DECIMAL128;
20✔
203
                val.decimal128 = to_capi(value.get<Decimal128>());
20✔
204
                break;
20✔
205
            }
×
206
            case type_Link: {
✔
207
                REALM_TERMINATE("Not implemented yet"); // LCOV_EXCL_LINE
×
208
            }
×
209
            case type_ObjectId: {
24✔
210
                val.type = RLM_TYPE_OBJECT_ID;
24✔
211
                val.object_id = to_capi(value.get<ObjectId>());
24✔
212
                break;
24✔
213
            }
×
214
            case type_TypedLink: {
14✔
215
                val.type = RLM_TYPE_LINK;
14✔
216
                auto link = value.get<ObjLink>();
14✔
217
                val.link.target_table = link.get_table_key().value;
14✔
218
                val.link.target = link.get_obj_key().value;
14✔
219
                break;
14✔
220
            }
×
221
            case type_UUID: {
20✔
222
                val.type = RLM_TYPE_UUID;
20✔
223
                auto uuid = value.get<UUID>();
20✔
224
                val.uuid = to_capi(uuid);
20✔
225
                break;
20✔
226
            }
×
227

×
228
            case type_LinkList:
✔
229
            case type_Mixed:
✔
230
                REALM_TERMINATE("Invalid Mixed value type"); // LCOV_EXCL_LINE
×
231
            default:
26✔
232
                if (type == type_List) {
26!
233
                    val.type = RLM_TYPE_LIST;
12✔
234
                }
12✔
235
                else if (type == type_Set) {
14!
236
                    val.type = RLM_TYPE_SET;
6✔
237
                }
6✔
238
                else if (type == type_Dictionary) {
8!
239
                    val.type = RLM_TYPE_DICTIONARY;
8✔
240
                }
8✔
241
        }
376✔
242
    }
376✔
243

233✔
244
    return val;
466✔
245
}
466✔
246

247
static inline SchemaMode from_capi(realm_schema_mode_e mode)
248
{
388✔
249
    switch (mode) {
388✔
250
        case RLM_SCHEMA_MODE_AUTOMATIC:
374✔
251
            return SchemaMode::Automatic;
374✔
252
        case RLM_SCHEMA_MODE_IMMUTABLE:
2✔
253
            return SchemaMode::Immutable;
2✔
254
        case RLM_SCHEMA_MODE_READ_ONLY:
2✔
255
            return SchemaMode::ReadOnly;
2✔
256
        case RLM_SCHEMA_MODE_SOFT_RESET_FILE:
2✔
257
            return SchemaMode::SoftResetFile;
2✔
258
        case RLM_SCHEMA_MODE_HARD_RESET_FILE:
2✔
259
            return SchemaMode::HardResetFile;
2✔
260
        case RLM_SCHEMA_MODE_ADDITIVE_DISCOVERED:
2✔
261
            return SchemaMode::AdditiveDiscovered;
2✔
262
        case RLM_SCHEMA_MODE_ADDITIVE_EXPLICIT:
2✔
263
            return SchemaMode::AdditiveExplicit;
2✔
264
        case RLM_SCHEMA_MODE_MANUAL:
2✔
265
            return SchemaMode::Manual;
2✔
266
    }
×
267
    REALM_TERMINATE("Invalid schema mode."); // LCOV_EXCL_LINE
×
268
}
×
269

270
static inline realm_schema_mode_e to_capi(SchemaMode mode)
271
{
16✔
272
    switch (mode) {
16✔
273
        case SchemaMode::Automatic:
2✔
274
            return RLM_SCHEMA_MODE_AUTOMATIC;
2✔
275
        case SchemaMode::Immutable:
2✔
276
            return RLM_SCHEMA_MODE_IMMUTABLE;
2✔
277
        case SchemaMode::ReadOnly:
2✔
278
            return RLM_SCHEMA_MODE_READ_ONLY;
2✔
279
        case SchemaMode::SoftResetFile:
2✔
280
            return RLM_SCHEMA_MODE_SOFT_RESET_FILE;
2✔
281
        case SchemaMode::HardResetFile:
2✔
282
            return RLM_SCHEMA_MODE_HARD_RESET_FILE;
2✔
283
        case SchemaMode::AdditiveDiscovered:
2✔
284
            return RLM_SCHEMA_MODE_ADDITIVE_DISCOVERED;
2✔
285
        case SchemaMode::AdditiveExplicit:
2✔
286
            return RLM_SCHEMA_MODE_ADDITIVE_EXPLICIT;
2✔
287
        case SchemaMode::Manual:
2✔
288
            return RLM_SCHEMA_MODE_MANUAL;
2✔
289
    }
×
290
    REALM_TERMINATE("Invalid schema mode."); // LCOV_EXCL_LINE
×
291
}
×
292

293
static inline SchemaSubsetMode from_capi(realm_schema_subset_mode_e subset_mode)
294
{
8✔
295
    switch (subset_mode) {
8✔
296
        case RLM_SCHEMA_SUBSET_MODE_ALL_CLASSES:
2✔
297
            return SchemaSubsetMode::AllClasses;
2✔
298
        case RLM_SCHEMA_SUBSET_MODE_ALL_PROPERTIES:
2✔
299
            return SchemaSubsetMode::AllProperties;
2✔
300
        case RLM_SCHEMA_SUBSET_MODE_COMPLETE:
2✔
301
            return SchemaSubsetMode::Complete;
2✔
302
        case RLM_SCHEMA_SUBSET_MODE_STRICT:
2✔
303
            return SchemaSubsetMode::Strict;
2✔
304
    }
×
305
    REALM_TERMINATE("Invalid subset schema mode."); // LCOV_EXCL_LINE
×
306
}
×
307

308
static inline realm_schema_subset_mode_e to_capi(const SchemaSubsetMode& subset_mode)
309
{
8✔
310
    if (subset_mode == SchemaSubsetMode::AllClasses)
8✔
311
        return RLM_SCHEMA_SUBSET_MODE_ALL_CLASSES;
2✔
312
    else if (subset_mode == SchemaSubsetMode::AllProperties)
6✔
313
        return RLM_SCHEMA_SUBSET_MODE_ALL_PROPERTIES;
2✔
314
    else if (subset_mode == SchemaSubsetMode::Complete)
4✔
315
        return RLM_SCHEMA_SUBSET_MODE_COMPLETE;
2✔
316
    else if (subset_mode == SchemaSubsetMode::Strict)
2✔
317
        return RLM_SCHEMA_SUBSET_MODE_STRICT;
2✔
318
    REALM_TERMINATE("Invalid subset schema mode."); // LCOV_EXCL_LINE
×
319
}
×
320

321
static inline realm_property_type_e to_capi(PropertyType type) noexcept
322
{
26,778✔
323
    type &= ~PropertyType::Flags;
26,778✔
324

13,389✔
325
    switch (type) {
26,778✔
326
        case PropertyType::Int:
2,722✔
327
            return RLM_PROPERTY_TYPE_INT;
2,722✔
328
        case PropertyType::Bool:
2,400✔
329
            return RLM_PROPERTY_TYPE_BOOL;
2,400✔
330
        case PropertyType::String:
2,724✔
331
            return RLM_PROPERTY_TYPE_STRING;
2,724✔
332
        case PropertyType::Data:
2,400✔
333
            return RLM_PROPERTY_TYPE_BINARY;
2,400✔
334
        case PropertyType::Mixed:
316✔
335
            return RLM_PROPERTY_TYPE_MIXED;
316✔
336
        case PropertyType::Date:
2,400✔
337
            return RLM_PROPERTY_TYPE_TIMESTAMP;
2,400✔
338
        case PropertyType::Float:
2,400✔
339
            return RLM_PROPERTY_TYPE_FLOAT;
2,400✔
340
        case PropertyType::Double:
2,700✔
341
            return RLM_PROPERTY_TYPE_DOUBLE;
2,700✔
342
        case PropertyType::Decimal:
2,400✔
343
            return RLM_PROPERTY_TYPE_DECIMAL128;
2,400✔
344
        case PropertyType::Object:
1,214✔
345
            return RLM_PROPERTY_TYPE_OBJECT;
1,214✔
346
        case PropertyType::LinkingObjects:
302✔
347
            return RLM_PROPERTY_TYPE_LINKING_OBJECTS;
302✔
348
        case PropertyType::ObjectId:
2,400✔
349
            return RLM_PROPERTY_TYPE_OBJECT_ID;
2,400✔
350
        case PropertyType::UUID:
2,400✔
351
            return RLM_PROPERTY_TYPE_UUID;
2,400✔
352
        // LCOV_EXCL_START
×
353
        case PropertyType::Nullable:
✔
354
            [[fallthrough]];
×
355
        case PropertyType::Flags:
✔
356
            [[fallthrough]];
×
357
        case PropertyType::Set:
✔
358
            [[fallthrough]];
×
359
        case PropertyType::Dictionary:
✔
360
            [[fallthrough]];
×
361
        case PropertyType::Collection:
✔
362
            [[fallthrough]];
×
363
        case PropertyType::Array:
✔
364
            REALM_UNREACHABLE();
×
365
            // LCOV_EXCL_STOP
13,389✔
366
    }
26,778✔
367
    REALM_TERMINATE("Unsupported property type"); // LCOV_EXCL_LINE
13,389✔
368
}
×
369

370
static inline PropertyType from_capi(realm_property_type_e type) noexcept
371
{
29,828✔
372
    switch (type) {
29,828✔
373
        case RLM_PROPERTY_TYPE_INT:
3,254✔
374
            return PropertyType::Int;
3,254✔
375
        case RLM_PROPERTY_TYPE_BOOL:
2,592✔
376
            return PropertyType::Bool;
2,592✔
377
        case RLM_PROPERTY_TYPE_STRING:
2,920✔
378
            return PropertyType::String;
2,920✔
379
        case RLM_PROPERTY_TYPE_BINARY:
2,592✔
380
            return PropertyType::Data;
2,592✔
381
        case RLM_PROPERTY_TYPE_MIXED:
324✔
382
            return PropertyType::Mixed;
324✔
383
        case RLM_PROPERTY_TYPE_TIMESTAMP:
2,592✔
384
            return PropertyType::Date;
2,592✔
385
        case RLM_PROPERTY_TYPE_FLOAT:
2,592✔
386
            return PropertyType::Float;
2,592✔
387
        case RLM_PROPERTY_TYPE_DOUBLE:
2,916✔
388
            return PropertyType::Double;
2,916✔
389
        case RLM_PROPERTY_TYPE_DECIMAL128:
2,592✔
390
            return PropertyType::Decimal;
2,592✔
391
        case RLM_PROPERTY_TYPE_OBJECT:
1,946✔
392
            return PropertyType::Object;
1,946✔
393
        case RLM_PROPERTY_TYPE_LINKING_OBJECTS:
324✔
394
            return PropertyType::LinkingObjects;
324✔
395
        case RLM_PROPERTY_TYPE_OBJECT_ID:
2,592✔
396
            return PropertyType::ObjectId;
2,592✔
397
        case RLM_PROPERTY_TYPE_UUID:
2,592✔
398
            return PropertyType::UUID;
2,592✔
399
    }
×
400
    REALM_TERMINATE("Unsupported property type"); // LCOV_EXCL_LINE
×
401
}
×
402

403

404
static inline Property from_capi(const realm_property_info_t& p) noexcept
405
{
29,828✔
406
    Property prop;
29,828✔
407
    prop.name = p.name;
29,828✔
408
    prop.public_name = p.public_name;
29,828✔
409
    prop.type = from_capi(p.type);
29,828✔
410
    prop.object_type = p.link_target;
29,828✔
411
    prop.link_origin_property_name = p.link_origin_property_name;
29,828✔
412
    prop.is_primary = Property::IsPrimary{bool(p.flags & RLM_PROPERTY_PRIMARY_KEY)};
29,828✔
413
    prop.is_indexed = Property::IsIndexed{bool(p.flags & RLM_PROPERTY_INDEXED)};
29,828✔
414
    prop.is_fulltext_indexed = Property::IsFulltextIndexed{bool(p.flags & RLM_PROPERTY_FULLTEXT_INDEXED)};
29,828✔
415

14,914✔
416
    if (bool(p.flags & RLM_PROPERTY_NULLABLE)) {
29,828✔
417
        prop.type |= PropertyType::Nullable;
14,582✔
418
    }
14,582✔
419
    switch (p.collection_type) {
29,828✔
420
        case RLM_COLLECTION_TYPE_NONE:
8,440✔
421
            break;
8,440✔
422
        case RLM_COLLECTION_TYPE_LIST: {
7,780✔
423
            prop.type |= PropertyType::Array;
7,780✔
424
            break;
7,780✔
425
        }
×
426
        case RLM_COLLECTION_TYPE_SET: {
6,804✔
427
            prop.type |= PropertyType::Set;
6,804✔
428
            break;
6,804✔
429
        }
×
430
        case RLM_COLLECTION_TYPE_DICTIONARY: {
6,804✔
431
            prop.type |= PropertyType::Dictionary;
6,804✔
432
            break;
6,804✔
433
        }
29,828✔
434
    }
29,828✔
435
    return prop;
29,828✔
436
}
29,828✔
437

438
static inline std::optional<CollectionType> from_capi(realm_collection_type_e type)
NEW
439
{
×
NEW
440
    switch (type) {
×
NEW
441
        case RLM_COLLECTION_TYPE_NONE:
×
NEW
442
            break;
×
NEW
443
        case RLM_COLLECTION_TYPE_LIST:
×
NEW
444
            return CollectionType::List;
×
NEW
445
        case RLM_COLLECTION_TYPE_SET:
×
NEW
446
            return CollectionType::Set;
×
NEW
447
        case RLM_COLLECTION_TYPE_DICTIONARY:
×
NEW
448
            return CollectionType::Dictionary;
×
NEW
449
    }
×
NEW
450
    return {};
×
NEW
451
}
×
452

453
static inline realm_property_info_t to_capi(const Property& prop) noexcept
454
{
26,778✔
455
    realm_property_info_t p;
26,778✔
456
    p.name = prop.name.c_str();
26,778✔
457
    p.public_name = prop.public_name.c_str();
26,778✔
458
    p.type = to_capi(prop.type & ~PropertyType::Flags);
26,778✔
459
    p.link_target = prop.object_type.c_str();
26,778✔
460
    p.link_origin_property_name = prop.link_origin_property_name.c_str();
26,778✔
461

13,389✔
462
    p.flags = RLM_PROPERTY_NORMAL;
26,778✔
463
    if (prop.is_indexed)
26,778✔
464
        p.flags |= RLM_PROPERTY_INDEXED;
306✔
465
    if (prop.is_fulltext_indexed)
26,778✔
466
        p.flags |= RLM_PROPERTY_FULLTEXT_INDEXED;
×
467
    if (prop.is_primary)
26,778✔
468
        p.flags |= RLM_PROPERTY_PRIMARY_KEY;
306✔
469
    if (bool(prop.type & PropertyType::Nullable))
26,778✔
470
        p.flags |= RLM_PROPERTY_NULLABLE;
13,226✔
471

13,389✔
472
    p.collection_type = RLM_COLLECTION_TYPE_NONE;
26,778✔
473
    if (bool(prop.type & PropertyType::Array))
26,778✔
474
        p.collection_type = RLM_COLLECTION_TYPE_LIST;
6,918✔
475
    if (bool(prop.type & PropertyType::Set))
26,778✔
476
        p.collection_type = RLM_COLLECTION_TYPE_SET;
6,300✔
477
    if (bool(prop.type & PropertyType::Dictionary))
26,778✔
478
        p.collection_type = RLM_COLLECTION_TYPE_DICTIONARY;
6,300✔
479

13,389✔
480
    p.key = prop.column_key.value;
26,778✔
481

13,389✔
482
    return p;
26,778✔
483
}
26,778✔
484

485
static inline realm_class_info_t to_capi(const ObjectSchema& o)
486
{
936✔
487
    realm_class_info_t info;
936✔
488
    info.name = o.name.c_str();
936✔
489
    info.primary_key = o.primary_key.c_str();
936✔
490
    info.num_properties = o.persisted_properties.size();
936✔
491
    info.num_computed_properties = o.computed_properties.size();
936✔
492
    info.key = o.table_key.value;
936✔
493
    switch (o.table_type) {
936✔
494
        case ObjectSchema::ObjectType::Embedded: {
300✔
495
            info.flags = RLM_CLASS_EMBEDDED;
300✔
496
            break;
300✔
497
        }
×
498
        case ObjectSchema::ObjectType::TopLevelAsymmetric: {
✔
499
            info.flags = RLM_CLASS_ASYMMETRIC;
×
500
            break;
×
501
        }
×
502
        case ObjectSchema::ObjectType::TopLevel: {
636✔
503
            info.flags = RLM_CLASS_NORMAL;
636✔
504
            break;
636✔
505
        }
×
506
        default:
✔
507
            REALM_TERMINATE(util::format("Invalid table type: %1", uint8_t(o.table_type)).c_str());
×
508
    }
936✔
509
    return info;
936✔
510
}
936✔
511

512
static inline realm_version_id_t to_capi(const VersionID& v)
513
{
×
514
    realm_version_id_t version_id;
×
515
    version_id.version = v.version;
×
516
    version_id.index = v.index;
×
517
    return version_id;
×
518
}
×
519

520
static inline realm_error_t to_capi(const Status& s)
521
{
8✔
522
    realm_error_t err;
8✔
523
    err.error = static_cast<realm_errno_e>(s.code());
8✔
524
    err.categories = static_cast<realm_error_category_e>(ErrorCodes::error_categories(s.code()).value());
8✔
525
    err.message = s.reason().c_str();
8✔
526
    return err;
8✔
527
}
8✔
528

529
} // namespace realm::c_api
530

531

532
#endif // REALM_OBJECT_STORE_C_API_CONVERSION_HPP
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

© 2026 Coveralls, Inc