![]() |
libsemigroups
v3.0.0
C++ library for semigroups and monoids
|
Defined in runner.hpp
Many of the classes in libsemigroups
implementing the algorithms that are the reason for the existence of this library, are derived from Runner. The Runner class exists to collect various common tasks required by such a derived class with a possibly long running run. These common tasks include:
Public Types | |
enum class | state { never_run = 0 , running_to_finish = 1 , running_for = 2 , running_until = 3 , timed_out = 4 , stopped_by_predicate = 6 , not_running = 7 , dead = 8 } |
Enum class for the state of the Runner. More... | |
![]() | |
using | nanoseconds = std::chrono::nanoseconds |
Alias for std::chrono::nanoseconds. | |
using | time_point = std::chrono::high_resolution_clock::time_point |
Alias for std::chrono::high_resolution_clock::time_point. | |
Public Member Functions | |
Runner () | |
Default constructor. | |
Runner (Runner &&other) | |
Move constructor. | |
Runner (Runner const &other) | |
Copy constructor. | |
state | current_state () const noexcept |
Return the current state. | |
bool | dead () const noexcept |
Check if the runner is dead. | |
bool | finished () const |
Check if run has been run to completion or not. | |
Runner & | init () |
Initialize an existing Runner object. | |
void | kill () noexcept |
Stop run from running (thread-safe). | |
Runner & | operator= (Runner &&other) |
Move assignment operator. | |
Runner & | operator= (Runner const &other) |
Copy assignment operator. | |
void | report_why_we_stopped () const |
Report why run stopped. | |
void | run () |
Run until finished. | |
void | run_for (std::chrono::nanoseconds t) |
Run for a specified amount of time. | |
template<typename Time> | |
void | run_for (Time t) |
Run for a specified amount of time. | |
void | run_until (bool(*func)()) |
Run until a nullary predicate returns true or finished. | |
template<typename Func> | |
void | run_until (Func &&func) |
Run until a nullary predicate returns true or finished. | |
bool | running () const noexcept |
Check if currently running. | |
bool | running_for () const noexcept |
Check if the runner is currently running for a particular length of time. | |
bool | running_until () const noexcept |
Check if the runner is currently running until a nullary predicate returns true . | |
bool | started () const noexcept |
Check if run has been called at least once before. | |
bool | stopped () const |
Check if the runner is stopped. | |
bool | stopped_by_predicate () const |
Check if the runner was stopped, or should stop, because of the argument last passed to run_until. | |
virtual bool | success () const |
Check if run has been run to completion successfully. | |
bool | timed_out () const |
Check if the amount of time passed to run_for has elapsed. | |
![]() | |
Reporter () | |
Default constructor. | |
Reporter (Reporter &&that) | |
Default move constructor. | |
Reporter (Reporter const &that) | |
Default copy constructor. | |
void | emit_divider () |
Reporter & | init () |
Initialize an existing Reporter object. | |
time_point | last_report () const noexcept |
Get the time point of the last report. | |
Reporter & | operator= (Reporter &&that) |
Default move assignment operator. | |
Reporter & | operator= (Reporter const &that) |
Default copy assignment operator. | |
bool | report () const |
Check if it is time to report. | |
std::string const & | report_divider () const noexcept |
Reporter & | report_divider (std::string const &val) |
nanoseconds | report_every () const noexcept |
Get the minimum elapsed time between reports. | |
Reporter & | report_every (nanoseconds val) noexcept |
Set the minimum elapsed time between reports in nanoseconds. | |
template<typename Time> | |
Reporter & | report_every (Time t) noexcept |
Set the minimum elapsed time between reports in a unit of time other than nanoseconds. | |
std::string const & | report_prefix () const noexcept |
Get the current prefix string for reporting. | |
Reporter & | report_prefix (std::string const &val) |
Set the prefix string for reporting. | |
Reporter const & | reset_last_report () const |
Set the last report time point to now. | |
Reporter const & | reset_start_time () const |
Reset the start time (and last report) to now. | |
time_point | start_time () const noexcept |
Get the start time. | |
Additional Inherited Members | |
![]() | |
static std::chrono::nanoseconds | delta (std::chrono::high_resolution_clock::time_point const &t) |
The time between a given point and now. | |
|
strong |
Enumerator | |
---|---|
never_run | Indicates that none of run, run_for, or run_until has been called since construction or the last call to init. |
running_to_finish | Indicates that the Runner is currently running to the finish (via run). |
running_for | Indicates that the Runner is currently running for a specific amount of time (via run_for). |
running_until | Indicates that the Runner is currently running until some condition is met (via run_until). |
timed_out | Indicates that the Runner was run via run_for for a specific amount of time and that time has elapsed. |
stopped_by_predicate | Indicates that the Runner was run via run_until until the condition specified by the argument to run_until was met. |
not_running | Indicates that the Runner is not in any of the previous states and is not currently running. This can occur when, for example, run throws an exception. |
dead | Indicates that the Runner was killed (by another thread). |
Runner | ( | ) |
Returns a runner that is not started, not finished, not dead, not timed out, will run FOREVER if not instructed otherwise, that last reported at the time of construction.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
nodiscard |
Runner & init | ( | ) |
|
inlinenoexcept |
This function can be used to terminate run() from another thread. After kill() has been called the Runner may no longer be in a valid state, but will return true
from dead() .
noexcept
and is guaranteed never to throw.void report_why_we_stopped | ( | ) | const |
Reports whether run() was stopped because it is finished(), timed_out(), or dead().
void run | ( | ) |
Run the main algorithm implemented by a derived class of Runner.
void run_for | ( | std::chrono::nanoseconds | t | ) |
For this to work it is necessary to periodically check if timed_out() returns true
, and to stop if it is, in the run() member function of any derived class of Runner.
t | the time in nanoseconds to run for. |
|
inline |
For this to work it is necessary to periodically check if timed_out() returns true
, and to stop if it is, in the run() member function of any derived class of Runner.
Time | unit of time. |
t | the time to run for (in Time ). |
|
inline |
func | a function pointer. |
void run_until | ( | Func && | func | ) |
Func | the type of the argument. |
func | a callable type that will exist for at least until this function returns, or a function pointer. |
|
inlinenodiscardnoexcept |
Returns true
if run() is in the process of running and false
it is not.
bool
.noexcept
and is guaranteed never to throw.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Returns true
if run() has started to run (it can be running or not).
bool
.noexcept
and is guaranteed never to throw.
|
inlinenodiscard |
This function can be used to check whether or not run() has been stopped for whatever reason. In other words, it checks if timed_out(), finished(), or dead().
bool
.
|
inlinenodiscard |
If this
is running, then the nullary predicate is called and its return value is returned. If this
is not running, then true
is returned if and only if the last time this
was running it was stopped by a call to the nullary predicate passed to run_until().
bool
.
|
inlinenodiscardvirtual |
|
inlinenodiscard |
bool