stlab.adobe.com Adobe Systems Incorporated

periodical.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_FUTURE_PERIODICAL_HPP
00010 #define ADOBE_FUTURE_PERIODICAL_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <adobe/future/platform_periodical_data.hpp>
00017 
00018 #include <boost/bind.hpp>
00019 #include <boost/function.hpp>
00020 
00021 #include <cassert>
00022 
00023 /*************************************************************************************************/
00024 
00025 namespace adobe {
00026 
00027 /*************************************************************************************************/
00028 
00029 class periodical_t
00030 {
00031 public:
00032     typedef boost::function<void ()> periodical_proc_t;
00033 
00034     explicit periodical_t(const periodical_proc_t& proc = periodical_proc_t(),
00035                           std::size_t              millisecond_delay = 200) :
00036         is_blocked_m(false),
00037         proc_m(proc),
00038         data_m(periodical_platform_data_t::fire_proc_t(), millisecond_delay)
00039     {
00040         // NOTE (fbrereto) : MSVC 8 doesn't allow "this" to be used
00041         //                   in a constructor initializer, so we
00042         //                   assign it here.
00043 
00044         data_m.fire_m = boost::bind(&periodical_t::fire, boost::ref(*this));
00045     }
00046 
00047     ~periodical_t()
00048     { /* the necessary stuff will auto-destruct */ }
00049 
00050     inline void monitor(const periodical_proc_t& proc)
00051     { proc_m = proc; }
00052 
00053     inline void fire() const
00054     {
00055         if (proc_m.empty() == false && is_blocked_m == false)
00056             proc_m();
00057     }
00058 
00059     bool is_blocked_m; // if true, the proc will not fire when the time comes
00060 
00061 private:
00062     periodical_proc_t          proc_m;
00063     periodical_platform_data_t data_m;
00064 };
00065 
00066 /*************************************************************************************************/
00067 
00068 } // namespace adobe
00069 
00070 /*************************************************************************************************/
00071 
00072 #endif
00073 
00074 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google