Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GNASH_VIRTUAL_CLOCK_H
00021 #define GNASH_VIRTUAL_CLOCK_H
00022
00023 #include <cassert>
00024
00025 namespace gnash
00026 {
00027
00029
00033 class VirtualClock
00034 {
00035 public:
00036
00038
00040
00045 virtual unsigned long int elapsed() const=0;
00046
00048 virtual void restart()=0;
00049
00050 virtual ~VirtualClock() {}
00051 };
00052
00054 class InterruptableVirtualClock : public VirtualClock
00055 {
00056
00057 public:
00058
00060
00069 InterruptableVirtualClock(VirtualClock& src)
00070 :
00071 _src(src),
00072 _elapsed(0),
00073 _offset(_src.elapsed()),
00074 _paused(true)
00075 {
00076 }
00077
00079 unsigned long int elapsed() const
00080 {
00081 if ( ! _paused )
00082 _elapsed = _src.elapsed()-_offset;
00083 return _elapsed;
00084 }
00085
00086 void restart()
00087 {
00088 _elapsed = 0;
00089 _offset = _src.elapsed();
00090 }
00091
00092 void pause()
00093 {
00094 if ( _paused ) return;
00095 _paused = true;
00096 }
00097
00098 void resume()
00099 {
00100 if ( ! _paused ) return;
00101 _paused = false;
00102
00103 unsigned long now = _src.elapsed();
00104 _offset = ( now - _elapsed );
00105 assert( now-_offset == _elapsed );
00106 }
00107
00108 private:
00109
00110 VirtualClock& _src;
00111
00112 mutable unsigned long int _elapsed;
00113
00114 unsigned long int _offset;
00115
00116 bool _paused;
00117 };
00118
00119
00120 }
00121
00122 #endif // GNASH_VIRTUAL_CLOCK_H
00123