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
20QT_BEGIN_NAMESPACE
21
22template<typename T>
23struct QQmlNullableValue
24{
25 QQmlNullableValue()
26 : value(T()) {}
27 QQmlNullableValue(const QQmlNullableValue<T> &o)
28 : isNull(o.isNull), value(o.value) {}
29 QQmlNullableValue(const T &t)
30 : isNull(false), value(t) {}
31 QQmlNullableValue<T> &operator=(const T &t)
32 { isNull = false; value = t; return *this; }
33 QQmlNullableValue<T> &operator=(const QQmlNullableValue<T> &o)
34 { isNull = o.isNull; value = o.value; return *this; }
35 operator T() const { return value; }
36
37 void invalidate() { isNull = true; }
38 bool isValid() const { return !isNull; }
39 bool isNull = true;
40 T value;
41};
42
43QT_END_NAMESPACE
44
45#endif // QQMLNULLABLEVALUE_P_H
46

source code of qtdeclarative/src/qml/qml/ftw/qqmlnullablevalue_p.h