diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-06-30 14:17:47 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-07-02 16:17:20 +0200 |
commit | e1fdef843fd8a6d8495bf96810e0ffc32d9ca0f6 (patch) | |
tree | bed0dc1d419dc11f294f19d2d8b77d3ddb64e5d6 /src/bluetooth | |
parent | a354431ba0d8c057bd360c0b23565b650814ffc3 (diff) |
Add comparison operators for QLECharacteristic & QLEDescriptor
Change-Id: I5e23af887aa423c6c80335399d0342bec964f6d2
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.cpp | 35 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.h | 2 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptor.cpp | 36 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptor.h | 2 |
4 files changed, 75 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp index f74aa808..aa1795c3 100644 --- a/src/bluetooth/qlowenergycharacteristic.cpp +++ b/src/bluetooth/qlowenergycharacteristic.cpp @@ -219,6 +219,41 @@ QLowEnergyCharacteristic &QLowEnergyCharacteristic::operator=(const QLowEnergyCh } /*! + Returns \c true if \a other is equal to this QLowEnergyCharacteristic; otherwise \c false. + + Two QLowEnergyCharcteristic instances are considered to be equal if they refer to + the same charcteristic on the same remote Bluetooth Low Energy device. + */ +bool QLowEnergyCharacteristic::operator==(const QLowEnergyCharacteristic &other) const +{ + if (d_ptr != other.d_ptr) + return false; + + if ((data && !other.data) || (!data && other.data)) + return false; + + if (!data) + return true; + + if (data->handle != other.data->handle) + return false; + + return true; +} + +/*! + Returns \c true if \a other is not equal to this QLowEnergyCharacteristic; otherwise \c false. + + Two QLowEnergyCharcteristic instances are considered to be equal if they refer to + the same charcteristic on the same remote Bluetooth Low Energy device. + */ + +bool QLowEnergyCharacteristic::operator!=(const QLowEnergyCharacteristic &other) const +{ + return !(*this == other); +} + +/*! Returns \c true if the QLowEnergyCharacteristic object is valid, otherwise returns \c false. An invalid characteristic object is not associated to any service diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h index 4478b910..9a14d57c 100644 --- a/src/bluetooth/qlowenergycharacteristic.h +++ b/src/bluetooth/qlowenergycharacteristic.h @@ -75,6 +75,8 @@ public: ~QLowEnergyCharacteristic(); QLowEnergyCharacteristic &operator=(const QLowEnergyCharacteristic &other); + bool operator==(const QLowEnergyCharacteristic &other) const; + bool operator!=(const QLowEnergyCharacteristic &other) const; QString name() const; diff --git a/src/bluetooth/qlowenergydescriptor.cpp b/src/bluetooth/qlowenergydescriptor.cpp index c0dfdbb8..d28e1a6e 100644 --- a/src/bluetooth/qlowenergydescriptor.cpp +++ b/src/bluetooth/qlowenergydescriptor.cpp @@ -137,6 +137,42 @@ QLowEnergyDescriptor &QLowEnergyDescriptor::operator=(const QLowEnergyDescriptor } /*! + Returns \c true if \a other is equal to this QLowEnergyCharacteristic; otherwise \c false. + + Two QLowEnergyDescriptor instances are considered to be equal if they refer to + the same descriptor on the same remote Bluetooth Low Energy device. + */ +bool QLowEnergyDescriptor::operator==(const QLowEnergyDescriptor &other) const +{ + if (d_ptr != other.d_ptr) + return false; + + if ((data && !other.data) || (!data && other.data)) + return false; + + if (!data) + return true; + + if (data->charHandle != other.data->charHandle + || data->descHandle != other.data->descHandle) { + return false; + } + + return true; +} + +/*! + Returns \c true if \a other is not equal to this QLowEnergyCharacteristic; otherwise \c false. + + Two QLowEnergyDescriptor instances are considered to be equal if they refer to + the same descriptor on the same remote Bluetooth Low Energy device. + */ +bool QLowEnergyDescriptor::operator!=(const QLowEnergyDescriptor &other) const +{ + return !(*this == other); +} + +/*! Returns \c true if the QLowEnergyDescriptor object is valid, otherwise returns \c false. An invalid descriptor instance is not associated to any service diff --git a/src/bluetooth/qlowenergydescriptor.h b/src/bluetooth/qlowenergydescriptor.h index d721b8fc..24aaf534 100644 --- a/src/bluetooth/qlowenergydescriptor.h +++ b/src/bluetooth/qlowenergydescriptor.h @@ -62,6 +62,8 @@ public: ~QLowEnergyDescriptor(); QLowEnergyDescriptor &operator=(const QLowEnergyDescriptor &other); + bool operator==(const QLowEnergyDescriptor &other) const; + bool operator!=(const QLowEnergyDescriptor &other) const; bool isValid() const; |