From ffa313e80a27005405334db6491075442f6e1abd Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 20 Dec 2018 08:35:51 +0100 Subject: Mac: o Using more natural byte ordering in the code. No external effect. o Using global ==, != and < operators instead of in-class operators for better compatibility with STL. ByteBuffer: o Renaming setPosition() to setCursor(). --- include/ble/Bluetooth.h | 27 +++++++++++++++++---------- include/ble/ByteBuffer.h | 8 +++++--- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index 28e2794..80becec 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -38,31 +38,38 @@ typedef std::shared_ptr BluetoothAdapterPtr; class Mac { public: - explicit Mac(uint8_t _5, uint8_t _4, uint8_t _3, uint8_t _2, uint8_t _1, uint8_t _0) : bytes() { - bytes[5] = _5; - bytes[4] = _4; - bytes[3] = _3; - bytes[2] = _2; - bytes[1] = _1; + explicit Mac(uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5) : bytes() { bytes[0] = _0; + bytes[1] = _1; + bytes[2] = _2; + bytes[3] = _3; + bytes[4] = _4; + bytes[5] = _5; }; string str() const; - bool operator==(Mac &other) const; +// bool operator==(const Mac &other) const; +// bool operator!=(const Mac &other) const; +// bool operator<(const Mac &other) const; - bool operator!=(Mac &other) const; - - void copy(uint8_t &_5, uint8_t &_4, uint8_t &_3, uint8_t &_2, uint8_t &_1, uint8_t &_0) const; + void copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const; static Mac parseMac(string s); friend bool operator<(const Mac &a, const Mac &b); + friend bool operator==(const Mac &a, const Mac &b); private: uint8_t bytes[6]; }; +std::ostream& operator<<(std::ostream& os, const Mac& mac); + +bool operator==(const Mac &a, const Mac &b); +bool operator!=(const Mac &a, const Mac &b); +bool operator<(const Mac &a, const Mac &b); + class BluetoothCallback { virtual ~BluetoothCallback() = default; diff --git a/include/ble/ByteBuffer.h b/include/ble/ByteBuffer.h index 6b09049..1ba088f 100644 --- a/include/ble/ByteBuffer.h +++ b/include/ble/ByteBuffer.h @@ -42,7 +42,7 @@ public: ByteBuffer(uint8_t *bytes, size_t size) noexcept : zero(bytes), end_(&bytes[size]), cursor(zero) {}; ByteBuffer(uint8_t *bytes, size_t size, size_t position) : zero(bytes), end_(&bytes[size]), cursor(zero) { - setPosition(position); + setCursor(position); }; template @@ -64,8 +64,10 @@ public: return end_ - cursor; } - inline ByteBuffer &setPosition(size_t newCursor) { - cursor = &zero[newCursor]; + inline ByteBuffer &setCursor(size_t newCursor) { + auto tmp = &zero[newCursor]; + assertCanAccessPtr(tmp); + cursor = tmp; return *this; } -- cgit v1.2.3