Valkyrie 2026
Loading...
Searching...
No Matches
valor::EigenUnit::UnitMap< UnitTags > Class Template Reference

A non-owning, unit-safe view over a raw double* buffer. More...

#include <valkyrie/util/eigenunit/UnitMap.h>

Public Types

using StorageType = Eigen::Matrix<double, Size, 1>
 The underlying Eigen storage type.
using MapType = Eigen::Map<StorageType>
 The mutable Eigen::Map type.
using ConstMapType = Eigen::Map<const StorageType>
 The constant Eigen::Map type.
using UnitTuple = std::tuple<UnitTags...>
 A tuple of the unit tags.

Public Member Functions

 UnitMap (double *ptr)
 Construct a mutable view over a raw buffer.
 UnitMap (const UnitMap &)=delete
UnitMapoperator= (const UnitMap &)=delete
 UnitMap (UnitMap &&)=default
 Move constructor.
UnitMapoperator= (UnitMap &&)=default
 Move assignment.
template<std::size_t N>
requires ValidIndex<N, UnitTags...>
constexpr auto Get () const
 Get the N-th element with its unit.
ConstMapType Raw () const
 Read-only access to the underlying Eigen map.
MapType Raw ()
 Mutable access to the underlying Eigen map.
template<std::size_t N>
requires ValidIndex<N, UnitTags...>
void Set (units::unit_t< std::tuple_element_t< N, UnitTuple > > val)
 Set the N-th element, writing through to the buffer.
template<typename... OtherTags>
requires UnitEquality<UnitTuple, std::tuple<OtherTags...>>
UnitMapoperator= (const UnitVector< OtherTags... > &vec)
 Assign all values from a compatible UnitVector, writing through.
UnitVector< UnitTags... > ToVector () const
 Produce an owned UnitVector copy of the mapped data.
 operator UnitVector< UnitTags... > () const
 Implicit conversion to UnitVector (copies data).
constexpr auto X () const
 Access the first element (x).
void X (units::unit_t< std::tuple_element_t< Size >=1 ? 0 :0, UnitTuple > > val)
 Set the first element (x).
constexpr auto Y () const
 Access the second element (y).
void Y (units::unit_t< std::tuple_element_t< Size >=2 ? 1 :0, UnitTuple > > val)
 Set the second element (y).
constexpr auto Z () const
 Access the third element (z).
void Z (units::unit_t< std::tuple_element_t< Size >=3 ? 2 :0, UnitTuple > > val)
 Set the third element (z).
constexpr auto W () const
 Access the fourth element (w).
void W (units::unit_t< std::tuple_element_t< Size >=4 ? 3 :0, UnitTuple > > val)
 Set the fourth element (w).

Static Public Attributes

static constexpr std::size_t Size = sizeof...(UnitTags)
 The number of elements in the map.

Friends

std::ostream & operator<< (std::ostream &os, const UnitMap &m)
 Debug printing support.

Detailed Description

template<typename... UnitTags>
class valor::EigenUnit::UnitMap< UnitTags >

A non-owning, unit-safe view over a raw double* buffer.

Wraps an Eigen::Map to provide zero-copy unit-checked access to external buffers (hardware registers, shared memory, C APIs, etc.). Mutations write back to the original buffer.

Template Parameters
UnitTagsThe unit types for each element.

Constructor & Destructor Documentation

◆ UnitMap()

template<typename... UnitTags>
valor::EigenUnit::UnitMap< UnitTags >::UnitMap ( double * ptr)
inlineexplicit

Construct a mutable view over a raw buffer.

Parameters
ptrPointer to at least Size doubles. Lifetime must exceed this map.

Member Function Documentation

◆ Get()

template<typename... UnitTags>
template<std::size_t N>
requires ValidIndex<N, UnitTags...>
auto valor::EigenUnit::UnitMap< UnitTags >::Get ( ) const
inlineconstexpr

Get the N-th element with its unit.

Template Parameters
NThe index of the element.

◆ operator=()

template<typename... UnitTags>
template<typename... OtherTags>
requires UnitEquality<UnitTuple, std::tuple<OtherTags...>>
UnitMap & valor::EigenUnit::UnitMap< UnitTags >::operator= ( const UnitVector< OtherTags... > & vec)
inline

Assign all values from a compatible UnitVector, writing through.

Parameters
vecThe source UnitVector.

◆ Set()

template<typename... UnitTags>
template<std::size_t N>
requires ValidIndex<N, UnitTags...>
void valor::EigenUnit::UnitMap< UnitTags >::Set ( units::unit_t< std::tuple_element_t< N, UnitTuple > > val)
inline

Set the N-th element, writing through to the buffer.

Template Parameters
NThe index of the element.
Parameters
valThe unit value to set.

◆ ToVector()

template<typename... UnitTags>
UnitVector< UnitTags... > valor::EigenUnit::UnitMap< UnitTags >::ToVector ( ) const
inline

Produce an owned UnitVector copy of the mapped data.

Returns
A new UnitVector with copied data.

The documentation for this class was generated from the following file:
  • src/main/include/valkyrie/util/eigenunit/UnitMap.h