Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
Units.hpp File Reference
#include "Phyth/Core/Dimension.hpp"
#include "Phyth/System/UnitsRegistry.hpp"
#include "Unit.hpp"
#include "Phyth/Core/Quantity.hpp"
Include dependency graph for Units.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Phyth::RadianTag
 
struct  Phyth::DegreeTag
 
struct  Phyth::NewtonMeterTag
 
struct  Phyth::VoltagePerMeterTag
 
struct  Phyth::DegreePerSecondTag
 

Namespaces

namespace  Phyth
 

Macros

#define PHYTH_CONCAT_IMPL(a, b)   a##b
 
#define PHYTH_CONCAT(a, b)   PHYTH_CONCAT_IMPL(a, b)
 
#define PHYTH_DEFINE_UNIT(dim_type, unit_type, suffix, scale_num, scale_den)
 Define a unit, literal operator, and registry entry.
 
#define PHYTH_DEFINE_UNIT_WITH_NAME(dim_type, unit_type, suffix, scale_num, scale_den, symbol)
 Same as DEFINE_UNIT with custom display symbol.
 
#define PHYTH_DEFINE_UNIT_WITH_TAG(dim_type, unit_type, suffix, scale_num, scale_den, symbol, tag)
 Define a unit with a tag type for type-safe differentiation.
 

Functions

 Phyth::PHYTH_DEFINE_UNIT_WITH_NAME (AngularVelocity, RadianPerSecond, radps, 1, 1, "rad/s")
 

Class Documentation

◆ Phyth::RadianTag

struct Phyth::RadianTag

Definition at line 103 of file Units.hpp.

◆ Phyth::DegreeTag

struct Phyth::DegreeTag

Definition at line 108 of file Units.hpp.

◆ Phyth::NewtonMeterTag

struct Phyth::NewtonMeterTag

Definition at line 139 of file Units.hpp.

◆ Phyth::VoltagePerMeterTag

struct Phyth::VoltagePerMeterTag

Definition at line 187 of file Units.hpp.

◆ Phyth::DegreePerSecondTag

struct Phyth::DegreePerSecondTag

Definition at line 203 of file Units.hpp.

Macro Definition Documentation

◆ PHYTH_CONCAT

#define PHYTH_CONCAT (   a,
  b 
)    PHYTH_CONCAT_IMPL(a, b)

Definition at line 11 of file Units.hpp.

◆ PHYTH_CONCAT_IMPL

#define PHYTH_CONCAT_IMPL (   a,
  b 
)    a##b

Definition at line 10 of file Units.hpp.

◆ PHYTH_DEFINE_UNIT

#define PHYTH_DEFINE_UNIT (   dim_type,
  unit_type,
  suffix,
  scale_num,
  scale_den 
)
Value:
using unit_type = Unit<dim_type, std::ratio<scale_num, scale_den>>; \
\
constexpr auto operator""_##suffix(long double x) { \
return Quantity<unit_type>(x); \
} \
\
constexpr auto operator""_##suffix(unsigned long long x) { \
return Quantity<unit_type>(x); \
} \
\
static const Phyth::UnitRegistrar<unit_type> PHYTH_CONCAT(registrar_, unit_type)(#unit_type, #suffix);
#define PHYTH_CONCAT(a, b)
Definition Units.hpp:11
Static registrar for unit types.

Define a unit, literal operator, and registry entry.

This macro creates:

  1. A unit type alias (e.g., Meter)
  2. A literal operator (e.g., 1.0_m)
  3. A static registrar that registers the unit's name and symbol
Parameters
dim_typeDimension type (e.g., Length, Mass)
unit_typeUnit type name (e.g., Meter, Kilogram)
suffixLiteral suffix (e.g., m, kg)
scale_numScale numerator relative to base unit
scale_denScale denominator relative to base unit

Example: PHYTH_DEFINE_UNIT(Length, Meter, m, 1, 1) // 1.0_m PHYTH_DEFINE_UNIT(Length, Kilometer, km, 1000, 1) // 1.0_km = 1000 m

Definition at line 32 of file Units.hpp.

◆ PHYTH_DEFINE_UNIT_WITH_NAME

#define PHYTH_DEFINE_UNIT_WITH_NAME (   dim_type,
  unit_type,
  suffix,
  scale_num,
  scale_den,
  symbol 
)
Value:
using unit_type = Unit<dim_type, std::ratio<scale_num, scale_den>>; \
\
constexpr auto operator""_##suffix(long double x) { \
return Quantity<unit_type>(x); \
} \
\
constexpr auto operator""_##suffix(unsigned long long x) { \
return Quantity<unit_type>(x); \
} \
\
static const Phyth::UnitRegistrar<unit_type> PHYTH_CONCAT(registrar_, unit_type)(#unit_type, symbol);

Same as DEFINE_UNIT with custom display symbol.

Parameters
dim_typeDimension type
unit_typeUnit type name
suffixLiteral suffix
scale_numScale numerator
scale_denScale denominator
symbolDisplay symbol (e.g., "m/s", "N/C")

Example: PHYTH_DEFINE_UNIT_WITH_NAME(Velocity, MeterPerSecond, mps, 1, 1, "m/s")

Definition at line 59 of file Units.hpp.

◆ PHYTH_DEFINE_UNIT_WITH_TAG

#define PHYTH_DEFINE_UNIT_WITH_TAG (   dim_type,
  unit_type,
  suffix,
  scale_num,
  scale_den,
  symbol,
  tag 
)
Value:
using unit_type = Unit<dim_type, std::ratio<scale_num, scale_den>, tag>; \
\
constexpr auto operator""_##suffix(long double x) { \
return Quantity<unit_type>(x); \
} \
\
constexpr auto operator""_##suffix(unsigned long long x) { \
return Quantity<unit_type>(x); \
} \
\
static const Phyth::UnitRegistrar<unit_type> PHYTH_CONCAT(registrar_, unit_type)(#unit_type, symbol);

Define a unit with a tag type for type-safe differentiation.

This is used when two units have the same dimension and scale but represent different physical concepts. For example, Radian and Degree are both dimensionless with scale 1, but they are distinct types.

Parameters
dim_typeDimension type
unit_typeUnit type name
suffixLiteral suffix
scale_numScale numerator
scale_denScale denominator
symbolDisplay symbol
tagTag type for type differentiation

Definition at line 88 of file Units.hpp.