#include <TCLTimer.h> ... class CTCLTimer : public CTCLInterpreterObject { public: CTCLTimer (); CTCLTimer(CTCLInterpreter* pInterp, UInt_t nMsec = 0); virtual ~CTCLTimer ( ); Tk_TimerToken getToken() const; UInt_t getMsec() const; Bool_t IsSet() const; virtual void operator() () = 0; void Set () ; void Set(UInt_t nms); void Clear () ; };
Tcl/Tk provide a mechanism for scheduling functions to be executed
after a time delay specified in milliseconds. The CTCLTimer
class is an abstract base class that provides an interface into the API
for that facility. To use CTCLTimer
you must
create a class derived from CTCLTimer
that
overrides and implement the operator()
function.
Create an object from the resulting function class. Use the object's
Set
and Clear
members to schedule
or cancel a scheduled execution. The code fragment
example below shows how to do this
to create a class that periodically emits the text "Tick" to stderr.
Many #include directives are missing for brevity.
// Interface toTicker
normally goes in a header. class Ticker : public CTCLTimer { public: Ticker(CTCLInterpreter* pInterp, int seconds); virtual ~Ticker(); virtual void operator()(); }; ... // Implementation ofTicker
normally goes in a .cpp // Constructor of Ticker: Ticker::Ticker(int seconds) : CTCLTimer(pInterp, seconds*1000) { Set(); // Schedule first one. } // Destructor.. chain to base class. Ticker::~Ticker() {} // called when timer goes off: void Ticker::operator()() { cerr << "Tick\n"; Set(); // Schedule next one. } ... Ticker Tick(pInterp, 1); // Tick every second.
Construct timer objects. The first form of the constructor creates a timer
object that must be later bound into an interpreter via a call to
CTCLInterpreterObject
::Bind
.
The seconf form of the contructor creates a timer object that is already
bound to pInterp
and has an initial schedule delay
of nMsec
.
These two members access internal state of the object.
getToken
returns the Tk_TimerToken
associated with the timer object. This is the Tcl/Tk token that
identifies the timer request to the interpreter.
getMsec
retrieves the current value of the delay parameter
in milliseconds.
This function must be overidden and implemented in concrete timer classes. See the example in DESCRIPTION above.
Set
schedules the object for execution. If
nms
is provided it is saved as the scheduling
parameter and determines the delay
in milliseconds before operator()
is
next called. If not provided, the most recently used delay will be
used again.
IsSet
returns kfTRUE if the
timer is currently pending, or kfFALSE if no pending
timer request is active.
If a Timer request is pending, cancels it. If no timer request is pending, this function does nothing, and does not report an error.