emlabcpp
modern opinionated embedded C++ library
emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte > Struct Template Reference

physical_quantity represents all physical units defined using the International System of Units and more. More...

#include <physical_quantity.h>

+ Inheritance diagram for emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >:
+ Collaboration diagram for emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >:

Static Public Member Functions

template<int Exp, char... Unit>
static consteval auto get_single_unit ()
 
static std::string_view get_unit ()
 
- Static Public Member Functions inherited from emlabcpp::quantity< physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >, float >
static std::string get_unit ()
 

Static Public Attributes

template<int Exp, char... Unit>
static constexpr std::array single_unit = get_single_unit< Exp, Unit... >()
 
static constexpr std::array unit
 

Additional Inherited Members

- Public Types inherited from emlabcpp::quantity< physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >, float >
using value_type = float
 
- Public Member Functions inherited from emlabcpp::quantity< physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >, float >
constexpr quantity () noexcept
 
constexpr quantity (Value val) noexcept
 Default constructor used to create a physical quantity from value. More...
 
constexpr float operator* () const noexcept
 Const reference to the internal value. More...
 
constexpr physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte > & operator+= (quantity const other) noexcept
 Add other quantity of same Derived and value_type. More...
 
constexpr physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte > & operator-= (quantity const other) noexcept
 Subtract other quantity of same Derived and value_type. More...
 
constexpr physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte > & operator/= (arithmetic auto const val) noexcept
 Divides quantity by it's value type. More...
 
constexpr physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte > & operator*= (arithmetic auto const val) noexcept
 Multiplies quantity by it's value type. More...
 
constexpr operator U () const noexcept
 Provides explicit conversion of internal value to type U. More...
 

Detailed Description

template<int Len, int Mass, int Time, int Current, int Temp, int Mol, int Li, int Angle, int Byte>
struct emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >

physical_quantity represents all physical units defined using the International System of Units and more.

The idea is that each used unit, is either one of the seven basic units, or defined as some combination of them. The combination is multiplication of exponents of basic units.

So, velocity is distance per time - m*s^-1.

We defined each physical unit by using a template, that has exponent of each basic unit as exponent. This makes it possible to specify any unit using this class - as combination of basic units.

We expand this by providing two additional 'basic' units - angle (which is handy for us) and byte.

Given that we have the exponents of basic units as integers in the type, we can write generic multiplication and division between all possible templates.

This trick is inspired by the haskell's dimensional library which does the same.

Member Function Documentation

◆ get_single_unit()

template<int Len, int Mass, int Time, int Current, int Temp, int Mol, int Li, int Angle, int Byte>
template<int Exp, char... Unit>
static consteval auto emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >::get_single_unit ( )
inlinestatic

◆ get_unit()

template<int Len, int Mass, int Time, int Current, int Temp, int Mol, int Li, int Angle, int Byte>
static std::string_view emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >::get_unit ( )
inlinestatic

Member Data Documentation

◆ single_unit

template<int Len, int Mass, int Time, int Current, int Temp, int Mol, int Li, int Angle, int Byte>
template<int Exp, char... Unit>
constexpr std::array emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >::single_unit = get_single_unit< Exp, Unit... >()
staticconstexpr

◆ unit

template<int Len, int Mass, int Time, int Current, int Temp, int Mol, int Li, int Angle, int Byte>
constexpr std::array emlabcpp::physical_quantity< Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte >::unit
staticconstexpr
Initial value:
single_unit< Len, 'm' >,
single_unit< Mass, 'k', 'g' >,
single_unit< Time, 's' >,
single_unit< Current, 'A' >,
single_unit< Temp, 'K' >,
single_unit< Mol, 'm', 'o', 'l' >,
single_unit< Li, 'c', 'd' >,
single_unit< Angle, 'r', 'a', 'd' >,
single_unit< Byte, 'B' > )
constexpr auto merge_arrays(Arr &&first, Arrs &&... arrs)
Expects multiple std::arrays on input, and merges all together into one std::array instance.
Definition: algorithm.h:531

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