emlabcpp
modern opinionated embedded C++ library
emlabcpp::protocol::register_map< Endianess, Regs > Class Template Reference

Register map is abstraction to work with registers of external devices. More...

#include <register_map.h>

+ Collaboration diagram for emlabcpp::protocol::register_map< Endianess, Regs >:

Public Types

using registers_tuple = std::tuple< Regs... >
 
using key_type = typename std::tuple_element_t< 0, registers_tuple >::key_type
 
using register_index = bounded< std::size_t, 0, registers_count - 1 >
 
using message_type = message< max_value_size >
 
template<key_type Key>
using reg_type = std::tuple_element_t< key_index< Key >, registers_tuple >
 
template<key_type Key>
using reg_value_type = typename reg_type< Key >::value_type
 
template<key_type Key>
using traits = typename reg_type< Key >::traits
 
template<key_type Key>
using reg_def_type = typename reg_type< Key >::def_type
 

Public Member Functions

 register_map ()=default
 
 register_map (typename Regs::value_type &... args)
 
constexpr register_map (Regs const &... regs)
 
template<key_type Key>
reg_value_type< Key > get_val () const
 
template<key_type Key>
constexpr void set_val (reg_value_type< Key > val)
 
template<typename UnaryCallable >
constexpr void setup_register (key_type key, UnaryCallable &&f)
 
template<typename UnaryCallable >
constexpr auto with_register (key_type key, UnaryCallable &&f) const
 
template<typename UnaryCallable >
constexpr auto with_register (key_type key, UnaryCallable &&f)
 

Static Public Member Functions

static constexpr bool contains (key_type key)
 
static constexpr std::size_t register_size (register_index i)
 
static constexpr key_type register_key (register_index i)
 
static constexpr void with_reg_type (key_type key, auto &&f)
 

Static Public Attributes

static constexpr std::endian endianess = Endianess
 
static constexpr auto max_key = std::max( { Regs::key... } )
 
static constexpr std::size_t registers_count = sizeof...( Regs )
 
static constexpr std::size_t max_value_size = std::max( { Regs::traits::max_size... } )
 
template<key_type Key>
static constexpr std::size_t key_index = get_reg_index( Key )
 
template<key_type Key>
static constexpr bool contains_key
 
static constexpr std::array< key_type, registers_countkeys = { Regs::key... }
 

Friends

constexpr friend auto operator<=> (register_map const &, register_map const &)=default
 

Detailed Description

template<std::endian Endianess, typename... Regs>
class emlabcpp::protocol::register_map< Endianess, Regs >

Register map is abstraction to work with registers of external devices.

It stores values of serializable types that can be accessed based on key (usually enum representing address of register in the device).You can access the value based on the key itself, both at compile time and at runtime. You can also iterate over the values and there is handler that allows serialization and deserialization of bytes into the values defined in the map. This includes additional information that can be accessed about the map. This can also be used as simple table of configuration values.

Member Typedef Documentation

◆ key_type

template<std::endian Endianess, typename... Regs>
using emlabcpp::protocol::register_map< Endianess, Regs >::key_type = typename std::tuple_element_t< 0, registers_tuple >::key_type

◆ message_type

template<std::endian Endianess, typename... Regs>
using emlabcpp::protocol::register_map< Endianess, Regs >::message_type = message< max_value_size >

◆ reg_def_type

template<std::endian Endianess, typename... Regs>
template<key_type Key>
using emlabcpp::protocol::register_map< Endianess, Regs >::reg_def_type = typename reg_type< Key >::def_type

◆ reg_type

template<std::endian Endianess, typename... Regs>
template<key_type Key>
using emlabcpp::protocol::register_map< Endianess, Regs >::reg_type = std::tuple_element_t< key_index< Key >, registers_tuple >

◆ reg_value_type

template<std::endian Endianess, typename... Regs>
template<key_type Key>
using emlabcpp::protocol::register_map< Endianess, Regs >::reg_value_type = typename reg_type< Key >::value_type

◆ register_index

template<std::endian Endianess, typename... Regs>
using emlabcpp::protocol::register_map< Endianess, Regs >::register_index = bounded< std::size_t, 0, registers_count - 1 >

◆ registers_tuple

template<std::endian Endianess, typename... Regs>
using emlabcpp::protocol::register_map< Endianess, Regs >::registers_tuple = std::tuple< Regs... >

◆ traits

template<std::endian Endianess, typename... Regs>
template<key_type Key>
using emlabcpp::protocol::register_map< Endianess, Regs >::traits = typename reg_type< Key >::traits

Constructor & Destructor Documentation

◆ register_map() [1/3]

template<std::endian Endianess, typename... Regs>
emlabcpp::protocol::register_map< Endianess, Regs >::register_map ( )
default

◆ register_map() [2/3]

template<std::endian Endianess, typename... Regs>
emlabcpp::protocol::register_map< Endianess, Regs >::register_map ( typename Regs::value_type &...  args)
inlineexplicit

◆ register_map() [3/3]

template<std::endian Endianess, typename... Regs>
constexpr emlabcpp::protocol::register_map< Endianess, Regs >::register_map ( Regs const &...  regs)
inlineexplicitconstexpr

Member Function Documentation

◆ contains()

template<std::endian Endianess, typename... Regs>
static constexpr bool emlabcpp::protocol::register_map< Endianess, Regs >::contains ( key_type  key)
inlinestaticconstexpr

◆ get_val()

template<std::endian Endianess, typename... Regs>
template<key_type Key>
reg_value_type< Key > emlabcpp::protocol::register_map< Endianess, Regs >::get_val ( ) const
inline

◆ register_key()

template<std::endian Endianess, typename... Regs>
static constexpr key_type emlabcpp::protocol::register_map< Endianess, Regs >::register_key ( register_index  i)
inlinestaticconstexpr

◆ register_size()

template<std::endian Endianess, typename... Regs>
static constexpr std::size_t emlabcpp::protocol::register_map< Endianess, Regs >::register_size ( register_index  i)
inlinestaticconstexpr

◆ set_val()

template<std::endian Endianess, typename... Regs>
template<key_type Key>
constexpr void emlabcpp::protocol::register_map< Endianess, Regs >::set_val ( reg_value_type< Key >  val)
inlineconstexpr

◆ setup_register()

template<std::endian Endianess, typename... Regs>
template<typename UnaryCallable >
constexpr void emlabcpp::protocol::register_map< Endianess, Regs >::setup_register ( key_type  key,
UnaryCallable &&  f 
)
inlineconstexpr

◆ with_reg_type()

template<std::endian Endianess, typename... Regs>
static constexpr void emlabcpp::protocol::register_map< Endianess, Regs >::with_reg_type ( key_type  key,
auto &&  f 
)
inlinestaticconstexpr

◆ with_register() [1/2]

template<std::endian Endianess, typename... Regs>
template<typename UnaryCallable >
constexpr auto emlabcpp::protocol::register_map< Endianess, Regs >::with_register ( key_type  key,
UnaryCallable &&  f 
)
inlineconstexpr

◆ with_register() [2/2]

template<std::endian Endianess, typename... Regs>
template<typename UnaryCallable >
constexpr auto emlabcpp::protocol::register_map< Endianess, Regs >::with_register ( key_type  key,
UnaryCallable &&  f 
) const
inlineconstexpr

Friends And Related Function Documentation

◆ operator<=>

template<std::endian Endianess, typename... Regs>
constexpr friend auto operator<=> ( register_map< Endianess, Regs > const &  ,
register_map< Endianess, Regs > const &   
)
friend

Member Data Documentation

◆ contains_key

template<std::endian Endianess, typename... Regs>
template<key_type Key>
constexpr bool emlabcpp::protocol::register_map< Endianess, Regs >::contains_key
staticconstexpr
Initial value:
=
key_index< Key > != std::tuple_size_v< registers_tuple >

◆ endianess

template<std::endian Endianess, typename... Regs>
constexpr std::endian emlabcpp::protocol::register_map< Endianess, Regs >::endianess = Endianess
staticconstexpr

◆ key_index

template<std::endian Endianess, typename... Regs>
template<key_type Key>
constexpr std::size_t emlabcpp::protocol::register_map< Endianess, Regs >::key_index = get_reg_index( Key )
staticconstexpr

◆ keys

template<std::endian Endianess, typename... Regs>
constexpr std::array< key_type, registers_count > emlabcpp::protocol::register_map< Endianess, Regs >::keys = { Regs::key... }
staticconstexpr

◆ max_key

template<std::endian Endianess, typename... Regs>
constexpr auto emlabcpp::protocol::register_map< Endianess, Regs >::max_key = std::max( { Regs::key... } )
staticconstexpr

◆ max_value_size

template<std::endian Endianess, typename... Regs>
constexpr std::size_t emlabcpp::protocol::register_map< Endianess, Regs >::max_value_size = std::max( { Regs::traits::max_size... } )
staticconstexpr

◆ registers_count

template<std::endian Endianess, typename... Regs>
constexpr std::size_t emlabcpp::protocol::register_map< Endianess, Regs >::registers_count = sizeof...( Regs )
staticconstexpr

The documentation for this class was generated from the following file: