Quantify
An extensible C++ units library
Loading...
Searching...
No Matches
Preprocessor Macros

Macros

#define UNIT_SYMBOL(...)
 
#define SCALE(NAME)
 
#define DERIVED_SCALE(NAME, ...)
 
#define UNIT(NAME, SYMBOL, FACTOR_NUM, FACTOR_DEN)
 
#define UNIT_IN_SCALE(SCALE, NAME, SYMBOL, FACTOR_NUM, FACTOR_DEN)
 
#define METRIC_UNIT(UNIT_NAME, SYMBOL, FACTOR_NUM, FACTOR_DEN)
 
#define SCALE_CONVERSION(FROM, TO)
 
#define SCALE_FORWARD_CONVERSION(...)
 
#define SCALE_BACKWARD_CONVERSION(...)
 

Detailed Description

Macro Definition Documentation

◆ DERIVED_SCALE

#define DERIVED_SCALE ( NAME,
... )
Value:
namespace NAME { \
using scale = typename reduce_scale<__VA_ARGS__>::type; \
template <typename Q> \
concept quantity = quantify::Quantity<Q, scale>; \
} \
namespace NAME
Unit agnostic type concept for use with the auto keyword.

Definition at line 33 of file unit_macros.h.

◆ METRIC_UNIT

#define METRIC_UNIT ( UNIT_NAME,
SYMBOL,
FACTOR_NUM,
FACTOR_DEN )
Value:
UNIT(nano##UNIT_NAME, "n" SYMBOL, 1UL * (FACTOR_NUM), 1000000000UL * (FACTOR_DEN)); \
UNIT(micro##UNIT_NAME, "u" SYMBOL, 1UL * (FACTOR_NUM), 1000000UL * (FACTOR_DEN)); \
UNIT(milli##UNIT_NAME, "m" SYMBOL, 1UL * (FACTOR_NUM), 1000UL * (FACTOR_DEN)); \
UNIT(centi##UNIT_NAME, "c" SYMBOL, 1UL * (FACTOR_NUM), 100UL * (FACTOR_DEN)); \
UNIT(deci##UNIT_NAME, "d" SYMBOL, 1UL * (FACTOR_NUM), 10UL * (FACTOR_DEN)); \
UNIT(UNIT_NAME, SYMBOL, 1UL * (FACTOR_NUM), 1UL * (FACTOR_DEN)); \
UNIT(deca##UNIT_NAME, "D" SYMBOL, 10UL * (FACTOR_NUM), 1UL * (FACTOR_DEN)); \
UNIT(hecto##UNIT_NAME, "h" SYMBOL, 100UL * (FACTOR_NUM), 1UL * (FACTOR_DEN)); \
UNIT(kilo##UNIT_NAME, "k" SYMBOL, 1000UL * (FACTOR_NUM), 1UL * (FACTOR_DEN)); \
UNIT(mega##UNIT_NAME, "M" SYMBOL, 1000000UL * (FACTOR_NUM), 1UL * (FACTOR_DEN))
#define UNIT(NAME, SYMBOL, FACTOR_NUM, FACTOR_DEN)
Definition unit_macros.h:41

Definition at line 59 of file unit_macros.h.

◆ SCALE

#define SCALE ( NAME)
Value:
namespace NAME { \
struct scale { \
UNIT_SYMBOL(#NAME) \
}; \
template <typename Q> \
concept quantity = quantify::Quantity<Q, scale>; \
} \
namespace NAME

Definition at line 23 of file unit_macros.h.

◆ SCALE_BACKWARD_CONVERSION

#define SCALE_BACKWARD_CONVERSION ( ...)
Value:
template <typename U_FROM, typename U_TO, typename T> \
static quantity<U_TO, T> backward(const quantity<U_FROM, T>& _quantity) { \
quantity<U_TO, T> result{ \
_quantity.value * U_FROM::template factor<T>::numerator / \
U_FROM::template factor<T>::denominator \
}; \
auto it = result.value; \
result.value = __VA_ARGS__; \
result.value = \
result.value * U_TO::template factor<T>::denominator / U_TO::template factor<T>::numerator; \
return result; \
} \
} \
;

Definition at line 94 of file unit_macros.h.

◆ SCALE_CONVERSION

#define SCALE_CONVERSION ( FROM,
TO )
Value:
template <> \
struct quantify::scale_conversion_t<FROM, TO> { \
using from_scale = FROM; \
using to_scale = TO;
#define TO(...)

Definition at line 72 of file unit_macros.h.

◆ SCALE_FORWARD_CONVERSION

#define SCALE_FORWARD_CONVERSION ( ...)
Value:
template <typename U_FROM, typename U_TO, typename T> \
static quantity<U_TO, T> forward(const quantity<U_FROM, T>& _quantity) { \
quantity<U_TO, T> result{ \
_quantity.value * U_FROM::template factor<T>::numerator / \
U_FROM::template factor<T>::denominator \
}; \
auto it = result.value; \
result.value = __VA_ARGS__; \
result.value = \
result.value * U_TO::template factor<T>::denominator / U_TO::template factor<T>::numerator; \
return result; \
}

Definition at line 78 of file unit_macros.h.

◆ UNIT

#define UNIT ( NAME,
SYMBOL,
FACTOR_NUM,
FACTOR_DEN )
Value:
struct NAME { \
using scale = scale; \
template <typename T> \
using reduce = NAME; \
UNIT_SYMBOL(SYMBOL) \
}
Static representation of a numerical ratio in the form of a fraction.
Definition ratio.cppm:26

Definition at line 41 of file unit_macros.h.

◆ UNIT_IN_SCALE

#define UNIT_IN_SCALE ( SCALE,
NAME,
SYMBOL,
FACTOR_NUM,
FACTOR_DEN )
Value:
struct NAME { \
using scale = SCALE; \
template <typename T> \
using reduce = NAME; \
UNIT_SYMBOL(SYMBOL) \
}
#define SCALE(NAME)
Definition unit_macros.h:23

Definition at line 50 of file unit_macros.h.

◆ UNIT_SYMBOL

#define UNIT_SYMBOL ( ...)
Value:
static constexpr inline std::string symbol() noexcept { \
return (__VA_ARGS__); \
}

Definition at line 18 of file unit_macros.h.