| 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 | |
| 6 | QT_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 1.05 part 8, 5.6.4. |
| 14 | It stores a complex number with float precision. |
| 15 | */ |
| 16 | |
| 17 | class QOpcUaComplexNumberData : public QSharedData |
| 18 | { |
| 19 | public: |
| 20 | float real{0}; |
| 21 | float imaginary{0}; |
| 22 | }; |
| 23 | |
| 24 | /*! |
| 25 | Default constructs a complex number with no parameters set. |
| 26 | */ |
| 27 | QOpcUaComplexNumber::QOpcUaComplexNumber() |
| 28 | : data(new QOpcUaComplexNumberData) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | QOpcUaComplexNumber::QOpcUaComplexNumber(const QOpcUaComplexNumber &rhs) |
| 33 | : data(rhs.data) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | /*! |
| 38 | Sets the values from \a rhs in this complex number. |
| 39 | */ |
| 40 | QOpcUaComplexNumber &QOpcUaComplexNumber::operator=(const QOpcUaComplexNumber &rhs) |
| 41 | { |
| 42 | if (this != &rhs) |
| 43 | data.operator=(o: rhs.data); |
| 44 | return *this; |
| 45 | } |
| 46 | |
| 47 | QOpcUaComplexNumber::~QOpcUaComplexNumber() |
| 48 | { |
| 49 | |
| 50 | } |
| 51 | |
| 52 | /*! |
| 53 | Returns the imaginary part of the complex number. |
| 54 | */ |
| 55 | float QOpcUaComplexNumber::imaginary() const |
| 56 | { |
| 57 | return data->imaginary; |
| 58 | } |
| 59 | |
| 60 | /*! |
| 61 | Sets the imaginary part of the complex number to \a imaginary. |
| 62 | */ |
| 63 | void QOpcUaComplexNumber::setImaginary(float imaginary) |
| 64 | { |
| 65 | data->imaginary = imaginary; |
| 66 | } |
| 67 | |
| 68 | /*! |
| 69 | Returns the real part of the complex number. |
| 70 | */ |
| 71 | float QOpcUaComplexNumber::real() const |
| 72 | { |
| 73 | return data->real; |
| 74 | } |
| 75 | |
| 76 | /*! |
| 77 | Sets the real part of the complex number to \a real. |
| 78 | */ |
| 79 | void QOpcUaComplexNumber::setReal(float real) |
| 80 | { |
| 81 | data->real = real; |
| 82 | } |
| 83 | |
| 84 | /*! |
| 85 | Constructs a complex number with real part \a real and imaginary part \a imaginary. |
| 86 | */ |
| 87 | QOpcUaComplexNumber::QOpcUaComplexNumber(float real, float imaginary) |
| 88 | : data(new QOpcUaComplexNumberData) |
| 89 | { |
| 90 | data->real = real; |
| 91 | data->imaginary = imaginary; |
| 92 | } |
| 93 | |
| 94 | /*! |
| 95 | Returns \c true if this complex number has the same value as \a rhs. |
| 96 | */ |
| 97 | bool QOpcUaComplexNumber::operator==(const QOpcUaComplexNumber &rhs) const |
| 98 | { |
| 99 | return qFloatDistance(a: data->real, b: rhs.real()) == 0 && |
| 100 | qFloatDistance(a: data->imaginary, b: rhs.imaginary()) == 0; |
| 101 | } |
| 102 | |
| 103 | /*! |
| 104 | Converts this complex number to \l QVariant. |
| 105 | */ |
| 106 | QOpcUaComplexNumber::operator QVariant() const |
| 107 | { |
| 108 | return QVariant::fromValue(value: *this); |
| 109 | } |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 |
