From: Andrew G. <ag...@us...> - 2005-04-08 18:03:56
|
Update of /cvsroot/zoolib/zoolib/src_other/tuplebase In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30825 Modified Files: ZTBSpec.cpp ZTBSpec.h Log Message: Add support for regular expression clauses. Index: ZTBSpec.cpp =================================================================== RCS file: /cvsroot/zoolib/zoolib/src_other/tuplebase/ZTBSpec.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ZTBSpec.cpp 7 Oct 2004 19:53:56 -0000 1.16 +++ ZTBSpec.cpp 8 Apr 2005 18:03:45 -0000 1.17 @@ -23,6 +23,7 @@ ------------------------------------------------------------ */ #include "ZTBSpec.h" +#include "ZRegex.h" #include "ZTextCollator.h" #include "ZTupleValueComp.h" @@ -141,7 +142,10 @@ for (vector<ZTBSpec::Criterion>::iterator i = ioCrit.begin(); i != ioCrit.end(); /* no Increment */) { ZTupleValue smallestLess, smallestLessEqual, largestGreater, largestGreaterEqual; - bool gotSmallestLess = false, gotSmallestLessEqual = false, gotLargestGreater = false, gotLargestGreaterEqual = false; + bool gotSmallestLess = false; + bool gotSmallestLessEqual = false; + bool gotLargestGreater = false; + bool gotLargestGreaterEqual = false; // For simplicity we simplify only if strength is zero if ((*i).fComp.fStrength != 0) @@ -340,7 +344,8 @@ if (isTautology) { - // We don't actually recognize tautologies yet. + // We don't actually recognize tautologies yet, so isTautology + // never gets set true and we won't execute thus. ioCrit.clear(); return true; } @@ -397,6 +402,19 @@ // ==================================================================================================== #pragma mark - +#pragma mark * ZTBSpec::Comp +ZTBSpec::Comp::Comp(ERel iRel, int iStrength) +: fRel(iRel), + fStrength(iStrength) + {} + +ZTBSpec::Comp::Comp(ERel iRel) +: fRel(iRel), + fStrength(0) + {} + +// ==================================================================================================== +#pragma mark - #pragma mark * ZTBSpec::Criterion ZTBSpec::Criterion::Criterion(const string& iPropName) @@ -493,12 +511,24 @@ return true; return ZTextCollator(fComp.fStrength).Contains(pattern, target); - break; } case eRel_Regex: { - // Not implemented yet - break; + #if ZCONFIG_Regex_Enabled + string target; + if (!iTuple.GetString(propNumber, target) || target.empty()) + return false; + + if (!fComp.fRegex) + fComp.fRegex = ZRegex(fTupleValue.GetString(), fComp.fStrength); + + if (!fComp.fRegex) + return false; + + return fComp.fRegex.Matches(target); + #else + return false; + #endif // ZCONFIG_Regex_Enabled } default: { @@ -619,7 +649,7 @@ void ZTBSpec::ToStream(const ZStreamW& iStreamW) const { - return sCriteriaToStream(iStreamW, fCriteria); + sCriteriaToStream(iStreamW, fCriteria); } ZTBSpec ZTBSpec::sAny() @@ -664,8 +694,8 @@ ZTBSpec ZTBSpec::sVectorContains(const string& iPropName, const ZTupleValue& iValue) { return ZTBSpec(iPropName, eRel_VectorContains, iValue); } -ZTBSpec ZTBSpec::sRegex(const string& iPropName, const string& iRegex) - { return ZTBSpec(iPropName, eRel_Regex, iRegex); } +ZTBSpec ZTBSpec::sRegex(const string& iPropName, const string& iRegex, int iStrength) + { return ZTBSpec(iPropName, eRel_Regex, iStrength, iRegex); } static void sCrossProduct(const vector<vector<ZTBSpec::Criterion> >& iSourceA, const vector<vector<ZTBSpec::Criterion> >& iSourceB, @@ -693,9 +723,9 @@ vector<vector<Criterion> > crossProduct; sCrossProduct(fCriteria, iOther.fCriteria, crossProduct); + sSimplify(crossProduct); // Here we use our special constructor that swaps its empty vector // with the passed in vector. - sSimplify(crossProduct); return ZTBSpec(crossProduct, true); } Index: ZTBSpec.h =================================================================== RCS file: /cvsroot/zoolib/zoolib/src_other/tuplebase/ZTBSpec.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- ZTBSpec.h 4 May 2004 22:24:36 -0000 1.11 +++ ZTBSpec.h 8 Apr 2005 18:03:46 -0000 1.12 @@ -26,6 +26,7 @@ #define __ZTBSpec__ 1 #include "zconfig.h" +#include "ZRegex.h" #include "ZTuple.h" // ==================================================================================================== @@ -56,11 +57,14 @@ class Comp { public: - Comp(ERel iRel, int iStrength) : fRel(iRel), fStrength(iStrength) {} - Comp(ERel iRel) : fRel(iRel), fStrength(0) {} + Comp(ERel iRel, int iStrength); + Comp(ERel iRel); ERel fRel; int fStrength; + #if ZCONFIG_Regex_Enabled + mutable ZRegex fRegex; + #endif }; class Criterion; @@ -131,7 +135,7 @@ static ZTBSpec sVectorContains(const std::string& iPropName, const ZTupleValue& iValue); /// Tuples whose string property \a iPropName matches the regex \a iRegex - static ZTBSpec sRegex(const std::string& iPropName, const std::string& iRegex); + static ZTBSpec sRegex(const std::string& iPropName, const std::string& iRegex, int iStrength); ZTBSpec operator&(const ZTBSpec& iOther) const; ZTBSpec& operator&=(const ZTBSpec& iOther); |