From 31fdf026f252e3ed1efaa95a15f81c973b7b49da Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 8 Dec 2015 13:47:52 -0800 Subject: [PATCH] constexpr a bunch of stuff. --- firmware/application/app_ais.cpp | 18 +++++++++--------- firmware/application/app_ais.hpp | 2 +- firmware/application/app_ert.hpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index b71463b2..6f2b3a30 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -34,7 +34,7 @@ namespace baseband { namespace ais { struct CRCBitRemap { - size_t operator()(const size_t bit_index) const { + constexpr size_t operator()(const size_t& bit_index) const { return bit_index; } }; @@ -58,23 +58,23 @@ struct PacketLengthRange { // static_assert((max_bits & 7) == 0, "minimum bits not a multiple of 8"); } - bool contains(const size_t bit_count) const { + constexpr bool contains(const size_t bit_count) const { return !is_above(bit_count) && !is_below(bit_count); } - bool is_above(const size_t bit_count) const { + constexpr bool is_above(const size_t bit_count) const { return (min() > bit_count); } - bool is_below(const size_t bit_count) const { + constexpr bool is_below(const size_t bit_count) const { return (max() < bit_count); } - size_t min() const { + constexpr size_t min() const { return min_bytes * 8; } - size_t max() const { + constexpr size_t max() const { return max_bytes * 8; } @@ -119,13 +119,13 @@ static constexpr std::array packet_length_range { { } }; struct PacketLengthValidator { - bool operator()(const uint_fast8_t message_id, const size_t length) { + constexpr bool operator()(const uint_fast8_t message_id, const size_t length) const { return packet_length_range[message_id].contains(length); } }; struct PacketTooLong { - bool operator()(const uint_fast8_t message_id, const size_t length) { + constexpr bool operator()(const uint_fast8_t message_id, const size_t length) const { return packet_length_range[message_id].is_below(length); } }; @@ -174,7 +174,7 @@ static std::string format_navigational_status(const unsigned int value) { } } -static char char_to_ascii(const uint8_t c) { +static constexpr char char_to_ascii(const uint8_t c) { return (c ^ 32) + 32; } diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index 74284f6f..160aec45 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -44,7 +44,7 @@ namespace baseband { namespace ais { struct BitRemap { - size_t operator()(const size_t bit_index) const { + constexpr size_t operator()(const size_t bit_index) const { return bit_index ^ 7; } }; diff --git a/firmware/application/app_ert.hpp b/firmware/application/app_ert.hpp index 9d0a29b0..0053dbce 100644 --- a/firmware/application/app_ert.hpp +++ b/firmware/application/app_ert.hpp @@ -39,7 +39,7 @@ using namespace lpc43xx; namespace ert { struct BitRemap { - size_t operator()(const size_t bit_index) const { + constexpr size_t operator()(const size_t bit_index) const { return bit_index; } };