Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
21
22template<typename T>
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.value))
34 , m_isNull(std::exchange(o.m_isNull, true))
35 {}
36
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
85private:
86 T m_value = T();
87 bool m_isNull = true;
88};
89
91
92#endif // QQMLNULLABLEVALUE_P_H
Combined button and popup list for selecting options.
GLdouble GLdouble t
Definition qopenglext.h:243
QQmlNullableValue< T > & operator=(T &&t) noexcept
QQmlNullableValue< T > & operator=(const QQmlNullableValue< T > &o)
QQmlNullableValue< T > & operator=(QQmlNullableValue< T > &&o) noexcept
QQmlNullableValue(const QQmlNullableValue< T > &o)
QQmlNullableValue(const T &t)
const T & value() const
QQmlNullableValue()=default
QQmlNullableValue< T > & operator=(const T &t)
QQmlNullableValue(T &&t) noexcept
QQmlNullableValue(QQmlNullableValue< T > &&o) noexcept