未验证 提交 44aaf132 编写于 作者: B Bascy 提交者: GitHub

Added BLEAddress operator overload methods (#4839)

Allows BLEAddress to be used as key in std::map etc
上级 560c0f45
...@@ -59,14 +59,37 @@ BLEAddress::BLEAddress(std::string stringAddress) { ...@@ -59,14 +59,37 @@ BLEAddress::BLEAddress(std::string stringAddress) {
* @return True if the addresses are equal. * @return True if the addresses are equal.
*/ */
bool BLEAddress::equals(BLEAddress otherAddress) { bool BLEAddress::equals(BLEAddress otherAddress) {
return memcmp(otherAddress.getNative(), m_address, 6) == 0; return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
} // equals } // equals
bool BLEAddress::operator==(const BLEAddress& otherAddress) const {
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0;
}
bool BLEAddress::operator!=(const BLEAddress& otherAddress) const {
return !(*this == otherAddress);
}
bool BLEAddress::operator<(const BLEAddress& otherAddress) const {
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) < 0;
}
bool BLEAddress::operator<=(const BLEAddress& otherAddress) const {
return !(*this > otherAddress);
}
bool BLEAddress::operator>=(const BLEAddress& otherAddress) const {
return !(*this < otherAddress);
}
bool BLEAddress::operator>(const BLEAddress& otherAddress) const {
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) > 0;
}
/** /**
* @brief Return the native representation of the address. * @brief Return the native representation of the address.
* @return The native representation of the address. * @return The native representation of the address.
*/ */
esp_bd_addr_t *BLEAddress::getNative() { esp_bd_addr_t *BLEAddress::getNative() {
return &m_address; return &m_address;
} // getNative } // getNative
......
...@@ -23,6 +23,12 @@ public: ...@@ -23,6 +23,12 @@ public:
BLEAddress(esp_bd_addr_t address); BLEAddress(esp_bd_addr_t address);
BLEAddress(std::string stringAddress); BLEAddress(std::string stringAddress);
bool equals(BLEAddress otherAddress); bool equals(BLEAddress otherAddress);
bool operator==(const BLEAddress& otherAddress) const;
bool operator!=(const BLEAddress& otherAddress) const;
bool operator<(const BLEAddress& otherAddress) const;
bool operator<=(const BLEAddress& otherAddress) const;
bool operator>(const BLEAddress& otherAddress) const;
bool operator>=(const BLEAddress& otherAddress) const;
esp_bd_addr_t* getNative(); esp_bd_addr_t* getNative();
std::string toString(); std::string toString();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册