1// Copyright (C) 2015 basysKom GmbH, opensource@basyskom.com
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qopcuacomplexnumber.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QOpcUaComplexNumber
10 \inmodule QtOpcUa
11 \brief The OPC UA ComplexNumber type.
12
13 The ComplexNumberType defined in OPC-UA part 8, 5.6.4.
14 It stores a complex number with float precision.
15*/
16
17class QOpcUaComplexNumberData : public QSharedData
18{
19public:
20 float real{0};
21 float imaginary{0};
22};
23
24QOpcUaComplexNumber::QOpcUaComplexNumber()
25 : data(new QOpcUaComplexNumberData)
26{
27}
28
29QOpcUaComplexNumber::QOpcUaComplexNumber(const QOpcUaComplexNumber &rhs)
30 : data(rhs.data)
31{
32}
33
34/*!
35 Sets the values from \a rhs in this complex number.
36*/
37QOpcUaComplexNumber &QOpcUaComplexNumber::operator=(const QOpcUaComplexNumber &rhs)
38{
39 if (this != &rhs)
40 data.operator=(o: rhs.data);
41 return *this;
42}
43
44QOpcUaComplexNumber::~QOpcUaComplexNumber()
45{
46
47}
48
49/*!
50 Returns the imaginary part of the complex number.
51*/
52float QOpcUaComplexNumber::imaginary() const
53{
54 return data->imaginary;
55}
56
57/*!
58 Sets the imaginary part of the complex number to \a imaginary.
59*/
60void QOpcUaComplexNumber::setImaginary(float imaginary)
61{
62 data->imaginary = imaginary;
63}
64
65/*!
66 Returns the real part of the complex number.
67*/
68float QOpcUaComplexNumber::real() const
69{
70 return data->real;
71}
72
73/*!
74 Sets the real part of the complex number to \a real.
75*/
76void QOpcUaComplexNumber::setReal(float real)
77{
78 data->real = real;
79}
80
81/*!
82 Constructs a complex number with real part \a real and imaginary part \a imaginary.
83*/
84QOpcUaComplexNumber::QOpcUaComplexNumber(float real, float imaginary)
85 : data(new QOpcUaComplexNumberData)
86{
87 data->real = real;
88 data->imaginary = imaginary;
89}
90
91/*!
92 Returns \c true if this complex number has the same value as \a rhs.
93*/
94bool QOpcUaComplexNumber::operator==(const QOpcUaComplexNumber &rhs) const
95{
96 return qFloatDistance(a: data->real, b: rhs.real()) == 0 &&
97 qFloatDistance(a: data->imaginary, b: rhs.imaginary()) == 0;
98}
99
100/*!
101 Converts this complex number to \l QVariant.
102*/
103QOpcUaComplexNumber::operator QVariant() const
104{
105 return QVariant::fromValue(value: *this);
106}
107
108QT_END_NAMESPACE
109

source code of qtopcua/src/opcua/client/qopcuacomplexnumber.cpp