From: <ag...@us...> - 2011-12-27 06:26:06
|
Revision: 2653 http://zoolib.svn.sourceforge.net/zoolib/?rev=2653&view=rev Author: agreen Date: 2011-12-27 06:26:00 +0000 (Tue, 27 Dec 2011) Log Message: ----------- RootAugment gives us something akin to parameterization. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp trunk/zoolib/source/cxx/zoolib/ZYadTree.h Modified: trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-12-27 03:26:23 UTC (rev 2652) +++ trunk/zoolib/source/cxx/zoolib/ZYadTree.cpp 2011-12-27 06:26:00 UTC (rev 2653) @@ -24,6 +24,8 @@ #include "zoolib/ZUtil_STL_map.h" #include "zoolib/ZYadTree.h" +#include "zoolib/ZLog.h" + using std::string; namespace ZooLib { @@ -43,12 +45,17 @@ public: Chain(const ZRef<Chain>& iParent, const ZRef<ZYadMapRPos>& iYadMapRPos); + Chain(const std::string& iRootAugmentName, const ZRef<Chain>& iRootAugment, + const ZRef<ZYadMapRPos>& iYadMapRPos); ZRef<Chain> Clone(); ZRef<ZYadR> ReadInc(string& oName); ZRef<ZYadR> ReadAt(const ZRef<CountedString>& iProtoName, const string& iName); + ZRef<Chain> WithRootAugment + (const std::string& iRootAugmentName, const ZRef<Chain>& iRootAugment); + private: ZRef<ZYadR> pReadAt(const string& iName); @@ -112,6 +119,11 @@ virtual void SetPosition(const string& iName); virtual ZRef<ZYadR> ReadAt(const string& iName); +// Our protocol + ZRef<Chain> GetChain(); + ZRef<YadMapRPos> WithRootAugment + (const std::string& iRootAugmentName, const ZRef<Chain>& iRootAugment); + private: const ZRef<CountedString> fProtoName; ZRef<Chain> fChain; @@ -153,6 +165,13 @@ ZAssert(not iYadMapRPos.DynamicCast<YadMapRPos>()); } +Chain::Chain(const std::string& iRootAugmentName, const ZRef<Chain>& iRootAugment, + const ZRef<ZYadMapRPos>& iYadMapRPos) +: fYadMapRPos(iYadMapRPos->Clone().DynamicCast<ZYadMapRPos>()) + { + ZUtil_STL::sInsertMustNotContain(fCacheByName, iRootAugmentName, iRootAugment); + } + ZRef<Chain> Chain::Clone() { return new Chain(*this); } @@ -205,15 +224,25 @@ } // Walk down the remainder of the trail - ZRef<Chain> result; - while (index < theTrail.Count()) + + if (index < theTrail.Count()) { - if (ZRef<ZYadMapRPos,0> theYadMapRPos = - cur->pReadAt(theTrail.At(index)).DynamicCast<ZYadMapRPos>()) - { break; } - else + for (;;) { - cur = new Chain(cur, theYadMapRPos); + const string theComp = theTrail.At(index); + if (ZQ<ZRef<Chain> > aChain = sQGet(cur->fCacheByName, theComp)) + { + cur = *aChain; + } + else if (ZRef<ZYadMapRPos,0> theYadMapRPos = + cur->pReadAt(theComp).DynamicCast<ZYadMapRPos>()) + { + break; + } + else + { + cur = new Chain(cur, theYadMapRPos); + } if (++index == theTrail.Count()) { theChain = cur; @@ -237,6 +266,15 @@ return null; } +ZRef<Chain> Chain::WithRootAugment + (const std::string& iRootAugmentName, const ZRef<Chain>& iRootAugment) + { + ZRef<ZYadMapRPos> newYad = fYadMapRPos->Clone().DynamicCast<ZYadMapRPos>(); + if (fParent) + return new Chain(fParent->WithRootAugment(iRootAugmentName, iRootAugment), newYad); + return new Chain(iRootAugmentName, iRootAugment, newYad); + } + // ================================================================================================= #pragma mark - #pragma mark * YadSeqRPos definition @@ -308,16 +346,38 @@ void YadMapRPos::SetPosition(const string& iName) { fPosition = iName; } +ZRef<Chain> YadMapRPos::GetChain() + { return fChain; } + +ZRef<YadMapRPos> YadMapRPos::WithRootAugment + (const std::string& iRootAugmentName, const ZRef<Chain>& iRootAugment) + { + ZRef<Chain> newChain = fChain->WithRootAugment(iRootAugmentName, iRootAugment); + return new YadMapRPos(fProtoName, newChain, string()); } + } // namespace YadTree // ================================================================================================= #pragma mark - #pragma mark * YadMapRPos definition +using namespace YadTree; + ZRef<ZYadMapRPos> sYadTree(const ZRef<ZYadMapRPos>& iYadMapRPos, const string& iProtoName) - { return new YadTree::YadMapRPos(new YadTree::CountedString(iProtoName), iYadMapRPos); } + { return new YadMapRPos(new CountedString(iProtoName), iYadMapRPos); } ZRef<ZYadMapRPos> sYadTree(const ZRef<ZYadMapRPos>& iYadMapRPos) { return sYadTree(iYadMapRPos, "_"); } +ZRef<ZYadMapRPos> sParameterizedYadTree(const ZRef<ZYadMapRPos>& iBase, + const std::string& iRootAugmentName, const ZRef<ZYadMapRPos>& iRootAugment) + { + if (ZRef<YadMapRPos> theBase = iBase.DynamicCast<YadMapRPos>()) + { + if (ZRef<YadMapRPos> theRootAugment = iRootAugment.DynamicCast<YadMapRPos>()) + return theBase->WithRootAugment(iRootAugmentName, theRootAugment->GetChain()); + } + return iBase; + } + } // namespace ZooLib Modified: trunk/zoolib/source/cxx/zoolib/ZYadTree.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYadTree.h 2011-12-27 03:26:23 UTC (rev 2652) +++ trunk/zoolib/source/cxx/zoolib/ZYadTree.h 2011-12-27 06:26:00 UTC (rev 2653) @@ -30,6 +30,9 @@ ZRef<ZYadMapRPos> sYadTree(const ZRef<ZYadMapRPos>& iYadMapRPos); +ZRef<ZYadMapRPos> sParameterizedYadTree(const ZRef<ZYadMapRPos>& iBase, + const std::string& iRootAugmentName, const ZRef<ZYadMapRPos>& iRootAugment); + } // namespace ZooLib #endif // __ZYadTree__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |