diff --git a/src/PacketSerial.h b/src/PacketSerial.h index 67de570..4765d17 100644 --- a/src/PacketSerial.h +++ b/src/PacketSerial.h @@ -36,7 +36,7 @@ class PacketSerial_ /// /// where buffer is a pointer to the incoming buffer array, and size is the /// number of bytes in the incoming buffer. - typedef void (*PacketHandlerFunction)(const uint8_t* buffer, size_t size); + using PacketHandlerFunction = void(*)(const uint8_t* buffer, size_t size); /// \brief A typedef describing the packet handler method. /// @@ -47,22 +47,12 @@ class PacketSerial_ /// where sender is a pointer to the PacketSerial_ instance that recieved /// the buffer, buffer is a pointer to the incoming buffer array, and size /// is the number of bytes in the incoming buffer. - typedef void (*PacketHandlerFunctionWithSender)(const void* sender, const uint8_t* buffer, size_t size); + using PacketHandlerFunctionWithSender = void(*)(const void* sender, const uint8_t* buffer, size_t size); /// \brief Construct a default PacketSerial_ device. - PacketSerial_(): - _receiveBufferIndex(0), - _stream(nullptr), - _onPacketFunction(nullptr), - _onPacketFunctionWithSender(nullptr), - _senderPtr(nullptr) - { - } - + PacketSerial_() = default; /// \brief Destroy the PacketSerial_ device. - ~PacketSerial_() - { - } + ~PacketSerial_() = default; /// \brief Begin a default serial connection with the given speed. /// @@ -167,7 +157,7 @@ class PacketSerial_ /// includes some network objects. /// /// \param stream A pointer to an Arduino `Stream`. - void setStream(Stream* stream) + void setStream(Stream* stream) noexcept { _stream = stream; } @@ -179,7 +169,7 @@ class PacketSerial_ /// takes ownership of the stream and thus does not have exclusive /// access to the stream anyway. /// \returns a non-const pointer to the stream, or nullptr if unset. - Stream* getStream() + Stream* getStream() noexcept { return _stream; } @@ -191,7 +181,7 @@ class PacketSerial_ /// takes ownership of the stream and thus does not have exclusive /// access to the stream anyway. /// \returns a const pointer to the stream, or nullptr if unset. - const Stream* getStream() const + const Stream* getStream() const noexcept { return _stream; } @@ -207,7 +197,7 @@ class PacketSerial_ /// myPacketSerial.update(); /// } /// - void update() + void update() noexcept { if (_stream == nullptr) return; @@ -402,14 +392,15 @@ class PacketSerial_ /// overflow() method is called. /// /// \returns true if the receive buffer overflowed. - bool overflow() const + constexpr bool overflow() const noexcept { return _recieveBufferOverflow; } - + PacketSerial_(const PacketSerial_&) = delete; + PacketSerial_(PacketSerial_&&) = delete; + PacketSerial_& operator = (const PacketSerial_&) = delete; + PacketSerial_& operator = (PacketSerial_&&) = delete; private: - PacketSerial_(const PacketSerial_&); - PacketSerial_& operator = (const PacketSerial_&); bool _recieveBufferOverflow = false; @@ -425,10 +416,10 @@ class PacketSerial_ /// \brief A typedef for the default COBS PacketSerial class. -typedef PacketSerial_ PacketSerial; +using PacketSerial = PacketSerial_; /// \brief A typedef for a PacketSerial type with COBS encoding. -typedef PacketSerial_ COBSPacketSerial; +using COBSPacketSerial = PacketSerial_; /// \brief A typedef for a PacketSerial type with SLIP encoding. -typedef PacketSerial_ SLIPPacketSerial; +using SLIPPacketSerial = PacketSerial_;