Libmagicxx v9.0.2
A C++ wrapper library over the Magic Number Recognition Library.
Loading...
Searching...
No Matches
recognition::utility::progress_tracker Class Reference

Thread-safe tracker for monitoring the progress of a job composed of multiple steps. More...

#include <progress_tracker.hpp>

Public Member Functions

 progress_tracker (std::uint64_t total_steps=1u) noexcept
 Construct progress_tracker with a given total number of steps.
 
void advance (std::uint64_t step_count=1u) noexcept
 Increments the number of completed steps.
 
std::uint64_t get_completed_steps () const noexcept
 
percentage get_completion_percentage () const noexcept
 
std::uint64_t get_incompleted_steps () const noexcept
 
std::uint64_t get_total_steps () const noexcept
 
bool is_completed () const noexcept
 
void mark_as_completed () noexcept
 Marks the job as fully completed.
 
void reset (std::uint64_t total_steps) noexcept
 Reset the tracker with a new total step count.
 
template<typename RepresentationType , typename PeriodType >
bool try_wait_for_completion (std::chrono::duration< RepresentationType, PeriodType > timeout) const
 Wait for the job to complete, or until the specified timeout duration elapses.
 
template<typename ClockType , typename DurationType >
bool try_wait_for_completion_until (std::chrono::time_point< ClockType, DurationType > deadline) const
 Wait until the job is complete or the specified deadline is reached.
 
void wait_for_completion () const
 Wait until all steps are completed.
 

Private Attributes

std::mutex m_mutex {}
 
std::condition_variable m_condition_variable {}
 
std::uint64_t m_total_steps
 
std::uint64_t m_completed_steps {0u}
 

Detailed Description

Thread-safe tracker for monitoring the progress of a job composed of multiple steps.

Constructor & Destructor Documentation

◆ progress_tracker()

recognition::utility::progress_tracker::progress_tracker ( std::uint64_t total_steps = 1u)
inlineexplicitnoexcept

Construct progress_tracker with a given total number of steps.

Parameters
total_stepsTotal number of steps (must be >= 1). Defaults to 1.

Member Function Documentation

◆ advance()

void recognition::utility::progress_tracker::advance ( std::uint64_t step_count = 1u)
inlinenoexcept

Increments the number of completed steps.

Parameters
step_countNumber of steps to mark as completed. Defaults to 1.

◆ get_completed_steps()

std::uint64_t recognition::utility::progress_tracker::get_completed_steps ( ) const
inlinenodiscardnoexcept
Returns
The number of completed steps.

◆ get_completion_percentage()

percentage recognition::utility::progress_tracker::get_completion_percentage ( ) const
inlinenodiscardnoexcept
Returns
The completion percentage of the job.

◆ get_incompleted_steps()

std::uint64_t recognition::utility::progress_tracker::get_incompleted_steps ( ) const
inlinenodiscardnoexcept
Returns
The number of steps that are yet to be completed.

◆ get_total_steps()

std::uint64_t recognition::utility::progress_tracker::get_total_steps ( ) const
inlinenodiscardnoexcept
Returns
The total number of steps.

◆ is_completed()

bool recognition::utility::progress_tracker::is_completed ( ) const
inlinenodiscardnoexcept
Returns
True if the job has completed all steps, false otherwise.

◆ mark_as_completed()

void recognition::utility::progress_tracker::mark_as_completed ( )
inlinenoexcept

Marks the job as fully completed.

◆ reset()

void recognition::utility::progress_tracker::reset ( std::uint64_t total_steps)
inlinenoexcept

Reset the tracker with a new total step count.

Parameters
total_stepsNew total number of steps (must be >= 1).

◆ try_wait_for_completion()

template<typename RepresentationType , typename PeriodType >
bool recognition::utility::progress_tracker::try_wait_for_completion ( std::chrono::duration< RepresentationType, PeriodType > timeout) const
inlinenodiscard

Wait for the job to complete, or until the specified timeout duration elapses.

Template Parameters
RepresentationTypeA representation type for the duration.
PeriodTypeA ratio type representing the duration's tick period.
Parameters
timeoutMaximum duration to wait.
Returns
True if the job completed before the timeout, false otherwise.

◆ try_wait_for_completion_until()

template<typename ClockType , typename DurationType >
bool recognition::utility::progress_tracker::try_wait_for_completion_until ( std::chrono::time_point< ClockType, DurationType > deadline) const
inlinenodiscard

Wait until the job is complete or the specified deadline is reached.

Template Parameters
ClockTypeA clock type used for time points.
DurationTypeA duration type representing the clock's precision or resolution.
Parameters
deadlineThe absolute time point to wait until.
Returns
True if the job completed before the deadline, false otherwise.

◆ wait_for_completion()

void recognition::utility::progress_tracker::wait_for_completion ( ) const
inline

Wait until all steps are completed.

Member Data Documentation

◆ m_completed_steps

std::uint64_t recognition::utility::progress_tracker::m_completed_steps {0u}
private

◆ m_condition_variable

std::condition_variable recognition::utility::progress_tracker::m_condition_variable {}
mutableprivate

◆ m_mutex

std::mutex recognition::utility::progress_tracker::m_mutex {}
mutableprivate

◆ m_total_steps

std::uint64_t recognition::utility::progress_tracker::m_total_steps
private

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