1 #ifndef ROSE_Progress_H
2 #define ROSE_Progress_H
4 #include <rosePublicConfig.h>
5 #include <boost/chrono.hpp>
6 #include <boost/thread.hpp>
7 #include <Rose/Constants.h>
8 #include <rose_isnan.h>
9 #include <Sawyer/SharedPointer.h>
10 #include <Sawyer/Stopwatch.h>
11 #include <Sawyer/Synchronization.h>
201 mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
202 #if SAWYER_MULTI_THREADED
203 mutable SAWYER_THREAD_TRAITS::ConditionVariable cv_;
205 std::vector<Report> reports_;
206 size_t reportNumber_;
239 void update(
double completion,
double maximum = 1.0);
240 void update(
const Report&);
258 Report
push(
double completion,
double maximum = 1.0);
259 Report
push(
const Report&);
277 void pop(
double completion,
double maximum = 1.0);
278 void pop(
const Report&);
302 void finished(
double completion,
double maximum = 1.0);
325 std::pair<Report,
double >
reportLatest(
const std::string &nameSeparator =
".")
const;
348 template<
class Functor>
349 bool reportRegularly(boost::chrono::milliseconds interval, Functor f,
const std::string &nameSeparator =
".")
const {
351 #if SAWYER_MULTI_THREADED && !defined(ROSE_USE_CMAKE)
354 if (!f(rpt.first, rpt.second))
358 boost::this_thread::sleep_for(interval);
385 template<
class Functor>
386 bool reportChanges(boost::chrono::milliseconds limit, Functor f,
const std::string &nameSeparator =
".")
const {
387 #if SAWYER_MULTI_THREADED && !defined(ROSE_USE_CMAKE) // makes no sense for single threaded. Does not compile with cmake
389 size_t seen = TERMINATING - 1;
391 SAWYER_THREAD_TRAITS::UniqueLock lock(mutex_);
392 while (reportNumber_ == seen)
394 ASSERT_forbid(reports_.empty());
395 Report report = reports_.back();
396 report.
name = reportNameNS(nameSeparator);
397 seen = reportNumber_;
402 if (TERMINATING == seen)
404 boost::this_thread::sleep_for(limit);
412 std::string reportNameNS(
const std::string &nameSeparator)
const;
447 if (!rose_isnan(afterCompletion))
456 if (!rose_isnan(afterCompletion))
463 progress_->pop(after_);
double maximum
Maximum value for completion.
bool reportRegularly(boost::chrono::milliseconds interval, Functor f, const std::string &nameSeparator=".") const
Invoke the specified function at regular intervals.
std::pair< Report, double > reportLatest(const std::string &nameSeparator=".") const
Latest report and its age in seconds.
void pop()
Pop the top progress phase from the stack.
A general, thread-safe way to report progress made on some task.
Report push()
Push a new progress phase onto the stack.
double completion
Estimated degree of completion.
Sawyer::SharedPointer< Progress > Ptr
Progress objects are reference counted.
std::string name
What is being reported.
ProgressTask(const Progress::Ptr &progress, const std::string &name, double afterCompletion=NAN)
Prepare existing progress object for subtask.
Report()
Initial progress report.
bool isFinished() const
Predicate indicating whether the task is finished.
Main namespace for the ROSE library.
void cancel()
Cancel all cleanup operations.
bool reportChanges(boost::chrono::milliseconds limit, Functor f, const std::string &nameSeparator=".") const
Invoke the specified function each time the progress changes.
Base class for reference counted objects.
void update(double completion, double maximum=1.0)
Make a progress report.
ProgressTask(const std::string &name, double afterCompletion=NAN)
Create progress object for subtask.
static Ptr instance()
Factory to create a new instance of this class.
Report(const std::string &name, double completion, double maximum=1.0)
Report with name and completion.
A single progress report.
const size_t INVALID_INDEX(static_cast< size_t >(-1))
Invalid array index.
void finished()
Indicate that the task is complete.
~ProgressTask()
Clean up subtask progress.
Report(double completion, double maximum=1.0)
Report completion with default name.
Progress::Ptr progress() const
Progress object being used.