diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-06-26 15:31:34 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-06-26 15:31:34 +0000 |
commit | 3ee98f3bac24fd1c70a9de3e0fbe774e762c25b3 (patch) | |
tree | ddc8d088662a88101670150c491012427c85b5bf /libdimensionxx/progress.cpp | |
parent | d56d643d412e06ff1e5239f8ebbd96f716b416bd (diff) | |
download | dimension-3ee98f3bac24fd1c70a9de3e0fbe774e762c25b3.tar.xz |
Add lots of comments, and some code fixes discovered in the process.
Diffstat (limited to 'libdimensionxx/progress.cpp')
-rw-r--r-- | libdimensionxx/progress.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/libdimensionxx/progress.cpp b/libdimensionxx/progress.cpp index ca74571..0a32b72 100644 --- a/libdimensionxx/progress.cpp +++ b/libdimensionxx/progress.cpp @@ -25,14 +25,17 @@ namespace Dimension Persist_Base::~Persist_Base() { } + // Construct a dmnsn_progress* wrapper Progress::Progress(dmnsn_progress* progress) : m_progress(new dmnsn_progress*(progress)) { } + // Construct a dmnsn_progress* wrapper, with a known persister Progress::Progress(dmnsn_progress* progress, const Persister& persister) : m_progress(new dmnsn_progress*(progress)), m_persister(persister) { } + // Finish the progress if not yet finished and we are unique Progress::~Progress() { if (m_progress && m_progress.unique()) { @@ -45,45 +48,55 @@ namespace Dimension } } + // Get the current progress double Progress::progress() const { return dmnsn_get_progress(dmnsn()); } + // Wait until progress() >= progress void Progress::wait(double progress) const { dmnsn_wait_progress(dmnsn(), progress); } + // Start a new level of loop nesting void Progress::new_element(unsigned int total) { dmnsn_new_progress_element(dmnsn(), total); } + // Increment the progress void Progress::increment() { dmnsn_increment_progress(dmnsn()); } + // Immediately finish the progress void Progress::done() { - dmnsn_progress_done(dmnsn()); + dmnsn_done_progress(dmnsn()); } + // Wait for progress completion void Progress::finish() { - if (m_progress.unique()) { - dmnsn_finish_progress(dmnsn()); - m_progress.reset(); - } else { + if (!m_progress) { + throw Dimension_Error("Attempt to finish Progress twice."); + } + + if (!m_progress.unique()) { throw Dimension_Error("Attempt to finish non-unique Progress."); } + + dmnsn_finish_progress(dmnsn()); + m_progress.reset(); // Don't try again } // Access the set of persisted objects @@ -93,6 +106,8 @@ namespace Dimension return m_persister; } + // Access the underlying dmnsn_progress* + dmnsn_progress* Progress::dmnsn() { |