Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlnullablevalue_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
ifndef
QQMLNULLABLEVALUE_P_H
6
#
define
QQMLNULLABLEVALUE_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
20
21
QT_BEGIN_NAMESPACE
22
23
template
<
typename
T>
24
struct
QQmlNullableValue
25
{
26
QQmlNullableValue() =
default
;
27
28
QQmlNullableValue(
const
QQmlNullableValue<T> &o)
29
: m_value(o.m_value)
30
, m_isNull(o.m_isNull)
31
{}
32
33
QQmlNullableValue(QQmlNullableValue<T> &&o)
noexcept
34
: m_value(std::move(o.m_value))
35
, m_isNull(std::exchange(o.m_isNull,
true
))
36
{}
37
38
QQmlNullableValue(
const
T &t)
39
: m_value(t)
40
, m_isNull(
false
)
41
{}
42
43
QQmlNullableValue(T &&t)
noexcept
44
: m_value(std::move(t))
45
, m_isNull(
false
)
46
{}
47
48
QQmlNullableValue<T> &operator=(
const
QQmlNullableValue<T> &o)
49
{
50
if
(&o !=
this
) {
51
m_value = o.m_value;
52
m_isNull = o.m_isNull;
53
}
54
return
*
this
;
55
}
56
57
QQmlNullableValue<T> &operator=(QQmlNullableValue<T> &&o)
noexcept
58
{
59
if
(&o !=
this
) {
60
m_value = std::move(o.m_value);
61
m_isNull = std::exchange(o.m_isNull,
true
);
62
}
63
return
*
this
;
64
}
65
66
QQmlNullableValue<T> &operator=(
const
T &t)
67
{
68
m_value = t;
69
m_isNull =
false
;
70
return
*
this
;
71
}
72
73
QQmlNullableValue<T> &operator=(T &&t)
noexcept
74
{
75
m_value = std::move(t);
76
m_isNull =
false
;
77
return
*
this
;
78
}
79
80
const
T &value()
const
{
return
m_value; }
81
operator T()
const
{
return
m_value; }
82
83
void
invalidate() { m_isNull =
true
; }
84
bool
isValid()
const
{
return
!m_isNull; }
85
86
private
:
87
T m_value = T();
88
bool
m_isNull =
true
;
89
};
90
91
QT_END_NAMESPACE
92
93
#
endif
// QQMLNULLABLEVALUE_P_H
qtdeclarative
src
qml
qml
ftw
qqmlnullablevalue_p.h
Generated on
for Qt by
1.16.1