From 0557af7235a779fed6be33d8f8d3e7ca1ccd9361 Mon Sep 17 00:00:00 2001 From: kongr45gpen <electrovesta@gmail.com> Date: Mon, 12 Nov 2018 02:30:17 +0200 Subject: [PATCH] Move implementations of Message functions to its header, so they can be inlined --- inc/Message.hpp | 46 +++++++++++++++++++++++++--------- src/Message.cpp | 48 +----------------------------------- src/Services/TestService.cpp | 3 --- 3 files changed, 36 insertions(+), 61 deletions(-) diff --git a/inc/Message.hpp b/inc/Message.hpp index 93bc12d0..5747a211 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -81,7 +81,9 @@ public: * * PTC = 1, PFC = 0 */ - void appendBoolean(bool value); + void appendBoolean(bool value) { + return appendByte(static_cast<uint8_t>(value)); + } /** * Adds an enumerated parameter consisting of an arbitrary number of bits to the end of the @@ -96,70 +98,92 @@ public: * * PTC = 1, PFC = 8 */ - void appendEnumerated(uint8_t value); + void appendEnumerated(uint8_t value) { + return appendByte(value); + }; /** * Adds an enumerated parameter consisting of 2 bytes to the end of the message * * PTC = 1, PFC = 16 */ - void appendEnumerated(uint16_t value); + void appendEnumerated(uint16_t value) { + return appendHalfword(value); + } /** * Adds an enumerated parameter consisting of 4 bytes to the end of the message * * PTC = 1, PFC = 32 */ - void appendEnumerated(uint32_t value); + void appendEnumerated(uint32_t value) { + return appendWord(value); + } /** * Adds a 1 byte unsigned integer to the end of the message * * PTC = 2, PFC = 4 */ - void appendInteger(uint8_t value); + void appendInteger(uint8_t value) { + return appendByte(value); + } /** * Adds a 2 byte unsigned integer to the end of the message * * PTC = 2, PFC = 8 */ - void appendInteger(uint16_t value); + void appendInteger(uint16_t value) { + return appendHalfword(value); + } /** * Adds a 4 byte unsigned integer to the end of the message * * PTC = 2, PFC = 14 */ - void appendInteger(uint32_t value); + void appendInteger(uint32_t value) { + return appendWord(value); + } /** * Adds a 1 byte signed integer to the end of the message * * PTC = 3, PFC = 4 */ - void appendInteger(int8_t value); + void appendInteger(int8_t value) { + return appendByte(reinterpret_cast<uint8_t&>(value)); + } /** * Adds a 2 byte signed integer to the end of the message * * PTC = 3, PFC = 8 */ - void appendInteger(int16_t value); + void appendInteger(int16_t value) { + return appendHalfword(reinterpret_cast<uint16_t&>(value)); + } /** * Adds a 4 byte signed integer to the end of the message * * PTC = 3, PFC = 14 */ - void appendInteger(int32_t value); + void appendInteger(int32_t value) { + return appendWord(reinterpret_cast<uint32_t&>(value)); + } /** * Adds a 4-byte single-precision floating point number to the end of the message * * PTC = 5, PFC = 1 */ - void appendReal(float value); + void appendReal(float value) { + static_assert(sizeof(uint32_t) == sizeof(value), "Floating point numbers must be 32 bits long"); + + return appendWord(reinterpret_cast<uint32_t&>(value)); + } }; diff --git a/src/Message.cpp b/src/Message.cpp index 61ef26af..eb9335d0 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -65,59 +65,13 @@ void Message::appendString(uint8_t size, const char *value) { dataSize += size; } -void Message::appendBoolean(bool value) { - return appendByte(static_cast<uint8_t>(value)); -} - -inline void Message::appendEnumerated(uint8_t bits, uint32_t value) { +void Message::appendEnumerated(uint8_t bits, uint32_t value) { // TODO: Implement 32-bit enums, if needed assert((value & 0xffff0000) != 0); return appendBits(bits, value); } -inline void Message::appendEnumerated(uint8_t value) { - return appendByte(value); -} - -inline void Message::appendEnumerated(uint16_t value) { - return appendHalfword(value); -} - -inline void Message::appendEnumerated(uint32_t value) { - return appendWord(value); -} - -inline void Message::appendInteger(uint8_t value) { - return appendByte(value); -} - -inline void Message::appendInteger(uint16_t value) { - return appendHalfword(value); -} - -inline void Message::appendInteger(uint32_t value) { - return appendWord(value); -} - -inline void Message::appendInteger(int8_t value) { - return appendByte(static_cast<uint8_t>(value)); -} - -void Message::appendInteger(int16_t value) { - return appendHalfword(static_cast<uint8_t>(value)); -} - -void Message::appendInteger(int32_t value) { - return appendWord(static_cast<uint8_t>(value)); -} - -void Message::appendReal(float value) { - static_assert(sizeof(uint32_t) == sizeof(value), "Floating point numbers must be 32 bits long"); - - return appendWord(reinterpret_cast<uint32_t&>(value)); -} - Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType, uint16_t applicationId) : serviceType(serviceType), messageType(messageType), packetType(packetType), applicationId(applicationId) {} diff --git a/src/Services/TestService.cpp b/src/Services/TestService.cpp index 6335e3ad..674b19db 100644 --- a/src/Services/TestService.cpp +++ b/src/Services/TestService.cpp @@ -1,6 +1,3 @@ - -#include <Services/TestService.hpp> - #include "Services/TestService.hpp" void TestService::areYouAlive(const Message &request) { -- GitLab