Skip to content

Added BLEAddress operator overload methods #4839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added <, <=, >, >= operator overloads to BLEAddress
- Allows use of BLEAddres as key in std::map<>
  • Loading branch information
Bascy committed Feb 19, 2021
commit c8a50d52eba708d71b33ff4ce7bcf59c40a4642c
18 changes: 17 additions & 1 deletion libraries/BLE/src/BLEAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,23 @@ bool BLEAddress::operator==(BLEAddress otherAddress) {
}

bool BLEAddress::operator!=(BLEAddress otherAddress) {
return !equals(otherAddress);
return ! this == otherAddress;
}

bool BLEAddress::operator<(BLEAddress otherAddress) {
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) < 0;
}

bool BLEAddress::operator<=(BLEAddress otherAddress) {
return !this > otherAddress;
}

bool BLEAddress::operator>=(BLEAddress otherAddress) {
return !this < otherAddress;
}

bool BLEAddress::operator>(BLEAddress otherAddress) {
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) > 0;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions libraries/BLE/src/BLEAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class BLEAddress {
bool equals(BLEAddress otherAddress);
bool operator==(BLEAddress otherAddress);
bool operator!=(BLEAddress otherAddress);
bool operator<(BLEAddress otherAddress);
bool operator<=(BLEAddress otherAddress);
bool operator>(BLEAddress otherAddress);
bool operator>=(BLEAddress otherAddress);
esp_bd_addr_t* getNative();
std::string toString();

Expand Down