You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
(25) |
Apr
(97) |
May
(56) |
Jun
(29) |
Jul
(65) |
Aug
(18) |
Sep
(14) |
Oct
(114) |
Nov
(12) |
Dec
(40) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(44) |
Feb
(47) |
Mar
(109) |
Apr
(114) |
May
(47) |
Jun
(36) |
Jul
(8) |
Aug
(23) |
Sep
(111) |
Oct
(64) |
Nov
(57) |
Dec
(26) |
2004 |
Jan
(2) |
Feb
(18) |
Mar
(11) |
Apr
(1) |
May
(52) |
Jun
(70) |
Jul
(37) |
Aug
(24) |
Sep
(4) |
Oct
(27) |
Nov
(4) |
Dec
(29) |
2005 |
Jan
(8) |
Feb
(36) |
Mar
(71) |
Apr
(31) |
May
(42) |
Jun
(2) |
Jul
(53) |
Aug
(43) |
Sep
(41) |
Oct
(55) |
Nov
(59) |
Dec
(51) |
2006 |
Jan
(36) |
Feb
(36) |
Mar
(19) |
Apr
(85) |
May
(33) |
Jun
(10) |
Jul
(110) |
Aug
(44) |
Sep
(10) |
Oct
(123) |
Nov
(27) |
Dec
|
2007 |
Jan
(34) |
Feb
(16) |
Mar
(21) |
Apr
(53) |
May
(6) |
Jun
(8) |
Jul
(117) |
Aug
(10) |
Sep
(131) |
Oct
(13) |
Nov
(8) |
Dec
(46) |
2008 |
Jan
(47) |
Feb
(44) |
Mar
(66) |
Apr
(2) |
May
(29) |
Jun
(37) |
Jul
(13) |
Aug
(22) |
Sep
(32) |
Oct
(55) |
Nov
(60) |
Dec
(108) |
2009 |
Jan
(23) |
Feb
(103) |
Mar
(98) |
Apr
(21) |
May
(78) |
Jun
(141) |
Jul
(130) |
Aug
(60) |
Sep
(56) |
Oct
(51) |
Nov
(26) |
Dec
(17) |
2010 |
Jan
(48) |
Feb
(49) |
Mar
(42) |
Apr
(123) |
May
(38) |
Jun
(89) |
Jul
(34) |
Aug
(64) |
Sep
(31) |
Oct
(113) |
Nov
(20) |
Dec
(104) |
2011 |
Jan
(110) |
Feb
(70) |
Mar
(43) |
Apr
(30) |
May
(48) |
Jun
(115) |
Jul
(186) |
Aug
(17) |
Sep
(69) |
Oct
(77) |
Nov
(25) |
Dec
(25) |
2012 |
Jan
(49) |
Feb
(9) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ag...@us...> - 2011-10-24 14:14:32
|
Revision: 2586 http://zoolib.svn.sourceforge.net/zoolib/?rev=2586&view=rev Author: agreen Date: 2011-10-24 14:14:21 +0000 (Mon, 24 Oct 2011) Log Message: ----------- Name change ZFuture-->ZDelivery. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h trunk/zoolib/source/cxx/zoolib/ZPromise.h Removed Paths: ------------- trunk/zoolib/source/cxx/zoolib/ZCallFuture.h trunk/zoolib/source/cxx/zoolib/ZFuture.h Added: trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h 2011-10-24 14:14:21 UTC (rev 2586) @@ -0,0 +1,54 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2011 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZCallByCaller__ +#define __ZCallByCaller__ 1 +#include "zconfig.h" + +#include "zoolib/ZCaller.h" +#include "zoolib/ZCallable.h" +#include "zoolib/ZCallable_Bind.h" +#include "zoolib/ZCallable_Function.h" +#include "zoolib/ZPromise.h" + +namespace ZooLib { + +// ================================================================================================= +#pragma mark - +#pragma mark * sCallByCaller + +template <class T> +void spCallWithPromise_T + (const ZRef<ZPromise<ZQ<T> > >& iPromise, const ZRef<ZCallable<T(void)> >& iCallable) + { iPromise->Set(sQCall(iCallable)); } + +template <class T> +ZRef<ZDelivery<ZQ<T> > > sCallByCaller + (const ZRef<ZCaller>& iCaller, const ZRef<ZCallable<T(void)> >& iCallable) + { + ZRef<ZPromise<ZQ<T> > > thePromise = sPromise<ZQ<T> >(); + if (iCaller) + iCaller->Queue(sBindR(sCallable(spCallWithPromise_T<T>), thePromise, iCallable)); + return thePromise->Get(); + } + +} // namespace ZooLib + +#endif // __ZCallByCaller__ Deleted: trunk/zoolib/source/cxx/zoolib/ZCallFuture.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCallFuture.h 2011-10-22 17:55:57 UTC (rev 2585) +++ trunk/zoolib/source/cxx/zoolib/ZCallFuture.h 2011-10-24 14:14:21 UTC (rev 2586) @@ -1,54 +0,0 @@ -/* ------------------------------------------------------------------------------------------------- -Copyright (c) 2011 Andrew Green -http://www.zoolib.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES -OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------------------------- */ - -#ifndef __ZCallFuture__ -#define __ZCallFuture__ 1 -#include "zconfig.h" - -#include "zoolib/ZCaller.h" -#include "zoolib/ZCallable.h" -#include "zoolib/ZCallable_Bind.h" -#include "zoolib/ZCallable_Function.h" -#include "zoolib/ZFuture.h" - -namespace ZooLib { - -// ================================================================================================= -#pragma mark - -#pragma mark * sCallFuture - -template <class T> -void sCallWithPromise_T - (const ZRef<ZPromise<ZQ<T> > >& iPromise, const ZRef<ZCallable<T(void)> >& iCallable) - { iPromise->Set(sQCall(iCallable)); } - -template <class T> -ZRef<ZFuture<ZQ<T> > > sCallFuture - (const ZRef<ZCaller>& iCaller, const ZRef<ZCallable<T(void)> >& iCallable) - { - ZRef<ZPromise<ZQ<T> > > thePromise = sPromise<ZQ<T> >(); - if (iCaller) - iCaller->Queue(sBindR(sCallable(sCallWithPromise_T<T>), thePromise, iCallable)); - return thePromise->Get(); - } - -} // namespace ZooLib - -#endif // __ZCallFuture__ Modified: trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h 2011-10-22 17:55:57 UTC (rev 2585) +++ trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h 2011-10-24 14:14:21 UTC (rev 2586) @@ -22,7 +22,7 @@ #define __ZCallable_Caller__ 1 #include "zconfig.h" -#include "zoolib/ZCallFuture.h" +#include "zoolib/ZCallByCaller.h" namespace ZooLib { namespace ZCallable_Caller { @@ -52,7 +52,7 @@ // From ZCallable virtual ZQ<R> QCall() { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, fCallable)->QGet().DGet(null); } @@ -81,7 +81,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0))->QGet().DGet(null); } @@ -110,7 +110,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1))->QGet().DGet(null); } @@ -139,7 +139,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2))->QGet().DGet(null); } @@ -168,7 +168,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3))->QGet().DGet(null); } @@ -198,7 +198,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4))->QGet().DGet(null); } @@ -228,7 +228,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5))->QGet().DGet(null); } @@ -258,7 +258,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6))->QGet().DGet(null); } @@ -288,7 +288,7 @@ // From ZCallable virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7))->QGet().DGet(null); } @@ -321,7 +321,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8))->QGet().DGet(null); } @@ -354,7 +354,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9))->QGet().DGet(null); } @@ -387,7 +387,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9, PA iA) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA))->QGet().DGet(null); } @@ -420,7 +420,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9, PA iA, PB iB) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iB))->QGet().DGet(null); } @@ -454,7 +454,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9, PA iA, PB iB, PC iC) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iB, iC))->QGet().DGet(null); } @@ -489,7 +489,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9, PA iA, PB iB, PC iC, PD iD) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iB, iC, iD))->QGet().DGet(null); } @@ -524,7 +524,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9, PA iA, PB iB, PC iC, PD iD, PE iE) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iB, iC, iD, iE))->QGet().DGet(null); } @@ -559,7 +559,7 @@ (P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7, P8 i8, P9 i9, PA iA, PB iB, PC iC, PD iD, PE iE, PF iF) { - return sCallFuture(fCaller, + return sCallByCaller(fCaller, sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iB, iC, iD, iE, iF))->QGet().DGet(null); } Deleted: trunk/zoolib/source/cxx/zoolib/ZFuture.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZFuture.h 2011-10-22 17:55:57 UTC (rev 2585) +++ trunk/zoolib/source/cxx/zoolib/ZFuture.h 2011-10-24 14:14:21 UTC (rev 2586) @@ -1,229 +0,0 @@ -/* ------------------------------------------------------------------------------------------------- -Copyright (c) 2011 Andrew Green -http://www.zoolib.org - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES -OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------------------------- */ - -#ifndef __ZFuture__ -#define __ZFuture__ 1 -#include "zconfig.h" - -#include "zoolib/ZCountedWithoutFinalize.h" -#include "zoolib/ZQ.h" -#include "zoolib/ZRef.h" -#include "zoolib/ZThread.h" - -namespace ZooLib { - -template <class T> class ZPromise; - -// ================================================================================================= -#pragma mark - -#pragma mark * ZFuture - -template <class T> -class ZFuture -: public ZCountedWithoutFinalize - { - ZFuture() - : fPromiseExists(true) - {} - -public: - virtual ~ZFuture() - {} - - void Wait() - { - ZAcqMtx acq(fMtx); - for (;;) - { - if (fVal || not fPromiseExists) - return; - fCnd.Wait(fMtx); - } - } - - bool WaitFor(double iTimeout) - { - ZAcqMtx acq(fMtx); - - if (fVal || not fPromiseExists) - return true; - - fCnd.WaitFor(fMtx, iTimeout); - - if (fVal || not fPromiseExists) - return true; - - return false; - } - - bool WaitUntil(ZTime iDeadline) - { - ZAcqMtx acq(fMtx); - - if (fVal || not fPromiseExists) - return true; - - fCnd.WaitUntil(fMtx, iDeadline); - - if (fVal || not fPromiseExists) - return true; - - return false; - } - - ZQ<T> QGet() - { - ZAcqMtx acq(fMtx); - while (fPromiseExists && not fVal) - fCnd.Wait(fMtx); - return fVal; - } - -private: - friend class ZPromise<T>; - ZMtx fMtx; - ZCnd fCnd; - bool fPromiseExists; - ZQ<T> fVal; - }; - -// ================================================================================================= -#pragma mark - -#pragma mark * ZPromise - -template <class T> -class ZPromise -: public ZCountedWithoutFinalize - { -public: - ZPromise() - : fFuture(new ZFuture<T>) - {} - - virtual ~ZPromise() - { - ZAcqMtx acq(fFuture->fMtx); - fFuture->fPromiseExists = false; - fFuture->fCnd.Broadcast(); - } - - bool IsSet() - { - ZAcqMtx acq(fFuture->fMtx); - return fFuture->fVal; - } - - void Set(const T& iVal) - { - ZAcqMtx acq(fFuture->fMtx); - fFuture->fVal.Set(iVal); - fFuture->fCnd.Broadcast(); - } - - bool SetIfNotSet(const T& iVal) - { - ZAcqMtx acq(fFuture->fMtx); - if (fFuture->fVal) - return false; - fFuture->fVal.Set(iVal); - fFuture->fCnd.Broadcast(); - return true; - } - - ZRef<ZFuture<T> > Get() - { return fFuture; } - -private: - ZRef<ZFuture<T> > fFuture; - }; - -// ================================================================================================= -#pragma mark - -#pragma mark * ZPromise<void> - -template <> -class ZPromise<void> -: public ZCountedWithoutFinalize - { -public: - ZPromise() - : fFuture(new ZFuture<void>) - {} - - virtual ~ZPromise() - { - ZAcqMtx acq(fFuture->fMtx); - fFuture->fPromiseExists = false; - fFuture->fCnd.Broadcast(); - } - - bool IsSet() - { - ZAcqMtx acq(fFuture->fMtx); - return fFuture->fVal; - } - - void Set() - { - ZAcqMtx acq(fFuture->fMtx); - fFuture->fVal.Set(); - fFuture->fCnd.Broadcast(); - } - - bool SetIfNotSet() - { - ZAcqMtx acq(fFuture->fMtx); - if (fFuture->fVal) - return false; - fFuture->fVal.Set(); - fFuture->fCnd.Broadcast(); - return true; - } - - ZRef<ZFuture<void> > Get() - { return fFuture; } - -private: - ZRef<ZFuture<void> > fFuture; - }; - -// ================================================================================================= -#pragma mark - -#pragma mark * sPromise - -template <class T> -ZRef<ZPromise<T> > sPromise() - { return new ZPromise<T>; } - -// ================================================================================================= -#pragma mark - -#pragma mark * sGetClear - -template <class T> -ZRef<ZFuture<T> > sGetClear(ZRef<ZPromise<T> >& ioPromise) - { - ZRef<ZFuture<T> > theFuture = ioPromise->Get(); - ioPromise.Clear(); - return theFuture; - } - -} // namespace ZooLib - -#endif // __ZFuture__ Added: trunk/zoolib/source/cxx/zoolib/ZPromise.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZPromise.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZPromise.h 2011-10-24 14:14:21 UTC (rev 2586) @@ -0,0 +1,229 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2011 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZPromise__ +#define __ZPromise__ 1 +#include "zconfig.h" + +#include "zoolib/ZCountedWithoutFinalize.h" +#include "zoolib/ZQ.h" +#include "zoolib/ZRef.h" +#include "zoolib/ZThread.h" + +namespace ZooLib { + +template <class T> class ZPromise; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZDelivery + +template <class T> +class ZDelivery +: public ZCountedWithoutFinalize + { + ZDelivery() + : fPromiseExists(true) + {} + +public: + virtual ~ZDelivery() + {} + + void Wait() + { + ZAcqMtx acq(fMtx); + for (;;) + { + if (fVal || not fPromiseExists) + return; + fCnd.Wait(fMtx); + } + } + + bool WaitFor(double iTimeout) + { + ZAcqMtx acq(fMtx); + + if (fVal || not fPromiseExists) + return true; + + fCnd.WaitFor(fMtx, iTimeout); + + if (fVal || not fPromiseExists) + return true; + + return false; + } + + bool WaitUntil(ZTime iDeadline) + { + ZAcqMtx acq(fMtx); + + if (fVal || not fPromiseExists) + return true; + + fCnd.WaitUntil(fMtx, iDeadline); + + if (fVal || not fPromiseExists) + return true; + + return false; + } + + ZQ<T> QGet() + { + ZAcqMtx acq(fMtx); + while (fPromiseExists && not fVal) + fCnd.Wait(fMtx); + return fVal; + } + +private: + friend class ZPromise<T>; + ZMtx fMtx; + ZCnd fCnd; + bool fPromiseExists; + ZQ<T> fVal; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZPromise + +template <class T> +class ZPromise +: public ZCountedWithoutFinalize + { +public: + ZPromise() + : fDelivery(new ZDelivery<T>) + {} + + virtual ~ZPromise() + { + ZAcqMtx acq(fDelivery->fMtx); + fDelivery->fPromiseExists = false; + fDelivery->fCnd.Broadcast(); + } + + bool IsSet() + { + ZAcqMtx acq(fDelivery->fMtx); + return fDelivery->fVal; + } + + void Set(const T& iVal) + { + ZAcqMtx acq(fDelivery->fMtx); + fDelivery->fVal.Set(iVal); + fDelivery->fCnd.Broadcast(); + } + + bool SetIfNotSet(const T& iVal) + { + ZAcqMtx acq(fDelivery->fMtx); + if (fDelivery->fVal) + return false; + fDelivery->fVal.Set(iVal); + fDelivery->fCnd.Broadcast(); + return true; + } + + ZRef<ZDelivery<T> > Get() + { return fDelivery; } + +private: + ZRef<ZDelivery<T> > fDelivery; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZPromise<void> + +template <> +class ZPromise<void> +: public ZCountedWithoutFinalize + { +public: + ZPromise() + : fDelivery(new ZDelivery<void>) + {} + + virtual ~ZPromise() + { + ZAcqMtx acq(fDelivery->fMtx); + fDelivery->fPromiseExists = false; + fDelivery->fCnd.Broadcast(); + } + + bool IsSet() + { + ZAcqMtx acq(fDelivery->fMtx); + return fDelivery->fVal; + } + + void Set() + { + ZAcqMtx acq(fDelivery->fMtx); + fDelivery->fVal.Set(); + fDelivery->fCnd.Broadcast(); + } + + bool SetIfNotSet() + { + ZAcqMtx acq(fDelivery->fMtx); + if (fDelivery->fVal) + return false; + fDelivery->fVal.Set(); + fDelivery->fCnd.Broadcast(); + return true; + } + + ZRef<ZDelivery<void> > Get() + { return fDelivery; } + +private: + ZRef<ZDelivery<void> > fDelivery; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * sPromise + +template <class T> +ZRef<ZPromise<T> > sPromise() + { return new ZPromise<T>; } + +// ================================================================================================= +#pragma mark - +#pragma mark * sGetClear + +template <class T> +ZRef<ZDelivery<T> > sGetClear(ZRef<ZPromise<T> >& ioPromise) + { + ZRef<ZDelivery<T> > theDelivery = ioPromise->Get(); + ioPromise.Clear(); + return theDelivery; + } + +} // namespace ZooLib + +#endif // __ZPromise__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-22 17:56:04
|
Revision: 2585 http://zoolib.svn.sourceforge.net/zoolib/?rev=2585&view=rev Author: agreen Date: 2011-10-22 17:55:57 +0000 (Sat, 22 Oct 2011) Log Message: ----------- sGetDuration-->spGetDuration Add ZTween_Null Use 0 <= iTime < 1 Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTween.h trunk/zoolib/source/cxx/zoolib/ZTween_Std.h Modified: trunk/zoolib/source/cxx/zoolib/ZTween.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-21 20:25:48 UTC (rev 2584) +++ trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-22 17:55:57 UTC (rev 2585) @@ -84,9 +84,38 @@ virtual double Duration() = 0; }; +// ================================================================================================= +#pragma mark - +#pragma mark * sTween_Null + template <class Val> -static double sGetDuration(const ZRef<ZTween<Val> >& iTween, ZQ<double>& ioCache) +class ZTween_Null { +public: + ZTween_Null() + {} + + virtual ZQ<Val> QValAt(double iTime) + { return null; } + + virtual double Duration() + { return 0; } + }; + +template <class Val> +ZRef<ZTween<Val> > sTween_Null() + { + static ZRef<ZTween<Val> > spTween = new ZTween_Null<Val>; + return spTween; + } + +// ================================================================================================= +#pragma mark - +#pragma mark * spGetDuration + +template <class Val> +double spGetDuration(const ZRef<ZTween<Val> >& iTween, ZQ<double>& ioCache) + { if (not ioCache) ioCache = iTween->Duration(); return *ioCache; @@ -111,7 +140,7 @@ { return fCombiner(f0->QValAt(iTime), f1->QValAt(iTime)); } virtual double Duration() - { return std::max(sGetDuration(f0, fD0), sGetDuration(f1, fD1)); } + { return std::max(spGetDuration(f0, fD0), spGetDuration(f1, fD1)); } private: Combiner fCombiner; @@ -194,7 +223,7 @@ { return fCombiner(f0->QValAt(iTime), f1->QValAt(iTime)); } virtual double Duration() - { return std::min(sGetDuration(f0, fD0), sGetDuration(f1, fD1)); } + { return std::min(spGetDuration(f0, fD0), spGetDuration(f1, fD1)); } private: Combiner fCombiner; @@ -252,14 +281,14 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - if (iTime < sGetDuration(f0, fD0)) + if (iTime < spGetDuration(f0, fD0)) return f0->QValAt(iTime); else - return f1->QValAt(iTime - sGetDuration(f0, fD0)); + return f1->QValAt(iTime - spGetDuration(f0, fD0)); } virtual double Duration() - { return sGetDuration(f0, fD0) + sGetDuration(f1, fD1); } + { return spGetDuration(f0, fD0) + spGetDuration(f1, fD1); } private: const ZRef<ZTween<Val> > f0, f1; @@ -311,12 +340,12 @@ // From ZTween virtual ZQ<Val0> QValAt(double iTime) { - const double time1 = iTime / sGetDuration(f0, fD0) * sGetDuration(f1, fD1); + const double time1 = iTime / spGetDuration(f0, fD0) * spGetDuration(f1, fD1); return fCombiner(f0->QValAt(iTime), f1->QValAt(time1)); } virtual double Duration() - { return sGetDuration(f0, fD0); } + { return spGetDuration(f0, fD0); } private: Combiner fCombiner; @@ -378,13 +407,13 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - const double childDuration = sGetDuration(fTween, fTweenDuration); + const double childDuration = spGetDuration(fTween, fTweenDuration); iTime = sMinMax(0.0, iTime, childDuration * fCount); return fTween->QValAt(fmod(iTime, childDuration)); } virtual double Duration() - { return fCount * sGetDuration(fTween, fTweenDuration); } + { return fCount * spGetDuration(fTween, fTweenDuration); } private: const ZRef<ZTween<Val> > fTween; @@ -417,9 +446,9 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - if (iTime < 0 || iTime > fDuration) + if (iTime < 0 || iTime >= fDuration) return null; - return fTween->QValAt(fmod(iTime, sGetDuration(fTween, fTweenDuration))); + return fTween->QValAt(fmod(iTime, spGetDuration(fTween, fTweenDuration))); } virtual double Duration() @@ -456,7 +485,7 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - if (iTime > fDuration) + if (iTime >= fDuration) return null; return fTween->QValAt(iTime); } @@ -494,13 +523,13 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - if (iTime > this->Duration()) + if (iTime >= this->Duration()) return null; return fTween->QValAt(iTime); } virtual double Duration() - { return std::min(fAtMost, sGetDuration(fTween, fTweenDuration)); } + { return std::min(fAtMost, spGetDuration(fTween, fTweenDuration)); } private: const ZRef<ZTween<Val> > fTween; @@ -533,13 +562,13 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - if (iTime > fAtLeast) + if (iTime >= fAtLeast) return null; - return fTween->QValAt(std::min(iTime, sGetDuration(fTween, fTweenDuration))); + return fTween->QValAt(std::min(iTime, spGetDuration(fTween, fTweenDuration))); } virtual double Duration() - { return std::max(fAtLeast, sGetDuration(fTween, fTweenDuration)); } + { return std::max(fAtLeast, spGetDuration(fTween, fTweenDuration)); } private: const ZRef<ZTween<Val> > fTween; @@ -574,7 +603,7 @@ { return fTween->QValAt(iTime - fDelay); } virtual double Duration() - { return std::max(0.0, sGetDuration(fTween, fTweenDuration) + fDelay); } + { return std::max(0.0, spGetDuration(fTween, fTweenDuration) + fDelay); } private: const ZRef<ZTween<Val> > fTween; @@ -610,15 +639,15 @@ if (fRate > 0) return fTween->QValAt(iTime / fRate); else - return fTween->QValAt(sGetDuration(fTween, fTweenDuration) + iTime/fRate); + return fTween->QValAt(spGetDuration(fTween, fTweenDuration) + iTime/fRate); } virtual double Duration() { if (fRate > 0) - return fRate * sGetDuration(fTween, fTweenDuration); + return fRate * spGetDuration(fTween, fTweenDuration); else - return -fRate * sGetDuration(fTween, fTweenDuration); + return -fRate * spGetDuration(fTween, fTweenDuration); } private: @@ -650,7 +679,7 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) - { return fTween->QValAt(iTime / sGetDuration(fTween, fTweenDuration)); } + { return fTween->QValAt(iTime / spGetDuration(fTween, fTweenDuration)); } virtual double Duration() { return 1; } @@ -685,7 +714,7 @@ // From ZTween virtual ZQ<Val> QValAt(double iTime) { - if (iTime < 0 || iTime > fDuration) + if (iTime < 0 || iTime >= fDuration) return null; return fVal; } @@ -737,7 +766,7 @@ } virtual double Duration() - { return sGetDuration(fTween, fTweenDuration); } + { return spGetDuration(fTween, fTweenDuration); } private: const ZRef<ZTween<Val> > fTween; Modified: trunk/zoolib/source/cxx/zoolib/ZTween_Std.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween_Std.h 2011-10-21 20:25:48 UTC (rev 2584) +++ trunk/zoolib/source/cxx/zoolib/ZTween_Std.h 2011-10-22 17:55:57 UTC (rev 2585) @@ -576,11 +576,6 @@ template <class Val> Val spTweenFun_ElasticIn(double iTime) { - if (iTime <= 0) - return 0; - else if (iTime >= 1) - return 1; - iTime -= 1; return -1 * (pow(2, 10*iTime) * sin((iTime-0.3)*2*M_PI/0.3)); } @@ -607,15 +602,8 @@ template <class Val> Val spTweenFun_ElasticOut(double iTime) - { - if (iTime <= 0) - return 0; - else if (iTime >= 1) - return 1; + { return pow(2, -10*iTime) * sin((iTime-0.3)*2*M_PI/0.3) + 1; } - return pow(2, -10*iTime) * sin((iTime-0.3)*2*M_PI/0.3) + 1; - } - template <class Val> ZRef<ZTween<Val> > sTween_ElasticOut() { return new ZTween_Fun<Val,spTweenFun_ElasticOut>; } @@ -645,7 +633,7 @@ virtual ZQ<Val> QValAt(double iTime) { - if (iTime < 0 || iTime > 1.0) + if (iTime < 0 || iTime >= 1.0) return null; return iTime * iTime * ((fFactor + 1 ) * iTime - fFactor); } @@ -678,7 +666,7 @@ virtual ZQ<Val> QValAt(double iTime) { - if (iTime < 0 || iTime > 1.0) + if (iTime < 0 || iTime >= 1.0) return null; iTime -= 1; return iTime * iTime * ((fFactor + 1) * iTime + fFactor) + 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-21 20:25:55
|
Revision: 2584 http://zoolib.svn.sourceforge.net/zoolib/?rev=2584&view=rev Author: agreen Date: 2011-10-21 20:25:48 +0000 (Fri, 21 Oct 2011) Log Message: ----------- Revise ZTween protocol so that it returns a ZQ<Val>, and is not expected to return a usable value outside of zero-->duration. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTween.h trunk/zoolib/source/cxx/zoolib/ZTween_Std.h Modified: trunk/zoolib/source/cxx/zoolib/ZTween.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-21 02:50:27 UTC (rev 2583) +++ trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-21 20:25:48 UTC (rev 2584) @@ -26,17 +26,18 @@ #include "zoolib/ZCompat_algorithm.h" // for std::binary_function #include "zoolib/ZCompat_cmath.h" // for fmod #include "zoolib/ZDebug.h" // for fmod +#include "zoolib/ZQ.h" #include "zoolib/ZRef.h" namespace ZooLib { template <class Val0, class Val1> -Val0 sCombineTweenVals(const Val0& iVal0, const Val1& iVal1); +ZQ<Val0> sCombineTweenVals(const ZQ<Val0>& iVal0Q, const ZQ<Val1>& iVal1Q); template <class Val0, class Val1> -struct TweenCombiner : public std::binary_function<Val0, Val1, Val0> +struct TweenCombiner : public std::binary_function<ZQ<Val0>, ZQ<Val1>, ZQ<Val0> > { - Val0 operator()(const Val0& i0, const Val1& i1) const + ZQ<Val0> operator()(const ZQ<Val0>& i0, const ZQ<Val1>& i1) const { return sCombineTweenVals<Val0,Val1>(i0, i1); } }; @@ -63,26 +64,23 @@ virtual ~ZTween() {} // Our protocol - Val ValAt(bool iWrap, double iTime) + Val ValAtWrapped(double iTime) { - if (iWrap) + const double duration = this->Duration(); + if (duration <= 0) { - const double duration = this->Duration(); - if (duration <= 0) - { - iTime = 0; - } - else - { - iTime = fmod(iTime, duration); - if (iTime < 0) - iTime += duration; - } + iTime = 0; } - return this->ValAt(iTime); + else + { + iTime = fmod(iTime, duration); + if (iTime < 0) + iTime += duration; + } + return this->QValAt(iTime).Get(); } - virtual Val ValAt(double iTime) = 0; + virtual ZQ<Val> QValAt(double iTime) = 0; virtual double Duration() = 0; }; @@ -109,8 +107,8 @@ {} // From ZTween - virtual Val0 ValAt(double iTime) - { return fCombiner(f0->ValAt(iTime), f1->ValAt(iTime)); } + virtual ZQ<Val0> QValAt(double iTime) + { return fCombiner(f0->QValAt(iTime), f1->QValAt(iTime)); } virtual double Duration() { return std::max(sGetDuration(f0, fD0), sGetDuration(f1, fD1)); } @@ -192,8 +190,8 @@ {} // From ZTween - virtual Val0 ValAt(double iTime) - { return fCombiner(f0->ValAt(iTime), f1->ValAt(iTime)); } + virtual ZQ<Val0> QValAt(double iTime) + { return fCombiner(f0->QValAt(iTime), f1->QValAt(iTime)); } virtual double Duration() { return std::min(sGetDuration(f0, fD0), sGetDuration(f1, fD1)); } @@ -252,14 +250,12 @@ {} // From ZTween - virtual Val ValAt(double iTime) + virtual ZQ<Val> QValAt(double iTime) { - if (iTime <= 0) - return f0->ValAt(iTime); - else if (iTime < sGetDuration(f0, fD0)) - return f0->ValAt(iTime); + if (iTime < sGetDuration(f0, fD0)) + return f0->QValAt(iTime); else - return f1->ValAt(iTime - sGetDuration(f0, fD0)); + return f1->QValAt(iTime - sGetDuration(f0, fD0)); } virtual double Duration() @@ -313,10 +309,10 @@ {} // From ZTween - virtual Val0 ValAt(double iTime) + virtual ZQ<Val0> QValAt(double iTime) { const double time1 = iTime / sGetDuration(f0, fD0) * sGetDuration(f1, fD1); - return fCombiner(f0->ValAt(iTime), f1->ValAt(time1)); + return fCombiner(f0->QValAt(iTime), f1->QValAt(time1)); } virtual double Duration() @@ -380,11 +376,11 @@ {} // From ZTween - virtual Val ValAt(double iTime) + virtual ZQ<Val> QValAt(double iTime) { const double childDuration = sGetDuration(fTween, fTweenDuration); iTime = sMinMax(0.0, iTime, childDuration * fCount); - return fTween->ValAt(fmod(iTime, childDuration)); + return fTween->QValAt(fmod(iTime, childDuration)); } virtual double Duration() @@ -419,10 +415,11 @@ {} // From ZTween - virtual Val ValAt(double iTime) + virtual ZQ<Val> QValAt(double iTime) { - const double theTime = sMinMax(0.0, iTime, fDuration); - return fTween->ValAt(fmod(theTime, sGetDuration(fTween, fTweenDuration))); + if (iTime < 0 || iTime > fDuration) + return null; + return fTween->QValAt(fmod(iTime, sGetDuration(fTween, fTweenDuration))); } virtual double Duration() @@ -457,8 +454,12 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fTween->ValAt(iTime); } + virtual ZQ<Val> QValAt(double iTime) + { + if (iTime > fDuration) + return null; + return fTween->QValAt(iTime); + } virtual double Duration() { return fDuration; } @@ -491,8 +492,12 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fTween->ValAt(iTime); } + virtual ZQ<Val> QValAt(double iTime) + { + if (iTime > this->Duration()) + return null; + return fTween->QValAt(iTime); + } virtual double Duration() { return std::min(fAtMost, sGetDuration(fTween, fTweenDuration)); } @@ -526,8 +531,12 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fTween->ValAt(iTime); } + virtual ZQ<Val> QValAt(double iTime) + { + if (iTime > fAtLeast) + return null; + return fTween->QValAt(std::min(iTime, sGetDuration(fTween, fTweenDuration))); + } virtual double Duration() { return std::max(fAtLeast, sGetDuration(fTween, fTweenDuration)); } @@ -561,8 +570,8 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fTween->ValAt(iTime - fDelay); } + virtual ZQ<Val> QValAt(double iTime) + { return fTween->QValAt(iTime - fDelay); } virtual double Duration() { return std::max(0.0, sGetDuration(fTween, fTweenDuration) + fDelay); } @@ -596,12 +605,12 @@ { ZAssert(fRate); } // From ZTween - virtual Val ValAt(double iTime) + virtual ZQ<Val> QValAt(double iTime) { if (fRate > 0) - return fTween->ValAt(iTime / fRate); + return fTween->QValAt(iTime / fRate); else - return fTween->ValAt(sGetDuration(fTween, fTweenDuration) + iTime/fRate); + return fTween->QValAt(sGetDuration(fTween, fTweenDuration) + iTime/fRate); } virtual double Duration() @@ -640,8 +649,8 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fTween->ValAt(iTime / sGetDuration(fTween, fTweenDuration)); } + virtual ZQ<Val> QValAt(double iTime) + { return fTween->QValAt(iTime / sGetDuration(fTween, fTweenDuration)); } virtual double Duration() { return 1; } @@ -674,8 +683,12 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fVal; } + virtual ZQ<Val> QValAt(double iTime) + { + if (iTime < 0 || iTime > fDuration) + return null; + return fVal; + } virtual double Duration() { return fDuration; } @@ -716,8 +729,12 @@ {} // From ZTween - virtual Val ValAt(double iTime) - { return fOffset + fTween->ValAt(iTime); } + virtual ZQ<Val> QValAt(double iTime) + { + if (ZQ<Val> theQ = fTween->QValAt(iTime)) + return *theQ + fOffset; + return null; + } virtual double Duration() { return sGetDuration(fTween, fTweenDuration); } Modified: trunk/zoolib/source/cxx/zoolib/ZTween_Std.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween_Std.h 2011-10-21 02:50:27 UTC (rev 2583) +++ trunk/zoolib/source/cxx/zoolib/ZTween_Std.h 2011-10-21 20:25:48 UTC (rev 2584) @@ -36,8 +36,12 @@ : public ZTween<Val> { public: - virtual Val ValAt(double iTime) - { return Fun(sMinMax(0.0, iTime, 1.0)); } + virtual ZQ<Val> QValAt(double iTime) + { + if (iTime < 0 || iTime >= 1.0) + return null; + return Fun(iTime); + } virtual double Duration() { return 1; } @@ -56,8 +60,12 @@ : fTween(iTween) {} - virtual Val ValAt(double iTime) - { return Fun(fTween->ValAt(iTime)); } + virtual ZQ<Val> QValAt(double iTime) + { + if (ZQ<Param> theQ = fTween->QValAt(iTime)) + return Fun(*theQ); + return null; + } virtual double Duration() { return fTween->Duration(); } @@ -79,8 +87,12 @@ : fTween(iTween) {} - virtual Val ValAt(double iTime) - { return Val(fTween->ValAt(iTime)); } + virtual ZQ<Val> QValAt(double iTime) + { + if (ZQ<Param> theQ = fTween->QValAt(iTime)) + return Val(*theQ); + return null; + } virtual double Duration() { return fTween->Duration(); } @@ -631,9 +643,10 @@ public: ZTween_Fun_BackIn(Val iFactor) : fFactor(iFactor) {} - virtual Val ValAt(double iTime) + virtual ZQ<Val> QValAt(double iTime) { - iTime = sMinMax(0.0, iTime, 1.0); + if (iTime < 0 || iTime > 1.0) + return null; return iTime * iTime * ((fFactor + 1 ) * iTime - fFactor); } @@ -663,9 +676,10 @@ public: ZTween_Fun_BackOut(Val iFactor) : fFactor(iFactor) {} - virtual Val ValAt(double iTime) + virtual ZQ<Val> QValAt(double iTime) { - iTime = sMinMax(0.0, iTime, 1.0); + if (iTime < 0 || iTime > 1.0) + return null; iTime -= 1; return iTime * iTime * ((fFactor + 1) * iTime + fFactor) + 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-21 02:50:33
|
Revision: 2583 http://zoolib.svn.sourceforge.net/zoolib/?rev=2583&view=rev Author: agreen Date: 2011-10-21 02:50:27 +0000 (Fri, 21 Oct 2011) Log Message: ----------- Do some caching, so we only have to chase proto links once. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-10-21 02:49:58 UTC (rev 2582) +++ trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-10-21 02:50:27 UTC (rev 2583) @@ -18,10 +18,11 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------- */ +#include "zoolib/ZCountedVal.h" #include "zoolib/ZGetSet.h" #include "zoolib/ZTrail.h" +#include "zoolib/ZUtil_STL_map.h" #include "zoolib/ZYadTree.h" -#include "zoolib/ZCountedVal.h" using std::string; @@ -37,6 +38,9 @@ class Chain : public ZCounted { +private: + Chain(const Chain& iOther); + public: Chain (const ZRef<Chain>& iParent, const ZRef<ZYadMapRPos>& iYadMapRPos); @@ -51,6 +55,9 @@ const ZRef<Chain> fParent; ZRef<ZYadMapRPos> fYadMapRPos; + + std::map<string8, ZRef<Chain> > fCacheByName; + std::map<string8, ZRef<Chain> > fCacheByTrail; }; // ================================================================================================= @@ -132,6 +139,13 @@ #pragma mark - #pragma mark * Chain definition +Chain::Chain(const Chain& iOther) +: fParent(iOther.fParent) +, fYadMapRPos(iOther.fYadMapRPos->Clone().DynamicCast<ZYadMapRPos>()) +, fCacheByName(iOther.fCacheByName) +, fCacheByTrail(iOther.fCacheByTrail) + {} + Chain::Chain(const ZRef<Chain>& iParent, const ZRef<ZYadMapRPos>& iYadMapRPos) : fParent(iParent) , fYadMapRPos(iYadMapRPos) @@ -140,7 +154,7 @@ } ZRef<Chain> Chain::Clone() - { return new Chain(fParent, fYadMapRPos->Clone().DynamicCast<ZYadMapRPos>()); } + { return new Chain(*this); } ZRef<ZYadR> Chain::ReadInc(string& oName) { return fYadMapRPos->ReadInc(oName); } @@ -153,46 +167,67 @@ if (ZRef<ZYadR> theYad = this->pReadAt(iName)) return spWrap(iProto, this, theYad); - if (ZRef<ZYadStrimR> theProtoYad = fYadMapRPos->ReadAt(iProto->Get()).DynamicCast<ZYadStrimR>()) + ZRef<Chain> theChain; + if (ZQ<ZRef<Chain> > theByNameQ = ZUtil_STL::sQGet(fCacheByName, iName)) { + theChain = *theByNameQ; + } + else if (ZRef<ZYadStrimR> theProtoYad = this->pReadAt(iProto->Get()).DynamicCast<ZYadStrimR>()) + { const string theTrailString = theProtoYad->GetStrimR().ReadAll8(); - if (theTrailString.size()) + if (ZQ<ZRef<Chain> > theByTrailQ = ZUtil_STL::sQGet(fCacheByTrail, theTrailString)) { - size_t index = 0; - const ZTrail theTrail = ZTrail(theTrailString).Normalized(); - ZRef<Chain> cur = this; - - if (theTrailString[0] == '/') + theChain = *theByTrailQ; + } + else + { + if (theTrailString.size()) { - // Walk up to the root. - for (ZRef<Chain> next = null; next = cur->fParent; cur = next) - {} - } - else - { - // Follow leading bounces. - for (/*no init*/; - cur && index < theTrail.Count() && theTrail.At(index).empty(); - ++index, cur = cur->fParent) - {} - } + size_t index = 0; + const ZTrail theTrail = ZTrail(theTrailString).Normalized(); + ZRef<Chain> cur = this; - // Walk down the remainder of the trail - while (index < theTrail.Count()) - { - if (ZRef<ZYadMapRPos,0> theYadMapRPos = - cur->pReadAt(theTrail.At(index)).DynamicCast<ZYadMapRPos>()) - { break; } + if (theTrailString[0] == '/') + { + // Walk up to the root. + for (ZRef<Chain> next = null; next = cur->fParent; cur = next) + {} + } else { - cur = new Chain(cur, theYadMapRPos); - if (++index == theTrail.Count()) - return cur->ReadAt(iProto, iName); + // Follow leading bounces. + for (/*no init*/; + cur && index < theTrail.Count() && theTrail.At(index).empty(); + ++index, cur = cur->fParent) + {} } + + // Walk down the remainder of the trail + ZRef<Chain> result; + while (index < theTrail.Count()) + { + if (ZRef<ZYadMapRPos,0> theYadMapRPos = + cur->pReadAt(theTrail.At(index)).DynamicCast<ZYadMapRPos>()) + { break; } + else + { + cur = new Chain(cur, theYadMapRPos); + if (++index == theTrail.Count()) + { + theChain = cur; + break; + } + } + } } + ZUtil_STL::sInsertMustNotContain(fCacheByTrail, theTrailString, theChain); } + ZUtil_STL::sInsertMustNotContain(fCacheByName, iName, theChain); } + if (theChain) + return theChain->ReadAt(iProto, iName); + // Yay, lexical scoping, disabled for now. if (false && fParent) return spWrap(iProto, fParent, fParent->pReadAt(iName)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-21 02:50:04
|
Revision: 2582 http://zoolib.svn.sourceforge.net/zoolib/?rev=2582&view=rev Author: agreen Date: 2011-10-21 02:49:58 +0000 (Fri, 21 Oct 2011) Log Message: ----------- It is cheaper to pass const& of ZRefs, then we only retain/release if we actually need to. sCog_Both doesn't do this yet, as it's a bit more fiddly than the others. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-20 21:47:08 UTC (rev 2581) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-21 02:49:58 UTC (rev 2582) @@ -214,7 +214,7 @@ template <class Param> ZCog<Param> spCogFun_Either(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1); + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_Either @@ -242,43 +242,53 @@ template <class Param> ZCog<Param> spCogFun_Either(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1) + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) { - ZAssert(lCog0 && lCog1); + ZAssert(iCog0 && iCog1); - if (sIsTerm(lCog0)) + if (sIsTerm(iCog0)) { - if (sIsTerm(lCog1)) - return lCog0; - if ((lCog1 = lCog1->Call(lCog1, iParam))) - return lCog1; - return lCog0; + if (sIsTerm(iCog1)) + return iCog0; + if (const ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam)) + return newCog1; + return iCog0; } - else if (sCallValidCogUnchanged(lCog0, iParam)) + else { - if (sIsTerm(lCog1)) - return lCog0; - if (sCallValidCogUnchanged(lCog1, iParam)) - return iSelf; - if (not lCog1 || sIsTerm(lCog1)) - return lCog0; - return spCog_Either(lCog0, lCog1); - } - else if (not lCog0) - { - if (sIsTerm(lCog1)) - return lCog1; + ZCog<Param> newCog0 = iCog0; + if (sCallValidCogUnchanged(newCog0, iParam)) + { + if (sIsTerm(iCog1)) + return newCog0; + + ZCog<Param> newCog1 = iCog1; + if (sCallValidCogUnchanged(newCog1, iParam)) + return iSelf; + if (not newCog1 || sIsTerm(newCog1)) + return newCog0; + return spCog_Either(newCog0, newCog1); + } + else if (not newCog0) + { + if (sIsTerm(iCog1)) + return iCog1; - return lCog1->Call(lCog1, iParam); + return iCog1->Call(iCog1, iParam); + } + else if (sIsTerm(iCog1)) + { + return spCog_Either(newCog0, iCog1); + } + else if (const ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam)) + { + return spCog_Either(newCog0, newCog1); + } + else + { + return newCog0; + } } - else if (sIsTerm(lCog1) || (lCog1 = lCog1->Call(lCog1, iParam))) - { - return spCog_Either(lCog0, lCog1); - } - else - { - return lCog0; - } } template <class Param> @@ -306,7 +316,7 @@ template <class Param> ZCog<Param> spCogFun_Both(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1); + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_Both @@ -330,9 +340,11 @@ template <class Param> ZCog<Param> spCogFun_Both(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1) + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) { - ZAssert(lCog0 && lCog1); + ZAssert(iCog0 && iCog1); + ZCog<Param> lCog0 = iCog0; + ZCog<Param> lCog1 = iCog1; if (sIsTerm(lCog0)) { @@ -410,7 +422,7 @@ template <class Param> ZCog<Param> spCogFun_Each(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1); + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_Each @@ -438,37 +450,41 @@ template <class Param> ZCog<Param> spCogFun_Each(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1) + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) { - ZAssert(lCog0 && lCog1); + ZAssert(iCog0 && iCog1); - if (sIsTerm(lCog0)) + if (sIsTerm(iCog0)) { - if (sIsTerm(lCog1)) - return lCog1; - return lCog1->Call(lCog1, iParam); + if (sIsTerm(iCog1)) + return iCog1; + return iCog1->Call(iCog1, iParam); } - else if (sCallValidCogUnchanged(lCog0, iParam)) - { - return iSelf; - } - else if (not lCog0) - { - if (sIsTerm(lCog1)) - return lCog1; - return lCog1->Call(lCog1, iParam); - } - else if (sIsTerm(lCog0)) - { - if (sIsTerm(lCog1)) - return lCog1; - if ((lCog1 = lCog1->Call(lCog1, iParam))) - return spCog_Each(lCog0, lCog1); - return lCog0; - } else { - return spCog_Each(lCog0, lCog1); + ZCog<Param> newCog0 = iCog0; + if (sCallValidCogUnchanged(newCog0, iParam)) + { + return iSelf; + } + else if (not newCog0) + { + if (sIsTerm(iCog1)) + return iCog1; + return iCog1->Call(iCog1, iParam); + } + else if (sIsTerm(newCog0)) + { + if (sIsTerm(iCog1)) + return iCog1; + if (const ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam)) + return spCog_Each(newCog0, newCog1); + return newCog0; + } + else + { + return spCog_Each(newCog0, iCog1); + } } } @@ -497,7 +513,7 @@ template <class Param> ZCog<Param> spCogFun_FollowedBy_First(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, const ZCog<Param>& iCog1); + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_FollowedBy_First @@ -525,7 +541,7 @@ template <class Param> ZCog<Param> spCogFun_FollowedBy_Subsequent(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, const ZCog<Param>& iCog1); + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_FollowedBy_Subsequent @@ -539,15 +555,16 @@ template <class Param> ZCog<Param> spCogFun_FollowedBy_Subsequent(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, const ZCog<Param>& iCog1) + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) { - ZAssert(lCog0 && iCog1); + ZAssert(iCog0 && iCog1); - if (sCallValidCogUnchanged(lCog0, iParam)) + ZCog<Param> newCog0 = iCog0; + if (sCallValidCogUnchanged(newCog0, iParam)) return iSelf; - if (lCog0 && not sIsTerm(lCog0)) - return spCog_FollowedBy_Subsequent(lCog0, iCog1); + if (newCog0 && not sIsTerm(newCog0)) + return spCog_FollowedBy_Subsequent(newCog0, iCog1); if (not sIsTerm(iCog1)) return iCog1->Call(iCog1, iParam); @@ -557,25 +574,25 @@ template <class Param> ZCog<Param> spCogFun_FollowedBy_First(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, const ZCog<Param>& iCog1) + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) { - ZAssert(lCog0 && iCog1); + ZAssert(iCog0 && iCog1); - if (sIsTerm(lCog0)) + if (sIsTerm(iCog0)) { if (sIsTerm(iCog1)) return iCog1; return iCog1->Call(iCog1, iParam); } - else if ((lCog0 = lCog0->Call(lCog0, iParam))) + else if (const ZCog<Param> newCog0 = iCog0->Call(iCog0, iParam)) { - if (sIsTerm(lCog0)) + if (sIsTerm(newCog0)) { if (sIsTerm(iCog1)) return iCog1; return iCog1->Call(iCog1, iParam); } - return spCog_FollowedBy_Subsequent(lCog0, iCog1); + return spCog_FollowedBy_Subsequent(newCog0, iCog1); } else { @@ -603,7 +620,7 @@ template <class Param> ZCog<Param> spCogFun_WhileUnchanged(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> iCog0, ZCog<Param> iCog1); + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_WhileUnchanged @@ -627,18 +644,23 @@ template <class Param> ZCog<Param> spCogFun_WhileUnchanged(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog0, ZCog<Param> lCog1) + const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) { - ZAssert(lCog0 && lCog1); + ZAssert(iCog0 && iCog1); - if (sIsTerm(lCog0) || sCallValidCogChanged(lCog0, iParam)) - return lCog0; + if (sIsTerm(iCog0)) + return iCog0; - if (sCallValidCogChanged(lCog1, iParam)) + ZCog<Param> newCog0 = iCog0; + if (sCallValidCogChanged(newCog0, iParam)) + return newCog0; + + ZCog<Param> newCog1 = iCog1; + if (sCallValidCogChanged(newCog1, iParam)) { - if (lCog1 && not sIsTerm(lCog1)) - return spCog_WhileUnchanged(lCog0, lCog1); - return lCog0; + if (newCog1 && not sIsTerm(newCog1)) + return spCog_WhileUnchanged(newCog0, newCog1); + return newCog0; } return iSelf; @@ -673,20 +695,24 @@ template <class Param> ZCog<Param> spCogFun_While(const ZCog<Param>& iSelf, Param iParam, - const ZCog<Param>& iCog_Init, ZCog<Param> lCog) + const ZCog<Param>& iCog_Init, const ZCog<Param>& iCog) { - ZAssert(iCog_Init && lCog); + ZAssert(iCog_Init && iCog); - if (sIsTerm(lCog) || sCallValidCogUnchanged(lCog, iParam)) + if (sIsTerm(iCog)) return iSelf; - if (not lCog) + ZCog<Param> newCog = iCog; + if (sCallValidCogUnchanged(newCog, iParam)) + return iSelf; + + if (not newCog) return null; - if (sIsTerm(lCog)) + if (sIsTerm(newCog)) return sCallCog(sCog_While(iCog_Init, iCog_Init), iParam); //## Dangerous else - return sCog_While(iCog_Init, lCog); + return sCog_While(iCog_Init, newCog); } template <class Param> @@ -721,18 +747,18 @@ template <class Param> ZCog<Param> spCogFun_Repeat(const ZCog<Param>& iSelf, Param iParam, - size_t iCount, const ZCog<Param>& iCog_Init, ZCog<Param> lCog) + size_t iCount, const ZCog<Param>& iCog_Init, const ZCog<Param>& iCog) { - if (sCallCogUnchanged(lCog, iParam)) + if (sCallCogUnchanged(iCog, iParam)) return iSelf; - if (not lCog) + if (not iCog) return null; - if (sIsTerm(lCog)) + if (sIsTerm(iCog)) return sCallCog(spCog_Repeat(iCount - 1, iCog_Init, iCog_Init), iParam); else - return spCog_Repeat(iCount, iCog_Init, lCog); + return spCog_Repeat(iCount, iCog_Init, iCog); } template <class Param> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-20 21:47:15
|
Revision: 2581 http://zoolib.svn.sourceforge.net/zoolib/?rev=2581&view=rev Author: agreen Date: 2011-10-20 21:47:08 +0000 (Thu, 20 Oct 2011) Log Message: ----------- Replace ZTween_Scale with a use of ZTween_Applied. Cache child Tween's durations. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTween.h Modified: trunk/zoolib/source/cxx/zoolib/ZTween.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-19 23:29:47 UTC (rev 2580) +++ trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-20 21:47:08 UTC (rev 2581) @@ -86,57 +86,14 @@ virtual double Duration() = 0; }; -// ================================================================================================= -#pragma mark - -#pragma mark * ZTween_Indirect - template <class Val> -class ZTween_Indirect -: public ZTween<Val> +static double sGetDuration(const ZRef<ZTween<Val> >& iTween, ZQ<double>& ioCache) { -public: - ZTween_Indirect() - {} + if (not ioCache) + ioCache = iTween->Duration(); + return *ioCache; + } - ZTween_Indirect(const ZRef<ZTween<Val> >& iTween) - : fTween(iTween) {} - -// From ZTween - virtual Val ValAt(double iTime) - { - if (ZRef<ZTween<Val> > theTween = fTween) - return theTween->ValAt(iTime); - return Val(); - } - - virtual double Duration() - { - if (ZRef<ZTween<Val> > theTween = fTween) - return theTween->Duration(); - return 0; - } - - ZRef<ZTween<Val> > Get() - { return fTween; } - - void Set(const ZRef<ZTween<Val> >& iTween) - { fTween = iTween; } - - bool CAS(const ZRef<ZTween<Val> >& iPrior, const ZRef<ZTween<Val> >& iNew) - { return fTween.CAS(iPrior, iNew); } - -private: - ZRef<ZTween<Val> > fTween; - }; - -template <class Val> -ZRef<ZTween_Indirect<Val> > sTween_Indirect(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Indirect<Val>(iTween); } - -template <class Val> -ZRef<ZTween_Indirect<Val> > sTween_Indirect() - { return new ZTween_Indirect<Val>(); } - // ================================================================================================= #pragma mark - #pragma mark * sTween_Either @@ -156,12 +113,16 @@ { return fCombiner(f0->ValAt(iTime), f1->ValAt(iTime)); } virtual double Duration() - { return std::max(f0->Duration(), f1->Duration()); } + { return std::max(sGetDuration(f0, fD0), sGetDuration(f1, fD1)); } private: Combiner fCombiner; + const ZRef<ZTween<Val0> > f0; + ZQ<double> fD0; + const ZRef<ZTween<Val1> > f1; + ZQ<double> fD1; }; template <class Val0, class Val1> @@ -235,12 +196,16 @@ { return fCombiner(f0->ValAt(iTime), f1->ValAt(iTime)); } virtual double Duration() - { return std::min(f0->Duration(), f1->Duration()); } + { return std::min(sGetDuration(f0, fD0), sGetDuration(f1, fD1)); } private: Combiner fCombiner; + const ZRef<ZTween<Val0> > f0; + ZQ<double> fD0; + const ZRef<ZTween<Val1> > f1; + ZQ<double> fD1; }; template <class Val0, class Val1> @@ -290,24 +255,19 @@ virtual Val ValAt(double iTime) { if (iTime <= 0) - { return f0->ValAt(iTime); - } + else if (iTime < sGetDuration(f0, fD0)) + return f0->ValAt(iTime); else - { - const double duration0 = f0->Duration(); - if (iTime < duration0) - return f0->ValAt(iTime); - else - return f1->ValAt(iTime - duration0); - } + return f1->ValAt(iTime - sGetDuration(f0, fD0)); } virtual double Duration() - { return f0->Duration() + f1->Duration(); } + { return sGetDuration(f0, fD0) + sGetDuration(f1, fD1); } private: const ZRef<ZTween<Val> > f0, f1; + ZQ<double> fD0, fD1; }; template <class Val> @@ -355,17 +315,21 @@ // From ZTween virtual Val0 ValAt(double iTime) { - const double time1 = iTime / f0->Duration() * f1->Duration(); + const double time1 = iTime / sGetDuration(f0, fD0) * sGetDuration(f1, fD1); return fCombiner(f0->ValAt(iTime), f1->ValAt(time1)); } virtual double Duration() - { return f0->Duration(); } + { return sGetDuration(f0, fD0); } private: Combiner fCombiner; + const ZRef<ZTween<Val0> > f0; + ZQ<double> fD0; + const ZRef<ZTween<Val1> > f1; + ZQ<double> fD1; }; template <class Val0, class Val1> @@ -418,16 +382,17 @@ // From ZTween virtual Val ValAt(double iTime) { - const double childDuration = fTween->Duration(); + const double childDuration = sGetDuration(fTween, fTweenDuration); iTime = sMinMax(0.0, iTime, childDuration * fCount); return fTween->ValAt(fmod(iTime, childDuration)); } virtual double Duration() - { return fCount * fTween->Duration(); } + { return fCount * sGetDuration(fTween, fTweenDuration); } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const size_t fCount; }; @@ -456,8 +421,8 @@ // From ZTween virtual Val ValAt(double iTime) { - iTime = sMinMax(0.0, iTime, fDuration); - return fTween->ValAt(fmod(iTime, fTween->Duration())); + const double theTime = sMinMax(0.0, iTime, fDuration); + return fTween->ValAt(fmod(theTime, sGetDuration(fTween, fTweenDuration))); } virtual double Duration() @@ -465,6 +430,7 @@ private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const double fDuration; }; @@ -529,10 +495,11 @@ { return fTween->ValAt(iTime); } virtual double Duration() - { return std::min(fAtMost, fTween->Duration()); } + { return std::min(fAtMost, sGetDuration(fTween, fTweenDuration)); } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const double fAtMost; }; @@ -563,10 +530,11 @@ { return fTween->ValAt(iTime); } virtual double Duration() - { return std::max(fAtLeast, fTween->Duration()); } + { return std::max(fAtLeast, sGetDuration(fTween, fTweenDuration)); } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const double fAtLeast; }; @@ -597,10 +565,11 @@ { return fTween->ValAt(iTime - fDelay); } virtual double Duration() - { return std::max(0.0, fTween->Duration() + fDelay); } + { return std::max(0.0, sGetDuration(fTween, fTweenDuration) + fDelay); } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const double fDelay; }; @@ -632,19 +601,20 @@ if (fRate > 0) return fTween->ValAt(iTime / fRate); else - return fTween->ValAt(fTween->Duration() + iTime/fRate); + return fTween->ValAt(sGetDuration(fTween, fTweenDuration) + iTime/fRate); } virtual double Duration() { if (fRate > 0) - return fRate * fTween->Duration(); + return fRate * sGetDuration(fTween, fTweenDuration); else - return -fRate * fTween->Duration(); + return -fRate * sGetDuration(fTween, fTweenDuration); } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const double fRate; }; @@ -671,13 +641,14 @@ // From ZTween virtual Val ValAt(double iTime) - { return fTween->ValAt(iTime / fTween->Duration); } + { return fTween->ValAt(iTime / sGetDuration(fTween, fTweenDuration)); } virtual double Duration() { return 1; } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; }; template <class Val> @@ -727,34 +698,8 @@ #pragma mark * sTween_Scale template <class Val> -class ZTween_Scale -: public ZTween<Val> - { -public: - ZTween_Scale(const ZRef<ZTween<Val> >& iTween, Val iScale) - : fTween(iTween) - , fScale(iScale) - {} - -// From ZTween - virtual Val ValAt(double iTime) - { return fScale * fTween->ValAt(iTime); } - - virtual double Duration() - { return fTween->Duration(); } - -private: - const ZRef<ZTween<Val> > fTween; - const Val fScale; - }; - -template <class Val> ZRef<ZTween<Val> > sTween_Scale(Val iScale, const ZRef<ZTween<Val> >& iTween) - { - if (iTween) - return new ZTween_Scale<Val>(iTween, iScale); - return null; - } + { return iTween ^ sTween_Const<Val>(iScale); } // ================================================================================================= #pragma mark - @@ -775,10 +720,11 @@ { return fOffset + fTween->ValAt(iTime); } virtual double Duration() - { return fTween->Duration(); } + { return sGetDuration(fTween, fTweenDuration); } private: const ZRef<ZTween<Val> > fTween; + ZQ<double> fTweenDuration; const Val fOffset; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-19 23:29:53
|
Revision: 2580 http://zoolib.svn.sourceforge.net/zoolib/?rev=2580&view=rev Author: agreen Date: 2011-10-19 23:29:47 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Get rid of //## marked code. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZThread_pthread.cpp trunk/zoolib/source/cxx/zoolib/ZYad.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZThread_pthread.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread_pthread.cpp 2011-10-19 18:09:36 UTC (rev 2579) +++ trunk/zoolib/source/cxx/zoolib/ZThread_pthread.cpp 2011-10-19 23:29:47 UTC (rev 2580) @@ -145,7 +145,6 @@ { if (EINTR == result) continue; -//## ZUnimplemented(); } break; } Modified: trunk/zoolib/source/cxx/zoolib/ZYad.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad.cpp 2011-10-19 18:09:36 UTC (rev 2579) +++ trunk/zoolib/source/cxx/zoolib/ZYad.cpp 2011-10-19 23:29:47 UTC (rev 2580) @@ -197,7 +197,7 @@ #pragma mark * ZYadSeqRClone void ZYadSeqRClone::Accept_Yad(ZVisitor_Yad& iVisitor) - { iVisitor.Visit_YadSeqR(this); }//## + { iVisitor.Visit_YadSeqR(this); } bool ZYadSeqRClone::IsSimple(const ZYadOptions& iOptions) { @@ -332,40 +332,6 @@ void ZYadMapRPos::Accept_Yad(ZVisitor_Yad& iVisitor) { iVisitor.Visit_YadMapRPos(this); } -#if 0 //## -bool ZYadMapRPos::IsSimple(const ZYadOptions& iOptions) - { - if (ZRef<ZYadMapRPos> clone = this->Clone()) - { - string dummy; - if (ZRef<ZYadR> theYadR = clone->ReadInc(dummy)) - { - if (!clone->Skip()) - { - // We've exhausted ouselves, so we had just one entry, and - // we're simple if that entry is simple. - return theYadR->IsSimple(iOptions); - } - else - { - // We have at least one more entry, so we're not simple. - return false; - } - } - else - { - // We're empty, and thus simple. - return true; - } - } - else - { - // We couldn't clone, so assume we're complex. - return false; - } - } -#endif //## - ZRef<ZYadR> ZYadMapRPos::ReadAt(const std::string& iName) { this->SetPosition(iName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-19 18:09:42
|
Revision: 2579 http://zoolib.svn.sourceforge.net/zoolib/?rev=2579&view=rev Author: agreen Date: 2011-10-19 18:09:36 +0000 (Wed, 19 Oct 2011) Log Message: ----------- We use ZAssert and so need ZDebug.h. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZMatrix.h Modified: trunk/zoolib/source/cxx/zoolib/ZMatrix.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZMatrix.h 2011-10-19 17:33:22 UTC (rev 2578) +++ trunk/zoolib/source/cxx/zoolib/ZMatrix.h 2011-10-19 18:09:36 UTC (rev 2579) @@ -22,6 +22,8 @@ #define __ZMatrix__ 1 #include "zconfig.h" +#include "zoolib/ZDebug.h" + namespace ZooLib { // For compatibility with OpenGL we store in column-major order. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-19 17:33:28
|
Revision: 2578 http://zoolib.svn.sourceforge.net/zoolib/?rev=2578&view=rev Author: agreen Date: 2011-10-19 17:33:22 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Add ZTween_Filter_Coerce, and use sp prefix on functions. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTween_Std.h Modified: trunk/zoolib/source/cxx/zoolib/ZTween_Std.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween_Std.h 2011-10-19 17:32:26 UTC (rev 2577) +++ trunk/zoolib/source/cxx/zoolib/ZTween_Std.h 2011-10-19 17:33:22 UTC (rev 2578) @@ -31,12 +31,12 @@ #pragma mark - #pragma mark * ZTween_Fun -template <class Return, Return(*Fun)(double)> +template <class Val, Val(*Fun)(double)> class ZTween_Fun -: public ZTween<Return> +: public ZTween<Val> { public: - virtual Return ValAt(double iTime) + virtual Val ValAt(double iTime) { return Fun(sMinMax(0.0, iTime, 1.0)); } virtual double Duration() @@ -47,16 +47,16 @@ #pragma mark - #pragma mark * ZTween_Filter_Fun -template <class Return, class Param, Return(*Fun)(Param)> +template <class Val, class Param, Val(*Fun)(Param)> class ZTween_Filter_Fun -: public ZTween<Return> +: public ZTween<Val> { public: ZTween_Filter_Fun(const ZRef<ZTween<Param> >& iTween) : fTween(iTween) {} - virtual Return ValAt(double iTime) + virtual Val ValAt(double iTime) { return Fun(fTween->ValAt(iTime)); } virtual double Duration() @@ -68,17 +68,40 @@ // ================================================================================================= #pragma mark - +#pragma mark * ZTween_Filter_Coerce + +template <class Val, class Param> +class ZTween_Filter_Coerce +: public ZTween<Val> + { +public: + ZTween_Filter_Coerce(const ZRef<ZTween<Param> >& iTween) + : fTween(iTween) + {} + + virtual Val ValAt(double iTime) + { return Val(fTween->ValAt(iTime)); } + + virtual double Duration() + { return fTween->Duration(); } + +private: + const ZRef<ZTween<Param> > fTween; + }; + +// ================================================================================================= +#pragma mark - #pragma mark * sTween_OneMinus template <class Val> -Val sTweenFun_OneMinus(Val iVal) +Val spTweenFun_OneMinus(Val iVal) { return 1 - iVal; } template <class Val> ZRef<ZTween<Val> > sTween_OneMinus(const ZRef<ZTween<Val> >& iTween) { if (iTween) - return new ZTween_Filter_Fun<Val,Val,sTweenFun_OneMinus>(iTween); + return new ZTween_Filter_Fun<Val,Val,spTweenFun_OneMinus>(iTween); return null; } @@ -87,12 +110,12 @@ #pragma mark * sTween_Linear template <class Val> -Val sTweenFun_Linear(double iTime) - { return iTime; } +Val spTweenFun_Linear(double iTime) + { return iTime; } template <class Val> ZRef<ZTween<Val> > sTween_Linear() - { return new ZTween_Fun<Val,sTweenFun_Linear>; } + { return new ZTween_Fun<Val,spTweenFun_Linear>; } template <class Val> ZRef<ZTween<Val> > sTween_Linear(double iDuration) @@ -111,12 +134,12 @@ #pragma mark * sTween_Triangle template <class Val> -Val sTweenFun_Triangle(double iTime) - { return 1 - fabs(iTime * 2 - 1); } +Val spTweenFun_Triangle(double iTime) + { return 1 - fabs(iTime * 2 - 1); } template <class Val> ZRef<ZTween<Val> > sTween_Triangle() - { return new ZTween_Fun<Val,sTweenFun_Triangle>; } + { return new ZTween_Fun<Val,spTweenFun_Triangle>; } template <class Val> ZRef<ZTween<Val> > sTween_Triangle(double iDuration) @@ -135,12 +158,12 @@ #pragma mark * sTween_Square template <class Val> -Val sTweenFun_Square(double iTime) +Val spTweenFun_Square(double iTime) { return iTime < 0.5 ? 0.0 : 1.0; } template <class Val> ZRef<ZTween<Val> > sTween_Square() - { return new ZTween_Fun<Val,sTweenFun_Square>; } + { return new ZTween_Fun<Val,spTweenFun_Square>; } template <class Val> ZRef<ZTween<Val> > sTween_Square(double iDuration) @@ -159,12 +182,12 @@ #pragma mark * sTween_Sin template <class Val> -Val sTweenFun_Sin(double iTime) - { return sin(iTime * M_PI); } +Val spTweenFun_Sin(double iTime) + { return sin(2 * M_PI * iTime); } template <class Val> ZRef<ZTween<Val> > sTween_Sin() - { return new ZTween_Fun<Val,sTweenFun_Sin>; } + { return new ZTween_Fun<Val,spTweenFun_Sin>; } template <class Val> ZRef<ZTween<Val> > sTween_Sin(double iDuration) @@ -175,12 +198,12 @@ #pragma mark * sTween_Cos template <class Val> -Val sTweenFun_Cos(double iTime) - { return cos(iTime * M_PI); } +Val spTweenFun_Cos(double iTime) + { return cos(2 * M_PI * iTime); } template <class Val> ZRef<ZTween<Val> > sTween_Cos() - { return new ZTween_Fun<Val,sTweenFun_Cos>; } + { return new ZTween_Fun<Val,spTweenFun_Cos>; } template <class Val> ZRef<ZTween<Val> > sTween_Cos(double iDuration) @@ -191,12 +214,12 @@ #pragma mark * sTween_QuadIn template <class Val> -Val sTweenFun_QuadIn(double iTime) - { return iTime * iTime; } +Val spTweenFun_QuadIn(double iTime) + { return iTime * iTime; } template <class Val> ZRef<ZTween<Val> > sTween_QuadIn() - { return new ZTween_Fun<Val,sTweenFun_QuadIn>; } + { return new ZTween_Fun<Val,spTweenFun_QuadIn>; } template <class Val> ZRef<ZTween<Val> > sTween_QuadIn(double iDuration) @@ -215,12 +238,12 @@ #pragma mark * sTween_QuadOut template <class Val> -Val sTweenFun_QuadOut(double iTime) - { return -iTime * (iTime - 2); } +Val spTweenFun_QuadOut(double iTime) + { return -iTime * (iTime - 2); } template <class Val> ZRef<ZTween<Val> > sTween_QuadOut() - { return new ZTween_Fun<Val,sTweenFun_QuadOut>; } + { return new ZTween_Fun<Val,spTweenFun_QuadOut>; } template <class Val> ZRef<ZTween<Val> > sTween_QuadOut(double iDuration) @@ -239,12 +262,12 @@ #pragma mark * sTween_CubicIn template <class Val> -Val sTweenFun_CubicIn(double iTime) - { return iTime * iTime * iTime; } +Val spTweenFun_CubicIn(double iTime) + { return iTime * iTime * iTime; } template <class Val> ZRef<ZTween<Val> > sTween_CubicIn() - { return new ZTween_Fun<Val,sTweenFun_CubicIn>; } + { return new ZTween_Fun<Val,spTweenFun_CubicIn>; } template <class Val> ZRef<ZTween<Val> > sTween_CubicIn(double iDuration) @@ -263,7 +286,7 @@ #pragma mark * sTween_CubicOut template <class Val> -Val sTweenFun_CubicOut(double iTime) +Val spTweenFun_CubicOut(double iTime) { iTime -= 1; return iTime * iTime * iTime; @@ -271,7 +294,7 @@ template <class Val> ZRef<ZTween<Val> > sTween_CubicOut() - { return new ZTween_Fun<Val,sTweenFun_CubicOut>; } + { return new ZTween_Fun<Val,spTweenFun_CubicOut>; } template <class Val> ZRef<ZTween<Val> > sTween_CubicOut(double iDuration) @@ -290,12 +313,12 @@ #pragma mark * sTween_QuartIn template <class Val> -Val sTweenFun_QuartIn(double iTime) - { return iTime * iTime * iTime * iTime; } +Val spTweenFun_QuartIn(double iTime) + { return iTime * iTime * iTime * iTime; } template <class Val> ZRef<ZTween<Val> > sTween_QuartIn() - { return new ZTween_Fun<Val,sTweenFun_QuartIn>; } + { return new ZTween_Fun<Val,spTweenFun_QuartIn>; } template <class Val> ZRef<ZTween<Val> > sTween_QuartIn(double iDuration) @@ -314,7 +337,7 @@ #pragma mark * sTween_QuartOut template <class Val> -Val sTweenFun_QuartOut(double iTime) +Val spTweenFun_QuartOut(double iTime) { iTime -= 1; return -1 * (iTime * iTime * iTime * iTime - 1); @@ -322,7 +345,7 @@ template <class Val> ZRef<ZTween<Val> > sTween_QuartOut() - { return new ZTween_Fun<Val,sTweenFun_QuartOut>; } + { return new ZTween_Fun<Val,spTweenFun_QuartOut>; } template <class Val> ZRef<ZTween<Val> > sTween_QuartOut(double iDuration) @@ -341,12 +364,12 @@ #pragma mark * sTween_QuintIn template <class Val> -Val sTweenFun_QuintIn(double iTime) - { return iTime * iTime * iTime * iTime * iTime; } +Val spTweenFun_QuintIn(double iTime) + { return iTime * iTime * iTime * iTime * iTime; } template <class Val> ZRef<ZTween<Val> > sTween_QuintIn() - { return new ZTween_Fun<Val,sTweenFun_QuintIn>; } + { return new ZTween_Fun<Val,spTweenFun_QuintIn>; } template <class Val> ZRef<ZTween<Val> > sTween_QuintIn(double iDuration) @@ -365,15 +388,15 @@ #pragma mark * sTween_QuintOut template <class Val> -Val sTweenFun_QuintOut(double iTime) +Val spTweenFun_QuintOut(double iTime) { iTime -= 1; return iTime * iTime * iTime * iTime * iTime + 1; - } + } template <class Val> ZRef<ZTween<Val> > sTween_QuintOut() - { return new ZTween_Fun<Val,sTweenFun_QuintOut>; } + { return new ZTween_Fun<Val,spTweenFun_QuintOut>; } template <class Val> ZRef<ZTween<Val> > sTween_QuintOut(double iDuration) @@ -392,12 +415,12 @@ #pragma mark * sTween_SinIn template <class Val> -Val sTweenFun_SinIn(double iTime) - { return -1 * cos(iTime * M_PI / 2) + 1; } +Val spTweenFun_SinIn(double iTime) + { return -1 * cos(iTime * M_PI / 2) + 1; } template <class Val> ZRef<ZTween<Val> > sTween_SinIn() - { return new ZTween_Fun<Val,sTweenFun_SinIn>; } + { return new ZTween_Fun<Val,spTweenFun_SinIn>; } template <class Val> ZRef<ZTween<Val> > sTween_SinIn(double iDuration) @@ -416,12 +439,12 @@ #pragma mark * sTween_SinOut template <class Val> -Val sTweenFun_SinOut(double iTime) +Val spTweenFun_SinOut(double iTime) { return sin(iTime * M_PI / 2); } template <class Val> ZRef<ZTween<Val> > sTween_SinOut() - { return new ZTween_Fun<Val,sTweenFun_SinOut>; } + { return new ZTween_Fun<Val,spTweenFun_SinOut>; } template <class Val> ZRef<ZTween<Val> > sTween_SinOut(double iDuration) @@ -440,12 +463,12 @@ #pragma mark * sTween_ExpoIn template <class Val> -Val sTweenFun_ExpoIn(double iTime) - { return iTime <= 0 ? 0 : pow(2, 10 * (iTime - 1)); } +Val spTweenFun_ExpoIn(double iTime) + { return iTime <= 0 ? 0 : pow(2, 10 * (iTime - 1)); } template <class Val> ZRef<ZTween<Val> > sTween_ExpoIn() - { return new ZTween_Fun<Val,sTweenFun_ExpoIn>; } + { return new ZTween_Fun<Val,spTweenFun_ExpoIn>; } template <class Val> ZRef<ZTween<Val> > sTween_ExpoIn(double iDuration) @@ -464,12 +487,12 @@ #pragma mark * sTween_ExpoOut template <class Val> -Val sTweenFun_ExpoOut(double iTime) +Val spTweenFun_ExpoOut(double iTime) { return iTime >= 1 ? 1 : (-pow(2, -10 * iTime) + 1); } template <class Val> ZRef<ZTween<Val> > sTween_ExpoOut() - { return new ZTween_Fun<Val,sTweenFun_ExpoOut>; } + { return new ZTween_Fun<Val,spTweenFun_ExpoOut>; } template <class Val> ZRef<ZTween<Val> > sTween_ExpoOut(double iDuration) @@ -488,12 +511,12 @@ #pragma mark * sTween_CircIn template <class Val> -Val sTweenFun_CircIn(double iTime) +Val spTweenFun_CircIn(double iTime) { return -1 * (sqrt(1 - iTime * iTime) - 1); } template <class Val> ZRef<ZTween<Val> > sTween_CircIn() - { return new ZTween_Fun<Val,sTweenFun_CircIn>; } + { return new ZTween_Fun<Val,spTweenFun_CircIn>; } template <class Val> ZRef<ZTween<Val> > sTween_CircIn(double iDuration) @@ -512,7 +535,7 @@ #pragma mark * sTween_CircOut template <class Val> -Val sTweenFun_CircOut(double iTime) +Val spTweenFun_CircOut(double iTime) { iTime -= 1; return sqrt(1 - iTime * iTime); @@ -520,7 +543,7 @@ template <class Val> ZRef<ZTween<Val> > sTween_CircOut() - { return new ZTween_Fun<Val,sTweenFun_CircOut>; } + { return new ZTween_Fun<Val,spTweenFun_CircOut>; } template <class Val> ZRef<ZTween<Val> > sTween_CircOut(double iDuration) @@ -539,7 +562,7 @@ #pragma mark * sTween_ElasticIn template <class Val> -Val sTweenFun_ElasticIn(double iTime) +Val spTweenFun_ElasticIn(double iTime) { if (iTime <= 0) return 0; @@ -552,7 +575,7 @@ template <class Val> ZRef<ZTween<Val> > sTween_ElasticIn() - { return new ZTween_Fun<Val,sTweenFun_ElasticIn>; } + { return new ZTween_Fun<Val,spTweenFun_ElasticIn>; } template <class Val> ZRef<ZTween<Val> > sTween_ElasticIn(double iDuration) @@ -571,7 +594,7 @@ #pragma mark * sTween_ElasticOut template <class Val> -Val sTweenFun_ElasticOut(double iTime) +Val spTweenFun_ElasticOut(double iTime) { if (iTime <= 0) return 0; @@ -583,7 +606,7 @@ template <class Val> ZRef<ZTween<Val> > sTween_ElasticOut() - { return new ZTween_Fun<Val,sTweenFun_ElasticOut>; } + { return new ZTween_Fun<Val,spTweenFun_ElasticOut>; } template <class Val> ZRef<ZTween<Val> > sTween_ElasticOut(double iDuration) @@ -667,7 +690,7 @@ #pragma mark * sTween_BounceIn template <class Val> -Val sTweenFun_BounceIn(double iTime) +Val spTweenFun_BounceIn(double iTime) { if (iTime < 1 / 2.75) return 7.5625 * iTime * iTime; @@ -692,7 +715,7 @@ template <class Val> ZRef<ZTween<Val> > sTween_BounceIn() - { return new ZTween_Fun<Val,sTweenFun_BounceIn>; } + { return new ZTween_Fun<Val,spTweenFun_BounceIn>; } template <class Val> ZRef<ZTween<Val> > sTween_BounceIn(double iDuration) @@ -711,12 +734,12 @@ #pragma mark * sTween_BounceOut template <class Val> -Val sTweenFun_BounceOut(double iTime) - { return sTweenFun_BounceIn<Val>(1 - iTime); } +Val spTweenFun_BounceOut(double iTime) + { return spTweenFun_BounceIn<Val>(1 - iTime); } template <class Val> ZRef<ZTween<Val> > sTween_BounceOut() - { return new ZTween_Fun<Val,sTweenFun_BounceOut>; } + { return new ZTween_Fun<Val,spTweenFun_BounceOut>; } template <class Val> ZRef<ZTween<Val> > sTween_BounceOut(double iDuration) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-19 17:32:32
|
Revision: 2577 http://zoolib.svn.sourceforge.net/zoolib/?rev=2577&view=rev Author: agreen Date: 2011-10-19 17:32:26 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Add a typedef for Val, so we can derive what we're working with from just the combiner type. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTween.h Modified: trunk/zoolib/source/cxx/zoolib/ZTween.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-19 17:31:31 UTC (rev 2576) +++ trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-19 17:32:26 UTC (rev 2577) @@ -208,9 +208,10 @@ ZRef<ZTween<Val> >& operator+=(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) { return io0 = io0 + i1; } -template <class Val> +template <class Val_p> struct ZTweenAccumulatorCombiner_Either { + typedef Val_p Val; void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const { io0 = sTween_Either<Val>(io0, i1); } }; @@ -258,9 +259,10 @@ ZRef<ZTween<Val0> >& operator*=(ZRef<ZTween<Val0> >& io0, const ZRef<ZTween<Val1> >& i1) { return io0 = io0 * i1; } -template <class Val> +template <class Val_p> struct ZTweenAccumulatorCombiner_Both { + typedef Val_p Val; void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const { if (io0) @@ -328,9 +330,10 @@ ZRef<ZTween<Val> >& operator|=(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) { return io0 = io0 | i1; } -template <class Val> +template <class Val_p> struct ZTweenAccumulatorCombiner_Each { + typedef Val_p Val; void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const { io0 = sTween_Each(io0, i1); } }; @@ -385,9 +388,10 @@ ZRef<ZTween<Val0> >& operator^=(ZRef<ZTween<Val0> >& io0, const ZRef<ZTween<Val1> >& i1) { return io0 = io0 ^ i1; } -template <class Val> +template <class Val_p> struct ZTweenAccumulatorCombiner_Applied { + typedef Val_p Val; void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const { if (io0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-19 17:31:37
|
Revision: 2576 http://zoolib.svn.sourceforge.net/zoolib/?rev=2576&view=rev Author: agreen Date: 2011-10-19 17:31:31 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Allow the ommission of unsignificant separators in seqs (if the option is set). Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp 2011-10-18 20:19:20 UTC (rev 2575) +++ trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp 2011-10-19 17:31:31 UTC (rev 2576) @@ -323,7 +323,10 @@ if (not sTryRead_CP(theStrimU, ',')) { if (not fReadOptions.fAllowSemiColons.DGet(false) || not sTryRead_CP(theStrimU, ';')) - spThrowParseException("Require ',' to separate array elements"); + { + if (not fReadOptions.fLooseSeparators.DGet(false)) + spThrowParseException("Require ',' to separate array elements"); + } } sSkip_WSAndCPlusPlusComments(theStrimU); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-18 20:19:26
|
Revision: 2575 http://zoolib.svn.sourceforge.net/zoolib/?rev=2575&view=rev Author: agreen Date: 2011-10-18 20:19:20 +0000 (Tue, 18 Oct 2011) Log Message: ----------- We need to see a definition for ZCaller. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCallFuture.h Modified: trunk/zoolib/source/cxx/zoolib/ZCallFuture.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCallFuture.h 2011-10-18 16:15:07 UTC (rev 2574) +++ trunk/zoolib/source/cxx/zoolib/ZCallFuture.h 2011-10-18 20:19:20 UTC (rev 2575) @@ -22,6 +22,7 @@ #define __ZCallFuture__ 1 #include "zconfig.h" +#include "zoolib/ZCaller.h" #include "zoolib/ZCallable.h" #include "zoolib/ZCallable_Bind.h" #include "zoolib/ZCallable_Function.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-18 16:15:16
|
Revision: 2574 http://zoolib.svn.sourceforge.net/zoolib/?rev=2574&view=rev Author: agreen Date: 2011-10-18 16:15:07 +0000 (Tue, 18 Oct 2011) Log Message: ----------- Wasn't assigning to io0. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-18 16:14:43 UTC (rev 2573) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-18 16:15:07 UTC (rev 2574) @@ -297,7 +297,7 @@ struct ZCogAccumulatorCombiner_Either { void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const - { sCog_Either(io0, i1); } + { io0 = sCog_Either(io0, i1); } }; // ================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-18 16:14:52
|
Revision: 2573 http://zoolib.svn.sourceforge.net/zoolib/?rev=2573&view=rev Author: agreen Date: 2011-10-18 16:14:43 +0000 (Tue, 18 Oct 2011) Log Message: ----------- Remove duplicate line. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZUtil_Strim.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZUtil_Strim.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZUtil_Strim.cpp 2011-10-17 16:20:25 UTC (rev 2572) +++ trunk/zoolib/source/cxx/zoolib/ZUtil_Strim.cpp 2011-10-18 16:14:43 UTC (rev 2573) @@ -224,7 +224,6 @@ { oIsNegative = false; return true; - return true; } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 16:20:31
|
Revision: 2572 http://zoolib.svn.sourceforge.net/zoolib/?rev=2572&view=rev Author: agreen Date: 2011-10-17 16:20:25 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Rename Combiner to AccumulatorCombiner, to emphasize where it's used. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h trunk/zoolib/source/cxx/zoolib/ZTween.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-17 16:19:41 UTC (rev 2571) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-17 16:20:25 UTC (rev 2572) @@ -294,15 +294,10 @@ { return ioCog0 = sCog_Either<Param>(ioCog0, iCallable1); } template <class Param> -struct ZCogCombiner_Either +struct ZCogAccumulatorCombiner_Either { void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const - { - if (io0) - io0 = sCog_Either(io0, i1); - else - io0 = i1; - } + { sCog_Either(io0, i1); } }; // ================================================================================================= @@ -398,7 +393,7 @@ { return ioCog0 = sCog_Both<Param>(ioCog0, iCallable1); } template <class Param> -struct ZCogCombiner_Both +struct ZCogAccumulatorCombiner_Both { void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const { @@ -490,15 +485,10 @@ { return ioCog0 = sCog_Each<Param>(ioCog0, iCallable1); } template <class Param> -struct ZCogCombiner_Each +struct ZCogAccumulatorCombiner_Each { void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const - { - if (io0) - io0 = sCog_Each(io0, i1); - else - io0 = i1; - } + { io0 = sCog_Each(io0, i1); } }; // ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/ZTween.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-17 16:19:41 UTC (rev 2571) +++ trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-17 16:20:25 UTC (rev 2572) @@ -184,16 +184,35 @@ ZRef<ZTween<Val0> >& operator+=(ZRef<ZTween<Val0> >& io0, const ZRef<ZTween<Val1> >& i1) { return io0 = io0 + i1; } +// ================================================================================================= +#pragma mark - +#pragma mark * sTween_Either (for homogenous pairs) + template <class Val> -struct ZTweenCombiner_Either +ZRef<ZTween<Val> > sTween_Either(const ZRef<ZTween<Val> >& i0, const ZRef<ZTween<Val> >& i1) { - void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const + if (i0) { - if (io0) - io0 = sTween_Either(io0, i1); - else - io0 = i1; + if (i1) + return new ZTween_Either<Val,Val>(i0, i1); + return i0; } + return i1; + } + +template <class Val> +ZRef<ZTween<Val> > operator+(const ZRef<ZTween<Val> >& i0, const ZRef<ZTween<Val> >& i1) + { return sTween_Either(i0, i1); } + +template <class Val> +ZRef<ZTween<Val> >& operator+=(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) + { return io0 = io0 + i1; } + +template <class Val> +struct ZTweenAccumulatorCombiner_Either + { + void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const + { io0 = sTween_Either<Val>(io0, i1); } }; // ================================================================================================= @@ -240,7 +259,7 @@ { return io0 = io0 * i1; } template <class Val> -struct ZTweenCombiner_Both +struct ZTweenAccumulatorCombiner_Both { void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const { @@ -310,15 +329,10 @@ { return io0 = io0 | i1; } template <class Val> -struct ZTweenCombiner_Each +struct ZTweenAccumulatorCombiner_Each { void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const - { - if (io0) - io0 = sTween_Each(io0, i1); - else - io0 = i1; - } + { io0 = sTween_Each(io0, i1); } }; // ================================================================================================= @@ -372,7 +386,7 @@ { return io0 = io0 ^ i1; } template <class Val> -struct ZTweenCombiner_Applied +struct ZTweenAccumulatorCombiner_Applied { void operator()(ZRef<ZTween<Val> >& io0, const ZRef<ZTween<Val> >& i1) const { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 16:19:47
|
Revision: 2571 http://zoolib.svn.sourceforge.net/zoolib/?rev=2571&view=rev Author: agreen Date: 2011-10-17 16:19:41 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Return null if a null tween is passed to us. Modified Paths: -------------- trunk/zoolib/source/cxx/more/zoolib/gameengine/ZGameEngine_Tweens.h Modified: trunk/zoolib/source/cxx/more/zoolib/gameengine/ZGameEngine_Tweens.h =================================================================== --- trunk/zoolib/source/cxx/more/zoolib/gameengine/ZGameEngine_Tweens.h 2011-10-17 16:19:12 UTC (rev 2570) +++ trunk/zoolib/source/cxx/more/zoolib/gameengine/ZGameEngine_Tweens.h 2011-10-17 16:19:41 UTC (rev 2571) @@ -35,7 +35,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_ScaleX(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sScaleX>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sScaleX>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -43,7 +47,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_ScaleY(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sScaleY>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sScaleY>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -51,7 +59,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_ScaleZ(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sScaleZ>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sScaleZ>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -59,7 +71,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_TranslateX(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTranslateX>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTranslateX>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -67,7 +83,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_TranslateY(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTranslateY>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTranslateY>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -75,7 +95,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_TranslateZ(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTranslateZ>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTranslateZ>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -87,7 +111,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_RotateX(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTweenFun_Rotate2PiX>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTweenFun_Rotate2PiX>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -99,7 +127,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_RotateY(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTweenFun_Rotate2PiY>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTweenFun_Rotate2PiY>(iTween); + return null; + } // ================================================================================================= #pragma mark - @@ -111,7 +143,11 @@ template <class Val> ZRef<ZTween<ZMatrix<Val,4,4> > > sTween_RotateZ(const ZRef<ZTween<Val> >& iTween) - { return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTweenFun_Rotate2PiZ>(iTween); } + { + if (iTween) + return new ZTween_Filter_Fun<ZMatrix<Val,4,4>,Val,sTweenFun_Rotate2PiZ>(iTween); + return null; + } } // namespace ZGameEngine } // namespace ZooLib This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 16:19:19
|
Revision: 2570 http://zoolib.svn.sourceforge.net/zoolib/?rev=2570&view=rev Author: agreen Date: 2011-10-17 16:19:12 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Add Get methods, generally for use when wrapped in a ZQ to make it more readable. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZMatrix.h Modified: trunk/zoolib/source/cxx/zoolib/ZMatrix.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZMatrix.h 2011-10-17 13:12:35 UTC (rev 2569) +++ trunk/zoolib/source/cxx/zoolib/ZMatrix.h 2011-10-17 16:19:12 UTC (rev 2570) @@ -117,9 +117,15 @@ E& operator[](size_t r) { return fE[0][r]; } - const E operator[](size_t r) const + E operator[](size_t r) const { return fE[0][r]; } + E& GetMutable(size_t r) + { return fE[0][r]; } + + E Get(size_t r) const + { return fE[0][r]; } + E fE[1][R]; }; @@ -159,9 +165,15 @@ E& operator[](size_t c) { return fE[c][0]; } - const E operator[](size_t c) const + E operator[](size_t c) const { return fE[c][0]; } + E& GetMutable(size_t c) + { return fE[c][0]; } + + E Get(size_t c) const + { return fE[c][0]; } + E fE[C][1]; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 13:12:41
|
Revision: 2569 http://zoolib.svn.sourceforge.net/zoolib/?rev=2569&view=rev Author: agreen Date: 2011-10-17 13:12:35 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Add ctor and assignment from ZMap_Yad and ZSeq_Yad. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h Modified: trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp 2011-10-17 13:12:00 UTC (rev 2568) +++ trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp 2011-10-17 13:12:35 UTC (rev 2569) @@ -59,6 +59,26 @@ return *this; } +ZVal_Yad::ZVal_Yad(const ZSeq_Yad& iSeq) +: fYad(iSeq.GetYad()) + {} + +ZVal_Yad& ZVal_Yad::operator=(const ZSeq_Yad& iSeq) + { + fYad = iSeq.GetYad(); + return *this; + } + +ZVal_Yad::ZVal_Yad(const ZMap_Yad& iMap) +: fYad(iMap.GetYad()) + {} + +ZVal_Yad& ZVal_Yad::operator=(const ZMap_Yad& iMap) + { + fYad = iMap.GetYad(); + return *this; + } + ZVal_Yad ZVal_Yad::Get(const string8& iName) const { if (ZRef<ZYadMapRPos> theYad = fYad.DynamicCast<ZYadMapRPos>()) Modified: trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h 2011-10-17 13:12:00 UTC (rev 2568) +++ trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h 2011-10-17 13:12:35 UTC (rev 2569) @@ -52,6 +52,12 @@ ZVal_Yad(const ZRef<ZYadR>& iYad); ZVal_Yad& operator=(const ZRef<ZYadR>& iYad); + ZVal_Yad(const ZSeq_Yad& iSeq); + ZVal_Yad& operator=(const ZSeq_Yad& iSeq); + + ZVal_Yad(const ZMap_Yad& iMap); + ZVal_Yad& operator=(const ZMap_Yad& iMap); + // ZVal protocol template <class S> ZQ<S> QGet() const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 13:12:06
|
Revision: 2568 http://zoolib.svn.sourceforge.net/zoolib/?rev=2568&view=rev Author: agreen Date: 2011-10-17 13:12:00 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Abbreviate some forms. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-10-17 13:11:14 UTC (rev 2567) +++ trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-10-17 13:12:00 UTC (rev 2568) @@ -161,16 +161,12 @@ size_t index = 0; const ZTrail theTrail = ZTrail(theTrailString).Normalized(); ZRef<Chain> cur = this; + if (theTrailString[0] == '/') { // Walk up to the root. - for (;;) - { - if (ZRef<Chain> next = cur->fParent) - cur = next; - else - break; - } + for (ZRef<Chain> next = null; next = cur->fParent; cur = next) + {} } else { @@ -184,7 +180,7 @@ // Walk down the remainder of the trail while (index < theTrail.Count()) { - if (ZRef<ZYadMapRPos,false> theYadMapRPos = + if (ZRef<ZYadMapRPos,0> theYadMapRPos = cur->pReadAt(theTrail.At(index)).DynamicCast<ZYadMapRPos>()) { break; } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 13:11:20
|
Revision: 2567 http://zoolib.svn.sourceforge.net/zoolib/?rev=2567&view=rev Author: agreen Date: 2011-10-17 13:11:14 +0000 (Mon, 17 Oct 2011) Log Message: ----------- Add ZCogCombiner variants, for use with ZAccumulator_T. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-17 13:10:37 UTC (rev 2566) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2011-10-17 13:11:14 UTC (rev 2567) @@ -293,6 +293,18 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { return ioCog0 = sCog_Either<Param>(ioCog0, iCallable1); } +template <class Param> +struct ZCogCombiner_Either + { + void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const + { + if (io0) + io0 = sCog_Either(io0, i1); + else + io0 = i1; + } + }; + // ================================================================================================= #pragma mark - #pragma mark * sCog_Both @@ -385,6 +397,18 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { return ioCog0 = sCog_Both<Param>(ioCog0, iCallable1); } +template <class Param> +struct ZCogCombiner_Both + { + void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const + { + if (io0) + io0 = sCog_Both(io0, i1); + else + io0 = i1; + } + }; + // ================================================================================================= #pragma mark - #pragma mark * sCog_Each @@ -465,6 +489,18 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { return ioCog0 = sCog_Each<Param>(ioCog0, iCallable1); } +template <class Param> +struct ZCogCombiner_Each + { + void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const + { + if (io0) + io0 = sCog_Each(io0, i1); + else + io0 = i1; + } + }; + // ================================================================================================= #pragma mark - #pragma mark * sCog_FollowedBy This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-17 13:10:48
|
Revision: 2566 http://zoolib.svn.sourceforge.net/zoolib/?rev=2566&view=rev Author: agreen Date: 2011-10-17 13:10:37 +0000 (Mon, 17 Oct 2011) Log Message: ----------- A further optional extension. Allow the ommission of separators in objects. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp trunk/zoolib/source/cxx/zoolib/ZYad_JSON.h Modified: trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp 2011-10-16 18:58:49 UTC (rev 2565) +++ trunk/zoolib/source/cxx/zoolib/ZYad_JSON.cpp 2011-10-17 13:10:37 UTC (rev 2566) @@ -140,14 +140,14 @@ string tempString; sRead_EscapedString(s, '"', tempString); - if (!sTryRead_CP(s, '"')) + if (not sTryRead_CP(s, '"')) throw ParseException("Expected '\"' to close a string"); oString += tempString; sSkip_WSAndCPlusPlusComments(s); - if (!sTryRead_CP(s, '"')) + if (not sTryRead_CP(s, '"')) return true; } } @@ -159,14 +159,14 @@ string tempString; sRead_EscapedString(s, '\'', tempString); - if (!sTryRead_CP(s, '\'')) + if (not sTryRead_CP(s, '\'')) throw ParseException("Expected \"'\" to close a string"); oString += tempString; sSkip_WSAndCPlusPlusComments(s); - if (!sTryRead_CP(s, '\'')) + if (not sTryRead_CP(s, '\'')) return true; } } @@ -287,7 +287,7 @@ { using namespace ZUtil_Strim; fStrimR.SkipAll(); - if (!sTryRead_CP(fStrimmerU->GetStrimU(), '"')) + if (not sTryRead_CP(fStrimmerU->GetStrimU(), '"')) throw ParseException("Missing string delimiter"); } @@ -320,9 +320,9 @@ if (not iIsFirst) { // Must read a separator - if (!sTryRead_CP(theStrimU, ',')) + if (not sTryRead_CP(theStrimU, ',')) { - if (!fReadOptions.fAllowSemiColons.DGet(false) || !sTryRead_CP(theStrimU, ';')) + if (not fReadOptions.fAllowSemiColons.DGet(false) || not sTryRead_CP(theStrimU, ';')) spThrowParseException("Require ',' to separate array elements"); } @@ -335,7 +335,7 @@ } } - if (!(oYadR = spMakeYadR_JSON(fStrimmerU, fReadOptions))) + if (not (oYadR = spMakeYadR_JSON(fStrimmerU, fReadOptions))) spThrowParseException("Expected a value"); } @@ -365,10 +365,13 @@ if (not iIsFirst) { // Must read a separator - if (!sTryRead_CP(theStrimU, ',')) + if (not sTryRead_CP(theStrimU, ',')) { - if (!fReadOptions.fAllowSemiColons.DGet(false) || !sTryRead_CP(theStrimU, ';')) - spThrowParseException("Require ',' to separate object elements"); + if (not fReadOptions.fAllowSemiColons.DGet(false) || not sTryRead_CP(theStrimU, ';')) + { + if (not fReadOptions.fLooseSeparators.DGet(false)) + spThrowParseException("Require ',' to separate object elements"); + } } sSkip_WSAndCPlusPlusComments(theStrimU); @@ -380,18 +383,18 @@ } } - if (!spTryRead_PropertyName(theStrimU, oName, fReadOptions.fAllowUnquotedPropertyNames.DGet(false))) + if (not spTryRead_PropertyName(theStrimU, oName, fReadOptions.fAllowUnquotedPropertyNames.DGet(false))) spThrowParseException("Expected a member name"); sSkip_WSAndCPlusPlusComments(theStrimU); - if (!sTryRead_CP(theStrimU, ':')) + if (not sTryRead_CP(theStrimU, ':')) { - if (!fReadOptions.fAllowEquals.DGet(false) || !sTryRead_CP(theStrimU, '=')) + if (not fReadOptions.fAllowEquals.DGet(false) || not sTryRead_CP(theStrimU, '=')) spThrowParseException("Expected ':' after a member name"); } - if (!(oYadR = spMakeYadR_JSON(fStrimmerU, fReadOptions))) + if (not (oYadR = spMakeYadR_JSON(fStrimmerU, fReadOptions))) spThrowParseException("Expected value after ':'"); } @@ -545,7 +548,7 @@ // 2. A non-empty tuple. // or if iOptions.fBreakStrings is true, any element is a string with embedded // line breaks or more than iOptions.fStringLineLength characters. - needsIndentation = ! iYadSeqR->IsSimple(fOptions); + needsIndentation = not iYadSeqR->IsSimple(fOptions); } if (needsIndentation) @@ -610,7 +613,7 @@ bool needsIndentation = false; if (fOptions.DoIndentation()) { - needsIndentation = ! iYadMapR->IsSimple(fOptions); + needsIndentation = not iYadMapR->IsSimple(fOptions); } if (needsIndentation) Modified: trunk/zoolib/source/cxx/zoolib/ZYad_JSON.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_JSON.h 2011-10-16 18:58:49 UTC (rev 2565) +++ trunk/zoolib/source/cxx/zoolib/ZYad_JSON.h 2011-10-17 13:10:37 UTC (rev 2566) @@ -39,6 +39,7 @@ ZQ<bool> fAllowEquals; ZQ<bool> fAllowSemiColons; ZQ<bool> fAllowTerminators; + ZQ<bool> fLooseSeparators; }; // ================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-16 18:58:55
|
Revision: 2565 http://zoolib.svn.sourceforge.net/zoolib/?rev=2565&view=rev Author: agreen Date: 2011-10-16 18:58:49 +0000 (Sun, 16 Oct 2011) Log Message: ----------- Break up into separate files, so we know where to look. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZSetRestore_T.h Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZSaveRestore_T.h Added: trunk/zoolib/source/cxx/zoolib/ZSaveRestore_T.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZSaveRestore_T.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZSaveRestore_T.h 2011-10-16 18:58:49 UTC (rev 2565) @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2011 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZSaveRestore_T__ +#define __ZSaveRestore_T__ 1 +#include "zconfig.h" + +#include "zoolib/ZCompat_algorithm.h" // For std::swap + +namespace ZooLib { + +// ================================================================================================= +#pragma mark - +#pragma mark * ZSaveRestore_T + +template <class T> +class ZSaveRestore_T + { +public: + ZSaveRestore_T(T& ioRef) + : fRef(ioRef) + , fValPrior(ioRef) + {} + + ~ZSaveRestore_T() + { std::swap(fRef, fValPrior); } + + const T& GetPrior() const + { return fValPrior; } + +private: + T& fRef; + T fValPrior; + }; + +} // namespace ZooLib + +#endif // __ZSaveRestore_T__ Modified: trunk/zoolib/source/cxx/zoolib/ZSetRestore_T.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZSetRestore_T.h 2011-10-16 18:58:32 UTC (rev 2564) +++ trunk/zoolib/source/cxx/zoolib/ZSetRestore_T.h 2011-10-16 18:58:49 UTC (rev 2565) @@ -28,30 +28,6 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSaveRestore_T - -template <class T> -class ZSaveRestore_T - { -public: - ZSaveRestore_T(T& ioRef) - : fRef(ioRef) - , fValPrior(ioRef) - {} - - ~ZSaveRestore_T() - { std::swap(fRef, fValPrior); } - - const T& GetPrior() const - { return fValPrior; } - -private: - T& fRef; - T fValPrior; - }; - -// ================================================================================================= -#pragma mark - #pragma mark * ZSetRestore_T template <class T> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-16 18:58:39
|
Revision: 2564 http://zoolib.svn.sourceforge.net/zoolib/?rev=2564&view=rev Author: agreen Date: 2011-10-16 18:58:32 +0000 (Sun, 16 Oct 2011) Log Message: ----------- Fix handling of the chain. Some steps in exploration of lexical scoping. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-10-16 04:26:32 UTC (rev 2563) +++ trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-10-16 18:58:32 UTC (rev 2564) @@ -47,6 +47,8 @@ ZRef<ZYadR> ReadAt(const ZRef<CountedString>& iProto, const string& iName); private: + ZRef<ZYadR> pReadAt(const string& iName); + const ZRef<Chain> fParent; ZRef<ZYadMapRPos> fYadMapRPos; }; @@ -133,7 +135,9 @@ Chain::Chain(const ZRef<Chain>& iParent, const ZRef<ZYadMapRPos>& iYadMapRPos) : fParent(iParent) , fYadMapRPos(iYadMapRPos) - {} + { + ZAssert(not iYadMapRPos.DynamicCast<YadMapRPos>()); + } ZRef<Chain> Chain::Clone() { return new Chain(fParent, fYadMapRPos->Clone().DynamicCast<ZYadMapRPos>()); } @@ -141,9 +145,12 @@ ZRef<ZYadR> Chain::ReadInc(string& oName) { return fYadMapRPos->ReadInc(oName); } +ZRef<ZYadR> Chain::pReadAt(const string& iName) + { return fYadMapRPos->ReadAt(iName); } + ZRef<ZYadR> Chain::ReadAt(const ZRef<CountedString>& iProto, const string& iName) { - if (ZRef<ZYadR> theYad = fYadMapRPos->ReadAt(iName)) + if (ZRef<ZYadR> theYad = this->pReadAt(iName)) return spWrap(iProto, this, theYad); if (ZRef<ZYadStrimR> theProtoYad = fYadMapRPos->ReadAt(iProto->Get()).DynamicCast<ZYadStrimR>()) @@ -178,23 +185,25 @@ while (index < theTrail.Count()) { if (ZRef<ZYadMapRPos,false> theYadMapRPos = - cur->ReadAt(iProto, theTrail.At(index)).DynamicCast<ZYadMapRPos>()) + cur->pReadAt(theTrail.At(index)).DynamicCast<ZYadMapRPos>()) { break; } else { cur = new Chain(cur, theYadMapRPos); if (++index == theTrail.Count()) - return spWrap(iProto, cur, theYadMapRPos->ReadAt(iName)); + return cur->ReadAt(iProto, iName); } } } } + + // Yay, lexical scoping, disabled for now. + if (false && fParent) + return spWrap(iProto, fParent, fParent->pReadAt(iName)); + return null; } -class Chain; - - // ================================================================================================= #pragma mark - #pragma mark * YadSeqRPos definition This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-16 04:26:38
|
Revision: 2563 http://zoolib.svn.sourceforge.net/zoolib/?rev=2563&view=rev Author: agreen Date: 2011-10-16 04:26:32 +0000 (Sun, 16 Oct 2011) Log Message: ----------- Fix ZTween_Rate's handling of negative (reversed) rates. Add ZTween_Normalize. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTween.h Modified: trunk/zoolib/source/cxx/zoolib/ZTween.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-16 04:26:02 UTC (rev 2562) +++ trunk/zoolib/source/cxx/zoolib/ZTween.h 2011-10-16 04:26:32 UTC (rev 2563) @@ -25,6 +25,7 @@ #include "zoolib/ZCountedWithoutFinalize.h" #include "zoolib/ZCompat_algorithm.h" // for std::binary_function #include "zoolib/ZCompat_cmath.h" // for fmod +#include "zoolib/ZDebug.h" // for fmod #include "zoolib/ZRef.h" namespace ZooLib { @@ -605,7 +606,7 @@ ZTween_Rate(const ZRef<ZTween<Val> >& iTween, double iRate) : fTween(iTween) , fRate(iRate) - {} + { ZAssert(fRate); } // From ZTween virtual Val ValAt(double iTime) @@ -613,7 +614,7 @@ if (fRate > 0) return fTween->ValAt(iTime / fRate); else - return fTween->ValAt((fTween->Duration() - iTime) / -fRate); + return fTween->ValAt(fTween->Duration() + iTime/fRate); } virtual double Duration() @@ -639,6 +640,38 @@ // ================================================================================================= #pragma mark - +#pragma mark * sTween_Normalize + +template <class Val> +class ZTween_Normalize +: public ZTween<Val> + { +public: + ZTween_Normalize(const ZRef<ZTween<Val> >& iTween, double iNormalize) + : fTween(iTween) + {} + +// From ZTween + virtual Val ValAt(double iTime) + { return fTween->ValAt(iTime / fTween->Duration); } + + virtual double Duration() + { return 1; } + +private: + const ZRef<ZTween<Val> > fTween; + }; + +template <class Val> +ZRef<ZTween<Val> > sTween_Normalize(const ZRef<ZTween<Val> >& iTween) + { + if (iTween) + return new ZTween_Normalize<Val>(iTween); + return null; + } + +// ================================================================================================= +#pragma mark - #pragma mark * sTween_Const template <class Val> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2011-10-16 04:26:08
|
Revision: 2562 http://zoolib.svn.sourceforge.net/zoolib/?rev=2562&view=rev Author: agreen Date: 2011-10-16 04:26:02 +0000 (Sun, 16 Oct 2011) Log Message: ----------- Add operator_bool for ZVal_yad. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h Modified: trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp 2011-10-16 04:25:32 UTC (rev 2561) +++ trunk/zoolib/source/cxx/zoolib/ZVal_Yad.cpp 2011-10-16 04:26:02 UTC (rev 2562) @@ -30,6 +30,9 @@ ZAny ZVal_Yad::AsAny() const { return this->pAsAny(); } +ZVal_Yad::operator operator_bool() const + { return operator_bool_gen::translate(fYad); } + ZVal_Yad::ZVal_Yad() {} Modified: trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h 2011-10-16 04:25:32 UTC (rev 2561) +++ trunk/zoolib/source/cxx/zoolib/ZVal_Yad.h 2011-10-16 04:26:02 UTC (rev 2562) @@ -42,6 +42,7 @@ { public: ZAny AsAny() const; + ZMACRO_operator_bool(ZVal_Yad, operator_bool) const; ZVal_Yad(); ZVal_Yad(const ZVal_Yad& iOther); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |