From 58bae306abde95da78f698408ac9d580d5a2b1d7 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Tue, 1 Aug 2023 23:48:06 +0200 Subject: bitfield: align comment style and replace return type by auto --- bitfield.h | 80 +++++++++++++++++++++++++++----------------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) (limited to 'bitfield.h') diff --git a/bitfield.h b/bitfield.h index 850a326..a49a997 100644 --- a/bitfield.h +++ b/bitfield.h @@ -6,22 +6,18 @@ namespace bitfield { namespace impl { -/** - * Constant check for supported underlying BITFILED types. - */ +/// Constant check for supported underlying BITFILED types. template static constexpr bool is_bitfield_type_v = std::is_integral::value && // NOLINT(misc-redundant-expression) std::is_unsigned::value && // NOLINT(misc-redundant-expression) !std::is_same::value; -/** - * Compute a BITMASK based on the HIGHBIT and LOWBIT template parameters. - * The HIGHBIT and LOWBIT are inclusive. - * - * # Example - * ComputeMask<4, 7, uint32_t>() -> 0xf0 - */ +/// Compute a BITMASK based on the HIGHBIT and LOWBIT template parameters. +/// The HIGHBIT and LOWBIT are inclusive. +/// +/// # Example +/// compute_mask<4, 7, uint32_t>() -> 0xf0 template static constexpr inline ValueType compute_mask() { using unsigned_t = typename std::make_unsigned::type; @@ -40,9 +36,7 @@ static constexpr inline ValueType compute_mask() { // -- FIELD REF ---------------------------------------------------------------- -/** - * A mutable reference to a single FIELD in a BITFIELD. - */ +/// A mutable reference to a single FIELD in a BITFIELD. template struct field_ref { constexpr explicit field_ref(ValueType& val) : m_val{val} {} @@ -80,9 +74,7 @@ struct field_ref { // -- CONST FIELD REF ---------------------------------------------------------- -/** - * A constant reference to a single FIELD in a BITFIELD. - */ +/// A constant reference to a single FIELD in a BITFIELD. template struct const_field_ref { constexpr explicit const_field_ref(const ValueType& val) : m_val{val} {} @@ -104,9 +96,7 @@ struct const_field_ref { // -- BITFIELD ----------------------------------------------------------------- -/** - * The BITFIELD base class. - */ +/// The BITFIELD base class. template struct bitfield { static_assert(impl::is_bitfield_type_v, @@ -138,25 +128,25 @@ struct bitfield { }; // -- MACROS ------------------------------------------------------------------- -// -// Code generator macros to conveniently define BITFIELDs with multiple FIELDs. -// -// # Example -// -// BITFIELD_START(status_reg, std::uint32_t) -// FIELD(N, 0, 0) -// FIELD(V, 1, 1) -// FIELD(C, 2, 2) -// FIELD(Z, 3, 3) -// FIELD(MODE, 4, 7) -// BITFIELD_END() -// -// status_ref r(0); -// -// std::uint32_t n = r.V(); -// r.V() = 0xfff; -// assert(r.V() == 0x1); -// assert(r == 0x2); + +/// Code generator macros to conveniently define BITFIELDs with multiple FIELDs. +/// +/// # Example +/// +/// BITFIELD_START(status_reg, std::uint32_t) +/// FIELD(N, 0, 0) +/// FIELD(V, 1, 1) +/// FIELD(C, 2, 2) +/// FIELD(Z, 3, 3) +/// FIELD(MODE, 4, 7) +/// BITFIELD_END() +/// +/// status_ref r(0); +/// +/// std::uint32_t n = r.V(); +/// r.V() = 0xfff; +/// assert(r.V() == 0x1); +/// assert(r == 0x2); #define BITFIELD_START(NAME, TYPE) \ struct NAME : public bitfield::bitfield { \ @@ -169,13 +159,13 @@ struct bitfield { } \ ; -#define FIELD(NAME, L, H) \ - constexpr ::bitfield::field_ref NAME() { \ - return ::bitfield::field_ref(m_val); \ - } \ - \ - constexpr ::bitfield::const_field_ref NAME() const { \ - return ::bitfield::const_field_ref(m_val); \ +#define FIELD(NAME, L, H) \ + constexpr auto NAME() { \ + return ::bitfield::field_ref(m_val); \ + } \ + \ + constexpr auto NAME() const { \ + return ::bitfield::const_field_ref(m_val); \ } // -- TESTS -------------------------------------------------------------------- -- cgit v1.2.3