From: <ag...@us...> - 2012-01-09 20:32:22
|
Revision: 2665 http://zoolib.svn.sourceforge.net/zoolib/?rev=2665&view=rev Author: agreen Date: 2012-01-09 20:32:16 +0000 (Mon, 09 Jan 2012) Log Message: ----------- Some cleanup. Lose the accumulators -- And-types need more work. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-09 20:06:48 UTC (rev 2664) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-09 20:32:16 UTC (rev 2665) @@ -200,16 +200,16 @@ { return sCompareAndSet(ioCog, ioCog->Call(ioCog, iParam)); } template <class Cog> -bool sCallCog_Changed(Cog& ioCog, const typename Cog::Param iParam) - { return sIsPending(ioCog) && sCompareAndSet(ioCog, ioCog->Call(ioCog, iParam)); } - -template <class Cog> bool sCallPendingCog_Unchanged(Cog& ioCog, const typename Cog::Param iParam) { return not sCompareAndSet(ioCog, ioCog->Call(ioCog, iParam)); } template <class Cog> +bool sCallCog_Changed(Cog& ioCog, const typename Cog::Param iParam) + { return sIsPending(ioCog) && sCallPendingCog_Changed(ioCog, iParam); } + +template <class Cog> bool sCallCog_Unchanged(Cog& ioCog, const typename Cog::Param iParam) - { return sIsFinished(ioCog) || not sCompareAndSet(ioCog, ioCog->Call(ioCog, iParam)); } + { return sIsFinished(ioCog) || sCallPendingCog_Unchanged(ioCog, iParam); } // ================================================================================================= #pragma mark - @@ -226,7 +226,7 @@ if (sCallPendingCog_Unchanged(lCog, iParam)) return iSelf; - if (not lCog) + if (sIsFalse(lCog)) return true; if (sIsTrue(lCog)) @@ -239,7 +239,8 @@ ZCog<Param> spCog_Not (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - ZAssert(iCallable && not sIsTrue(iCallable)); + ZAssert(sIsPending(iCallable)); + static ZMACRO_auto(spCallable, sCallable(spCogFun_Not<Param>)); return sBindR(spCallable, iCallable); } @@ -248,7 +249,7 @@ ZCog<Param> sCog_Not (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - if (not iCallable) + if (sIsFalse(iCallable)) return true; if (sIsTrue(iCallable)) @@ -277,7 +278,7 @@ if (sCallPendingCog_Unchanged(lCog, iParam)) return iSelf; - if (not lCog || sIsTrue(lCog)) + if (sIsFinished(lCog)) return true; return spCog_Tautology(lCog); @@ -287,7 +288,8 @@ ZCog<Param> spCog_Tautology (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - ZAssert(iCallable && not sIsTrue(iCallable)); + ZAssert(sIsPending(iCallable)); + static ZMACRO_auto(spCallable, sCallable(spCogFun_Tautology<Param>)); return sBindR(spCallable, iCallable); } @@ -296,7 +298,7 @@ ZCog<Param> sCog_Tautology (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - if (not iCallable || sIsTrue(iCallable)) + if (sIsFinished(iCallable)) return true; return spCog_Tautology(iCallable); @@ -321,7 +323,7 @@ if (sCallPendingCog_Unchanged(lCog, iParam)) return iSelf; - if (not lCog || sIsTrue(lCog)) + if (sIsFinished(lCog)) return false; return spCog_Contradiction(lCog); @@ -331,7 +333,8 @@ ZCog<Param> spCog_Contradiction (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - ZAssert(iCallable && not sIsTrue(iCallable)); + ZAssert(sIsPending(iCallable)); + static ZMACRO_auto(spCallable, sCallable(spCogFun_Contradiction<Param>)); return sBindR(spCallable, iCallable); } @@ -340,7 +343,7 @@ ZCog<Param> sCog_Contradiction (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - if (not iCallable || sIsTrue(iCallable)) + if (sIsFinished(iCallable)) return false; return spCog_Contradiction(iCallable); @@ -368,7 +371,7 @@ if (sCallPendingCog_Unchanged(lCog, iParam)) return iSelf; - if (not lCog) + if (sIsFalse(lCog)) return false; if (not sIsTrue(lCog)) @@ -388,6 +391,7 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { ZAssert(iCallable_Init && iCallable); + static ZMACRO_auto(spCallable, sCallable(spCogFun_Repeat<Param>)); return sBindR(spCallable, iCallable_Init, iCallable); } @@ -396,7 +400,7 @@ ZCog<Param> sCog_Repeat (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) { - if (not iCallable) + if (sIsFalse(iCallable)) return false; if (sIsTrue(iCallable)) @@ -411,7 +415,7 @@ // ================================================================================================= #pragma mark - -#pragma mark * Binary sequential, sCog_Then +#pragma mark * Binary linear, sCog_Then // Call cog0 till it finishes, if true then call cog1 @@ -432,7 +436,7 @@ if (sIsTrue(lCog)) { - if (iCog1 && not sIsTrue(iCog1)) + if (sIsPending(iCog1)) return iCog1->Call(iCog1, iParam); return iCog1; } @@ -483,6 +487,38 @@ // ================================================================================================= #pragma mark - +#pragma mark * Binary linear, sCog_Each + +// Call cog0 till it finishes, then call cog1 + +template <class Param> +ZCog<Param> sCog_Each + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { + if (sIsPending(iCallable0)) + { + if (sIsPending(iCallable1)) + return +iCallable0 >> iCallable1; + return iCallable0; + } + return iCallable1; + } + +template <class Param> +ZCog<Param> operator^ + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { return sCog_Each<Param>(iCallable0, iCallable1); } + +template <class Param> +ZCog<Param>& operator^= + (ZCog<Param>& ioCog0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { return ioCog0 = ioCog0 ^ iCallable1; } + +// ================================================================================================= +#pragma mark - #pragma mark * Binary parallel, sCog_And template <class Param> @@ -495,6 +531,7 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { ZAssert(sIsPending(iCallable0) && not sIsTrue(iCallable1)); + static ZMACRO_auto(spCallable, sCallable(spCogFun_And<Param>)); return sBindR(spCallable, iCallable0, iCallable1); } @@ -524,14 +561,14 @@ if (sCallPendingCog_Unchanged(lCog0, iParam)) { - if (not iCog1) + if (sIsFalse(iCog1)) return false; ZCog<Param> lCog1 = iCog1; if (sCallPendingCog_Unchanged(lCog1, iParam)) return iSelf; - if (not lCog1) + if (sIsFalse(lCog1)) return false; if (sIsTrue(lCog1)) @@ -539,13 +576,13 @@ return spCog_And(lCog0, lCog1); } - else if (not lCog0) + else if (sIsFalse(lCog0)) { return false; } else if (sIsTrue(lCog0)) { - if (not iCog1) + if (sIsFalse(iCog1)) return false; if (sIsTrue(iCog1)) @@ -555,7 +592,7 @@ } else { - if (not iCog1) + if (sIsFalse(iCog1)) return false; if (sIsTrue(iCog1)) @@ -584,18 +621,6 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { return ioCog0 = sCog_And<Param>(ioCog0, iCallable1); } -template <class Param> -struct ZCogAccumulatorCombiner_And - { - void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const - { - if (io0) - io0 = sCog_And(io0, i1); - else - io0 = i1; - } - }; - // ================================================================================================= #pragma mark - #pragma mark * Binary parallel, sCog_Or @@ -610,6 +635,7 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { ZAssert(sIsPending(iCallable0) && sIsPending(iCallable1)); + static ZMACRO_auto(spCallable, sCallable(spCogFun_Or<Param>)); return sBindR(spCallable, iCallable0, iCallable1); } @@ -646,7 +672,7 @@ if (sCallPendingCog_Unchanged(lCog1, iParam)) return iSelf; - if (not lCog1) + if (sIsFalse(lCog1)) return lCog0; if (sIsTrue(lCog1)) @@ -654,7 +680,7 @@ return spCog_Or(lCog0, lCog1); } - else if (not lCog0) + else if (sIsFalse(lCog0)) { if (sIsTrue(iCog1)) return true; @@ -693,26 +719,9 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { return ioCog0 = sCog_Or<Param>(ioCog0, iCallable1); } -template <class Param> -struct ZCogAccumulatorCombiner_Or - { - void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const - { - if (io0) - { - if (i1) - io0 = sCog_Or(io0, i1); - } - else - { - io0 = i1; - } - } - }; - // ================================================================================================= #pragma mark - -#pragma mark * sCog_With +#pragma mark * Binary parallel, sCog_With // Call cog1 so long as cog0 is pending. @@ -787,7 +796,7 @@ // ================================================================================================= #pragma mark - -#pragma mark * sCog_WithUnchanged +#pragma mark * Binary parallel, sCog_WithUnchanged // Call cog1 so long as cog0 is pending and unchanged. @@ -800,7 +809,8 @@ (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { - ZAssert(iCallable0 && iCallable1); + ZAssert(sIsPending(iCallable0) && sIsPending(iCallable1)); + static ZMACRO_auto(spCallable, sCallable(spCogFun_WithUnchanged<Param>)); return sBindR(spCallable, iCallable0, iCallable1); } @@ -848,45 +858,6 @@ const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { return ioCog0 = sCog_WithUnchanged<Param>(ioCog0, iCallable1); } -// ================================================================================================= -#pragma mark - -#pragma mark * Binary, sCog_Each - -// Call cog0 till it finishes, then call cog1 - -template <class Param> -ZCog<Param> sCog_Each - (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, - const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { - if (sIsPending(iCallable0)) - { - if (sIsPending(iCallable1)) - return +iCallable0 >> iCallable1; - return iCallable0; - } - return iCallable1; - } - -template <class Param> -ZCog<Param> operator^ - (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, - const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { return sCog_Each<Param>(iCallable0, iCallable1); } - -template <class Param> -ZCog<Param>& operator^= - (ZCog<Param>& ioCog0, - const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { return ioCog0 = ioCog0 ^ iCallable1; } - -template <class Param> -struct ZCogAccumulatorCombiner_Each - { - void operator()(ZCog<Param>& io0, const ZCog<Param>& i1) const - { io0 ^= i1; } - }; - } // namespace ZooLib #endif // __ZCog_h__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-01-10 04:45:03
|
Revision: 2667 http://zoolib.svn.sourceforge.net/zoolib/?rev=2667&view=rev Author: agreen Date: 2012-01-10 04:44:56 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Comment. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 04:43:22 UTC (rev 2666) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 04:44:56 UTC (rev 2667) @@ -415,7 +415,7 @@ // ================================================================================================= #pragma mark - -#pragma mark * Binary linear, sCog_Then +#pragma mark * Binary sequential, sCog_Then // Call cog0 till it finishes, if true then call cog1 @@ -487,7 +487,7 @@ // ================================================================================================= #pragma mark - -#pragma mark * Binary linear, sCog_Each +#pragma mark * Binary sequential, sCog_Each // Call cog0 till it finishes, then call cog1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-01-10 05:25:04
|
Revision: 2669 http://zoolib.svn.sourceforge.net/zoolib/?rev=2669&view=rev Author: agreen Date: 2012-01-10 05:24:58 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Tweaks. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 04:54:04 UTC (rev 2668) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 05:24:58 UTC (rev 2669) @@ -108,13 +108,18 @@ //-- - static ZCog sFalse() - { return null; } - + static const ZCog& sFalse(); static const ZCog& sTrue(); }; template <class Param> +const ZCog<Param>& ZCog<Param>::sFalse() + { + static const ZCog<Param> spCog; + return spCog; + } + +template <class Param> ZCog<Param> spCogFun_True(const ZCog<Param>& iSelf, Param iParam) { // Shouldn't ever call this. @@ -366,16 +371,15 @@ ZCog<Param> spCogFun_Repeat(const ZCog<Param>& iSelf, Param iParam, const ZCog<Param>& iCog_Init, const ZCog<Param>& iCog) { - ZCog<Param> lCog = iCog; - - if (sCallPendingCog_Unchanged(lCog, iParam)) + ZCog<Param> newCog = iCog; + if (sCallPendingCog_Unchanged(newCog, iParam)) return iSelf; - if (sIsFalse(lCog)) + if (sIsFalse(newCog)) return false; - if (not sIsTrue(lCog)) - return spCog_Repeat(iCog_Init, lCog); + if (not sIsTrue(newCog)) + return spCog_Repeat(iCog_Init, newCog); // To get unbroken repetition on hitting a term we need to call the new cog, // don't make the call if we'd just be calling an iSelf-equivalent. @@ -436,9 +440,9 @@ if (sIsTrue(lCog)) { - if (sIsPending(iCog1)) - return iCog1->Call(iCog1, iParam); - return iCog1; + if (sIsFinished(iCog1)) + return iCog1; + return iCog1->Call(iCog1, iParam); } return spCog_Then(lCog, iCog1); @@ -564,17 +568,17 @@ if (sIsFalse(iCog1)) return false; - ZCog<Param> lCog1 = iCog1; - if (sCallPendingCog_Unchanged(lCog1, iParam)) + ZCog<Param> newCog1 = iCog1; + if (sCallPendingCog_Unchanged(newCog1, iParam)) return iSelf; - if (sIsFalse(lCog1)) + if (sIsFalse(newCog1)) return false; - if (sIsTrue(lCog1)) + if (sIsTrue(newCog1)) return lCog0; - return spCog_And(lCog0, lCog1); + return spCog_And(lCog0, newCog1); } else if (sIsFalse(lCog0)) { @@ -598,11 +602,11 @@ if (sIsTrue(iCog1)) return lCog0; - if (ZCog<Param> lCog1 = iCog1->Call(iCog1, iParam)) + if (ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam)) { - if (sIsTrue(lCog1)) + if (sIsTrue(newCog1)) return lCog0; - return spCog_And(lCog0, lCog1); + return spCog_And(lCog0, newCog1); } return false; @@ -668,17 +672,17 @@ if (sIsTrue(iCog1)) return true; - ZCog<Param> lCog1 = iCog1; - if (sCallPendingCog_Unchanged(lCog1, iParam)) + ZCog<Param> newCog1 = iCog1; + if (sCallPendingCog_Unchanged(newCog1, iParam)) return iSelf; - if (sIsFalse(lCog1)) + if (sIsFalse(newCog1)) return lCog0; - if (sIsTrue(lCog1)) + if (sIsTrue(newCog1)) return true; - return spCog_Or(lCog0, lCog1); + return spCog_Or(lCog0, newCog1); } else if (sIsFalse(lCog0)) { @@ -696,11 +700,11 @@ if (sIsTrue(iCog1)) return true; - if (ZCog<Param> lCog1 = iCog1->Call(iCog1, iParam)) + if (ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam)) { - if (sIsTrue(lCog1)) + if (sIsTrue(newCog1)) return true; - return spCog_Or(lCog0, lCog1); + return spCog_Or(lCog0, newCog1); } return lCog0; @@ -727,7 +731,7 @@ template <class Param> ZCog<Param> spCogFun_With(const ZCog<Param>& iSelf, Param iParam, - const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); + ZCog<Param> lCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_With @@ -752,33 +756,33 @@ template <class Param> ZCog<Param> spCogFun_With(const ZCog<Param>& iSelf, Param iParam, - const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) + ZCog<Param> lCog0, const ZCog<Param>& iCog1) { - ZAssert(sIsPending(iCog0) && sIsPending(iCog1)); + ZAssert(sIsPending(lCog0) && sIsPending(iCog1)); - ZCog<Param> newCog0 = iCog0; - if (sCallPendingCog_Unchanged(newCog0, iParam)) + if (sCallPendingCog_Unchanged(lCog0, iParam)) { ZCog<Param> newCog1 = iCog1; if (sCallPendingCog_Unchanged(newCog1, iParam)) return iSelf; if (sIsFinished(newCog1)) - return newCog0; + return lCog0; - return spCog_With(newCog0, newCog1); + return spCog_With(lCog0, newCog1); } - else if (sIsPending(newCog0)) + else if (sIsPending(lCog0)) { ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam); - if (sIsPending(newCog1)) - return spCog_With(newCog0, newCog1); - return newCog0; + if (sIsFinished(newCog1)) + return lCog0; + + return spCog_With(lCog0, newCog1); } else { - return newCog0; + return lCog0; } } @@ -802,7 +806,7 @@ template <class Param> ZCog<Param> spCogFun_WithUnchanged(const ZCog<Param>& iSelf, Param iParam, - const ZCog<Param>& iCog0, const ZCog<Param>& iCog1); + ZCog<Param> lCog0, const ZCog<Param>& iCog1); template <class Param> ZCog<Param> spCog_WithUnchanged @@ -827,23 +831,21 @@ template <class Param> ZCog<Param> spCogFun_WithUnchanged(const ZCog<Param>& iSelf, Param iParam, - const ZCog<Param>& iCog0, const ZCog<Param>& iCog1) + ZCog<Param> lCog0, const ZCog<Param>& iCog1) { - ZAssert(sIsPending(iCog0) && sIsPending(iCog1)); + ZAssert(sIsPending(lCog0) && sIsPending(iCog1)); - ZCog<Param> newCog0 = iCog0; - if (sCallPendingCog_Changed(newCog0, iParam)) - return newCog0; + if (sCallPendingCog_Changed(lCog0, iParam)) + return lCog0; ZCog<Param> newCog1 = iCog1; - if (sCallPendingCog_Changed(newCog1, iParam)) - { - if (sIsPending(newCog1)) - return spCog_WithUnchanged(newCog0, newCog1); - return newCog0; - } + if (sCallPendingCog_Unchanged(newCog1, iParam)) + return iSelf; - return iSelf; + if (sIsFinished(newCog1)) + return lCog0; + + return spCog_WithUnchanged(lCog0, newCog1); } template <class Param> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-01-10 17:16:32
|
Revision: 2670 http://zoolib.svn.sourceforge.net/zoolib/?rev=2670&view=rev Author: agreen Date: 2012-01-10 17:16:21 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Simplify sCog_Each. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 05:24:58 UTC (rev 2669) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 17:16:21 UTC (rev 2670) @@ -500,13 +500,9 @@ (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { - if (sIsPending(iCallable0)) - { - if (sIsPending(iCallable1)) - return +iCallable0 >> iCallable1; - return iCallable0; - } - return iCallable1; + if (sIsFinished(iCallable0)) + return iCallable1; + return +iCallable0 >> iCallable1; } template <class Param> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-01-11 21:28:09
|
Revision: 2671 http://zoolib.svn.sourceforge.net/zoolib/?rev=2671&view=rev Author: agreen Date: 2012-01-11 21:27:58 +0000 (Wed, 11 Jan 2012) Log Message: ----------- Simplify sCog_Each. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-10 17:16:21 UTC (rev 2670) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-11 21:27:58 UTC (rev 2671) @@ -499,11 +499,7 @@ ZCog<Param> sCog_Each (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { - if (sIsFinished(iCallable0)) - return iCallable1; - return +iCallable0 >> iCallable1; - } + { return +iCallable0 >> iCallable1; } template <class Param> ZCog<Param> operator^ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-01-12 23:16:24
|
Revision: 2674 http://zoolib.svn.sourceforge.net/zoolib/?rev=2674&view=rev Author: agreen Date: 2012-01-12 23:16:18 +0000 (Thu, 12 Jan 2012) Log Message: ----------- Harminize body of With and WithUnchanged. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-11 21:31:41 UTC (rev 2673) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-12 23:16:18 UTC (rev 2674) @@ -827,17 +827,19 @@ { ZAssert(sIsPending(lCog0) && sIsPending(iCog1)); - if (sCallPendingCog_Changed(lCog0, iParam)) - return lCog0; + if (sCallPendingCog_Unchanged(lCog0, iParam)) + { + ZCog<Param> newCog1 = iCog1; + if (sCallPendingCog_Unchanged(newCog1, iParam)) + return iSelf; - ZCog<Param> newCog1 = iCog1; - if (sCallPendingCog_Unchanged(newCog1, iParam)) - return iSelf; + if (sIsFinished(newCog1)) + return lCog0; - if (sIsFinished(newCog1)) - return lCog0; + return spCog_WithUnchanged(lCog0, newCog1); + } - return spCog_WithUnchanged(lCog0, newCog1); + return lCog0; } template <class Param> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-01-28 18:15:34
|
Revision: 2696 http://zoolib.svn.sourceforge.net/zoolib/?rev=2696&view=rev Author: agreen Date: 2012-01-28 18:15:28 +0000 (Sat, 28 Jan 2012) Log Message: ----------- Comment. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-28 18:15:20 UTC (rev 2695) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-01-28 18:15:28 UTC (rev 2696) @@ -121,7 +121,7 @@ template <class Param> ZCog<Param> spCogFun_True(const ZCog<Param>& iSelf, Param iParam) { - // Shouldn't ever call this. + // Must not ever call this. ZUnimplemented(); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-02-03 07:30:09
|
Revision: 2710 http://zoolib.svn.sourceforge.net/zoolib/?rev=2710&view=rev Author: agreen Date: 2012-02-03 07:29:58 +0000 (Fri, 03 Feb 2012) Log Message: ----------- Add sCog_While. Make cog classification a bit more readable. Comments. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-02-03 07:28:50 UTC (rev 2709) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-02-03 07:29:58 UTC (rev 2710) @@ -160,11 +160,11 @@ template <class Param> bool sIsFinished(const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) - { return not iCallable || sIsTrue(iCallable); } + { return sIsFalse(iCallable) || sIsTrue(iCallable); } template <class Param> bool sIsPending(const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable) - { return iCallable && not sIsTrue(iCallable); } + { return not sIsFinished(iCallable); } // ================================================================================================= // MARK:- sCallCog variants @@ -373,8 +373,8 @@ if (not sIsTrue(newCog)) return spCog_Repeat(iCog_Init, newCog); - // To get unbroken repetition on hitting a term we need to call the new cog, - // don't make the call if we'd just be calling an iSelf-equivalent. + // To get unbroken repetition on hitting a term we need to call the new cog, but don't + // make the call if we'd be calling an iSelf-equivalent (infinite recursion would ensue). if (iCog_Init == iCog) return iSelf; else @@ -704,9 +704,85 @@ { return ioCog0 = sCog_Or<Param>(ioCog0, iCallable1); } // ================================================================================================= +// MARK: - Binary parallel, sCog_While + +// Call cog0 and cog1 while cog1 is pending, result from cog1. + +template <class Param> +ZCog<Param> spCogFun_While(const ZCog<Param>& iSelf, Param iParam, + ZCog<Param> lCog0, const ZCog<Param>& iCog1); + +template <class Param> +ZCog<Param> spCog_While + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { + ZAssert(sIsPending(iCallable0) && sIsPending(iCallable1)); + + static ZMACRO_auto(spCallable, sCallable(spCogFun_While<Param>)); + return sBindR(spCallable, iCallable0, iCallable1); + } + +template <class Param> +ZCog<Param> sCog_While + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { + if (sIsPending(iCallable0) && sIsPending(iCallable1)) + return spCog_While(iCallable0, iCallable1); + return iCallable1; + } + +template <class Param> +ZCog<Param> spCogFun_While(const ZCog<Param>& iSelf, Param iParam, + ZCog<Param> lCog0, const ZCog<Param>& iCog1) + { + ZAssert(sIsPending(lCog0) && sIsPending(iCog1)); + + if (sCallPendingCog_Unchanged(lCog0, iParam)) + { + ZCog<Param> newCog1 = iCog1; + if (sCallPendingCog_Unchanged(newCog1, iParam)) + return iSelf; + + if (sIsFinished(newCog1)) + return newCog1; + + return spCog_While(lCog0, newCog1); + } + else if (sIsFinished(lCog0)) + { + return iCog1->Call(iCog1, iParam); + } + else + { + ZCog<Param> newCog1 = iCog1->Call(iCog1, iParam); + + if (sIsFinished(newCog1)) + return newCog1; + + return spCog_While(lCog0, newCog1); + } + } + +#if 0 +template <class Param> +ZCog<Param> operator/ + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { return sCog_While<Param>(iCallable0, iCallable1); } + +template <class Param> +ZCog<Param>& operator/= + (ZCog<Param>& ioCog0, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) + { return ioCog0 = sCog_While<Param>(ioCog0, iCallable1); } +#endif + +// ================================================================================================= // MARK: - Binary parallel, sCog_With -// Call cog1 so long as cog0 is pending. +// Call cog0 and cog1 so long as cog0 is pending, result from cog0 template <class Param> ZCog<Param> spCogFun_With(const ZCog<Param>& iSelf, Param iParam, @@ -780,7 +856,7 @@ // ================================================================================================= // MARK: - Binary parallel, sCog_WithUnchanged -// Call cog1 so long as cog0 is pending and unchanged. +// Call cog0 and cog1 so long as cog0 is pending and unchanged, result from cog0 template <class Param> ZCog<Param> spCogFun_WithUnchanged(const ZCog<Param>& iSelf, Param iParam, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2012-02-04 20:55:46
|
Revision: 2711 http://zoolib.svn.sourceforge.net/zoolib/?rev=2711&view=rev Author: agreen Date: 2012-02-04 20:55:40 +0000 (Sat, 04 Feb 2012) Log Message: ----------- Add sCog_If, which supersedes sCog_Then. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCog.h Modified: trunk/zoolib/source/cxx/zoolib/ZCog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-02-03 07:29:58 UTC (rev 2710) +++ trunk/zoolib/source/cxx/zoolib/ZCog.h 2012-02-04 20:55:40 UTC (rev 2711) @@ -107,32 +107,25 @@ //-- - static const ZCog& sFalse(); - static const ZCog& sTrue(); - }; + static const ZCog& sFalse() + { + static const ZCog<Param> spCog; + return spCog; + } -template <class Param> -const ZCog<Param>& ZCog<Param>::sFalse() - { - static const ZCog<Param> spCog; - return spCog; - } + static ZCog spCogFun_True(const ZCog& iSelf, Param iParam) + { + // Must not ever call this. + ZUnimplemented(); + } -template <class Param> -ZCog<Param> spCogFun_True(const ZCog<Param>& iSelf, Param iParam) - { - // Must not ever call this. - ZUnimplemented(); - return null; - } + static const ZCog& sTrue() + { + static const ZCog spCog = sCallable(spCogFun_True); + return spCog; + } + }; -template <class Param> -const ZCog<Param>& ZCog<Param>::sTrue() - { - static const ZCog<Param> spCog = sCallable(spCogFun_True<Param>); - return spCog; - } - // ================================================================================================= // MARK: - Nullary, sCog_Unknown @@ -363,6 +356,9 @@ ZCog<Param> spCogFun_Repeat(const ZCog<Param>& iSelf, Param iParam, const ZCog<Param>& iCog_Init, const ZCog<Param>& iCog) { + // We don't do the usual trick of having iCog be a value param called 'lCog', because we may + // need to compare it's original value against iCog_Init later. + ZCog<Param> newCog = iCog; if (sCallPendingCog_Unchanged(newCog, iParam)) return iSelf; @@ -410,75 +406,78 @@ { return sCog_Repeat<Param>(iCallable); } // ================================================================================================= -// MARK: - Binary sequential, sCog_Then +// MARK: - Ternary sequential, sCog_If // Call cog0 till it finishes, if true then call cog1 template <class Param> -ZCog<Param> spCog_Then - (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, +ZCog<Param> spCog_If + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCondition, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1); template <class Param> -ZCog<Param> spCogFun_Then(const ZCog<Param>& iSelf, Param iParam, - ZCog<Param> lCog, const ZCog<Param>& iCog1) +ZCog<Param> spCogFun_If(const ZCog<Param>& iSelf, Param iParam, + ZCog<Param> lCondition, + const ZCog<Param>& iCog0, + const ZCog<Param>& iCog1) { - if (sCallPendingCog_Unchanged(lCog, iParam)) + if (sCallPendingCog_Unchanged(lCondition, iParam)) return iSelf; - if (sIsFalse(lCog)) - return false; + if (sIsTrue(lCondition)) + { + if (sIsFinished(iCog0)) + return iCog0; + return iCog0->Call(iCog0, iParam); + } - if (sIsTrue(lCog)) + if (sIsFalse(lCondition)) { if (sIsFinished(iCog1)) return iCog1; return iCog1->Call(iCog1, iParam); } - return spCog_Then(lCog, iCog1); + return spCog_If(lCondition, iCog0, iCog1); } template <class Param> -ZCog<Param> sCog_Then - (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, +ZCog<Param> sCog_If + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCondition, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { - if (sIsFalse(iCallable0)) - return false; + if (sIsTrue(iCondition)) + return iCallable0; - if (sIsTrue(iCallable0)) + if (sIsFalse(iCondition)) return iCallable1; - return spCog_Then(iCallable0, iCallable1); + return spCog_If(iCondition, iCallable0, iCallable1); } template <class Param> -ZCog<Param> spCog_Then - (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, +ZCog<Param> spCog_If + (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCondition, + const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) { - if (sIsFalse(iCallable0)) - return false; - - if (sIsTrue(iCallable0)) - return iCallable1; - - static ZMACRO_auto(spCallable, sCallable(spCogFun_Then<Param>)); - return sBindR(spCallable, iCallable0, iCallable1); + static ZMACRO_auto(spCallable, sCallable(spCogFun_If<Param>)); + return sBindR(spCallable, iCondition, iCallable0, iCallable1); } template <class Param> ZCog<Param> operator>> (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { return sCog_Then<Param>(iCallable0, iCallable1); } + { return sCog_If<Param>(iCallable0, iCallable1, null); } template <class Param> ZCog<Param>& operator>>= (ZCog<Param>& ioCog0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { return ioCog0 = sCog_Then<Param>(ioCog0, iCallable1); } + { return ioCog0 = sCog_If<Param>(ioCog0, iCallable1, null); } // ================================================================================================= // MARK: - Binary sequential, sCog_Each @@ -489,7 +488,8 @@ ZCog<Param> sCog_Each (const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable0, const ZRef<ZCallable<ZCog<Param>(const ZCog<Param>&,Param)> >& iCallable1) - { return +iCallable0 >> iCallable1; } + { return sCog_If(iCallable0, iCallable1, iCallable1); } +// { return +iCallable0 >> iCallable1; } template <class Param> ZCog<Param> operator^ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |