diff --git a/libresapi/src/api/FileSearchHandler.cpp b/libresapi/src/api/FileSearchHandler.cpp index 386db94c9..3833b4c9d 100644 --- a/libresapi/src/api/FileSearchHandler.cpp +++ b/libresapi/src/api/FileSearchHandler.cpp @@ -173,8 +173,8 @@ void FileSearchHandler::handleCreateSearch(Request &req, Response &resp) return; } - NameExpression exprs(ContainsAllStrings,words,true) ; - LinearizedExpression lin_exp ; + RsRegularExpression::NameExpression exprs(RsRegularExpression::ContainsAllStrings,words,true) ; + RsRegularExpression::LinearizedExpression lin_exp ; exprs.linearize(lin_exp) ; uint32_t search_id = RSRandom::random_u32(); diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index aa1e351ae..1735beb79 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -595,7 +595,7 @@ bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list &results) const +int InternalFileHierarchyStorage::searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const { #ifdef TODO for(std::map::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.h b/libretroshare/src/file_sharing/dir_hierarchy.h index f01f2c056..fb83e5d9d 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.h +++ b/libretroshare/src/file_sharing/dir_hierarchy.h @@ -140,7 +140,7 @@ public: // search. SearchHash is logarithmic. The other two are linear. bool searchHash(const RsFileHash& hash,std::list& results); - int searchBoolExp(Expression * exp, std::list &results) const ; + int searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const ; int searchTerms(const std::list& terms, std::list &results) const ; bool check(std::string& error_string) const ;// checks consistency of storage. diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 2adc54498..2a7cd8f91 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -203,7 +203,7 @@ int DirectoryStorage::searchTerms(const std::list& terms, std::list RS_STACK_MUTEX(mDirStorageMtx) ; return mFileHierarchy->searchTerms(terms,results); } -int DirectoryStorage::searchBoolExp(Expression * exp, std::list &results) const +int DirectoryStorage::searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const { RS_STACK_MUTEX(mDirStorageMtx) ; return mFileHierarchy->searchBoolExp(exp,results); diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index cfec2a018..be420f618 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -50,7 +50,7 @@ class DirectoryStorage void save() const ; virtual int searchTerms(const std::list& terms, std::list &results) const ; - virtual int searchBoolExp(Expression * exp, std::list &results) const ; + virtual int searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const ; virtual int searchHash(const RsFileHash& hash, std::list &results) const ; bool getDirUpdateTS(EntryIndex index,time_t& recurs_max_modf_TS,time_t& local_update_TS) ; diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index db73972e2..ea77de3a6 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -814,7 +814,7 @@ int p3FileDatabase::SearchKeywords(const std::list& keywords, std:: return filterResults(firesults,results,flags,client_peer_id) ; } -int p3FileDatabase::SearchBoolExp(Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const +int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const { RS_STACK_MUTEX(mFLSMtx) ; diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index b15a74488..f832dfc53 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -103,7 +103,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub virtual bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list& parent_groups) const; virtual int SearchKeywords(const std::list& keywords, std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) ; - virtual int SearchBoolExp(Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const ; + virtual int SearchBoolExp(RsRegularExpression::Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const ; // ftSearch virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const; diff --git a/libretroshare/src/file_sharing/rsexpr.cc b/libretroshare/src/file_sharing/rsexpr.cc index c9e1ff798..6b4d7ce20 100644 --- a/libretroshare/src/file_sharing/rsexpr.cc +++ b/libretroshare/src/file_sharing/rsexpr.cc @@ -26,6 +26,7 @@ #include "dbase/findex.h" #include "retroshare/rsexpr.h" +#include "retroshare/rstypes.h" #include #include @@ -34,33 +35,35 @@ eval functions of relational expressions. ******************************************************************************************/ +namespace RsRegularExpression +{ template<> void RelExpression::linearize(LinearizedExpression& e) const { - e._ints.push_back(Op) ; - e._ints.push_back(LowerValue) ; - e._ints.push_back(HigherValue) ; + e._ints.push_back(Op) ; + e._ints.push_back(LowerValue) ; + e._ints.push_back(HigherValue) ; } -bool DateExpression::eval(FileEntry *file) +bool DateExpression::eval(const ExpFileEntry& file) { - return evalRel(file->modtime); + return evalRel(file.file_modtime()); } -bool SizeExpressionMB::eval(FileEntry *file) +bool SizeExpressionMB::eval(const ExpFileEntry& file) { - return evalRel((int)(file->size/(uint64_t)(1024*1024))); + return evalRel((int)(file.file_size()/(uint64_t)(1024*1024))); } -bool SizeExpression::eval(FileEntry *file) +bool SizeExpression::eval(const ExpFileEntry& file) { - return evalRel(file->size); + return evalRel(file.file_size()); } -bool PopExpression::eval(FileEntry *file) +bool PopExpression::eval(const ExpFileEntry& file) { - return evalRel(file->pop); + return evalRel(file.file_popularity()); } /****************************************************************************************** @@ -68,98 +71,93 @@ Code for evaluating string expressions ******************************************************************************************/ -bool NameExpression::eval(FileEntry *file) +bool NameExpression::eval(const ExpFileEntry& file) { - return evalStr(file->name); + return evalStr(file.file_name()); } -bool PathExpression::eval(FileEntry *file){ - std::string path; - /*Construct the path of this file*/ - DirEntry * curr = file->parent; - while ( curr != NULL ){ - path = curr->name+"/"+ path; - curr = curr->parent; - } - return evalStr(path); +bool PathExpression::eval(const ExpFileEntry& file) +{ + return evalStr(file.file_parent_path()); } -bool ExtExpression::eval(FileEntry *file){ - std::string ext; - /*Get the part of the string after the last instance of . in the filename */ - size_t index = file->name.find_last_of('.'); - if (index != std::string::npos) { - ext = file->name.substr(index+1); - if (ext != "" ){ - return evalStr(ext); - } - } - return false; +bool ExtExpression::eval(const ExpFileEntry& file) +{ + std::string ext; + /*Get the part of the string after the last instance of . in the filename */ + size_t index = file.file_name().find_last_of('.'); + if (index != std::string::npos) { + ext = file.file_name().substr(index+1); + if (ext != "" ){ + return evalStr(ext); + } + } + return false; } -bool HashExpression::eval(FileEntry *file){ - return evalStr(file->hash.toStdString()); +bool HashExpression::eval(const ExpFileEntry& file){ + return evalStr(file.file_hash().toStdString()); } /*Check whether two strings are 'equal' to each other*/ static bool StrEquals(const std::string & str1, const std::string & str2, - bool IgnoreCase ){ - if ( str1.size() != str2.size() ){ - return false; - } else if (IgnoreCase) { - std::equal( str1.begin(), str1.end(), - str2.begin(), CompareCharIC() ); - } - return std::equal( str1.begin(), str1.end(), - str2.begin()); + bool IgnoreCase ){ + if ( str1.size() != str2.size() ){ + return false; + } else if (IgnoreCase) { + std::equal( str1.begin(), str1.end(), + str2.begin(), CompareCharIC() ); + } + return std::equal( str1.begin(), str1.end(), + str2.begin()); } /*Check whether one string contains the other*/ static bool StrContains( const std::string & str1, const std::string & str2, - bool IgnoreCase){ + bool IgnoreCase){ - std::string::const_iterator iter ; - if (IgnoreCase) { - iter = std::search( str1.begin(), str1.end(), - str2.begin(), str2.end(), CompareCharIC() ); - } else { - iter = std::search( str1.begin(), str1.end(), - str2.begin(), str2.end()); - } - - return ( iter != str1.end() ); + std::string::const_iterator iter ; + if (IgnoreCase) { + iter = std::search( str1.begin(), str1.end(), + str2.begin(), str2.end(), CompareCharIC() ); + } else { + iter = std::search( str1.begin(), str1.end(), + str2.begin(), str2.end()); + } + + return ( iter != str1.end() ); } bool StringExpression :: evalStr ( const std::string &str ){ - std::list::iterator iter; - switch (Op) { - case ContainsAllStrings: - for ( iter = terms.begin(); iter != terms.end(); ++iter ) { - if ( StrContains (str, *iter, IgnoreCase) == false ){ - return false; - } - } - return true; - break; - case ContainsAnyStrings: - for ( iter = terms.begin(); iter != terms.end(); ++iter ) { - if ( StrContains (str,*iter, IgnoreCase) == true ) { - return true; - } - } - break; - case EqualsString: - for ( iter = terms.begin(); iter != terms.end(); ++iter ) { - if ( StrEquals (str,*iter, IgnoreCase) == true ) { - return true; - } - } - break; - default: - return false; - } - return false; + std::list::iterator iter; + switch (Op) { + case ContainsAllStrings: + for ( iter = terms.begin(); iter != terms.end(); ++iter ) { + if ( StrContains (str, *iter, IgnoreCase) == false ){ + return false; + } + } + return true; + break; + case ContainsAnyStrings: + for ( iter = terms.begin(); iter != terms.end(); ++iter ) { + if ( StrContains (str,*iter, IgnoreCase) == true ) { + return true; + } + } + break; + case EqualsString: + for ( iter = terms.begin(); iter != terms.end(); ++iter ) { + if ( StrEquals (str,*iter, IgnoreCase) == true ) { + return true; + } + } + break; + default: + return false; + } + return false; } /************************************************************************* @@ -168,122 +166,123 @@ bool StringExpression :: evalStr ( const std::string &str ){ void CompoundExpression::linearize(LinearizedExpression& e) const { - e._tokens.push_back(LinearizedExpression::EXPR_COMP) ; - e._ints.push_back(Op) ; + e._tokens.push_back(LinearizedExpression::EXPR_COMP) ; + e._ints.push_back(Op) ; - Lexp->linearize(e) ; - Rexp->linearize(e) ; + Lexp->linearize(e) ; + Rexp->linearize(e) ; } void StringExpression::linearize(LinearizedExpression& e) const { - e._ints.push_back(Op) ; - e._ints.push_back(IgnoreCase) ; - e._ints.push_back(terms.size()) ; + e._ints.push_back(Op) ; + e._ints.push_back(IgnoreCase) ; + e._ints.push_back(terms.size()) ; - for(std::list::const_iterator it(terms.begin());it!=terms.end();++it) - e._strings.push_back(*it) ; + for(std::list::const_iterator it(terms.begin());it!=terms.end();++it) + e._strings.push_back(*it) ; } Expression *LinearizedExpression::toExpr(const LinearizedExpression& e) { - int i=0,j=0,k=0 ; - return toExpr(e,i,j,k) ; + int i=0,j=0,k=0 ; + return toExpr(e,i,j,k) ; } void LinearizedExpression::readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list& strings,bool& b,StringOperator& op) { - op = static_cast(e._ints[n_ints++]) ; - b = e._ints[n_ints++] ; - int n = e._ints[n_ints++] ; + op = static_cast(e._ints[n_ints++]) ; + b = e._ints[n_ints++] ; + int n = e._ints[n_ints++] ; - strings.clear() ; - for(int i=0;i(e._tokens[n_tok++]) ; + LinearizedExpression::token tok = static_cast(e._tokens[n_tok++]) ; - switch(tok) - { - case EXPR_DATE: { - RelOperator op = static_cast(e._ints[n_ints++]) ; - int lv = e._ints[n_ints++] ; - int hv = e._ints[n_ints++] ; + switch(tok) + { + case EXPR_DATE: { + RelOperator op = static_cast(e._ints[n_ints++]) ; + int lv = e._ints[n_ints++] ; + int hv = e._ints[n_ints++] ; - return new DateExpression(op,lv,hv) ; - } + return new DateExpression(op,lv,hv) ; + } - case EXPR_POP: { - RelOperator op = static_cast(e._ints[n_ints++]) ; - int lv = e._ints[n_ints++] ; - int hv = e._ints[n_ints++] ; + case EXPR_POP: { + RelOperator op = static_cast(e._ints[n_ints++]) ; + int lv = e._ints[n_ints++] ; + int hv = e._ints[n_ints++] ; - return new PopExpression(op,lv,hv) ; - } - case EXPR_SIZE: { - RelOperator op = static_cast(e._ints[n_ints++]) ; - int lv = e._ints[n_ints++] ; - int hv = e._ints[n_ints++] ; + return new PopExpression(op,lv,hv) ; + } + case EXPR_SIZE: { + RelOperator op = static_cast(e._ints[n_ints++]) ; + int lv = e._ints[n_ints++] ; + int hv = e._ints[n_ints++] ; - return new SizeExpression(op,lv,hv) ; - } - case EXPR_HASH: { - std::list strings ; - StringOperator op ; - bool b ; + return new SizeExpression(op,lv,hv) ; + } + case EXPR_HASH: { + std::list strings ; + StringOperator op ; + bool b ; - readStringExpr(e,n_ints,n_strings,strings,b,op) ; - return new HashExpression(op,strings) ; - } - case EXPR_NAME: { - std::list strings ; - StringOperator op ; - bool b ; + readStringExpr(e,n_ints,n_strings,strings,b,op) ; + return new HashExpression(op,strings) ; + } + case EXPR_NAME: { + std::list strings ; + StringOperator op ; + bool b ; - readStringExpr(e,n_ints,n_strings,strings,b,op) ; + readStringExpr(e,n_ints,n_strings,strings,b,op) ; - return new NameExpression(op,strings,b) ; - } - case EXPR_PATH: { - std::list strings ; - StringOperator op ; - bool b ; + return new NameExpression(op,strings,b) ; + } + case EXPR_PATH: { + std::list strings ; + StringOperator op ; + bool b ; - readStringExpr(e,n_ints,n_strings,strings,b,op) ; + readStringExpr(e,n_ints,n_strings,strings,b,op) ; - return new ExtExpression(op,strings,b) ; - } - case EXPR_EXT: { - std::list strings ; - StringOperator op ; - bool b ; + return new ExtExpression(op,strings,b) ; + } + case EXPR_EXT: { + std::list strings ; + StringOperator op ; + bool b ; - readStringExpr(e,n_ints,n_strings,strings,b,op) ; + readStringExpr(e,n_ints,n_strings,strings,b,op) ; - return new ExtExpression(op,strings,b) ; - } - case EXPR_COMP: { - LogicalOperator op = static_cast(e._ints[n_ints++]) ; + return new ExtExpression(op,strings,b) ; + } + case EXPR_COMP: { + LogicalOperator op = static_cast(e._ints[n_ints++]) ; - Expression *e1 = toExpr(e,n_tok,n_ints,n_strings) ; - Expression *e2 = toExpr(e,n_tok,n_ints,n_strings) ; + Expression *e1 = toExpr(e,n_tok,n_ints,n_strings) ; + Expression *e2 = toExpr(e,n_tok,n_ints,n_strings) ; - return new CompoundExpression(op,e1,e2) ; - } - case EXPR_SIZE_MB: { - RelOperator op = static_cast(e._ints[n_ints++]) ; - int lv = e._ints[n_ints++] ; - int hv = e._ints[n_ints++] ; + return new CompoundExpression(op,e1,e2) ; + } + case EXPR_SIZE_MB: { + RelOperator op = static_cast(e._ints[n_ints++]) ; + int lv = e._ints[n_ints++] ; + int hv = e._ints[n_ints++] ; - return new SizeExpressionMB(op,lv,hv) ; - } - default: - std::cerr << "No expression match the current value " << tok << std::endl ; - return NULL ; - } + return new SizeExpressionMB(op,lv,hv) ; + } + default: + std::cerr << "No expression match the current value " << tok << std::endl ; + return NULL ; + } } +} diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 4b4d4c1e3..1a558f9d6 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -569,11 +569,11 @@ int ftServer::SearchKeywords(std::list keywords, std::listSearchKeywords(keywords, results,flags,peer_id); } -int ftServer::SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags) +int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags) { return mFileDatabase->SearchBoolExp(exp, results,flags,RsPeerId()); } -int ftServer::SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) +int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) { return mFileDatabase->SearchBoolExp(exp,results,flags,peer_id) ; } diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index da1deb009..1173d8311 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -184,8 +184,8 @@ public: virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags); virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id); - virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags); - virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id); + virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags); + virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id); /*** * Utility Functions diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index f839ab2d5..e30e3637e 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -59,6 +59,7 @@ file_lists { file_sharing/rsfilelistitems.cc } + dsdv { DEFINES *= SERVICES_DSDV HEADERS += services/p3dsdv.h \ diff --git a/libretroshare/src/retroshare/rsexpr.h b/libretroshare/src/retroshare/rsexpr.h index 87d216387..fc339e87c 100644 --- a/libretroshare/src/retroshare/rsexpr.h +++ b/libretroshare/src/retroshare/rsexpr.h @@ -1,6 +1,3 @@ -#ifndef RS_EXPRESSIONS_H -#define RS_EXPRESSIONS_H - /* * rs-core/src/rsiface: rsexpr.h * @@ -26,38 +23,41 @@ * */ +#pragma once #include #include #include +#include "retroshare/rstypes.h" /****************************************************************************************** Enumerations defining the Operators usable in the Boolean search expressions ******************************************************************************************/ - +namespace RsRegularExpression +{ enum LogicalOperator{ - AndOp=0, /* exp AND exp */ - OrOp=1, /* exp OR exp */ - XorOp=2 /* exp XOR exp */ + AndOp=0, /* exp AND exp */ + OrOp=1, /* exp OR exp */ + XorOp=2 /* exp XOR exp */ }; -/*Operators for String Queries*/ +/* Operators for String Queries */ enum StringOperator{ - ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */ - ContainsAllStrings = 1, /* same as above except that it contains ALL of the strings */ - EqualsString = 2 /* exactly equal*/ + ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */ + ContainsAllStrings = 1, /* same as above except that it contains ALL of the strings */ + EqualsString = 2 /* exactly equal*/ }; -/*Relational operators ( >, <, >=, <=, == and InRange )*/ +/* Comparison operators ( >, <, >=, <=, == and InRange ) */ enum RelOperator{ - Equals = 0, - GreaterEquals = 1, - Greater = 2, - SmallerEquals = 3, - Smaller = 4, - InRange = 5 /* lower limit <= value <= upper limit*/ + Equals = 0, + GreaterEquals = 1, + Greater = 2, + SmallerEquals = 3, + Smaller = 4, + InRange = 5 /* lower limit <= value <= upper limit*/ }; /******************************************************************************************** @@ -69,26 +69,26 @@ class Expression ; class LinearizedExpression { - public: - std::vector _tokens ; - std::vector _ints ; - std::vector _strings ; +public: + std::vector _tokens ; + std::vector _ints ; + std::vector _strings ; - typedef enum { EXPR_DATE= 0, - EXPR_POP = 1, - EXPR_SIZE= 2, - EXPR_HASH= 3, - EXPR_NAME= 4, - EXPR_PATH= 5, - EXPR_EXT = 6, - EXPR_COMP= 7, - EXPR_SIZE_MB=8 } token ; + typedef enum { EXPR_DATE = 0, + EXPR_POP = 1, + EXPR_SIZE = 2, + EXPR_HASH = 3, + EXPR_NAME = 4, + EXPR_PATH = 5, + EXPR_EXT = 6, + EXPR_COMP = 7, + EXPR_SIZE_MB = 8 } token ; - static Expression *toExpr(const LinearizedExpression& e) ; + static Expression *toExpr(const LinearizedExpression& e) ; - private: - static Expression *toExpr(const LinearizedExpression& e,int&,int&,int&) ; - static void readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list& strings,bool& b,StringOperator& op) ; +private: + static Expression *toExpr(const LinearizedExpression& e,int&,int&,int&) ; + static void readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list& strings,bool& b,StringOperator& op) ; }; @@ -96,110 +96,122 @@ class LinearizedExpression Boolean Search Expression classes: - Expression: The base class of all expression typest - CompoundExpression: The expression which uses a logical operator to combine - the results of two expressions - StringExpression: An expression which uses some sort of string comparison. - RelExpression: A Relational Expression where > < >= <= == make sense. - e.g. size date etc + Expression: The base class of all expression typest + CompoundExpression: The expression which uses a logical operator to combine + the results of two expressions + StringExpression: An expression which uses some sort of string comparison. + RelExpression: A Relational Expression where > < >= <= == make sense. + e.g. size date etc ******************************************************************************************/ -class FileEntry; +/*! + * \brief The ExpFileEntry class + * This is the base class the regular expressions can operate on. Derive it to fit your own needs! + */ +class ExpFileEntry +{ +public: + virtual const std::string& file_name() const =0; + virtual uint64_t file_size() const =0; + virtual time_t file_modtime() const =0; + virtual time_t file_popularity() const =0; + virtual const std::string file_parent_path() const =0; + virtual const RsFileHash& file_hash() const =0; +}; class Expression { - public: - virtual bool eval (FileEntry *file) = 0; - virtual ~Expression() {}; +public: + virtual bool eval (const ExpFileEntry& file) = 0; + virtual ~Expression() {}; - virtual void linearize(LinearizedExpression& e) const = 0 ; + virtual void linearize(LinearizedExpression& e) const = 0 ; }; - class CompoundExpression : public Expression { - public: - CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2) - : Lexp(exp1), Rexp(exp2), Op(op){ } +public: + CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2) + : Lexp(exp1), Rexp(exp2), Op(op){ } - bool eval (FileEntry *file) { - if (Lexp == NULL or Rexp == NULL) { - return false; - } - switch (Op){ - case AndOp: - return Lexp->eval(file) && Rexp->eval(file); - case OrOp: - return Lexp->eval(file) || Rexp->eval(file); - case XorOp: - return Lexp->eval(file) ^ Rexp->eval(file); - default: - return false; - } - } - virtual ~CompoundExpression(){ - delete Lexp; - delete Rexp; - } + bool eval (const ExpFileEntry& file) { + if (Lexp == NULL or Rexp == NULL) { + return false; + } + switch (Op){ + case AndOp: + return Lexp->eval(file) && Rexp->eval(file); + case OrOp: + return Lexp->eval(file) || Rexp->eval(file); + case XorOp: + return Lexp->eval(file) ^ Rexp->eval(file); + default: + return false; + } + } + virtual ~CompoundExpression(){ + delete Lexp; + delete Rexp; + } - virtual void linearize(LinearizedExpression& e) const ; - private: - Expression *Lexp; - Expression *Rexp; - enum LogicalOperator Op; + virtual void linearize(LinearizedExpression& e) const ; +private: + Expression *Lexp; + Expression *Rexp; + enum LogicalOperator Op; }; class StringExpression: public Expression { - public: - StringExpression(enum StringOperator op, std::list &t, bool ic): Op(op),terms(t), IgnoreCase(ic){} +public: + StringExpression(enum StringOperator op, std::list &t, bool ic): Op(op),terms(t), IgnoreCase(ic){} - virtual void linearize(LinearizedExpression& e) const ; - protected: - bool evalStr(const std::string &str); + virtual void linearize(LinearizedExpression& e) const ; +protected: + bool evalStr(const std::string &str); - enum StringOperator Op; - std::list terms; - bool IgnoreCase; + enum StringOperator Op; + std::list terms; + bool IgnoreCase; }; template class RelExpression: public Expression { - public: - RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {} +public: + RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {} - virtual void linearize(LinearizedExpression& e) const ; - protected: - bool evalRel(T val); + virtual void linearize(LinearizedExpression& e) const ; +protected: + bool evalRel(T val); - enum RelOperator Op; - T LowerValue; - T HigherValue; + enum RelOperator Op; + T LowerValue; + T HigherValue; }; template<> void RelExpression::linearize(LinearizedExpression& e) const ; template bool RelExpression::evalRel(T val) { - switch (Op) { - case Equals: - return LowerValue == val; - case GreaterEquals: - return LowerValue >= val; - case Greater: - return LowerValue > val; - case SmallerEquals: - return LowerValue <= val; - case Smaller: - return LowerValue < val; - case InRange: - return (LowerValue <= val) && (val <= HigherValue); - default: - return false; - } + switch (Op) { + case Equals: + return LowerValue == val; + case GreaterEquals: + return LowerValue >= val; + case Greater: + return LowerValue > val; + case SmallerEquals: + return LowerValue <= val; + case Smaller: + return LowerValue < val; + case InRange: + return (LowerValue <= val) && (val <= HigherValue); + default: + return false; + } } @@ -212,12 +224,12 @@ Binary Predicate for Case Insensitive search *Factor locales in the comparison */ struct CompareCharIC : - public std::binary_function< char , char , bool> { + public std::binary_function< char , char , bool> { - bool operator () ( char ch1 , char ch2 ) const { - return tolower( static_cast < unsigned char > (ch1) ) - == tolower( static_cast < unsigned char > (ch2) ); - } + bool operator () ( char ch1 , char ch2 ) const { + return tolower( static_cast < unsigned char > (ch1) ) + == tolower( static_cast < unsigned char > (ch2) ); + } }; @@ -228,55 +240,55 @@ Some implementations of StringExpressions. class NameExpression: public StringExpression { - public: - NameExpression(enum StringOperator op, std::list &t, bool ic): - StringExpression(op,t,ic) {} - bool eval(FileEntry *file); +public: + NameExpression(enum StringOperator op, std::list &t, bool ic): + StringExpression(op,t,ic) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_NAME) ; - StringExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_NAME) ; + StringExpression::linearize(e) ; + } }; class PathExpression: public StringExpression { public: - PathExpression(enum StringOperator op, std::list &t, bool ic): - StringExpression(op,t,ic) {} - bool eval(FileEntry *file); + PathExpression(enum StringOperator op, std::list &t, bool ic): + StringExpression(op,t,ic) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_PATH) ; - StringExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_PATH) ; + StringExpression::linearize(e) ; + } }; class ExtExpression: public StringExpression { public: - ExtExpression(enum StringOperator op, std::list &t, bool ic): - StringExpression(op,t,ic) {} - bool eval(FileEntry *file); + ExtExpression(enum StringOperator op, std::list &t, bool ic): + StringExpression(op,t,ic) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_EXT) ; - StringExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_EXT) ; + StringExpression::linearize(e) ; + } }; class HashExpression: public StringExpression { public: - HashExpression(enum StringOperator op, std::list &t): - StringExpression(op,t, true) {} - bool eval(FileEntry *file); + HashExpression(enum StringOperator op, std::list &t): + StringExpression(op,t, true) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_HASH) ; - StringExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_HASH) ; + StringExpression::linearize(e) ; + } }; /****************************************************************************************** @@ -286,62 +298,62 @@ Some implementations of Relational Expressions. class DateExpression: public RelExpression { - public: - DateExpression(enum RelOperator op, int v): RelExpression(op,v,v){} - DateExpression(enum RelOperator op, int lv, int hv): - RelExpression(op,lv,hv) {} - bool eval(FileEntry *file); +public: + DateExpression(enum RelOperator op, int v): RelExpression(op,v,v){} + DateExpression(enum RelOperator op, int lv, int hv): + RelExpression(op,lv,hv) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_DATE) ; - RelExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_DATE) ; + RelExpression::linearize(e) ; + } }; class SizeExpression: public RelExpression { - public: - SizeExpression(enum RelOperator op, int v): RelExpression(op,v,v){} - SizeExpression(enum RelOperator op, int lv, int hv): - RelExpression(op,lv,hv) {} - bool eval(FileEntry *file); +public: + SizeExpression(enum RelOperator op, int v): RelExpression(op,v,v){} + SizeExpression(enum RelOperator op, int lv, int hv): + RelExpression(op,lv,hv) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ; - RelExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ; + RelExpression::linearize(e) ; + } }; class SizeExpressionMB: public RelExpression { - public: - SizeExpressionMB(enum RelOperator op, int v): RelExpression(op,v,v){} - SizeExpressionMB(enum RelOperator op, int lv, int hv): - RelExpression(op,lv,hv) {} - bool eval(FileEntry *file); +public: + SizeExpressionMB(enum RelOperator op, int v): RelExpression(op,v,v){} + SizeExpressionMB(enum RelOperator op, int lv, int hv): + RelExpression(op,lv,hv) {} + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ; - RelExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ; + RelExpression::linearize(e) ; + } }; class PopExpression: public RelExpression { - public: - PopExpression(enum RelOperator op, int v): RelExpression(op,v,v){} - PopExpression(enum RelOperator op, int lv, int hv): RelExpression(op,lv,hv) {} - PopExpression(const LinearizedExpression& e) ; - bool eval(FileEntry *file); +public: + PopExpression(enum RelOperator op, int v): RelExpression(op,v,v){} + PopExpression(enum RelOperator op, int lv, int hv): RelExpression(op,lv,hv) {} + PopExpression(const LinearizedExpression& e) ; + bool eval(const ExpFileEntry& file); - virtual void linearize(LinearizedExpression& e) const - { - e._tokens.push_back(LinearizedExpression::EXPR_POP) ; - RelExpression::linearize(e) ; - } + virtual void linearize(LinearizedExpression& e) const + { + e._tokens.push_back(LinearizedExpression::EXPR_POP) ; + RelExpression::linearize(e) ; + } }; +} -#endif /* RS_EXPRESSIONS_H */ diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index d49324933..2236a6a8b 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -36,7 +36,7 @@ class RsFiles; extern RsFiles *rsFiles; -class Expression; +namespace RsRegularExpression { class Expression; } class CacheStrapper ; class CacheTransfer; @@ -190,8 +190,8 @@ class RsFiles virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) = 0; virtual int SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0; - virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags) = 0; - virtual int SearchBoolExp(Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0; + virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags) = 0; + virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0; /*** * Utility Functions. diff --git a/libretroshare/src/retroshare/rsturtle.h b/libretroshare/src/retroshare/rsturtle.h index 6fb1b045c..59b787c8e 100644 --- a/libretroshare/src/retroshare/rsturtle.h +++ b/libretroshare/src/retroshare/rsturtle.h @@ -35,7 +35,7 @@ #include "retroshare/rstypes.h" -class LinearizedExpression ; +namespace RsRegularExpression { class LinearizedExpression ; } class RsTurtleClientService ; class RsTurtle; @@ -102,7 +102,7 @@ class RsTurtle // as they come back. // virtual TurtleRequestId turtleSearch(const std::string& match_string) = 0 ; - virtual TurtleRequestId turtleSearch(const LinearizedExpression& expr) = 0 ; + virtual TurtleRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) = 0 ; // Initiates tunnel handling for the given file hash. tunnels. Launches // an exception if an error occurs during the initialization process. The diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index b3bcb1630..25d1972a5 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1763,7 +1763,7 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list initialResults; // to do: split search string into words. - Expression *exp = LinearizedExpression::toExpr(expr) ; + RsRegularExpression::Expression *exp = RsRegularExpression::LinearizedExpression::toExpr(expr) ; if(exp == NULL) return ; @@ -1820,7 +1820,7 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match) return id ; } -TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr) +TurtleRequestId p3turtle::turtleSearch(const RsRegularExpression::LinearizedExpression& expr) { // generate a new search id. diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index e5faca3bc..bfda7663e 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -239,7 +239,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config // remove the specific file search packets from the turtle router. // virtual TurtleSearchRequestId turtleSearch(const std::string& string_to_match) ; - virtual TurtleSearchRequestId turtleSearch(const LinearizedExpression& expr) ; + virtual TurtleSearchRequestId turtleSearch(const RsRegularExpression::LinearizedExpression& expr) ; // Initiates tunnel handling for the given file hash. tunnels. Launches // an exception if an error occurs during the initialization process. The diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 114ee97ef..11e1969e7 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -102,7 +102,7 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem RsTurtleRegExpSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {} RsTurtleRegExpSearchRequestItem(void *data,uint32_t size) ; - LinearizedExpression expr ; // Reg Exp in linearised mode + RsRegularExpression::LinearizedExpression expr ; // Reg Exp in linearised mode virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; } virtual void performLocalSearch(std::list&) const ; diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index 4c6d9481e..fa80c7ec9 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -774,7 +774,7 @@ void SearchDialog::initSearchResult(const QString& txt, qulonglong searchId, int ui.searchSummaryWidget->setCurrentItem(item2); } -void SearchDialog::advancedSearch(Expression* expression) +void SearchDialog::advancedSearch(RsRegularExpression::Expression* expression) { advSearchDialog->hide(); @@ -782,7 +782,7 @@ void SearchDialog::advancedSearch(Expression* expression) std::list results; // send a turtle search request - LinearizedExpression e ; + RsRegularExpression::LinearizedExpression e ; expression->linearize(e) ; TurtleRequestId req_id = rsTurtle->turtleSearch(e) ; @@ -843,8 +843,8 @@ void SearchDialog::searchKeywords(const QString& keywords) if (n < 1) return; - NameExpression exprs(ContainsAllStrings,words,true) ; - LinearizedExpression lin_exp ; + RsRegularExpression::NameExpression exprs(RsRegularExpression::ContainsAllStrings,words,true) ; + RsRegularExpression::LinearizedExpression lin_exp ; exprs.linearize(lin_exp) ; TurtleRequestId req_id ; diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h index c0682ecb0..bfc5892cc 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.h @@ -27,9 +27,10 @@ #include "mainpage.h" class AdvancedSearchDialog; -class Expression; class RSTreeWidgetItemCompareRole; +namespace RsRegularExpression { class Expression; } + #define FRIEND_SEARCH 1 #define ANONYMOUS_SEARCH 2 class SearchDialog : public MainPage @@ -99,7 +100,7 @@ private slots: void showAdvSearchDialog(bool=true); /** perform the advanced search */ - void advancedSearch(Expression*); + void advancedSearch(RsRegularExpression::Expression*); void selectSearchResults(int index = -1); void hideOrShowSearchResult(QTreeWidgetItem* resultItem, QString currentSearchId = QString(), int fileTypeIndex = -1); diff --git a/retroshare-gui/src/gui/advsearch/advancedsearchdialog.cpp b/retroshare-gui/src/gui/advsearch/advancedsearchdialog.cpp index 3d60260be..d4b629b4b 100644 --- a/retroshare-gui/src/gui/advsearch/advancedsearchdialog.cpp +++ b/retroshare-gui/src/gui/advsearch/advancedsearchdialog.cpp @@ -119,9 +119,9 @@ void AdvancedSearchDialog::prepareSearch() } -Expression * AdvancedSearchDialog::getRsExpr() +RsRegularExpression::Expression * AdvancedSearchDialog::getRsExpr() { - Expression * wholeExpression; + RsRegularExpression::Expression * wholeExpression; // process the special case: first expression wholeExpression = expressions->at(0)->getRsExpression(); @@ -131,7 +131,7 @@ Expression * AdvancedSearchDialog::getRsExpr() for (int i = 1; i < expressions->size(); ++i) { // extract the expression information and compound it with the // first expression - wholeExpression = new CompoundExpression(expressions->at(i)->getOperator(), + wholeExpression = new RsRegularExpression::CompoundExpression(expressions->at(i)->getOperator(), wholeExpression, expressions->at(i)->getRsExpression()); } diff --git a/retroshare-gui/src/gui/advsearch/advancedsearchdialog.h b/retroshare-gui/src/gui/advsearch/advancedsearchdialog.h index 296829057..02626283a 100644 --- a/retroshare-gui/src/gui/advsearch/advancedsearchdialog.h +++ b/retroshare-gui/src/gui/advsearch/advancedsearchdialog.h @@ -36,10 +36,10 @@ class AdvancedSearchDialog : public QDialog, public Ui::AdvancedSearchDialog public: AdvancedSearchDialog(QWidget * parent = 0 ); - Expression * getRsExpr(); + RsRegularExpression::Expression * getRsExpr(); QString getSearchAsString(); signals: - void search(Expression*); + void search(RsRegularExpression::Expression*); private slots: void deleteExpression(ExpressionWidget*); diff --git a/retroshare-gui/src/gui/advsearch/expressionwidget.cpp b/retroshare-gui/src/gui/advsearch/expressionwidget.cpp index 013bec182..d5e83c3fc 100644 --- a/retroshare-gui/src/gui/advsearch/expressionwidget.cpp +++ b/retroshare-gui/src/gui/advsearch/expressionwidget.cpp @@ -130,7 +130,7 @@ void ExpressionWidget::deleteExpression() emit signalDelete(this); } -LogicalOperator ExpressionWidget::getOperator() +RsRegularExpression::LogicalOperator ExpressionWidget::getOperator() { return exprOpElem->getLogicalOperator(); } @@ -145,9 +145,9 @@ static int checkedConversion(uint64_t s) return (int)s ; } -Expression* ExpressionWidget::getRsExpression() +RsRegularExpression::Expression* ExpressionWidget::getRsExpression() { - Expression * expr = NULL; + RsRegularExpression::Expression * expr = NULL; std::list wordList; uint64_t lowVal = 0; @@ -174,54 +174,54 @@ Expression* ExpressionWidget::getRsExpression() switch (searchType) { case NameSearch: - expr = new NameExpression(exprCondElem->getStringOperator(), + expr = new RsRegularExpression::NameExpression(exprCondElem->getStringOperator(), wordList, exprParamElem->ignoreCase()); break; case PathSearch: - expr = new PathExpression(exprCondElem->getStringOperator(), + expr = new RsRegularExpression::PathExpression(exprCondElem->getStringOperator(), wordList, exprParamElem->ignoreCase()); break; case ExtSearch: - expr = new ExtExpression(exprCondElem->getStringOperator(), + expr = new RsRegularExpression::ExtExpression(exprCondElem->getStringOperator(), wordList, exprParamElem->ignoreCase()); break; case HashSearch: - expr = new HashExpression(exprCondElem->getStringOperator(), + expr = new RsRegularExpression::HashExpression(exprCondElem->getStringOperator(), wordList); break; case DateSearch: if (inRangedConfig) { - expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal)); + expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal)); } else { - expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue())); + expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue())); } break; case PopSearch: if (inRangedConfig) { - expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal)); + expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal)); } else { - expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue())); + expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue())); } break; case SizeSearch: if (inRangedConfig) { if(lowVal >= (uint64_t)(1024*1024*1024) || highVal >= (uint64_t)(1024*1024*1024)) - expr = new SizeExpressionMB(exprCondElem->getRelOperator(), (int)(lowVal / (1024*1024)), (int)(highVal / (1024*1024))); + expr = new RsRegularExpression::SizeExpressionMB(exprCondElem->getRelOperator(), (int)(lowVal / (1024*1024)), (int)(highVal / (1024*1024))); else - expr = new SizeExpression(exprCondElem->getRelOperator(), lowVal, highVal); + expr = new RsRegularExpression::SizeExpression(exprCondElem->getRelOperator(), lowVal, highVal); } else { uint64_t s = exprParamElem->getIntValue() ; if(s >= (uint64_t)(1024*1024*1024)) - expr = new SizeExpressionMB(exprCondElem->getRelOperator(), (int)(s/(1024*1024))) ; + expr = new RsRegularExpression::SizeExpressionMB(exprCondElem->getRelOperator(), (int)(s/(1024*1024))) ; else - expr = new SizeExpression(exprCondElem->getRelOperator(), (int)s) ; + expr = new RsRegularExpression::SizeExpression(exprCondElem->getRelOperator(), (int)s) ; } break; }; diff --git a/retroshare-gui/src/gui/advsearch/expressionwidget.h b/retroshare-gui/src/gui/advsearch/expressionwidget.h index 21f964449..2ebc6b851 100644 --- a/retroshare-gui/src/gui/advsearch/expressionwidget.h +++ b/retroshare-gui/src/gui/advsearch/expressionwidget.h @@ -45,11 +45,11 @@ public: /** delivers the expression represented by this widget the operator to join this expression with any previous expressions is provided by the getOperator method */ - Expression* getRsExpression(); + RsRegularExpression::Expression* getRsExpression(); /** supplies the operator to be used when joining this expression to the whole query */ - LogicalOperator getOperator(); + RsRegularExpression::LogicalOperator getOperator(); QString toString(); diff --git a/retroshare-gui/src/gui/advsearch/guiexprelement.cpp b/retroshare-gui/src/gui/advsearch/guiexprelement.cpp index f3ed6debe..7cf7e0732 100644 --- a/retroshare-gui/src/gui/advsearch/guiexprelement.cpp +++ b/retroshare-gui/src/gui/advsearch/guiexprelement.cpp @@ -62,9 +62,9 @@ QStringList GuiExprElement::relOptionsList; QMap GuiExprElement::TermsIndexMap; -QMap GuiExprElement::logicalOpIndexMap; -QMap GuiExprElement::strConditionIndexMap; -QMap GuiExprElement::relConditionIndexMap; +QMap GuiExprElement::logicalOpIndexMap; +QMap GuiExprElement::strConditionIndexMap; +QMap GuiExprElement::relConditionIndexMap; QMap GuiExprElement::logicalOpStrMap; QMap GuiExprElement::termsStrMap; @@ -141,9 +141,9 @@ void GuiExprElement::initialiseOptionsLists() GuiExprElement::relOptionsList.append(RANGE); // now the maps - GuiExprElement::logicalOpIndexMap[GuiExprElement::AND_INDEX] = AndOp; - GuiExprElement::logicalOpIndexMap[GuiExprElement::OR_INDEX] = OrOp; - GuiExprElement::logicalOpIndexMap[GuiExprElement::XOR_INDEX] = XorOp; + GuiExprElement::logicalOpIndexMap[GuiExprElement::AND_INDEX] = RsRegularExpression::AndOp; + GuiExprElement::logicalOpIndexMap[GuiExprElement::OR_INDEX] = RsRegularExpression::OrOp; + GuiExprElement::logicalOpIndexMap[GuiExprElement::XOR_INDEX] = RsRegularExpression::XorOp; GuiExprElement::TermsIndexMap[GuiExprElement::NAME_INDEX] = NameSearch; GuiExprElement::TermsIndexMap[GuiExprElement::PATH_INDEX] = PathSearch; @@ -153,9 +153,9 @@ void GuiExprElement::initialiseOptionsLists() GuiExprElement::TermsIndexMap[GuiExprElement::SIZE_INDEX] = SizeSearch; GuiExprElement::TermsIndexMap[GuiExprElement::POP_INDEX] = PopSearch; - GuiExprElement::strConditionIndexMap[GuiExprElement::CONTAINS_INDEX] = ContainsAnyStrings; - GuiExprElement::strConditionIndexMap[GuiExprElement::CONTALL_INDEX] = ContainsAllStrings; - GuiExprElement::strConditionIndexMap[GuiExprElement::IS_INDEX] = EqualsString; + GuiExprElement::strConditionIndexMap[GuiExprElement::CONTAINS_INDEX] = RsRegularExpression::ContainsAnyStrings; + GuiExprElement::strConditionIndexMap[GuiExprElement::CONTALL_INDEX] = RsRegularExpression::ContainsAllStrings; + GuiExprElement::strConditionIndexMap[GuiExprElement::IS_INDEX] = RsRegularExpression::EqualsString; /* W A R N I N G !!!! the cb elements correspond to their inverse rel op counterparts in rsexpr.h due to the nature of @@ -166,12 +166,12 @@ void GuiExprElement::initialiseOptionsLists() files where the condition is greater than the file size i.e. files whose size is less than or equal to the condition Therefore we invert the mapping of rel conditions here to match the behaviour of the impl. */ - GuiExprElement::relConditionIndexMap[GuiExprElement::LT_INDEX] = GreaterEquals; - GuiExprElement::relConditionIndexMap[GuiExprElement::LTE_INDEX] = Greater; - GuiExprElement::relConditionIndexMap[GuiExprElement::EQUAL_INDEX] = Equals; - GuiExprElement::relConditionIndexMap[GuiExprElement::GTE_INDEX] = Smaller; - GuiExprElement::relConditionIndexMap[GuiExprElement::GT_INDEX] = SmallerEquals; - GuiExprElement::relConditionIndexMap[GuiExprElement::RANGE_INDEX] = InRange; + GuiExprElement::relConditionIndexMap[GuiExprElement::LT_INDEX] = RsRegularExpression::GreaterEquals; + GuiExprElement::relConditionIndexMap[GuiExprElement::LTE_INDEX] = RsRegularExpression::Greater; + GuiExprElement::relConditionIndexMap[GuiExprElement::EQUAL_INDEX] = RsRegularExpression::Equals; + GuiExprElement::relConditionIndexMap[GuiExprElement::GTE_INDEX] = RsRegularExpression::Smaller; + GuiExprElement::relConditionIndexMap[GuiExprElement::GT_INDEX] = RsRegularExpression::SmallerEquals; + GuiExprElement::relConditionIndexMap[GuiExprElement::RANGE_INDEX] = RsRegularExpression::InRange; // the string to index map GuiExprElement::termsStrMap[GuiExprElement::NAME_INDEX] = NAME; @@ -260,7 +260,7 @@ QString ExprOpElement::toString() } -LogicalOperator ExprOpElement::getLogicalOperator() +RsRegularExpression::LogicalOperator ExprOpElement::getLogicalOperator() { return GuiExprElement::logicalOpIndexMap[cb->currentIndex()]; } @@ -313,12 +313,12 @@ QString ExprConditionElement::toString() return GuiExprElement::relConditionStrMap[cb->currentIndex()]; } -RelOperator ExprConditionElement::getRelOperator() +RsRegularExpression::RelOperator ExprConditionElement::getRelOperator() { return GuiExprElement::relConditionIndexMap[cb->currentIndex()]; } -StringOperator ExprConditionElement::getStringOperator() +RsRegularExpression::StringOperator ExprConditionElement::getStringOperator() { return GuiExprElement::strConditionIndexMap[cb->currentIndex()]; } diff --git a/retroshare-gui/src/gui/advsearch/guiexprelement.h b/retroshare-gui/src/gui/advsearch/guiexprelement.h index 075eddf41..0b78f7975 100644 --- a/retroshare-gui/src/gui/advsearch/guiexprelement.h +++ b/retroshare-gui/src/gui/advsearch/guiexprelement.h @@ -114,9 +114,9 @@ protected: static QStringList relOptionsList; // provides a mapping of condition operators to RSExpr reloperators - static QMap logicalOpIndexMap; - static QMap strConditionIndexMap; - static QMap relConditionIndexMap; + static QMap logicalOpIndexMap; + static QMap strConditionIndexMap; + static QMap relConditionIndexMap; // provides a mapping of indexes to translatable strings static QMap logicalOpStrMap; @@ -134,7 +134,7 @@ class ExprOpElement : public GuiExprElement public: ExprOpElement(QWidget * parent = 0); - LogicalOperator getLogicalOperator(); + RsRegularExpression::LogicalOperator getLogicalOperator(); QString toString(); private: QComboBox * cb; @@ -148,8 +148,8 @@ class ExprTermsElement : public GuiExprElement public: ExprTermsElement(QWidget * parent = 0); int getTermsIndex(); - RelOperator getRelOperator(); - StringOperator getStringOperator(); + RsRegularExpression::RelOperator getRelOperator(); + RsRegularExpression::StringOperator getStringOperator(); void set(int i) {cb->setCurrentIndex(i);} QString toString(); @@ -167,8 +167,8 @@ class ExprConditionElement : public GuiExprElement public: ExprConditionElement(ExprSearchType, QWidget * parent = 0); - RelOperator getRelOperator(); - StringOperator getStringOperator(); + RsRegularExpression::RelOperator getRelOperator(); + RsRegularExpression::StringOperator getStringOperator(); void adjustForSearchType(ExprSearchType); void set(int i) {cb->setCurrentIndex(i);} QString toString();