xentara-workbench-plugin v1.0.1
The Xentara Workbench Plugin Framework
Loading...
Searching...
No Matches
xentara::workbench::chrono::Duration Class Referencefinal

A time duration decomposed into value and units. More...

#include <xentara/workbench/chrono/Duration.hpp>

Classes

struct  Zero
 A special class that can be used to compare a duration with 0. More...
 

Public Types

enum class  Units {
  Nanoseconds , Microseconds , Milliseconds , Seconds ,
  Minutes , Hours
}
 Supported time units. More...
 

Public Member Functions

constexpr Duration () noexcept=default
 Default constructor that creates a duration of 0s.
 
constexpr Duration (double value, Units units) noexcept
 Constructor that sets the value.
 
template<typename Repetitions , typename Period >
constexpr Duration (std::chrono::duration< Repetitions, Period > duration) noexcept
 Conversion constructor from a chrono duration.
 
template<typename Repetitions , typename Period >
constexpr operator std::chrono::duration< Repetitions, Period > () const noexcept
 conversion to an std::chrono::duration
 
auto save (utils::json::encoder::Value &jsonValue) const -> void
 Writes the time duration to a JSON value.
 
auto saveTo (utils::json::encoder::Object &jsonObject, std::string_view name) const -> void
 Adds the time duration to a JSON object.
 
auto saveTo (utils::json::encoder::Array &jsonArray) const -> void
 Writes the time duration to a JSON array.
 
constexpr auto units () const noexcept -> Units
 Return the time unit component of the time value.
 
constexpr auto value () const noexcept -> double
 Return the time value component of the time value.
 

Static Public Member Functions

static consteval auto zero () -> Zero
 returns a value that can be used to compare a duration with 0
 
static auto load (utils::json::decoder::Value &jsonValue) -> Duration
 Loads the time duration from a JSON value.
 
static auto load (utils::json::decoder::Value &jsonValue, xentara::utils::json::decoder::AllowLegacyMicrosecondsTag) -> Duration
 Loads the time duration from a JSON value, with support for legacy configurations that contain microseconds.
 

Detailed Description

A time duration decomposed into value and units.

Member Enumeration Documentation

◆ Units

Supported time units.

Enumerator
Nanoseconds 

The value is interpreted as nanoseconds.

Microseconds 
Milliseconds 
Seconds 
Minutes 
Hours 

Constructor & Destructor Documentation

◆ Duration() [1/3]

constexpr xentara::workbench::chrono::Duration::Duration ( )
constexprdefaultnoexcept

Default constructor that creates a duration of 0s.

◆ Duration() [2/3]

constexpr xentara::workbench::chrono::Duration::Duration ( double  value,
Units  units 
)
constexprnoexcept

Constructor that sets the value.

Parameters
valueThe value
unitsThe units the value is in

◆ Duration() [3/3]

template<typename Repetitions , typename Period >
constexpr xentara::workbench::chrono::Duration::Duration ( std::chrono::duration< Repetitions, Period >  duration)
constexprnoexcept

Conversion constructor from a chrono duration.

This constructor can be used to initialize a Duration object from a chrono literal.

Example:

using namespace std::literals;
xentara::workbench::chrono::duration _timeout { 500ms };

Member Function Documentation

◆ load() [1/2]

static auto xentara::workbench::chrono::Duration::load ( utils::json::decoder::Value jsonValue) -> Duration
static

Loads the time duration from a JSON value.

Parameters
jsonValueThe value

◆ load() [2/2]

static auto xentara::workbench::chrono::Duration::load ( utils::json::decoder::Value jsonValue,
xentara::utils::json::decoder::AllowLegacyMicrosecondsTag   
) -> Duration
static

Loads the time duration from a JSON value, with support for legacy configurations that contain microseconds.

Parameters
jsonValueThe value

◆ operator std::chrono::duration< Repetitions, Period >()

template<typename Repetitions , typename Period >
constexpr xentara::workbench::chrono::Duration::operator std::chrono::duration< Repetitions, Period > ( ) const
constexprnoexcept

conversion to an std::chrono::duration

◆ save()

auto xentara::workbench::chrono::Duration::save ( utils::json::encoder::Value jsonValue) const -> void

Writes the time duration to a JSON value.

Parameters
jsonValueThe value

◆ saveTo() [1/2]

auto xentara::workbench::chrono::Duration::saveTo ( utils::json::encoder::Array jsonArray) const -> void

Writes the time duration to a JSON array.

Parameters
jsonArrayThe array

◆ saveTo() [2/2]

auto xentara::workbench::chrono::Duration::saveTo ( utils::json::encoder::Object jsonObject,
std::string_view  name 
) const -> void

Adds the time duration to a JSON object.

Parameters
jsonObjectThe object
nameThe member name

◆ units()

constexpr auto xentara::workbench::chrono::Duration::units ( ) const -> Units
constexprnoexcept

Return the time unit component of the time value.

Returns
The time unit

◆ value()

constexpr auto xentara::workbench::chrono::Duration::value ( ) const -> double
constexprnoexcept

Return the time value component of the time value.

Returns
THe time value

◆ zero()

static consteval auto xentara::workbench::chrono::Duration::zero ( ) -> Zero
static

returns a value that can be used to compare a duration with 0