Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 44aaf13

Browse filesBrowse 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
Copy full SHA for 44aaf13

File tree

Expand file treeCollapse file tree

2 files changed

+31
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-2
lines changed

‎libraries/BLE/src/BLEAddress.cpp

Copy file name to clipboardExpand all lines: libraries/BLE/src/BLEAddress.cpp
+25-2Lines 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
bool BLEAddress::equals(BLEAddress otherAddress) {
62-
return memcmp(otherAddress.getNative(), m_address, 6) == 0;
62+
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
6363
} // equals
6464

65+
bool BLEAddress::operator==(const BLEAddress& otherAddress) const {
66+
return memcmp(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+
return memcmp(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+
return memcmp(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

Copy file name to clipboardExpand all lines: libraries/BLE/src/BLEAddress.h
+6Lines 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
bool equals(BLEAddress otherAddress);
26+
bool operator==(const BLEAddress& otherAddress) const;
27+
bool operator!=(const BLEAddress& otherAddress) const;
28+
bool operator<(const BLEAddress& otherAddress) const;
29+
bool operator<=(const BLEAddress& otherAddress) const;
30+
bool operator>(const BLEAddress& otherAddress) const;
31+
bool operator>=(const BLEAddress& otherAddress) const;
2632
esp_bd_addr_t* getNative();
2733
std::string toString();
2834

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.