• 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

78.22
/src/realm/data_type.hpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 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
 *
17
 **************************************************************************/
18

19
#ifndef REALM_DATA_TYPE_HPP
20
#define REALM_DATA_TYPE_HPP
21

22
#include <stdint.h>
23
#include <realm/util/to_string.hpp>
24
#include <realm/util/features.h>
25

26
namespace realm {
27

28
class StringData;
29
class BinaryData;
30
class Timestamp;
31
class Decimal128;
32

33
typedef int64_t Int;
34
typedef bool Bool;
35
typedef float Float;
36
typedef double Double;
37
typedef realm::StringData String;
38
typedef realm::BinaryData Binary;
39
typedef realm::Decimal128 Decimal;
40

41
struct ColumnType;
42

43
struct DataType {
44
    enum class Type {
45
        // Note: Value assignments must be kept in sync with <realm/column_type.h>
46
        // Note: Any change to this enum is a file-format breaking change.
47
        Int = 0,
48
        Bool = 1,
49
        String = 2,
50
        Binary = 4,
51
        Mixed = 6,
52
        Timestamp = 8,
53
        Float = 9,
54
        Double = 10,
55
        Decimal = 11,
56
        Link = 12,
57
        LinkList = 13,
58
        ObjectId = 15,
59
        TypedLink = 16,
60
        UUID = 17,
61
    };
62

63
    constexpr explicit DataType(int t) noexcept
64
        : m_type(Type(t))
65
    {
163,559,388✔
66
    }
163,559,388✔
67

68
    constexpr DataType(Type t = Type::Int) noexcept
69
        : m_type(t)
70
    {
492,380✔
71
    }
492,380✔
72

73
    constexpr bool operator==(const DataType& rhs) const noexcept
74
    {
104,657,466✔
75
        return m_type == rhs.m_type;
104,657,466✔
76
    }
104,657,466✔
77
    constexpr bool operator!=(const DataType& rhs) const noexcept
78
    {
1,828,095✔
79
        return !(*this == rhs);
1,828,095✔
80
    }
1,828,095✔
81

82
    // Allow switch statements over the struct.
83
    constexpr operator Type() const noexcept
84
    {
82,494,291✔
85
        return m_type;
82,494,291✔
86
    }
82,494,291✔
87

88
    constexpr explicit operator int() const noexcept
89
    {
162,487,566✔
90
        return int(m_type);
162,487,566✔
91
    }
162,487,566✔
92

93
    constexpr explicit operator int64_t() const noexcept
94
    {
53,580✔
95
        return int64_t(m_type);
53,580✔
96
    }
53,580✔
97

98
    constexpr explicit operator uint64_t() const noexcept
99
    {
×
100
        return uint64_t(m_type);
×
101
    }
×
102

103
    // FIXME: Remove this
104
    constexpr explicit operator ColumnType() const noexcept;
105

106
    constexpr explicit operator util::Printable() const noexcept;
107

108
    constexpr bool is_valid() const noexcept
109
    {
1,404,075✔
110
        switch (m_type) {
1,404,075✔
111
            case Type::Int:
731,895✔
112
            case Type::Bool:
733,119✔
113
            case Type::String:
739,827✔
114
            case Type::Binary:
742,530✔
115
            case Type::Mixed:
744,732✔
116
            case Type::Timestamp:
746,556✔
117
            case Type::Float:
748,212✔
118
            case Type::Double:
751,782✔
119
            case Type::Decimal:
754,695✔
120
            case Type::Link:
755,259✔
121
            case Type::LinkList:
755,259✔
122
            case Type::ObjectId:
1,399,425✔
123
            case Type::TypedLink:
1,399,437✔
124
            case Type::UUID:
1,401,048✔
125
                return true;
1,401,048✔
126
        }
3,030✔
127
        return false;
3,030✔
128
    }
3,030✔
129

130
    Type m_type;
131
};
132

133
static constexpr DataType type_Int = DataType{DataType::Type::Int};
134
static constexpr DataType type_Bool = DataType{DataType::Type::Bool};
135
static constexpr DataType type_String = DataType{DataType::Type::String};
136
static constexpr DataType type_Binary = DataType{DataType::Type::Binary};
137
static constexpr DataType type_Mixed = DataType{DataType::Type::Mixed};
138
static constexpr DataType type_Timestamp = DataType{DataType::Type::Timestamp};
139
static constexpr DataType type_Float = DataType{DataType::Type::Float};
140
static constexpr DataType type_Double = DataType{DataType::Type::Double};
141
static constexpr DataType type_Decimal = DataType{DataType::Type::Decimal};
142
static constexpr DataType type_Link = DataType{DataType::Type::Link};
143
static constexpr DataType type_LinkList = DataType{DataType::Type::LinkList};
144
static constexpr DataType type_ObjectId = DataType{DataType::Type::ObjectId};
145
static constexpr DataType type_TypedLink = DataType{DataType::Type::TypedLink};
146
static constexpr DataType type_UUID = DataType{DataType::Type::UUID};
147

148
// Deprecated column types that must still be handled in migration code, but not
149
// in every enum everywhere. Note that `DataType::is_valid()` returns false for
150
// these.
151
static constexpr DataType type_OldTable = DataType{5};
152
static constexpr DataType type_OldDateTime = DataType{7};
153
static_assert(!type_OldTable.is_valid());
154
static_assert(!type_OldDateTime.is_valid());
155

156
// Non primitive types
157
static constexpr DataType type_TypeOfValue = DataType{18};
158
static constexpr DataType type_List = DataType{19};
159
static constexpr DataType type_Set = DataType{20};
160
static constexpr DataType type_Dictionary = DataType{21};
161
static constexpr DataType type_Geospatial = DataType{22};
162

163
constexpr inline DataType::operator util::Printable() const noexcept
164
{
717,138✔
165
    switch (*this) {
717,138✔
166
        case type_Int:
243,510✔
167
            return "type_Int";
243,510✔
168
        case type_Bool:
16,458✔
169
            return "type_Bool";
16,458✔
170
        case type_String:
273,306✔
171
            return "type_String";
273,306✔
172
        case type_Binary:
17,484✔
173
            return "type_Binary";
17,484✔
174
        case type_Mixed:
13,254✔
175
            return "type_Mixed";
13,254✔
176
        case type_Timestamp:
30,738✔
177
            return "type_Timestamp";
30,738✔
178
        case type_Float:
17,040✔
179
            return "type_Float";
17,040✔
180
        case type_Double:
17,916✔
181
            return "type_Double";
17,916✔
182
        case type_Decimal:
17,028✔
183
            return "type_Decimal";
17,028✔
184
        case type_Link:
6✔
185
            return "type_Link";
6✔
186
        case type_LinkList:
6✔
187
            return "type_LinkList";
6✔
188
        case type_ObjectId:
53,454✔
189
            return "type_ObjectId";
53,454✔
190
        case type_TypedLink:
6✔
191
            return "type_TypedLink";
6✔
192
        case type_UUID:
16,914✔
193
            return "type_UUID";
16,914✔
194
    }
18✔
195
    if (*this == type_OldTable) {
18✔
196
        return "type_OldTable";
6✔
197
    }
6✔
198
    if (*this == type_OldDateTime) {
12✔
199
        return "type_OldDateTime";
6✔
200
    }
6✔
201
    if (*this == type_TypeOfValue) {
6✔
202
        return "type_TypeOfValue";
6✔
203
    }
6✔
NEW
204
    if (*this == type_List) {
×
NEW
205
        return "type_List";
×
NEW
206
    }
×
NEW
207
    if (*this == type_Set) {
×
NEW
208
        return "type_Set";
×
NEW
209
    }
×
NEW
210
    if (*this == type_Dictionary) {
×
NEW
211
        return "type_Dictionary";
×
NEW
212
    }
×
213
    if (*this == type_Geospatial) {
×
214
        return "type_Geospatial";
×
215
    }
×
216
    return "type_UNKNOWN";
×
217
}
×
218

219
template <class O>
220
constexpr inline O& operator<<(O& os, const DataType& data_type) noexcept
221
{
×
222
    util::Printable printable{data_type};
×
223
    printable.print(os, false);
×
224
    return os;
×
225
}
×
226

227
const char* get_data_type_name(DataType type) noexcept;
228

229
} // namespace realm
230

231
#endif // REALM_DATA_TYPE_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