4#include <Rose/BasicTypes.h>
6#include <Rose/Constants.h>
7#include <ROSE_UNUSED.h>
9#include <boost/chrono.hpp>
10#include <boost/thread.hpp>
11#include <rose_isnan.h>
12#include <Sawyer/Stopwatch.h>
13#include <Sawyer/Synchronization.h>
203 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
204#if SAWYER_MULTI_THREADED
205 mutable SAWYER_THREAD_TRAITS::ConditionVariable cv_;
207 std::vector<Report> reports_;
208 size_t reportNumber_;
241 void update(
double completion,
double maximum = 1.0);
279 void pop(
double completion,
double maximum = 1.0);
304 void finished(
double completion,
double maximum = 1.0);
350 template<
class Functor>
351 bool reportRegularly(boost::chrono::milliseconds interval, Functor f,
const std::string &nameSeparator =
".")
const {
353#if SAWYER_MULTI_THREADED && !defined(ROSE_USE_CMAKE)
356 if (!f(rpt.first, rpt.second))
360 boost::this_thread::sleep_for(interval);
363 ROSE_UNUSED(interval);
365 ROSE_UNUSED(nameSeparator);
390 template<
class Functor>
391 bool reportChanges(boost::chrono::milliseconds limit, Functor f,
const std::string &nameSeparator =
".")
const {
392#if SAWYER_MULTI_THREADED && !defined(ROSE_USE_CMAKE)
394 size_t seen = TERMINATING - 1;
396 SAWYER_THREAD_TRAITS::UniqueLock lock(mutex_);
397 while (reportNumber_ == seen)
399 ASSERT_forbid(reports_.empty());
400 Report report = reports_.back();
401 report.
name = reportNameNS(nameSeparator);
402 seen = reportNumber_;
407 if (TERMINATING == seen)
409 boost::this_thread::sleep_for(limit);
414 ROSE_UNUSED(nameSeparator);
420 std::string reportNameNS(
const std::string &nameSeparator)
const;
455 if (!rose_isnan(afterCompletion))
464 if (!rose_isnan(afterCompletion))
471 progress_->pop(after_);
~ProgressTask()
Clean up subtask progress.
ProgressTask(const Progress::Ptr &progress, const std::string &name, double afterCompletion=NAN)
Prepare existing progress object for subtask.
ProgressTask(const std::string &name, double afterCompletion=NAN)
Create progress object for subtask.
void cancel()
Cancel all cleanup operations.
Progress::Ptr progress() const
Progress object being used.
A general, thread-safe way to report progress made on some task.
void update(const Report &)
Make a progress report.
bool reportRegularly(boost::chrono::milliseconds interval, Functor f, const std::string &nameSeparator=".") const
Invoke the specified function at regular intervals.
void finished()
Indicate that the task is complete.
static Ptr instance()
Factory to create a new instance of this class.
void finished(const Report &)
Indicate that the task is complete.
bool reportChanges(boost::chrono::milliseconds limit, Functor f, const std::string &nameSeparator=".") const
Invoke the specified function each time the progress changes.
std::pair< Report, double > reportLatest(const std::string &nameSeparator=".") const
Latest report and its age in seconds.
Report push(double completion, double maximum=1.0)
Push a new progress phase onto the stack.
Report push()
Push a new progress phase onto the stack.
ProgressPtr Ptr
Progress objects are reference counted.
void pop()
Pop the top progress phase from the stack.
bool isFinished() const
Predicate indicating whether the task is finished.
void pop(const Report &)
Pop the top progress phase from the stack.
void update(double completion, double maximum=1.0)
Make a progress report.
Report push(const Report &)
Push a new progress phase onto the stack.
void pop(double completion, double maximum=1.0)
Pop the top progress phase from the stack.
void finished(double completion, double maximum=1.0)
Indicate that the task is complete.
Base class for reference counted objects.
const size_t INVALID_INDEX
Invalid array index.
A single progress report.
Report(const std::string &name, double completion, double maximum=1.0)
Report with name and completion.
Report(double completion, double maximum=1.0)
Report completion with default name.
std::string name
What is being reported.
double completion
Estimated degree of completion.
double maximum
Maximum value for completion.
Report()
Initial progress report.