template class Poco::Util::Units::Value

Overview

A Value with a unit. More…

#include <Units.h>

template <
    typename V,
    typename U
    >
class Value
{
public:
    // typedefs

    typedef V ValueType;
    typedef U Unit;

    // construction

    Value();
    Value(const ValueType& v);

    template <
        typename OV,
        typename OU
        >
    Value(const Value<OV, OU>& v);

    // methods

    const ValueType&
    get() const;

    template <
        typename OV,
        typename OU
        >
    Value&
    operator=(const Value<OV, OU>& other);

    template <
        typename OV,
        typename OU
        >
    Value
    operator+(const Value<OV, OU>& other) const;

    template <
        typename OV,
        typename OU
        >
    Value&
    operator+=(const Value<OV, OU>& other);

    template <
        typename OV,
        typename OU
        >
    Value&
    operator-=(const Value<OV, OU>& other);

    template <
        typename OV,
        typename OU
        >
    Value
    operator-(const Value<OV, OU>& other) const;

    Value
    operator-() const;

    template <
        typename OV,
        typename OU
        >
    Value<V, Compose<U, OU>>
    operator*(const Value<OV, OU>& other) const;

    Value
    operator*(const ValueType& v) const;

    Value&
    operator*=(const ValueType& v);

    template <
        typename OV,
        typename OU
        >
    Value<V, Compose<U, Power<OU, -1>>>
    operator/(const Value<OV, OU>& other) const;

    Value
    operator/(const ValueType& v) const;

    Value&
    operator/=(const ValueType& v);

    template <
        typename OV,
        typename OU
        >
    bool
    operator==(const Value<OV, OU>& other) const;

    template <
        typename OV,
        typename OU
        >
    bool
    operator!=(const Value<OV, OU>& other) const;

    template <
        typename OV,
        typename OU
        >
    bool
    operator<(const Value<OV, OU>& other) const;

    template <
        typename OV,
        typename OU
        >
    bool
    operator<=(const Value<OV, OU>& other) const;

    template <
        typename OV,
        typename OU
        >
    bool
    operator>(const Value<OV, OU>& other) const;

    template <
        typename OV,
        typename OU
        >
    bool
    operator>=(const Value<OV, OU>& other) const;

    Value&
    operator++();

    Value
    operator++(int);

    Value&
    operator--();

    Value
    operator--(int);
};

Detailed Documentation

A Value with a unit.

- V is the type you are storing
- U is the unit of the Value

This class is usually not used directly; client code should use the typedef’d instantiations defined in the Values and Constants namespace.

Example:

using namespace Poco::Util::Units::Values;

std::cout << "One mile is " << km(mile(1)) << std::endl;
    // Output: One mile is 1.60934 km

std::cout << "Flow rate is " << m3(mile(1)*inch(80)*foot(9))/s(minute(5));
    // Output: Flow rate is 29.9026 (m)^3.(s)^-1

hours h;
h = cm(3);   // Compile-time error: incompatible units
h = 4;       // Compile-time error: 4 of what?
h = days(4); // Ok: h is 96 hours