| 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 1.05 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 | /*! |
| 25 | Default constructs a double complex number with no parameters set. |
| 26 | */ |
| 27 | QOpcUaDoubleComplexNumber::QOpcUaDoubleComplexNumber() |
| 28 | : data(new QOpcUaDoubleComplexNumberData) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | QOpcUaDoubleComplexNumber::QOpcUaDoubleComplexNumber(const QOpcUaDoubleComplexNumber &rhs) |
| 33 | : data(rhs.data) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | /*! |
| 38 | Sets the values from \a rhs in this double complex number. |
| 39 | */ |
| 40 | QOpcUaDoubleComplexNumber &QOpcUaDoubleComplexNumber::operator=(const QOpcUaDoubleComplexNumber &rhs) |
| 41 | { |
| 42 | if (this != &rhs) |
| 43 | data.operator=(o: rhs.data); |
| 44 | return *this; |
| 45 | } |
| 46 | |
| 47 | QOpcUaDoubleComplexNumber::~QOpcUaDoubleComplexNumber() |
| 48 | { |
| 49 | |
| 50 | } |
| 51 | |
| 52 | /*! |
| 53 | Returns the imaginary part of the complex number. |
| 54 | */ |
| 55 | double QOpcUaDoubleComplexNumber::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 QOpcUaDoubleComplexNumber::setImaginary(double imaginary) |
| 64 | { |
| 65 | data->imaginary = imaginary; |
| 66 | } |
| 67 | |
| 68 | /*! |
| 69 | Returns the real part of the complex number. |
| 70 | */ |
| 71 | double QOpcUaDoubleComplexNumber::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 QOpcUaDoubleComplexNumber::setReal(double real) |
| 80 | { |
| 81 | data->real = real; |
| 82 | } |
| 83 | |
| 84 | /*! |
| 85 | Constructs a double complex number with real part \a real and imaginary part \a imaginary. |
| 86 | */ |
| 87 | QOpcUaDoubleComplexNumber::QOpcUaDoubleComplexNumber(double real, double imaginary) |
| 88 | : data(new QOpcUaDoubleComplexNumberData) |
| 89 | { |
| 90 | data->real = real; |
| 91 | data->imaginary = imaginary; |
| 92 | } |
| 93 | |
| 94 | /*! |
| 95 | Returns \c true if this double complex number has the same value as \a rhs. |
| 96 | */ |
| 97 | bool QOpcUaDoubleComplexNumber::operator==(const QOpcUaDoubleComplexNumber &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 double complex number to \l QVariant. |
| 105 | */ |
| 106 | QOpcUaDoubleComplexNumber::operator QVariant() const |
| 107 | { |
| 108 | return QVariant::fromValue(value: *this); |
| 109 | } |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 |
