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
4
#
ifndef
QQMLNULLABLEVALUE_P_H
5
#
define
QQMLNULLABLEVALUE_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
19
20
QT_BEGIN_NAMESPACE
21
22
template
<
typename
T>
23
struct
QQmlNullableValue
24
{
25
QQmlNullableValue() =
default
;
26
27
QQmlNullableValue(
const
QQmlNullableValue<T> &o)
28
: m_value(o.m_value)
29
, m_isNull(o.m_isNull)
30
{}
31
32
QQmlNullableValue(QQmlNullableValue<T> &&o)
noexcept
33
: m_value(std::move(o.m_value))
34
, m_isNull(std::exchange(o.m_isNull,
true
))
35
{}
36
37
QQmlNullableValue(
const
T &t)
38
: m_value(t)
39
, m_isNull(
false
)
40
{}
41
42
QQmlNullableValue(T &&t)
noexcept
43
: m_value(std::move(t))
44
, m_isNull(
false
)
45
{}
46
47
QQmlNullableValue<T> &operator=(
const
QQmlNullableValue<T> &o)
48
{
49
if
(&o !=
this
) {
50
m_value = o.m_value;
51
m_isNull = o.m_isNull;
52
}
53
return
*
this
;
54
}
55
56
QQmlNullableValue<T> &operator=(QQmlNullableValue<T> &&o)
noexcept
57
{
58
if
(&o !=
this
) {
59
m_value = std::move(o.m_value);
60
m_isNull = std::exchange(o.m_isNull,
true
);
61
}
62
return
*
this
;
63
}
64
65
QQmlNullableValue<T> &operator=(
const
T &t)
66
{
67
m_value = t;
68
m_isNull =
false
;
69
return
*
this
;
70
}
71
72
QQmlNullableValue<T> &operator=(T &&t)
noexcept
73
{
74
m_value = std::move(t);
75
m_isNull =
false
;
76
return
*
this
;
77
}
78
79
const
T &value()
const
{
return
m_value; }
80
operator T()
const
{
return
m_value; }
81
82
void
invalidate() { m_isNull =
true
; }
83
bool
isValid()
const
{
return
!m_isNull; }
84
85
private
:
86
T m_value = T();
87
bool
m_isNull =
true
;
88
};
89
90
QT_END_NAMESPACE
91
92
#
endif
// QQMLNULLABLEVALUE_P_H
qtdeclarative
src
qml
qml
ftw
qqmlnullablevalue_p.h
Generated on
for Qt by
1.14.0