Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Callbacks and Timers » Callbacks with 'Disable' feature
Re: Callbacks with 'Disable' feature [message #29140 is a reply to message #29138] Thu, 07 October 2010 11:39 Go to previous messageGo to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
maybe sth as simple as this..
template <class P1>
class Callback1 : Moveable< Callback1<P1> > {
	Callback1Action<P1> *action;
	bool act;

	void Retain() const { if(action ) AtomicInc(action->count); }
	void Release()      { if(action  && AtomicDec(action->count) == 0) delete action; }

	bool operator==(const Callback1&);
	bool operator!=(const Callback1&);

public:
	typedef Callback1 CLASSNAME;

	Callback1& operator=(const Callback1& c);
	Callback1(const Callback1& c);
	void Clear()        { Release(); action = NULL; }

	void Enable(bool b = true) { act = b; }
	void Disable() { Enable(false); }
	bool Enabled() const { return act; }

	operator bool() const          { return action && action->IsValid(); }
	void Execute(P1 p1) const      { if(act && action) action->Execute(p1); }
	void operator()(P1 p1) const   { Execute(p1); }

	explicit Callback1(Callback1Action <P1> *newaction) { act = true; action = newaction; }
	Callback1() { act = true; action = NULL; }
	Callback1(_CNULL) { act = true; action = NULL; }
	~Callback1();

	static Callback1 Empty() { return CNULL; }

};

[Updated on: Thu, 07 October 2010 11:39]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: how to use timer id? and how to kill a timer
Next Topic: FIX: Callback / Tuple
Goto Forum:
  


Current Time: Wed May 15 00:10:23 CEST 2024

Total time taken to generate the page: 0.02064 seconds