microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Enumerations | Functions
bitfield.hpp File Reference

Named bitfield and register-value formatting views. More...

#include "../microfmt.hpp"
#include <cstdint>
#include <string_view>
#include "bitfield.ipp"
Include dependency graph for bitfield.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  microfmt::bit_field
 
struct  microfmt::bitfield_view
 
struct  microfmt::formatter< bitfield_view >
 

Namespaces

namespace  microfmt
 

Macros

#define MICROFMT_BIT_FLAG(pos, name)    ::microfmt::bit_field { (1u << (pos)), static_cast<uint8_t>(pos), (name), ::microfmt::bit_type::flag }
 
#define MICROFMT_BIT_VALUE_DEC(mask, shift, name)    ::microfmt::bit_field { (mask), static_cast<uint8_t>(shift), (name), ::microfmt::bit_type::value_dec }
 
#define MICROFMT_BIT_VALUE_HEX(mask, shift, name)    ::microfmt::bit_field { (mask), static_cast<uint8_t>(shift), (name), ::microfmt::bit_type::value_hex }
 
#define MICROFMT_DEFINE_REGISTER_TYPE(TypeName, UnderlyingType, ...)
 

Enumerations

enum class  microfmt::bit_type : uint8_t { microfmt::flag , microfmt::value_hex , microfmt::value_dec }
 

Functions

constexpr bitfield_view microfmt::bits (uint32_t raw_val, span< const bit_field > fields, bool show_raw_hex=true, microfmt::string_view sep=" | ") noexcept
 

Detailed Description

Named bitfield and register-value formatting views.

Macro Definition Documentation

◆ MICROFMT_BIT_FLAG

#define MICROFMT_BIT_FLAG (   pos,
  name 
)     ::microfmt::bit_field { (1u << (pos)), static_cast<uint8_t>(pos), (name), ::microfmt::bit_type::flag }

◆ MICROFMT_BIT_VALUE_DEC

#define MICROFMT_BIT_VALUE_DEC (   mask,
  shift,
  name 
)     ::microfmt::bit_field { (mask), static_cast<uint8_t>(shift), (name), ::microfmt::bit_type::value_dec }

◆ MICROFMT_BIT_VALUE_HEX

#define MICROFMT_BIT_VALUE_HEX (   mask,
  shift,
  name 
)     ::microfmt::bit_field { (mask), static_cast<uint8_t>(shift), (name), ::microfmt::bit_type::value_hex }

◆ MICROFMT_DEFINE_REGISTER_TYPE

#define MICROFMT_DEFINE_REGISTER_TYPE (   TypeName,
  UnderlyingType,
  ... 
)
Value:
struct TypeName { \
UnderlyingType value{0}; \
\
constexpr TypeName() noexcept = default; \
constexpr TypeName(UnderlyingType v) noexcept : value(v) {} \
constexpr explicit operator UnderlyingType() const noexcept { return value; } \
\
static constexpr ::microfmt::bit_field fields[] = {__VA_ARGS__}; \
}; \
\
template <> struct microfmt::formatter<TypeName> { \
constexpr void parse(::microfmt::format_parse_context &) noexcept {} \
void format(const TypeName &reg, const ::microfmt::sink &out) const noexcept { \
f.format(::microfmt::bits(static_cast<uint32_t>(reg.value), ::microfmt::span(TypeName::fields)), out); \
} \
};
Definition microfmt.hpp:881
constexpr bitfield_view bits(uint32_t raw_val, span< const bit_field > fields, bool show_raw_hex=true, microfmt::string_view sep=" | ") noexcept
Definition bitfield.hpp:36
RELOCO_CONSTEXPR20 buffer_sink< N > format(microfmt::string_view fmt, const Args &...args) noexcept
Definition microfmt.hpp:1786
Definition microfmt.hpp:985