units
Use physical dimensions at compile-time or run-time.
Public Types | Public Member Functions | Private Attributes | List of all members
vnix::units::dyndim_base Class Reference

Base-type for a dimensioned value whose dimension is specified, perhaps dynamically at run-time, by way of the constructor. More...

#include <dyndim-base.hpp>

Inheritance diagram for vnix::units::dyndim_base:
[legend]
Collaboration diagram for vnix::units::dyndim_base:
[legend]

Public Types

using recip_basedim = dyndim_base
 Base-dimensions corresponding to reciprocal of dimensioned quantity. More...
 

Public Member Functions

constexpr dyndim_base (dim dd)
 Initialize from exponents representing dimension. More...
 
constexpr dim d () const
 Exponent for each unit in dimensioned quantity. More...
 
constexpr void number () const
 Throw if dimension be non-null. More...
 
template<typename B >
constexpr void comparison (B const &b) const
 Test for comparison of dimensioned values. More...
 
template<typename B >
constexpr dyndim_base sum (B const &b) const
 Dimension for sum of dimensioned values. More...
 
template<typename B >
constexpr dyndim_base diff (B const &b) const
 Dimension for difference of dimensioned values. More...
 
template<typename B >
constexpr dyndim_base prod (B const &b) const
 Dimension for product of dimensioned values. More...
 
template<typename B >
constexpr dyndim_base quot (B const &b) const
 Dimension for quotient of dimensioned values. More...
 
constexpr recip_basedim recip () const
 Dimension for reciprocal of dimensioned value. More...
 
template<int64_t PN, int64_t PD = 1>
constexpr dyndim_base pow () const
 Dimension for rational power of dimensioned value. More...
 
constexpr dyndim_base pow (dim::rat p) const
 Dimension for rational power of dimensioned value. More...
 
constexpr dyndim_base sqrt () const
 Dimension for square-root of dimensioned value. More...
 

Private Attributes

dim d_
 Exponents representing dimension. More...
 

Detailed Description

Base-type for a dimensioned value whose dimension is specified, perhaps dynamically at run-time, by way of the constructor.

The dimension is specified as a set of exponents, one for each of the five base dimensions (time, length, mass, charge, and temperature).

For statdim_base, the dimension is always known statically at compile-time. For dyndim_base, the dimension is known statically at compile-time only if the dimension be specified to the constructor as a constant expression.

Definition at line 24 of file dyndim-base.hpp.

Member Typedef Documentation

Base-dimensions corresponding to reciprocal of dimensioned quantity.

Definition at line 82 of file dyndim-base.hpp.

Constructor & Destructor Documentation

constexpr vnix::units::dyndim_base::dyndim_base ( dim  dd)
inline

Initialize from exponents representing dimension.

Definition at line 29 of file dyndim-base.hpp.

29 : d_(dd) {}
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the caller graph for this function:

Member Function Documentation

template<typename B >
constexpr void vnix::units::dyndim_base::comparison ( B const &  b) const
inline

Test for comparison of dimensioned values.

Template Parameters
Bdyndim_base or statdim_base.
Parameters
bDimension of right side.

Definition at line 43 of file dyndim-base.hpp.

43  {
44  if (d_ != b.d()) { throw "incompatible dimensions for comparison"; }
45  }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25
constexpr dim vnix::units::dyndim_base::d ( ) const
inline

Exponent for each unit in dimensioned quantity.

This is not static because it needs to be consistent with signature of dyndim.

Definition at line 33 of file dyndim-base.hpp.

33 { return d_; }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the caller graph for this function:

template<typename B >
constexpr dyndim_base vnix::units::dyndim_base::diff ( B const &  b) const
inline

Dimension for difference of dimensioned values.

Template Parameters
Bdyndim_base or statdim_base.
Parameters
bDimension of subtractor.
Returns
Dimension of difference.

Definition at line 60 of file dyndim-base.hpp.

60  {
61  if (d_ != b.d()) { throw "incompatible dimensions for subtraction"; }
62  return d_;
63  }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the caller graph for this function:

constexpr void vnix::units::dyndim_base::number ( ) const
inline

Throw if dimension be non-null.

Definition at line 36 of file dyndim-base.hpp.

36  {
37  if (d() != nul_dim) { throw "dimensioned quantity is not a number"; }
38  }
constexpr dim d() const
Exponent for each unit in dimensioned quantity.
Definition: dyndim-base.hpp:33
static constexpr dim nul_dim
Null dimension.
Definition: dim.hpp:263

Here is the call graph for this function:

template<int64_t PN, int64_t PD = 1>
constexpr dyndim_base vnix::units::dyndim_base::pow ( ) const
inline

Dimension for rational power of dimensioned value.

Template Parameters
PNNumerator of power.
PDDenominator of power.
Returns
Dimension of result.

Definition at line 92 of file dyndim-base.hpp.

92  {
93  return d_ * dim::rat(PN, PD);
94  }
rational< 4, 2 > rat
Type of rational for dimensioned values.
Definition: dim.hpp:26
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the call graph for this function:

Here is the caller graph for this function:

constexpr dyndim_base vnix::units::dyndim_base::pow ( dim::rat  p) const
inline

Dimension for rational power of dimensioned value.

Parameters
pRational power.
Returns
Dimension of result.

Definition at line 99 of file dyndim-base.hpp.

99 { return d_ * p; }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename B >
constexpr dyndim_base vnix::units::dyndim_base::prod ( B const &  b) const
inline

Dimension for product of dimensioned values.

Template Parameters
Bdyndim_base or statdim_base.
Parameters
bDimension of factor.
Returns
Dimension of product.

Definition at line 69 of file dyndim-base.hpp.

69  {
70  return d_ + b.d();
71  }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the caller graph for this function:

template<typename B >
constexpr dyndim_base vnix::units::dyndim_base::quot ( B const &  b) const
inline

Dimension for quotient of dimensioned values.

Template Parameters
Bdyndim_base or statdim_base.
Parameters
bDimension of divisor.
Returns
Dimension of quotient.

Definition at line 77 of file dyndim-base.hpp.

77  {
78  return d_ - b.d();
79  }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the caller graph for this function:

constexpr recip_basedim vnix::units::dyndim_base::recip ( ) const
inline

Dimension for reciprocal of dimensioned value.

Returns
Dimension of reciprocal.

Definition at line 86 of file dyndim-base.hpp.

86 { return nul_dim - d_; }
static constexpr dim nul_dim
Null dimension.
Definition: dim.hpp:263
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the call graph for this function:

Here is the caller graph for this function:

constexpr dyndim_base vnix::units::dyndim_base::sqrt ( ) const
inline

Dimension for square-root of dimensioned value.

Returns
Dimension of square-root.

Definition at line 103 of file dyndim-base.hpp.

103 { return d_ / dim::rat(2); }
rational< 4, 2 > rat
Type of rational for dimensioned values.
Definition: dim.hpp:26
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename B >
constexpr dyndim_base vnix::units::dyndim_base::sum ( B const &  b) const
inline

Dimension for sum of dimensioned values.

Template Parameters
Bdyndim_base or statdim_base.
Parameters
bDimension of addend.
Returns
Dimension of sum.

Definition at line 51 of file dyndim-base.hpp.

51  {
52  if (d_ != b.d()) { throw "incompatible dimensions for addition"; }
53  return d_;
54  }
dim d_
Exponents representing dimension.
Definition: dyndim-base.hpp:25

Here is the caller graph for this function:

Member Data Documentation

dim vnix::units::dyndim_base::d_
private

Exponents representing dimension.

Definition at line 25 of file dyndim-base.hpp.


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