diff --git a/libretroshare/src/retroshare/rsexpr.h b/libretroshare/src/retroshare/rsexpr.h index 4cf9e7983..771c215fc 100644 --- a/libretroshare/src/retroshare/rsexpr.h +++ b/libretroshare/src/retroshare/rsexpr.h @@ -28,6 +28,7 @@ #include #include #include +#include "util/rsprint.h" #include "retroshare/rstypes.h" /****************************************************************************************** @@ -127,6 +128,7 @@ public: virtual ~Expression() {}; virtual void linearize(LinearizedExpression& e) const = 0 ; + virtual std::string toStdString() const = 0 ; }; class CompoundExpression : public Expression @@ -155,6 +157,18 @@ public: delete Rexp; } + virtual std::string toStdString() const + { + switch(Op) + { + case AndOp: return "(" + Lexp->toStdString() + ") AND (" + Rexp->toStdString() +")" ; + case OrOp: return "(" + Lexp->toStdString() + ") OR (" + Rexp->toStdString() +")" ; + case XorOp: return "(" + Lexp->toStdString() + ") XOR (" + Rexp->toStdString() +")" ; + default: + return "" ; + } + } + virtual void linearize(LinearizedExpression& e) const ; private: Expression *Lexp; @@ -169,6 +183,7 @@ public: StringExpression(enum StringOperator op, std::list &t, bool ic): Op(op),terms(t), IgnoreCase(ic){} virtual void linearize(LinearizedExpression& e) const ; + virtual std::string toStdString(const std::string& varstr) const; protected: bool evalStr(const std::string &str); @@ -184,6 +199,7 @@ public: RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {} virtual void linearize(LinearizedExpression& e) const ; + virtual std::string toStdString(const std::string& typestr) const; protected: bool evalRel(T val); @@ -214,6 +230,22 @@ bool RelExpression::evalRel(T val) { } } +template +std::string RelExpression::toStdString(const std::string& typestr) const +{ + std::string LowerValueStr = RsUtil::NumberToString(LowerValue) ; + + switch (Op) { + case Equals: return typestr + " = " + LowerValueStr ; + case GreaterEquals: return typestr + " <= "+ LowerValueStr ; + case Greater: return typestr + " < " + LowerValueStr ; + case SmallerEquals: return typestr + " >= "+ LowerValueStr ; + case Smaller: return typestr + " > " + LowerValueStr ; + case InRange: return LowerValueStr + " <= " + typestr + " <= " + RsUtil::NumberToString(HigherValue) ; + default: + return ""; + } +} /****************************************************************************************** Binary Predicate for Case Insensitive search @@ -245,6 +277,8 @@ public: StringExpression(op,t,ic) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString() const { return StringExpression::toStdString("NAME"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_NAME) ; @@ -258,6 +292,8 @@ public: StringExpression(op,t,ic) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString()const { return StringExpression::toStdString("PATH"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_PATH) ; @@ -271,6 +307,8 @@ public: StringExpression(op,t,ic) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString()const { return StringExpression::toStdString("EXTENSION"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_EXT) ; @@ -284,6 +322,8 @@ public: StringExpression(op,t, true) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString() const { return StringExpression::toStdString("HASH"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_HASH) ; @@ -304,6 +344,8 @@ public: RelExpression(op,lv,hv) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString() const { return RelExpression::toStdString("DATE"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_DATE) ; @@ -319,6 +361,8 @@ public: RelExpression(op,lv,hv) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString() const { return RelExpression::toStdString("SIZE"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ; @@ -334,6 +378,8 @@ public: RelExpression(op,lv,hv) {} bool eval(const ExpFileEntry& file); + virtual std::string toStdString() const { return RelExpression::toStdString("SIZE"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ; @@ -348,6 +394,8 @@ public: PopExpression(const LinearizedExpression& e) ; bool eval(const ExpFileEntry& file); + virtual std::string toStdString() const { return RelExpression::toStdString("POPULARITY"); } + virtual void linearize(LinearizedExpression& e) const { e._tokens.push_back(LinearizedExpression::EXPR_POP) ; diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 9fe58915b..3271044a4 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1785,6 +1785,10 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::listtoStdString() << std::endl; +#endif + // now, search! rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId()); diff --git a/libretroshare/src/util/rsexpr.cc b/libretroshare/src/util/rsexpr.cc index 7e35a1873..9a6de7076 100644 --- a/libretroshare/src/util/rsexpr.cc +++ b/libretroshare/src/util/rsexpr.cc @@ -128,6 +128,32 @@ static bool StrContains( const std::string & str1, const std::string & str2, } +std::string StringExpression::toStdString(const std::string& varstr) const +{ + std::string strlist ; + for (auto iter = terms.begin(); iter != terms.end(); ++iter ) + strlist += *iter + ","; + + if(!strlist.empty()) + strlist.pop_back(); // pops the last "," + + switch(Op) + { + case ContainsAllStrings: return varstr + " CONTAINS ALL "+strlist ; + case ContainsAnyStrings: if(terms.size() == 1) + return varstr + " CONTAINS "+strlist ; + else + return varstr + " CONTAINS ONE OF "+strlist ; + case EqualsString: if(terms.size() == 1) + return varstr + " IS "+strlist ; + else + return varstr + " IS ONE OF "+strlist ; + + default: + return "" ; + } +} + bool StringExpression :: evalStr ( const std::string &str ){ std::list::iterator iter; switch (Op) {