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 "qopcuadoublecomplexnumber.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QOpcUaDoubleComplexNumber |
10 | \inmodule QtOpcUa |
11 | \brief The OPC UA DoubleComplexNumber type. |
12 | |
13 | The DoubleComplexNumberType defined in OPC-UA part 8, 5.6.5. |
14 | It stores a complex number with double precision. |
15 | */ |
16 | |
17 | class QOpcUaDoubleComplexNumberData : public QSharedData |
18 | { |
19 | public: |
20 | double real{0}; |
21 | double imaginary{0}; |
22 | }; |
23 | |
24 | QOpcUaDoubleComplexNumber::QOpcUaDoubleComplexNumber() |
25 | : data(new QOpcUaDoubleComplexNumberData) |
26 | { |
27 | } |
28 | |
29 | QOpcUaDoubleComplexNumber::QOpcUaDoubleComplexNumber(const QOpcUaDoubleComplexNumber &rhs) |
30 | : data(rhs.data) |
31 | { |
32 | } |
33 | |
34 | /*! |
35 | Sets the values from \a rhs in this double complex number. |
36 | */ |
37 | QOpcUaDoubleComplexNumber &QOpcUaDoubleComplexNumber::operator=(const QOpcUaDoubleComplexNumber &rhs) |
38 | { |
39 | if (this != &rhs) |
40 | data.operator=(o: rhs.data); |
41 | return *this; |
42 | } |
43 | |
44 | QOpcUaDoubleComplexNumber::~QOpcUaDoubleComplexNumber() |
45 | { |
46 | |
47 | } |
48 | |
49 | /*! |
50 | Returns the imaginary part of the complex number. |
51 | */ |
52 | double QOpcUaDoubleComplexNumber::imaginary() const |
53 | { |
54 | return data->imaginary; |
55 | } |
56 | |
57 | /*! |
58 | Sets the imaginary part of the complex number to \a imaginary. |
59 | */ |
60 | void QOpcUaDoubleComplexNumber::setImaginary(double imaginary) |
61 | { |
62 | data->imaginary = imaginary; |
63 | } |
64 | |
65 | /*! |
66 | Returns the real part of the complex number. |
67 | */ |
68 | double QOpcUaDoubleComplexNumber::real() const |
69 | { |
70 | return data->real; |
71 | } |
72 | |
73 | /*! |
74 | Sets the real part of the complex number to \a real. |
75 | */ |
76 | void QOpcUaDoubleComplexNumber::setReal(double real) |
77 | { |
78 | data->real = real; |
79 | } |
80 | |
81 | /*! |
82 | Constructs a double complex number with real part \a real and imaginary part \a imaginary. |
83 | */ |
84 | QOpcUaDoubleComplexNumber::QOpcUaDoubleComplexNumber(double real, double imaginary) |
85 | : data(new QOpcUaDoubleComplexNumberData) |
86 | { |
87 | data->real = real; |
88 | data->imaginary = imaginary; |
89 | } |
90 | |
91 | /*! |
92 | Returns \c true if this double complex number has the same value as \a rhs. |
93 | */ |
94 | bool QOpcUaDoubleComplexNumber::operator==(const QOpcUaDoubleComplexNumber &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 double complex number to \l QVariant. |
102 | */ |
103 | QOpcUaDoubleComplexNumber::operator QVariant() const |
104 | { |
105 | return QVariant::fromValue(value: *this); |
106 | } |
107 | |
108 | QT_END_NAMESPACE |
109 |