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
Callbacks with 'Disable' feature [message #29138] Thu, 07 October 2010 09:43 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi all

Callbacks so far only have the Clear() behaviour. sometimes it is good to simply 'pause' its function, but later be able to reactivate them.. (withoud need to know where the callback goes to..class independant Smile

so what about a Enable() / Disable() methodpair..??

[Updated on: Thu, 07 October 2010 09:44]

Report message to a moderator

Re: Callbacks with 'Disable' feature [message #29140 is a reply to message #29138] Thu, 07 October 2010 11:39 Go to previous messageGo to next 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

Re: Callbacks with 'Disable' feature [message #29142 is a reply to message #29140] Thu, 07 October 2010 11:44 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
BTW: in Callback.h:161 is missing the Execute() definition for Gate4<>. here comes with act already placed..

template <class P1, class P2, class P3, class P4>
bool Gate4<P1, P2, P3, P4>::Execute(P1 p1, P2 p2, P3 p3, P4 p4) const {
	return (void *)action == (void *)1 ? true : (act && action) ? action->Execute(p1, p2, p3, p4) : false;
}
Re: Callbacks with 'Disable' feature [message #29220 is a reply to message #29142] Mon, 11 October 2010 16:52 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
any comments on this?
Re: Callbacks with 'Disable' feature [message #29221 is a reply to message #29220] Mon, 11 October 2010 19:34 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi kohait,

The only comment I can give you is that I actually never needed such thing. I think there are two possible cases: 1) You need to disable some specific callbacks, or 2) you need to disable callback on a specific place of your code. Both are very easily solvable even without Callback::Disable(). For 1) it is just adding "if(DoNotExecuteNow) return;" on the beginning of the callback functions you might need to disable. For the second case, it would be similar, but the if would be outside of the call, something like "if(!DoNotExecuteNow) WhenSomething();".

IMHO there is not much need for changes. Actually I never even used the Clear() method Smile

Best regards,
Honza
Re: Callbacks with 'Disable' feature [message #29229 is a reply to message #29221] Tue, 12 October 2010 10:15 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i'd be a solution ofcorse, in places where u need it. but just as Clear() it could be a helper in the cases where needed..
it was only a proposal..thanks for comment

cheers
Re: Callbacks with 'Disable' feature [message #29249 is a reply to message #29229] Wed, 13 October 2010 09:44 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
what about the missing fix? i removed the act && action..
Quote:


Callback.h:161 is missing the Execute() definition for Gate4<>


i'm wondering that noone has needed it so far Smile

template <class P1, class P2, class P3, class P4>
bool Gate4<P1, P2, P3, P4>::Execute(P1 p1, P2 p2, P3 p3, P4 p4) const {
	return (void *)action == (void *)1 ? true : action ? action->Execute(p1, p2, p3, p4) : false;
}
Re: Callbacks with 'Disable' feature [message #29407 is a reply to message #29249] Tue, 19 October 2010 10:18 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
dont forget the fix above, or should i post it in an extra thread?
Re: Callbacks with 'Disable' feature [message #29423 is a reply to message #29407] Tue, 19 October 2010 15:32 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thank you for the fix, good catch, applied.

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


Current Time: Thu Mar 28 12:35:12 CET 2024

Total time taken to generate the page: 0.01571 seconds