|
From: <ag...@us...> - 2011-01-02 00:36:29
|
Revision: 1839
http://zoolib.svn.sourceforge.net/zoolib/?rev=1839&view=rev
Author: agreen
Date: 2011-01-02 00:36:23 +0000 (Sun, 02 Jan 2011)
Log Message:
-----------
Change ZDelegate protocol so that we Set a callable, rather
than adding it, letting us make dynamic use of a ZDelegate.
Modified Paths:
--------------
trunk/zoolib/source/cxx/zoolib/ZDelegate.h
trunk/zoolib/source/cxx/zoolib/ZDelegate.mm
Modified: trunk/zoolib/source/cxx/zoolib/ZDelegate.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZDelegate.h 2010-12-29 19:32:40 UTC (rev 1838)
+++ trunk/zoolib/source/cxx/zoolib/ZDelegate.h 2011-01-02 00:36:23 UTC (rev 1839)
@@ -55,7 +55,7 @@
#ifdef __OBJC__
template <class Callable>
- void Add(SEL iSEL, ZRef<Callable> iCallable);
+ void Set(SEL iSEL, ZRef<Callable> iCallable);
operator id();
@@ -70,46 +70,46 @@
class Wrapper;
ZooLib_ZDelegate_Proxy* fProxy;
- std::map<SEL, Wrapper*> fWrappers;
+ std::map<SEL, ZRef<Wrapper> > fWrappers;
#ifdef __OBJC__
template <class Signature> class Wrapper_T;
template <class R>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(void)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(void)> > iCallable);
template <class R,
class P0>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0)> > iCallable);
template <class R,
class P0, class P1>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1)> > iCallable);
template <class R,
class P0, class P1, class P2>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2)> > iCallable);
template <class R,
class P0, class P1, class P2, class P3>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3)> > iCallable);
template <class R,
class P0, class P1, class P2, class P3, class P4>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4)> > iCallable);
template <class R,
class P0, class P1, class P2, class P3, class P4, class P5>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5)> > iCallable);
template <class R,
class P0, class P1, class P2, class P3, class P4, class P5, class P6>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6)> > iCallable);
template <class R,
class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- static Wrapper* spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6,P7)> > iCallable);
+ static ZRef<Wrapper> spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6,P7)> > iCallable);
#endif // __OBJC__
};
@@ -121,6 +121,7 @@
#pragma mark * ZDelegate::Wrapper
class ZDelegate::Wrapper
+: public ZCounted
{
friend class ZDelegate;
@@ -819,42 +820,50 @@
template <class R,
class P0>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0)>(iCallable); }
template <class R,
class P0, class P1>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1)>(iCallable); }
template <class R,
class P0, class P1, class P2>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1,P2)>(iCallable); }
template <class R,
class P0, class P1, class P2, class P3>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1,P2,P3)>(iCallable); }
template <class R,
class P0, class P1, class P2, class P3, class P4>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1,P2,P3,P4)>(iCallable); }
template <class R,
class P0, class P1, class P2, class P3, class P4, class P5>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1,P2,P3,P4,P5)>(iCallable); }
template <class R,
class P0, class P1, class P2, class P3, class P4, class P5, class P6>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1,P2,P3,P4,P5,P6)>(iCallable); }
template <class R,
class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
-ZDelegate::Wrapper* ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6,P7)> > iCallable)
+ZRef<ZDelegate::Wrapper>
+ZDelegate::spMakeWrapper(ZRef<ZCallable<R(P0,P1,P2,P3,P4,P5,P6,P7)> > iCallable)
{ return new ZDelegate::Wrapper_T<R(P0,P1,P2,P3,P4,P5,P6,P7)>(iCallable); }
// =================================================================================================
@@ -862,10 +871,12 @@
#pragma mark * ZDelegate::Add
template <class Callable>
-void ZDelegate::Add(SEL iSEL, ZRef<Callable> iCallable)
+void ZDelegate::Set(SEL iSEL, ZRef<Callable> iCallable)
{
- ZAssert(fWrappers.end() == fWrappers.find(iSEL));
- fWrappers[iSEL] = spMakeWrapper(iCallable);
+ if (iCallable)
+ fWrappers[iSEL] = spMakeWrapper(iCallable);
+ else
+ fWrappers.erase(iSEL);
}
#endif // __OBJC__
Modified: trunk/zoolib/source/cxx/zoolib/ZDelegate.mm
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZDelegate.mm 2010-12-29 19:32:40 UTC (rev 1838)
+++ trunk/zoolib/source/cxx/zoolib/ZDelegate.mm 2011-01-02 00:36:23 UTC (rev 1839)
@@ -96,8 +96,6 @@
{
fProxy->fDelegate = nil;
[fProxy release];
- for (map<SEL, Wrapper*>::iterator i = fWrappers.begin(); i != fWrappers.end(); ++i)
- delete i->second;
}
ZDelegate::operator id()
@@ -108,14 +106,14 @@
void ZDelegate::pForwardInvocation(NSInvocation* anInvocation)
{
- map<SEL, Wrapper*>::iterator i = fWrappers.find([anInvocation selector]);
+ map<SEL, ZRef<Wrapper> >::iterator i = fWrappers.find([anInvocation selector]);
if (fWrappers.end() != i)
i->second->ForwardInvocation(anInvocation);
}
NSMethodSignature* ZDelegate::pMethodSignatureForSelector(SEL aSelector)
{
- map<SEL, Wrapper*>::iterator i = fWrappers.find(aSelector);
+ map<SEL, ZRef<Wrapper> >::iterator i = fWrappers.find(aSelector);
if (fWrappers.end() != i)
return i->second->fNSMethodSignature;
return nil;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|