Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48721 - in sandbox/guigl: boost/guigl libs/guigl/example libs/guigl/src
From: stipe_at_[hidden]
Date: 2008-09-11 02:11:25


Author: srajko
Date: 2008-09-11 02:11:24 EDT (Thu, 11 Sep 2008)
New Revision: 48721
URL: http://svn.boost.org/trac/boost/changeset/48721

Log:
added timeout callback support
Text files modified:
   sandbox/guigl/boost/guigl/application.hpp | 1 +
   sandbox/guigl/libs/guigl/example/window_example.cpp | 6 ++++++
   sandbox/guigl/libs/guigl/src/application.cpp | 24 ++++++++++++++++++++++++
   3 files changed, 31 insertions(+), 0 deletions(-)

Modified: sandbox/guigl/boost/guigl/application.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/application.hpp (original)
+++ sandbox/guigl/boost/guigl/application.hpp 2008-09-11 02:11:24 EDT (Thu, 11 Sep 2008)
@@ -18,6 +18,7 @@
 public:
     static void run();
     static boost::signal<void()> &on_idle();
+ static void timeout(const boost::function<void()> &, unsigned milliseconds);
 };
 
 }}

Modified: sandbox/guigl/libs/guigl/example/window_example.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/example/window_example.cpp (original)
+++ sandbox/guigl/libs/guigl/example/window_example.cpp 2008-09-11 02:11:24 EDT (Thu, 11 Sep 2008)
@@ -35,6 +35,11 @@
     application::on_idle().disconnect_all_slots();
 }
 
+void timer()
+{
+ std::cout << "5 seconds have elapsed." << std::endl;
+}
+
 int main()
 {
     window test_window1(( _label = "window example 1", _size=size_type(300,300) ));
@@ -81,5 +86,6 @@
     test_window_3d << new two_spheres(default_parameters());
     
     application::on_idle().connect(&idle);
+ application::timeout(&timer, 5000);
     application::run();
 }
\ No newline at end of file

Modified: sandbox/guigl/libs/guigl/src/application.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/src/application.cpp (original)
+++ sandbox/guigl/libs/guigl/src/application.cpp 2008-09-11 02:11:24 EDT (Thu, 11 Sep 2008)
@@ -18,6 +18,18 @@
     {
         application::on_idle()();
     }
+
+ static std::map<int, boost::function<void()> > &outstanding_timers()
+ {
+ static std::map<int, boost::function<void()> > outstanding;
+ return outstanding;
+ }
+
+ void timer_func(int id)
+ {
+ outstanding_timers()[id]();
+ outstanding_timers().erase(id);
+ }
 }
 
 void application::run()
@@ -32,4 +44,16 @@
     return signal;
 }
 
+void application::timeout(const boost::function<void()> &func, unsigned milliseconds)
+{
+
+ int id=0;
+ while(outstanding_timers().find(id) != outstanding_timers().end())
+ id++;
+
+ outstanding_timers()[id] = func;
+ glutTimerFunc(milliseconds, timer_func, id);
+}
+
+
 }}
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk