|
Boost : |
From: Rainer Deyke (root_at_[hidden])
Date: 2001-05-07 22:57:57
----- Original Message -----
From: "Jesse Jones" <jesjones_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, May 07, 2001 4:55 PM
Subject: [boost] Re: about function.hpp
> Sure, you return a cookie used to identify the timer. But if you make
> the reasonable requirement that you can't install multiple timers
> on one callback you can ditch the cookie. I don't think it buys you
> anything: it's just one more piece of data for users to juggle.
> Whereas with my approach you can create a new callback whenever you
> need to interact with the timer.
In the specific case of timers, you probably want a class to manage the
lifetime of a timer:
class Timer {
Timer(const function<void>& g, int ms) : f(g) { whatever.add_timer(f,
ms); }
~Timer() { whatever.remove_timer(f); }
private:
boost::function<void> f;
};
Without such a class, your code is either not exception safe, or exceedingly
difficult to read/maintain, or both. Given the necessity of such a class,
it doesn't really matter if the underlying mechanism uses cookies or not.
-- Rainer Deyke (root_at_[hidden]) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk