[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5820] Add a delay function
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5820] Add a delay function |
Date: |
Fri, 08 Nov 2013 13:06:18 +0000 |
Revision: 5820
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5820
Author: chicares
Date: 2013-11-08 13:06:17 +0000 (Fri, 08 Nov 2013)
Log Message:
-----------
Add a delay function
Modified Paths:
--------------
lmi/trunk/Makefile.am
lmi/trunk/objects.make
lmi/trunk/progress_meter.cpp
lmi/trunk/progress_meter.hpp
lmi/trunk/progress_meter_wx.cpp
Modified: lmi/trunk/Makefile.am
===================================================================
--- lmi/trunk/Makefile.am 2013-11-07 14:08:11 UTC (rev 5819)
+++ lmi/trunk/Makefile.am 2013-11-08 13:06:17 UTC (rev 5820)
@@ -878,7 +878,8 @@
null_stream.cpp \
progress_meter.cpp \
progress_meter_cli.cpp \
- progress_meter_test.cpp
+ progress_meter_test.cpp \
+ timer.cpp
test_progress_meter_CXXFLAGS = $(AM_CXXFLAGS)
test_progress_meter_LDADD = \
liblmi.la
Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make 2013-11-07 14:08:11 UTC (rev 5819)
+++ lmi/trunk/objects.make 2013-11-08 13:06:17 UTC (rev 5820)
@@ -881,6 +881,7 @@
progress_meter.o \
progress_meter_cli.o \
progress_meter_test.o \
+ timer.o \
regex_test$(EXEEXT): EXTRA_LDFLAGS = -Wl,--allow-multiple-definition
regex_test$(EXEEXT): \
Modified: lmi/trunk/progress_meter.cpp
===================================================================
--- lmi/trunk/progress_meter.cpp 2013-11-07 14:08:11 UTC (rev 5819)
+++ lmi/trunk/progress_meter.cpp 2013-11-08 13:06:17 UTC (rev 5820)
@@ -29,6 +29,7 @@
#include "progress_meter.hpp"
#include "alert.hpp"
+#include "timer.hpp" // lmi_sleep()
#include <sstream>
@@ -85,6 +86,11 @@
{
}
+void progress_meter::dawdle(int seconds) const
+{
+ do_dawdle(seconds);
+}
+
bool progress_meter::reflect_progress()
{
if(max_count_ <= count_)
@@ -125,3 +131,14 @@
return max_count_;
}
+/// Pause for the number of seconds given in the argument.
+///
+/// This default implementation calls lmi_sleep(). The overriding
+/// implementation for a GUI library would naturally use a more
+/// sophisticated technique.
+
+void progress_meter::do_dawdle(int seconds) const
+{
+ lmi_sleep(seconds);
+}
+
Modified: lmi/trunk/progress_meter.hpp
===================================================================
--- lmi/trunk/progress_meter.hpp 2013-11-07 14:08:11 UTC (rev 5819)
+++ lmi/trunk/progress_meter.hpp 2013-11-08 13:06:17 UTC (rev 5820)
@@ -56,6 +56,8 @@
/// specified by progress_meter_unit_test_stream(), to facilitate
/// unit testing. Used only with the command-line interface.
///
+/// dawdle(): Pause for the number of seconds given in the argument.
+///
/// reflect_progress(): Perform periodic processing: throw an
/// exception if the iteration counter equals or exceeds its maximum;
/// then increment the counter; then call show_progress_message() and
@@ -76,6 +78,8 @@
///
/// Protected interface--virtual.
///
+/// do_dawdle(): Implement dawdle().
+///
/// progress_message(): Return a string to be displayed when progress
/// is reported.
///
@@ -108,6 +112,18 @@
///
/// Design alternatives considered; rationale for design choices.
///
+/// dawdle() is a non-static public member. It cannot be a private
+/// member called by reflect_progress(), as in this example:
+/// for(...) {
+/// if(condition)
+/// do_something();
+/// reflect_progress(seconds_to_dawdle);
+/// because no pause is wanted when the condition is false. It cannot
+/// be static, because it must call virtual do_dawdle() to distinguish
+/// behavior by user interface. It's a member of this class only for
+/// convenience; if it turns out to be useful outside this context,
+/// then it should become a standalone function in a different module.
+///
/// reflect_progress() throws an exception if the iteration counter
/// equals or exceeds its maximum. This condition is tested before
/// incrementing the counter. Thus, it enforces the invariant expected
@@ -191,6 +207,7 @@
,e_unit_test_mode
};
+ void dawdle(int seconds) const;
bool reflect_progress();
void culminate();
@@ -206,9 +223,10 @@
int count() const;
int max_count() const;
- virtual std::string progress_message() const = 0;
- virtual bool show_progress_message() = 0;
- virtual void culminate_ui() = 0;
+ virtual void do_dawdle(int seconds) const ;
+ virtual std::string progress_message () const = 0;
+ virtual bool show_progress_message() = 0;
+ virtual void culminate_ui () = 0;
private:
int count_;
Modified: lmi/trunk/progress_meter_wx.cpp
===================================================================
--- lmi/trunk/progress_meter_wx.cpp 2013-11-07 14:08:11 UTC (rev 5819)
+++ lmi/trunk/progress_meter_wx.cpp 2013-11-08 13:06:17 UTC (rev 5820)
@@ -28,9 +28,10 @@
#include "progress_meter.hpp"
-#include "wx_utility.hpp"
+#include "wx_utility.hpp" // TopWindow()
#include <wx/progdlg.h>
+#include <wx/utils.h> // wxSleep()
#include <sstream>
@@ -66,6 +67,8 @@
virtual ~concrete_progress_meter();
private:
+ // progress_meter overrides.
+ virtual void do_dawdle(int seconds) const;
// progress_meter required implementation.
virtual std::string progress_message() const;
virtual bool show_progress_message();
@@ -104,6 +107,11 @@
{
}
+void concrete_progress_meter::do_dawdle(int seconds) const
+{
+ wxSleep(seconds);
+}
+
std::string concrete_progress_meter::progress_message() const
{
std::ostringstream oss;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5820] Add a delay function,
Greg Chicares <=