|
|
constexpr | Scalar () |
| | Default constructor.
|
| |
|
constexpr | Scalar (Counter n) |
| | Construct to have value that is n scaled units.
|
| |
|
constexpr | Scalar (self_type const &that) |
| | Copy constructor.
|
| |
| template<typename I> |
| constexpr | Scalar (Scalar< N, I, T > const &that) |
| | Copy constructor.
|
| |
| template<intmax_t S, typename I> |
| constexpr | Scalar (Scalar< S, I, T > const &that) |
| |
| template<intmax_t S, typename I> |
| self_type & | operator= (Scalar< S, I, T > const &that) |
| |
|
self_type & | operator= (self_type const &that) |
| | Self type assignment.
|
| |
| self_type & | assign (Counter n) |
| |
| template<intmax_t S, typename I> |
| self_type & | assign (Scalar< S, I, T > const &that) |
| |
|
constexpr Counter | count () const |
| | The number of scale units.
|
| |
|
constexpr Counter | value () const |
| | The scaled value.
|
| |
|
constexpr | operator Counter () const |
| | User conversion to scaled value.
|
| |
| self_type & | operator+= (self_type const &that) |
| |
| template<intmax_t S, typename I> |
| self_type & | operator+= (Scalar< S, I, T > const &that) |
| |
| self_type & | operator++ () |
| | Increment - increase count by 1.
|
| |
| self_type | operator++ (int) |
| | Increment - increase count by 1.
|
| |
| self_type & | operator-- () |
| | Decrement - decrease count by 1.
|
| |
| self_type | operator-- (int) |
| | Decrement - decrease count by 1.
|
| |
| self_type & | inc (Counter n) |
| | Increment by n.
|
| |
| self_type & | dec (Counter n) |
| | Decrement by n.
|
| |
| self_type & | operator-= (self_type const &that) |
| |
| template<intmax_t S, typename I> |
| self_type & | operator-= (Scalar< S, I, T > const &that) |
| |
| self_type & | operator*= (C n) |
| | Multiplication - multiple the count by n.
|
| |
| self_type & | operator/= (C n) |
| | Division - divide (rounding down) the count by n.
|
| |
| self_type | operator() (Counter n) const |
| | Utility overload of the function operator to create instances at the same scale.
|
| |
| self_type | plus (Counter n) const |
| | Return a value at the same scale with a count increased by n.
|
| |
| self_type | minus (Counter n) const |
| | Return a value at the same scale with a count decreased by n.
|
| |
| template<intmax_t S, typename I> |
| auto | operator+= (Scalar< S, I, T > const &that) -> self_type & |
| |
| template<intmax_t S, typename I> |
| auto | operator-= (Scalar< S, I, T > const &that) -> self_type & |
| |
template<intmax_t N, typename C = int, typename T = tag::generic>
class swoc::Scalar< N, C, T >
A class to hold scaled values.
Instances of this class have a count and a scale. The "value" of the instance is count * scale. The scale is stored in the compiler in the class symbol table and so only the count is a run time value. An instance with a large scale can be assigned to an instance with a smaller scale and the conversion is done automatically. Conversions from a smaller to larger scale must be explicit using round_up and round_down. This prevents inadvertent changes in value. Because the scales are not the same these conversions can be lossy and the two conversions determine whether, in such a case, the result should be rounded up or down to the nearest scale value.
N sets the scale. C is the type used to hold the count, which is in units of N.
T is a "tag" type which is used only to distinguish the base metric for the scale. Scalar types that have different tags are not interoperable although they can be converted manually by converting to units and then explicitly constructing a new Scalar instance. This is by design. This can be ignored - if not specified then it defaults to a "generic" tag. The type can be (and usually is) defined in name only).
- Note
- This is modeled somewhat on
std::chrono and serves a similar function for different and simpler cases (where the ratio is always an integer, never a fraction).
- See also
- round_up
-
round_down
Definition at line 172 of file Scalar.h.