diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-20 08:35:51 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-20 08:35:51 +0100 |
commit | ffa313e80a27005405334db6491075442f6e1abd (patch) | |
tree | 23a48c91cfc0810afe88cc6104d0667516fbd4a9 /include/ble | |
parent | af416f81b14a3bee682e300b165a6efdb9739d54 (diff) | |
download | ble-toys-ffa313e80a27005405334db6491075442f6e1abd.tar.gz ble-toys-ffa313e80a27005405334db6491075442f6e1abd.tar.bz2 ble-toys-ffa313e80a27005405334db6491075442f6e1abd.tar.xz ble-toys-ffa313e80a27005405334db6491075442f6e1abd.zip |
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().
Diffstat (limited to 'include/ble')
-rw-r--r-- | include/ble/Bluetooth.h | 27 | ||||
-rw-r--r-- | include/ble/ByteBuffer.h | 8 |
2 files changed, 22 insertions, 13 deletions
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<BluetoothAdapter> 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<size_t N> @@ -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; } |