#include "dbase.h" bool _isBitSet(int _byte, short _bitno) { int val; val = 1 << _bitno; return (_byte & val) >> _bitno; } void _bitSet(int *ptr, short _bitno) { int val; val = 1 << _bitno; *ptr |= val; return; } void _bitReset(int *ptr, short _bitno) { int val; val = 1 << _bitno; *ptr &= ~val; return; } Vector StringToToken(const String &str) { Vector tkn; int p, s=0, e=0; for(p=0; p<=str.GetCount(); p++) { int h=0, b=0; while(((str.Mid(p, 1) != "," && str.Mid(p, 1) != " ") || h > 0 || b > 0) && p < str.GetCount()) { if(str.Mid(p, 1) == "\"" && h == 0) h++; else if(str.Mid(p, 1) == "\"" && h > 0) h--; else if(str.Mid(p, 1) == ")") b--; else if(str.Mid(p, 1) == "(") b++; p++; } e=p; if(str.Mid(s, e-s).GetCount() > 0) { if(tkn.GetCount() > 0) { if(str.Mid(s, e-s) == "=" || str.Mid(s, e-s) == "<" || str.Mid(s, e-s) == ">" || str.Mid(s, e-s) == "<=" || str.Mid(s, e-s) == ">=") { tkn.Top().Cat(str.Mid(s, e-s)); } else if(tkn.Top().Right(1) == "=" || tkn.Top().Right(1) == "<" || tkn.Top().Right(1) == ">") { tkn.Top().Cat(str.Mid(s, e-s)); } else { tkn.Add(str.Mid(s, e-s)); } } else { tkn.Add(str.Mid(s, e-s)); } #ifdef _WITH_DEBUG RLOG("StringToToken(): " + tkn.Top()); #endif } s=e+1; } return tkn; } bool lmlEval(String eqt) { unsigned int i, l, m, s, e; String a, b; bool j = true; a = eqt; while(j) { l = 0; m = 0; for(i=0; i m) m = l; } s = 1; e = a.GetLength()-2; l = 0; bool f = false; for(i=0; i 0) b = a.Mid(s, e); else b = a; if(lplEval(b) == true) { a.Remove(s-1, e+2); a.Insert(s-1, "T"); } else { a.Remove(s-1, e+2); a.Insert(s-1, "F"); } #ifdef _WITH_DEBUG RLOG(a); #endif if(m < 1) j = false; } if(strcmp(a.Mid(0, 1), "T") == 0) return true; return false; } bool lplEval(String eqt) { Vector token; unsigned int i; token = StringToToken(eqt); #ifdef _WITH_DEBUG for(i=0; i x; Array lo; bool z; unsigned int k; k = 0; x.Add(false); for(i=0; i 0) { // se c'è condizione WHERE // copio la condizione where eqt = whr; f = 0; // inizio a convertire i songoli token di confronto while(f"); fd = temp.Left(a); j = strspn((char*)~temp.Mid(a), "=<>"); opr = temp.Mid(a, j); val = RemoveQuote(temp.Mid(j+a)); if(strcmp((char*)~opr, "=") == 0) { if(IsEqual(rec1.GetValue(fd), val)) { temp = "T"; } else temp = "F"; } else if(strcmp((char*)~opr, "<") == 0) { if(IsSmaller(rec1.GetValue(fd), val)) { temp = "T"; } else temp = "F"; } else if(strcmp((char*)~opr, ">") == 0) { if(IsBigger(rec1.GetValue(fd), val)) { temp = "T"; } else temp = "F"; } else if(strcmp((char*)~opr, "<=") == 0) { if(IsSmallerEqual(rec1.GetValue(fd), val)) { temp = "T"; } else temp = "F"; } else if(strcmp((char*)~opr, ">=") == 0) { if(IsBiggerEqual(rec1.GetValue(fd), val)) { temp = "T"; } else temp = "F"; } else temp = "F"; eqt.Remove(s, len); eqt.Insert(s, temp); ++f -= len; } } } // token di confronto convertiti, ora la stringa e' in formato (T AND F) ... // valuto il risultato della condizione if(lmlEval(eqt)) { validRecord = true; } } else { // altrimenti senza WHERE validRecord = true; } return validRecord; } VectorMap > StringToVector(const String &s) { StringStream ss(s); VectorMap > m; ss.SetLoading(); m.Serialize(ss); //LoadFromString(m, s); return m; } String VectorToString(VectorMap > &v) { StringStream ss; //ss.Create(); ss.SetStoring(); v.Serialize(ss); return ss.GetResult(); //return StoreAsString(v); }