Class ostk::physics::Unit

class Unit

Unit.

A unit of measurement is a definite magnitude of a quantity, defined and adopted by convention or by law, that is used as a standard for measurement of the same kind of quantity. Any other quantity of that kind can be expressed as a multiple of the unit of measurement.

https://en.wikipedia.org/wiki/Unit_of_measurement

Public Types

enum class Type

Values:

enumerator Undefined
enumerator None
enumerator Length
enumerator Mass
enumerator Time
enumerator Temperature
enumerator ElectricCurrent
enumerator LuminousIntensity
enumerator Derived

Public Functions

Unit() = delete

Deleted default constructor.

Unit(const Unit &aUnit)

Copy constructor.

Unit unit(Unit::Length(unit::Length::Unit::Meter));
Parameters:

aUnit -- [in] A unit to copy

Unit &operator=(const Unit &aUnit)

Copy assignment operator.

Unit unit = Unit::Length(unit::Length::Unit::Meter);
Parameters:

aUnit -- [in] A unit to copy

Returns:

A reference to this unit

bool operator==(const Unit &aUnit) const

Equal to operator.

Unit::Length(unit::Length::Unit::Meter) == Unit::Length(unit::Length::Unit::Meter); // True
Parameters:

aUnit -- [in] A unit to compare with

Returns:

True if units are equal

bool operator!=(const Unit &aUnit) const

Not equal to operator.

Unit::Length(unit::Length::Unit::Meter) != Unit::None(); // True
Parameters:

aUnit -- [in] A unit to compare with

Returns:

True if units are not equal

bool isDefined() const

Check if the unit is defined.

Unit::Length(unit::Length::Unit::Meter).isDefined(); // True
Returns:

True if defined

bool isNone() const

Check if the unit is none.

Unit::None().isNone(); // True
Returns:

True if none

Unit::Type getType() const

Get the unit type.

Unit::Length(unit::Length::Unit::Meter).getType(); // Unit::Type::Length
Returns:

The unit type

Real ratioTo(const Unit &aUnit) const

Get the conversion ratio to another unit.

Unit::Length(unit::Length::Unit::Meter).ratioTo(Unit::Length(unit::Length::Unit::Meter)); // 1.0
Parameters:

aUnit -- [in] A unit to convert to

Returns:

The conversion ratio

String toString() const

Convert to string representation.

Unit::Length(unit::Length::Unit::Meter).toString();
Returns:

A string representation

Public Static Functions

static Unit Undefined()

Construct an undefined unit.

Unit unit = Unit::Undefined();
Returns:

An undefined unit

static Unit None()

Construct a dimensionless (none) unit.

Unit unit = Unit::None();
Returns:

A dimensionless unit

static Unit Length(const unit::Length::Unit &aLengthUnit)

Construct a length unit.

Unit unit = Unit::Length(unit::Length::Unit::Meter);
Parameters:

aLengthUnit -- [in] A length unit

Returns:

A unit

static Unit Derived(const unit::Derived::Unit &aDerivedUnit)

Construct a derived unit.

Unit unit = Unit::Derived(unit::Derived::Unit::MeterPerSecond());
Parameters:

aDerivedUnit -- [in] A derived unit

Returns:

A unit

static String StringFromType(const Unit::Type &aType)

Get the string representation of a unit type.

Unit::StringFromType(Unit::Type::Length); // "Length"
Parameters:

aType -- [in] A unit type

Returns:

The string representation

Friends

friend std::ostream &operator<<(std::ostream &anOutputStream, const Unit &aUnit)

Output stream operator.

std::cout << Unit::Length(unit::Length::Unit::Meter);
Parameters:
  • anOutputStream -- [in] An output stream

  • aUnit -- [in] A unit

Returns:

A reference to the output stream