Flow 1.0.0
Flow project: Public API.
Public Attributes | Related Functions | List of all members
flow::perf::Duration_set Struct Reference

Convenience wrapper around an array<Duration, N>, which stores a duration for each of the N possible clock types in perf::Clock_type. More...

#include <clock_type_fwd.hpp>

Public Attributes

std::array< Duration, size_t(Clock_type::S_END_SENTINEL)> m_values
 The underlying data, directly readable and writable by user. NOT ZERO-INITIALIZED ON CONSTRUCTION (or ever).
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const Duration_set &duration_set)
 Prints string representation of the given Duration_set value to the given ostream. More...
 
Duration_setoperator+= (Duration_set &target, const Duration_set &to_add)
 Advances each Duration in the target Duration_set by the given respective addend Durations (negative Duration causes advancing backwards). More...
 
Duration_setoperator*= (Duration_set &target, uint64_t mult_scale)
 Scales each Duration in the target Duration_set by the given numerical constant. More...
 
Duration_setoperator/= (Duration_set &target, uint64_t div_scale)
 Divides each Duration in the target Duration_set by the given numerical constant. More...
 

Detailed Description

Convenience wrapper around an array<Duration, N>, which stores a duration for each of the N possible clock types in perf::Clock_type.

It is a completely tight wrapper, not even adding zeroing of the array values on construction. It only adds convenience operations (possibly as free functions), namely some common math (such as scaling all N values by some numeric factor) and stream I/O.

Design rationale

Performance is absolutely key, so this is to be identical to the underlying (and publicly accessible) array in terms of data storage and operations. I wrote this struct to avoid overloading things like operator-(a, b) and operator<<(ostream&, x), when the underlying type of a, b,xis a standardarray`: we don't want to overload such operations on a general type, even if it's only in our namespace. Historically, the first cut simply made non-operator-overload free function versions of such things operating directly on the arrays.

Friends And Related Function Documentation

◆ operator*=()

Duration_set & operator*= ( Duration_set target,
uint64_t  mult_scale 
)
related

Scales each Duration in the target Duration_set by the given numerical constant.

Note
If you plan to use division as well, always first multiply, then divide, to avoid rounding errors (assuming overflow is not a possibility).
Todo:
Maybe allow operator*=(Duration_set) by a potentially negative number; same for division.
Parameters
targetThe set of Durations each of which may be modified.
mult_scaleConstant by which to multiply each target Duration.
Returns
Reference to mutable target to enable standard *= semantics.

◆ operator+=()

Duration_set & operator+= ( Duration_set target,
const Duration_set to_add 
)
related

Advances each Duration in the target Duration_set by the given respective addend Durations (negative Duration causes advancing backwards).

Parameters
targetThe set of Durations each of which may be modified.
to_addThe set of Durations each of which is added to a target Duration.
Returns
Reference to mutable target to enable standard += semantics.

◆ operator/=()

Duration_set & operator/= ( Duration_set target,
uint64_t  div_scale 
)
related

Divides each Duration in the target Duration_set by the given numerical constant.

Note
If you plan to user multiplication as well, always first multiply, then divide, to avoid rounding errors (and assuming overflow is not a possibility).
Parameters
targetThe set of Durations each of which may be modified.
div_scaleConstant by which to divide each target Duration.
Returns
Reference to mutable target to enable standard /= semantics.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const Duration_set duration_set 
)
related

Prints string representation of the given Duration_set value to the given ostream.

Parameters
osStream to which to write.
duration_setObject to serialize.
Returns
os.

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