Skip to content

Commit 44aaf13

Browse files
authored
Added BLEAddress operator overload methods (espressif#4839)
Allows BLEAddress to be used as key in std::map etc
1 parent 560c0f4 commit 44aaf13

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

‎libraries/BLE/src/BLEAddress.cpp‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,37 @@ BLEAddress::BLEAddress(std::string stringAddress){
5959
* @return True if the addresses are equal.
6060
*/
6161
boolBLEAddress::equals(BLEAddress otherAddress){
62-
returnmemcmp(otherAddress.getNative(), m_address, 6) == 0;
62+
returnmemcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
6363
} // equals
6464

65+
bool BLEAddress::operator==(const BLEAddress& otherAddress) const{
66+
returnmemcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0;
67+
}
68+
69+
bool BLEAddress::operator!=(const BLEAddress& otherAddress) const{
70+
return !(*this == otherAddress);
71+
}
72+
73+
bool BLEAddress::operator<(const BLEAddress& otherAddress) const{
74+
returnmemcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) < 0;
75+
}
76+
77+
bool BLEAddress::operator<=(const BLEAddress& otherAddress) const{
78+
return !(*this > otherAddress);
79+
}
80+
81+
bool BLEAddress::operator>=(const BLEAddress& otherAddress) const{
82+
return !(*this < otherAddress);
83+
}
84+
85+
bool BLEAddress::operator>(const BLEAddress& otherAddress) const{
86+
returnmemcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) > 0;
87+
}
6588

6689
/**
6790
* @brief Return the native representation of the address.
6891
* @return The native representation of the address.
69-
*/
92+
*/
7093
esp_bd_addr_t *BLEAddress::getNative(){
7194
return &m_address;
7295
} // getNative

‎libraries/BLE/src/BLEAddress.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class BLEAddress{
2323
BLEAddress(esp_bd_addr_t address);
2424
BLEAddress(std::string stringAddress);
2525
boolequals(BLEAddress otherAddress);
26+
booloperator==(const BLEAddress& otherAddress) const;
27+
booloperator!=(const BLEAddress& otherAddress) const;
28+
booloperator<(const BLEAddress& otherAddress) const;
29+
booloperator<=(const BLEAddress& otherAddress) const;
30+
booloperator>(const BLEAddress& otherAddress) const;
31+
booloperator>=(const BLEAddress& otherAddress) const;
2632
esp_bd_addr_t* getNative();
2733
std::string toString();
2834

0 commit comments

Comments
(0)