mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
moved regular expression classes into a separate namespace
This commit is contained in:
parent
e9418bb5c6
commit
a2e34f9cc6
@ -173,8 +173,8 @@ void FileSearchHandler::handleCreateSearch(Request &req, Response &resp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NameExpression exprs(ContainsAllStrings,words,true) ;
|
RsRegularExpression::NameExpression exprs(RsRegularExpression::ContainsAllStrings,words,true) ;
|
||||||
LinearizedExpression lin_exp ;
|
RsRegularExpression::LinearizedExpression lin_exp ;
|
||||||
exprs.linearize(lin_exp) ;
|
exprs.linearize(lin_exp) ;
|
||||||
|
|
||||||
uint32_t search_id = RSRandom::random_u32();
|
uint32_t search_id = RSRandom::random_u32();
|
||||||
|
@ -595,7 +595,7 @@ bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list<D
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InternalFileHierarchyStorage::searchBoolExp(Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const
|
int InternalFileHierarchyStorage::searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const
|
||||||
{
|
{
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
for(std::map<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it)
|
for(std::map<RsFileHash,DirectoryStorage::EntryIndex>::const_iterator it(mFileHashes.begin());it!=mFileHashes.end();++it)
|
||||||
|
@ -140,7 +140,7 @@ public:
|
|||||||
// search. SearchHash is logarithmic. The other two are linear.
|
// search. SearchHash is logarithmic. The other two are linear.
|
||||||
|
|
||||||
bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
|
bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
|
||||||
int searchBoolExp(Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
int searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
||||||
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
||||||
|
|
||||||
bool check(std::string& error_string) const ;// checks consistency of storage.
|
bool check(std::string& error_string) const ;// checks consistency of storage.
|
||||||
|
@ -203,7 +203,7 @@ int DirectoryStorage::searchTerms(const std::list<std::string>& terms, std::list
|
|||||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||||
return mFileHierarchy->searchTerms(terms,results);
|
return mFileHierarchy->searchTerms(terms,results);
|
||||||
}
|
}
|
||||||
int DirectoryStorage::searchBoolExp(Expression * exp, std::list<EntryIndex> &results) const
|
int DirectoryStorage::searchBoolExp(RsRegularExpression::Expression * exp, std::list<EntryIndex> &results) const
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||||
return mFileHierarchy->searchBoolExp(exp,results);
|
return mFileHierarchy->searchBoolExp(exp,results);
|
||||||
|
@ -50,7 +50,7 @@ class DirectoryStorage
|
|||||||
void save() const ;
|
void save() const ;
|
||||||
|
|
||||||
virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const ;
|
virtual int searchTerms(const std::list<std::string>& terms, std::list<EntryIndex> &results) const ;
|
||||||
virtual int searchBoolExp(Expression * exp, std::list<EntryIndex> &results) const ;
|
virtual int searchBoolExp(RsRegularExpression::Expression * exp, std::list<EntryIndex> &results) const ;
|
||||||
virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const ;
|
virtual int searchHash(const RsFileHash& hash, std::list<EntryIndex> &results) const ;
|
||||||
|
|
||||||
bool getDirUpdateTS(EntryIndex index,time_t& recurs_max_modf_TS,time_t& local_update_TS) ;
|
bool getDirUpdateTS(EntryIndex index,time_t& recurs_max_modf_TS,time_t& local_update_TS) ;
|
||||||
|
@ -814,7 +814,7 @@ int p3FileDatabase::SearchKeywords(const std::list<std::string>& keywords, std::
|
|||||||
|
|
||||||
return filterResults(firesults,results,flags,client_peer_id) ;
|
return filterResults(firesults,results,flags,client_peer_id) ;
|
||||||
}
|
}
|
||||||
int p3FileDatabase::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const
|
int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mFLSMtx) ;
|
RS_STACK_MUTEX(mFLSMtx) ;
|
||||||
|
|
||||||
|
@ -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<std::string>& parent_groups) const;
|
virtual bool findLocalFile(const RsFileHash& hash,FileSearchFlags flags,const RsPeerId& peer_id, std::string &fullpath, uint64_t &size,FileStorageFlags& storage_flags,std::list<std::string>& parent_groups) const;
|
||||||
|
|
||||||
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
|
virtual int SearchKeywords(const std::list<std::string>& keywords, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) ;
|
||||||
virtual int SearchBoolExp(Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
virtual int SearchBoolExp(RsRegularExpression::Expression *exp, std::list<DirDetails>& results,FileSearchFlags flags,const RsPeerId& peer_id) const ;
|
||||||
|
|
||||||
// ftSearch
|
// ftSearch
|
||||||
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "dbase/findex.h"
|
#include "dbase/findex.h"
|
||||||
#include "retroshare/rsexpr.h"
|
#include "retroshare/rsexpr.h"
|
||||||
|
#include "retroshare/rstypes.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
@ -34,33 +35,35 @@ eval functions of relational expressions.
|
|||||||
|
|
||||||
******************************************************************************************/
|
******************************************************************************************/
|
||||||
|
|
||||||
|
namespace RsRegularExpression
|
||||||
|
{
|
||||||
template<>
|
template<>
|
||||||
void RelExpression<int>::linearize(LinearizedExpression& e) const
|
void RelExpression<int>::linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._ints.push_back(Op) ;
|
e._ints.push_back(Op) ;
|
||||||
e._ints.push_back(LowerValue) ;
|
e._ints.push_back(LowerValue) ;
|
||||||
e._ints.push_back(HigherValue) ;
|
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){
|
bool PathExpression::eval(const ExpFileEntry& file)
|
||||||
std::string path;
|
{
|
||||||
/*Construct the path of this file*/
|
return evalStr(file.file_parent_path());
|
||||||
DirEntry * curr = file->parent;
|
|
||||||
while ( curr != NULL ){
|
|
||||||
path = curr->name+"/"+ path;
|
|
||||||
curr = curr->parent;
|
|
||||||
}
|
|
||||||
return evalStr(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExtExpression::eval(FileEntry *file){
|
bool ExtExpression::eval(const ExpFileEntry& file)
|
||||||
std::string ext;
|
{
|
||||||
/*Get the part of the string after the last instance of . in the filename */
|
std::string ext;
|
||||||
size_t index = file->name.find_last_of('.');
|
/*Get the part of the string after the last instance of . in the filename */
|
||||||
if (index != std::string::npos) {
|
size_t index = file.file_name().find_last_of('.');
|
||||||
ext = file->name.substr(index+1);
|
if (index != std::string::npos) {
|
||||||
if (ext != "" ){
|
ext = file.file_name().substr(index+1);
|
||||||
return evalStr(ext);
|
if (ext != "" ){
|
||||||
}
|
return evalStr(ext);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HashExpression::eval(FileEntry *file){
|
bool HashExpression::eval(const ExpFileEntry& file){
|
||||||
return evalStr(file->hash.toStdString());
|
return evalStr(file.file_hash().toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Check whether two strings are 'equal' to each other*/
|
/*Check whether two strings are 'equal' to each other*/
|
||||||
static bool StrEquals(const std::string & str1, const std::string & str2,
|
static bool StrEquals(const std::string & str1, const std::string & str2,
|
||||||
bool IgnoreCase ){
|
bool IgnoreCase ){
|
||||||
if ( str1.size() != str2.size() ){
|
if ( str1.size() != str2.size() ){
|
||||||
return false;
|
return false;
|
||||||
} else if (IgnoreCase) {
|
} else if (IgnoreCase) {
|
||||||
std::equal( str1.begin(), str1.end(),
|
std::equal( str1.begin(), str1.end(),
|
||||||
str2.begin(), CompareCharIC() );
|
str2.begin(), CompareCharIC() );
|
||||||
}
|
}
|
||||||
return std::equal( str1.begin(), str1.end(),
|
return std::equal( str1.begin(), str1.end(),
|
||||||
str2.begin());
|
str2.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Check whether one string contains the other*/
|
/*Check whether one string contains the other*/
|
||||||
static bool StrContains( const std::string & str1, const std::string & str2,
|
static bool StrContains( const std::string & str1, const std::string & str2,
|
||||||
bool IgnoreCase){
|
bool IgnoreCase){
|
||||||
|
|
||||||
std::string::const_iterator iter ;
|
std::string::const_iterator iter ;
|
||||||
if (IgnoreCase) {
|
if (IgnoreCase) {
|
||||||
iter = std::search( str1.begin(), str1.end(),
|
iter = std::search( str1.begin(), str1.end(),
|
||||||
str2.begin(), str2.end(), CompareCharIC() );
|
str2.begin(), str2.end(), CompareCharIC() );
|
||||||
} else {
|
} else {
|
||||||
iter = std::search( str1.begin(), str1.end(),
|
iter = std::search( str1.begin(), str1.end(),
|
||||||
str2.begin(), str2.end());
|
str2.begin(), str2.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( iter != str1.end() );
|
return ( iter != str1.end() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool StringExpression :: evalStr ( const std::string &str ){
|
bool StringExpression :: evalStr ( const std::string &str ){
|
||||||
std::list<std::string>::iterator iter;
|
std::list<std::string>::iterator iter;
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
case ContainsAllStrings:
|
case ContainsAllStrings:
|
||||||
for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
|
for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
|
||||||
if ( StrContains (str, *iter, IgnoreCase) == false ){
|
if ( StrContains (str, *iter, IgnoreCase) == false ){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case ContainsAnyStrings:
|
case ContainsAnyStrings:
|
||||||
for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
|
for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
|
||||||
if ( StrContains (str,*iter, IgnoreCase) == true ) {
|
if ( StrContains (str,*iter, IgnoreCase) == true ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EqualsString:
|
case EqualsString:
|
||||||
for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
|
for ( iter = terms.begin(); iter != terms.end(); ++iter ) {
|
||||||
if ( StrEquals (str,*iter, IgnoreCase) == true ) {
|
if ( StrEquals (str,*iter, IgnoreCase) == true ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@ -168,122 +166,123 @@ bool StringExpression :: evalStr ( const std::string &str ){
|
|||||||
|
|
||||||
void CompoundExpression::linearize(LinearizedExpression& e) const
|
void CompoundExpression::linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_COMP) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_COMP) ;
|
||||||
e._ints.push_back(Op) ;
|
e._ints.push_back(Op) ;
|
||||||
|
|
||||||
Lexp->linearize(e) ;
|
Lexp->linearize(e) ;
|
||||||
Rexp->linearize(e) ;
|
Rexp->linearize(e) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringExpression::linearize(LinearizedExpression& e) const
|
void StringExpression::linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._ints.push_back(Op) ;
|
e._ints.push_back(Op) ;
|
||||||
e._ints.push_back(IgnoreCase) ;
|
e._ints.push_back(IgnoreCase) ;
|
||||||
e._ints.push_back(terms.size()) ;
|
e._ints.push_back(terms.size()) ;
|
||||||
|
|
||||||
for(std::list<std::string>::const_iterator it(terms.begin());it!=terms.end();++it)
|
for(std::list<std::string>::const_iterator it(terms.begin());it!=terms.end();++it)
|
||||||
e._strings.push_back(*it) ;
|
e._strings.push_back(*it) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression *LinearizedExpression::toExpr(const LinearizedExpression& e)
|
Expression *LinearizedExpression::toExpr(const LinearizedExpression& e)
|
||||||
{
|
{
|
||||||
int i=0,j=0,k=0 ;
|
int i=0,j=0,k=0 ;
|
||||||
return toExpr(e,i,j,k) ;
|
return toExpr(e,i,j,k) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinearizedExpression::readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list<std::string>& strings,bool& b,StringOperator& op)
|
void LinearizedExpression::readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list<std::string>& strings,bool& b,StringOperator& op)
|
||||||
{
|
{
|
||||||
op = static_cast<StringOperator>(e._ints[n_ints++]) ;
|
op = static_cast<StringOperator>(e._ints[n_ints++]) ;
|
||||||
b = e._ints[n_ints++] ;
|
b = e._ints[n_ints++] ;
|
||||||
int n = e._ints[n_ints++] ;
|
int n = e._ints[n_ints++] ;
|
||||||
|
|
||||||
strings.clear() ;
|
strings.clear() ;
|
||||||
for(int i=0;i<n;++i)
|
for(int i=0;i<n;++i)
|
||||||
strings.push_back(e._strings[n_strings++]) ;
|
strings.push_back(e._strings[n_strings++]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression *LinearizedExpression::toExpr(const LinearizedExpression& e,int& n_tok,int& n_ints,int& n_strings)
|
Expression *LinearizedExpression::toExpr(const LinearizedExpression& e,int& n_tok,int& n_ints,int& n_strings)
|
||||||
{
|
{
|
||||||
LinearizedExpression::token tok = static_cast<LinearizedExpression::token>(e._tokens[n_tok++]) ;
|
LinearizedExpression::token tok = static_cast<LinearizedExpression::token>(e._tokens[n_tok++]) ;
|
||||||
|
|
||||||
switch(tok)
|
switch(tok)
|
||||||
{
|
{
|
||||||
case EXPR_DATE: {
|
case EXPR_DATE: {
|
||||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||||
int lv = e._ints[n_ints++] ;
|
int lv = e._ints[n_ints++] ;
|
||||||
int hv = 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: {
|
case EXPR_POP: {
|
||||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||||
int lv = e._ints[n_ints++] ;
|
int lv = e._ints[n_ints++] ;
|
||||||
int hv = e._ints[n_ints++] ;
|
int hv = e._ints[n_ints++] ;
|
||||||
|
|
||||||
return new PopExpression(op,lv,hv) ;
|
return new PopExpression(op,lv,hv) ;
|
||||||
}
|
}
|
||||||
case EXPR_SIZE: {
|
case EXPR_SIZE: {
|
||||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||||
int lv = e._ints[n_ints++] ;
|
int lv = e._ints[n_ints++] ;
|
||||||
int hv = e._ints[n_ints++] ;
|
int hv = e._ints[n_ints++] ;
|
||||||
|
|
||||||
return new SizeExpression(op,lv,hv) ;
|
return new SizeExpression(op,lv,hv) ;
|
||||||
}
|
}
|
||||||
case EXPR_HASH: {
|
case EXPR_HASH: {
|
||||||
std::list<std::string> strings ;
|
std::list<std::string> strings ;
|
||||||
StringOperator op ;
|
StringOperator op ;
|
||||||
bool b ;
|
bool b ;
|
||||||
|
|
||||||
readStringExpr(e,n_ints,n_strings,strings,b,op) ;
|
readStringExpr(e,n_ints,n_strings,strings,b,op) ;
|
||||||
return new HashExpression(op,strings) ;
|
return new HashExpression(op,strings) ;
|
||||||
}
|
}
|
||||||
case EXPR_NAME: {
|
case EXPR_NAME: {
|
||||||
std::list<std::string> strings ;
|
std::list<std::string> strings ;
|
||||||
StringOperator op ;
|
StringOperator op ;
|
||||||
bool b ;
|
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) ;
|
return new NameExpression(op,strings,b) ;
|
||||||
}
|
}
|
||||||
case EXPR_PATH: {
|
case EXPR_PATH: {
|
||||||
std::list<std::string> strings ;
|
std::list<std::string> strings ;
|
||||||
StringOperator op ;
|
StringOperator op ;
|
||||||
bool b ;
|
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) ;
|
return new ExtExpression(op,strings,b) ;
|
||||||
}
|
}
|
||||||
case EXPR_EXT: {
|
case EXPR_EXT: {
|
||||||
std::list<std::string> strings ;
|
std::list<std::string> strings ;
|
||||||
StringOperator op ;
|
StringOperator op ;
|
||||||
bool b ;
|
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) ;
|
return new ExtExpression(op,strings,b) ;
|
||||||
}
|
}
|
||||||
case EXPR_COMP: {
|
case EXPR_COMP: {
|
||||||
LogicalOperator op = static_cast<LogicalOperator>(e._ints[n_ints++]) ;
|
LogicalOperator op = static_cast<LogicalOperator>(e._ints[n_ints++]) ;
|
||||||
|
|
||||||
Expression *e1 = 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) ;
|
Expression *e2 = toExpr(e,n_tok,n_ints,n_strings) ;
|
||||||
|
|
||||||
return new CompoundExpression(op,e1,e2) ;
|
return new CompoundExpression(op,e1,e2) ;
|
||||||
}
|
}
|
||||||
case EXPR_SIZE_MB: {
|
case EXPR_SIZE_MB: {
|
||||||
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
RelOperator op = static_cast<RelOperator>(e._ints[n_ints++]) ;
|
||||||
int lv = e._ints[n_ints++] ;
|
int lv = e._ints[n_ints++] ;
|
||||||
int hv = e._ints[n_ints++] ;
|
int hv = e._ints[n_ints++] ;
|
||||||
|
|
||||||
return new SizeExpressionMB(op,lv,hv) ;
|
return new SizeExpressionMB(op,lv,hv) ;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
std::cerr << "No expression match the current value " << tok << std::endl ;
|
std::cerr << "No expression match the current value " << tok << std::endl ;
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -569,11 +569,11 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetai
|
|||||||
return mFileDatabase->SearchKeywords(keywords, results,flags,peer_id);
|
return mFileDatabase->SearchKeywords(keywords, results,flags,peer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags)
|
int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags)
|
||||||
{
|
{
|
||||||
return mFileDatabase->SearchBoolExp(exp, results,flags,RsPeerId());
|
return mFileDatabase->SearchBoolExp(exp, results,flags,RsPeerId());
|
||||||
}
|
}
|
||||||
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id)
|
||||||
{
|
{
|
||||||
return mFileDatabase->SearchBoolExp(exp,results,flags,peer_id) ;
|
return mFileDatabase->SearchBoolExp(exp,results,flags,peer_id) ;
|
||||||
}
|
}
|
||||||
|
@ -184,8 +184,8 @@ public:
|
|||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags);
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id);
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions
|
* Utility Functions
|
||||||
|
@ -59,6 +59,7 @@ file_lists {
|
|||||||
file_sharing/rsfilelistitems.cc
|
file_sharing/rsfilelistitems.cc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dsdv {
|
dsdv {
|
||||||
DEFINES *= SERVICES_DSDV
|
DEFINES *= SERVICES_DSDV
|
||||||
HEADERS += services/p3dsdv.h \
|
HEADERS += services/p3dsdv.h \
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#ifndef RS_EXPRESSIONS_H
|
|
||||||
#define RS_EXPRESSIONS_H
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* rs-core/src/rsiface: rsexpr.h
|
* rs-core/src/rsiface: rsexpr.h
|
||||||
*
|
*
|
||||||
@ -26,38 +23,41 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "retroshare/rstypes.h"
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
Enumerations defining the Operators usable in the Boolean search expressions
|
Enumerations defining the Operators usable in the Boolean search expressions
|
||||||
******************************************************************************************/
|
******************************************************************************************/
|
||||||
|
|
||||||
|
namespace RsRegularExpression
|
||||||
|
{
|
||||||
enum LogicalOperator{
|
enum LogicalOperator{
|
||||||
AndOp=0, /* exp AND exp */
|
AndOp=0, /* exp AND exp */
|
||||||
OrOp=1, /* exp OR exp */
|
OrOp=1, /* exp OR exp */
|
||||||
XorOp=2 /* exp XOR exp */
|
XorOp=2 /* exp XOR exp */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*Operators for String Queries*/
|
/* Operators for String Queries */
|
||||||
enum StringOperator{
|
enum StringOperator{
|
||||||
ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */
|
ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */
|
||||||
ContainsAllStrings = 1, /* same as above except that it contains ALL of the strings */
|
ContainsAllStrings = 1, /* same as above except that it contains ALL of the strings */
|
||||||
EqualsString = 2 /* exactly equal*/
|
EqualsString = 2 /* exactly equal*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Relational operators ( >, <, >=, <=, == and InRange )*/
|
/* Comparison operators ( >, <, >=, <=, == and InRange ) */
|
||||||
enum RelOperator{
|
enum RelOperator{
|
||||||
Equals = 0,
|
Equals = 0,
|
||||||
GreaterEquals = 1,
|
GreaterEquals = 1,
|
||||||
Greater = 2,
|
Greater = 2,
|
||||||
SmallerEquals = 3,
|
SmallerEquals = 3,
|
||||||
Smaller = 4,
|
Smaller = 4,
|
||||||
InRange = 5 /* lower limit <= value <= upper limit*/
|
InRange = 5 /* lower limit <= value <= upper limit*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************************************************************************************
|
/********************************************************************************************
|
||||||
@ -69,26 +69,26 @@ class Expression ;
|
|||||||
|
|
||||||
class LinearizedExpression
|
class LinearizedExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<uint8_t> _tokens ;
|
std::vector<uint8_t> _tokens ;
|
||||||
std::vector<uint32_t> _ints ;
|
std::vector<uint32_t> _ints ;
|
||||||
std::vector<std::string> _strings ;
|
std::vector<std::string> _strings ;
|
||||||
|
|
||||||
typedef enum { EXPR_DATE= 0,
|
typedef enum { EXPR_DATE = 0,
|
||||||
EXPR_POP = 1,
|
EXPR_POP = 1,
|
||||||
EXPR_SIZE= 2,
|
EXPR_SIZE = 2,
|
||||||
EXPR_HASH= 3,
|
EXPR_HASH = 3,
|
||||||
EXPR_NAME= 4,
|
EXPR_NAME = 4,
|
||||||
EXPR_PATH= 5,
|
EXPR_PATH = 5,
|
||||||
EXPR_EXT = 6,
|
EXPR_EXT = 6,
|
||||||
EXPR_COMP= 7,
|
EXPR_COMP = 7,
|
||||||
EXPR_SIZE_MB=8 } token ;
|
EXPR_SIZE_MB = 8 } token ;
|
||||||
|
|
||||||
static Expression *toExpr(const LinearizedExpression& e) ;
|
static Expression *toExpr(const LinearizedExpression& e) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Expression *toExpr(const LinearizedExpression& e,int&,int&,int&) ;
|
static Expression *toExpr(const LinearizedExpression& e,int&,int&,int&) ;
|
||||||
static void readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list<std::string>& strings,bool& b,StringOperator& op) ;
|
static void readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list<std::string>& strings,bool& b,StringOperator& op) ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -96,110 +96,122 @@ class LinearizedExpression
|
|||||||
Boolean Search Expression
|
Boolean Search Expression
|
||||||
classes:
|
classes:
|
||||||
|
|
||||||
Expression: The base class of all expression typest
|
Expression: The base class of all expression typest
|
||||||
CompoundExpression: The expression which uses a logical operator to combine
|
CompoundExpression: The expression which uses a logical operator to combine
|
||||||
the results of two expressions
|
the results of two expressions
|
||||||
StringExpression: An expression which uses some sort of string comparison.
|
StringExpression: An expression which uses some sort of string comparison.
|
||||||
RelExpression: A Relational Expression where > < >= <= == make sense.
|
RelExpression: A Relational Expression where > < >= <= == make sense.
|
||||||
e.g. size date etc
|
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
|
class Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool eval (FileEntry *file) = 0;
|
virtual bool eval (const ExpFileEntry& file) = 0;
|
||||||
virtual ~Expression() {};
|
virtual ~Expression() {};
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const = 0 ;
|
virtual void linearize(LinearizedExpression& e) const = 0 ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CompoundExpression : public Expression
|
class CompoundExpression : public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2)
|
CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2)
|
||||||
: Lexp(exp1), Rexp(exp2), Op(op){ }
|
: Lexp(exp1), Rexp(exp2), Op(op){ }
|
||||||
|
|
||||||
bool eval (FileEntry *file) {
|
bool eval (const ExpFileEntry& file) {
|
||||||
if (Lexp == NULL or Rexp == NULL) {
|
if (Lexp == NULL or Rexp == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (Op){
|
switch (Op){
|
||||||
case AndOp:
|
case AndOp:
|
||||||
return Lexp->eval(file) && Rexp->eval(file);
|
return Lexp->eval(file) && Rexp->eval(file);
|
||||||
case OrOp:
|
case OrOp:
|
||||||
return Lexp->eval(file) || Rexp->eval(file);
|
return Lexp->eval(file) || Rexp->eval(file);
|
||||||
case XorOp:
|
case XorOp:
|
||||||
return Lexp->eval(file) ^ Rexp->eval(file);
|
return Lexp->eval(file) ^ Rexp->eval(file);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual ~CompoundExpression(){
|
virtual ~CompoundExpression(){
|
||||||
delete Lexp;
|
delete Lexp;
|
||||||
delete Rexp;
|
delete Rexp;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const ;
|
virtual void linearize(LinearizedExpression& e) const ;
|
||||||
private:
|
private:
|
||||||
Expression *Lexp;
|
Expression *Lexp;
|
||||||
Expression *Rexp;
|
Expression *Rexp;
|
||||||
enum LogicalOperator Op;
|
enum LogicalOperator Op;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StringExpression: public Expression
|
class StringExpression: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StringExpression(enum StringOperator op, std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
|
StringExpression(enum StringOperator op, std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const ;
|
virtual void linearize(LinearizedExpression& e) const ;
|
||||||
protected:
|
protected:
|
||||||
bool evalStr(const std::string &str);
|
bool evalStr(const std::string &str);
|
||||||
|
|
||||||
enum StringOperator Op;
|
enum StringOperator Op;
|
||||||
std::list<std::string> terms;
|
std::list<std::string> terms;
|
||||||
bool IgnoreCase;
|
bool IgnoreCase;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class RelExpression: public Expression
|
class RelExpression: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {}
|
RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {}
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const ;
|
virtual void linearize(LinearizedExpression& e) const ;
|
||||||
protected:
|
protected:
|
||||||
bool evalRel(T val);
|
bool evalRel(T val);
|
||||||
|
|
||||||
enum RelOperator Op;
|
enum RelOperator Op;
|
||||||
T LowerValue;
|
T LowerValue;
|
||||||
T HigherValue;
|
T HigherValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> void RelExpression<int>::linearize(LinearizedExpression& e) const ;
|
template<> void RelExpression<int>::linearize(LinearizedExpression& e) const ;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
bool RelExpression<T>::evalRel(T val) {
|
bool RelExpression<T>::evalRel(T val) {
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
case Equals:
|
case Equals:
|
||||||
return LowerValue == val;
|
return LowerValue == val;
|
||||||
case GreaterEquals:
|
case GreaterEquals:
|
||||||
return LowerValue >= val;
|
return LowerValue >= val;
|
||||||
case Greater:
|
case Greater:
|
||||||
return LowerValue > val;
|
return LowerValue > val;
|
||||||
case SmallerEquals:
|
case SmallerEquals:
|
||||||
return LowerValue <= val;
|
return LowerValue <= val;
|
||||||
case Smaller:
|
case Smaller:
|
||||||
return LowerValue < val;
|
return LowerValue < val;
|
||||||
case InRange:
|
case InRange:
|
||||||
return (LowerValue <= val) && (val <= HigherValue);
|
return (LowerValue <= val) && (val <= HigherValue);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -212,12 +224,12 @@ Binary Predicate for Case Insensitive search
|
|||||||
*Factor locales in the comparison
|
*Factor locales in the comparison
|
||||||
*/
|
*/
|
||||||
struct CompareCharIC :
|
struct CompareCharIC :
|
||||||
public std::binary_function< char , char , bool> {
|
public std::binary_function< char , char , bool> {
|
||||||
|
|
||||||
bool operator () ( char ch1 , char ch2 ) const {
|
bool operator () ( char ch1 , char ch2 ) const {
|
||||||
return tolower( static_cast < unsigned char > (ch1) )
|
return tolower( static_cast < unsigned char > (ch1) )
|
||||||
== tolower( static_cast < unsigned char > (ch2) );
|
== tolower( static_cast < unsigned char > (ch2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -228,55 +240,55 @@ Some implementations of StringExpressions.
|
|||||||
|
|
||||||
class NameExpression: public StringExpression
|
class NameExpression: public StringExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NameExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
NameExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
||||||
StringExpression(op,t,ic) {}
|
StringExpression(op,t,ic) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_NAME) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_NAME) ;
|
||||||
StringExpression::linearize(e) ;
|
StringExpression::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PathExpression: public StringExpression {
|
class PathExpression: public StringExpression {
|
||||||
public:
|
public:
|
||||||
PathExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
PathExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
||||||
StringExpression(op,t,ic) {}
|
StringExpression(op,t,ic) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_PATH) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_PATH) ;
|
||||||
StringExpression::linearize(e) ;
|
StringExpression::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExtExpression: public StringExpression {
|
class ExtExpression: public StringExpression {
|
||||||
public:
|
public:
|
||||||
ExtExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
ExtExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
||||||
StringExpression(op,t,ic) {}
|
StringExpression(op,t,ic) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_EXT) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_EXT) ;
|
||||||
StringExpression::linearize(e) ;
|
StringExpression::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class HashExpression: public StringExpression {
|
class HashExpression: public StringExpression {
|
||||||
public:
|
public:
|
||||||
HashExpression(enum StringOperator op, std::list<std::string> &t):
|
HashExpression(enum StringOperator op, std::list<std::string> &t):
|
||||||
StringExpression(op,t, true) {}
|
StringExpression(op,t, true) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_HASH) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_HASH) ;
|
||||||
StringExpression::linearize(e) ;
|
StringExpression::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
@ -286,62 +298,62 @@ Some implementations of Relational Expressions.
|
|||||||
|
|
||||||
class DateExpression: public RelExpression<int>
|
class DateExpression: public RelExpression<int>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DateExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
DateExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||||
DateExpression(enum RelOperator op, int lv, int hv):
|
DateExpression(enum RelOperator op, int lv, int hv):
|
||||||
RelExpression<int>(op,lv,hv) {}
|
RelExpression<int>(op,lv,hv) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_DATE) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_DATE) ;
|
||||||
RelExpression<int>::linearize(e) ;
|
RelExpression<int>::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SizeExpression: public RelExpression<int>
|
class SizeExpression: public RelExpression<int>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SizeExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
SizeExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||||
SizeExpression(enum RelOperator op, int lv, int hv):
|
SizeExpression(enum RelOperator op, int lv, int hv):
|
||||||
RelExpression<int>(op,lv,hv) {}
|
RelExpression<int>(op,lv,hv) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ;
|
||||||
RelExpression<int>::linearize(e) ;
|
RelExpression<int>::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SizeExpressionMB: public RelExpression<int>
|
class SizeExpressionMB: public RelExpression<int>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SizeExpressionMB(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
SizeExpressionMB(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||||
SizeExpressionMB(enum RelOperator op, int lv, int hv):
|
SizeExpressionMB(enum RelOperator op, int lv, int hv):
|
||||||
RelExpression<int>(op,lv,hv) {}
|
RelExpression<int>(op,lv,hv) {}
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ;
|
||||||
RelExpression<int>::linearize(e) ;
|
RelExpression<int>::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class PopExpression: public RelExpression<int>
|
class PopExpression: public RelExpression<int>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PopExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
PopExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||||
PopExpression(enum RelOperator op, int lv, int hv): RelExpression<int>(op,lv,hv) {}
|
PopExpression(enum RelOperator op, int lv, int hv): RelExpression<int>(op,lv,hv) {}
|
||||||
PopExpression(const LinearizedExpression& e) ;
|
PopExpression(const LinearizedExpression& e) ;
|
||||||
bool eval(FileEntry *file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_POP) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_POP) ;
|
||||||
RelExpression<int>::linearize(e) ;
|
RelExpression<int>::linearize(e) ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* RS_EXPRESSIONS_H */
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
class RsFiles;
|
class RsFiles;
|
||||||
extern RsFiles *rsFiles;
|
extern RsFiles *rsFiles;
|
||||||
|
|
||||||
class Expression;
|
namespace RsRegularExpression { class Expression; }
|
||||||
class CacheStrapper ;
|
class CacheStrapper ;
|
||||||
class CacheTransfer;
|
class CacheTransfer;
|
||||||
|
|
||||||
@ -190,8 +190,8 @@ class RsFiles
|
|||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
|
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions.
|
* Utility Functions.
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include "retroshare/rstypes.h"
|
#include "retroshare/rstypes.h"
|
||||||
|
|
||||||
class LinearizedExpression ;
|
namespace RsRegularExpression { class LinearizedExpression ; }
|
||||||
class RsTurtleClientService ;
|
class RsTurtleClientService ;
|
||||||
|
|
||||||
class RsTurtle;
|
class RsTurtle;
|
||||||
@ -102,7 +102,7 @@ class RsTurtle
|
|||||||
// as they come back.
|
// as they come back.
|
||||||
//
|
//
|
||||||
virtual TurtleRequestId turtleSearch(const std::string& match_string) = 0 ;
|
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
|
// Initiates tunnel handling for the given file hash. tunnels. Launches
|
||||||
// an exception if an error occurs during the initialization process. The
|
// an exception if an error occurs during the initialization process. The
|
||||||
|
@ -1763,7 +1763,7 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
|||||||
std::list<DirDetails> initialResults;
|
std::list<DirDetails> initialResults;
|
||||||
|
|
||||||
// to do: split search string into words.
|
// to do: split search string into words.
|
||||||
Expression *exp = LinearizedExpression::toExpr(expr) ;
|
RsRegularExpression::Expression *exp = RsRegularExpression::LinearizedExpression::toExpr(expr) ;
|
||||||
|
|
||||||
if(exp == NULL)
|
if(exp == NULL)
|
||||||
return ;
|
return ;
|
||||||
@ -1820,7 +1820,7 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
|||||||
|
|
||||||
return id ;
|
return id ;
|
||||||
}
|
}
|
||||||
TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
TurtleRequestId p3turtle::turtleSearch(const RsRegularExpression::LinearizedExpression& expr)
|
||||||
{
|
{
|
||||||
// generate a new search id.
|
// generate a new search id.
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||||||
// remove the specific file search packets from the turtle router.
|
// remove the specific file search packets from the turtle router.
|
||||||
//
|
//
|
||||||
virtual TurtleSearchRequestId turtleSearch(const std::string& string_to_match) ;
|
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
|
// Initiates tunnel handling for the given file hash. tunnels. Launches
|
||||||
// an exception if an error occurs during the initialization process. The
|
// an exception if an error occurs during the initialization process. The
|
||||||
|
@ -102,7 +102,7 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
|
|||||||
RsTurtleRegExpSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {}
|
RsTurtleRegExpSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {}
|
||||||
RsTurtleRegExpSearchRequestItem(void *data,uint32_t size) ;
|
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 RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; }
|
||||||
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const ;
|
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const ;
|
||||||
|
@ -774,7 +774,7 @@ void SearchDialog::initSearchResult(const QString& txt, qulonglong searchId, int
|
|||||||
ui.searchSummaryWidget->setCurrentItem(item2);
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchDialog::advancedSearch(Expression* expression)
|
void SearchDialog::advancedSearch(RsRegularExpression::Expression* expression)
|
||||||
{
|
{
|
||||||
advSearchDialog->hide();
|
advSearchDialog->hide();
|
||||||
|
|
||||||
@ -782,7 +782,7 @@ void SearchDialog::advancedSearch(Expression* expression)
|
|||||||
std::list<DirDetails> results;
|
std::list<DirDetails> results;
|
||||||
|
|
||||||
// send a turtle search request
|
// send a turtle search request
|
||||||
LinearizedExpression e ;
|
RsRegularExpression::LinearizedExpression e ;
|
||||||
expression->linearize(e) ;
|
expression->linearize(e) ;
|
||||||
|
|
||||||
TurtleRequestId req_id = rsTurtle->turtleSearch(e) ;
|
TurtleRequestId req_id = rsTurtle->turtleSearch(e) ;
|
||||||
@ -843,8 +843,8 @@ void SearchDialog::searchKeywords(const QString& keywords)
|
|||||||
if (n < 1)
|
if (n < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NameExpression exprs(ContainsAllStrings,words,true) ;
|
RsRegularExpression::NameExpression exprs(RsRegularExpression::ContainsAllStrings,words,true) ;
|
||||||
LinearizedExpression lin_exp ;
|
RsRegularExpression::LinearizedExpression lin_exp ;
|
||||||
exprs.linearize(lin_exp) ;
|
exprs.linearize(lin_exp) ;
|
||||||
|
|
||||||
TurtleRequestId req_id ;
|
TurtleRequestId req_id ;
|
||||||
|
@ -27,9 +27,10 @@
|
|||||||
#include "mainpage.h"
|
#include "mainpage.h"
|
||||||
|
|
||||||
class AdvancedSearchDialog;
|
class AdvancedSearchDialog;
|
||||||
class Expression;
|
|
||||||
class RSTreeWidgetItemCompareRole;
|
class RSTreeWidgetItemCompareRole;
|
||||||
|
|
||||||
|
namespace RsRegularExpression { class Expression; }
|
||||||
|
|
||||||
#define FRIEND_SEARCH 1
|
#define FRIEND_SEARCH 1
|
||||||
#define ANONYMOUS_SEARCH 2
|
#define ANONYMOUS_SEARCH 2
|
||||||
class SearchDialog : public MainPage
|
class SearchDialog : public MainPage
|
||||||
@ -99,7 +100,7 @@ private slots:
|
|||||||
void showAdvSearchDialog(bool=true);
|
void showAdvSearchDialog(bool=true);
|
||||||
|
|
||||||
/** perform the advanced search */
|
/** perform the advanced search */
|
||||||
void advancedSearch(Expression*);
|
void advancedSearch(RsRegularExpression::Expression*);
|
||||||
|
|
||||||
void selectSearchResults(int index = -1);
|
void selectSearchResults(int index = -1);
|
||||||
void hideOrShowSearchResult(QTreeWidgetItem* resultItem, QString currentSearchId = QString(), int fileTypeIndex = -1);
|
void hideOrShowSearchResult(QTreeWidgetItem* resultItem, QString currentSearchId = QString(), int fileTypeIndex = -1);
|
||||||
|
@ -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
|
// process the special case: first expression
|
||||||
wholeExpression = expressions->at(0)->getRsExpression();
|
wholeExpression = expressions->at(0)->getRsExpression();
|
||||||
@ -131,7 +131,7 @@ Expression * AdvancedSearchDialog::getRsExpr()
|
|||||||
for (int i = 1; i < expressions->size(); ++i) {
|
for (int i = 1; i < expressions->size(); ++i) {
|
||||||
// extract the expression information and compound it with the
|
// extract the expression information and compound it with the
|
||||||
// first expression
|
// first expression
|
||||||
wholeExpression = new CompoundExpression(expressions->at(i)->getOperator(),
|
wholeExpression = new RsRegularExpression::CompoundExpression(expressions->at(i)->getOperator(),
|
||||||
wholeExpression,
|
wholeExpression,
|
||||||
expressions->at(i)->getRsExpression());
|
expressions->at(i)->getRsExpression());
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,10 @@ class AdvancedSearchDialog : public QDialog, public Ui::AdvancedSearchDialog
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
AdvancedSearchDialog(QWidget * parent = 0 );
|
AdvancedSearchDialog(QWidget * parent = 0 );
|
||||||
Expression * getRsExpr();
|
RsRegularExpression::Expression * getRsExpr();
|
||||||
QString getSearchAsString();
|
QString getSearchAsString();
|
||||||
signals:
|
signals:
|
||||||
void search(Expression*);
|
void search(RsRegularExpression::Expression*);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void deleteExpression(ExpressionWidget*);
|
void deleteExpression(ExpressionWidget*);
|
||||||
|
@ -130,7 +130,7 @@ void ExpressionWidget::deleteExpression()
|
|||||||
emit signalDelete(this);
|
emit signalDelete(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogicalOperator ExpressionWidget::getOperator()
|
RsRegularExpression::LogicalOperator ExpressionWidget::getOperator()
|
||||||
{
|
{
|
||||||
return exprOpElem->getLogicalOperator();
|
return exprOpElem->getLogicalOperator();
|
||||||
}
|
}
|
||||||
@ -145,9 +145,9 @@ static int checkedConversion(uint64_t s)
|
|||||||
return (int)s ;
|
return (int)s ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression* ExpressionWidget::getRsExpression()
|
RsRegularExpression::Expression* ExpressionWidget::getRsExpression()
|
||||||
{
|
{
|
||||||
Expression * expr = NULL;
|
RsRegularExpression::Expression * expr = NULL;
|
||||||
|
|
||||||
std::list<std::string> wordList;
|
std::list<std::string> wordList;
|
||||||
uint64_t lowVal = 0;
|
uint64_t lowVal = 0;
|
||||||
@ -174,54 +174,54 @@ Expression* ExpressionWidget::getRsExpression()
|
|||||||
switch (searchType)
|
switch (searchType)
|
||||||
{
|
{
|
||||||
case NameSearch:
|
case NameSearch:
|
||||||
expr = new NameExpression(exprCondElem->getStringOperator(),
|
expr = new RsRegularExpression::NameExpression(exprCondElem->getStringOperator(),
|
||||||
wordList,
|
wordList,
|
||||||
exprParamElem->ignoreCase());
|
exprParamElem->ignoreCase());
|
||||||
break;
|
break;
|
||||||
case PathSearch:
|
case PathSearch:
|
||||||
expr = new PathExpression(exprCondElem->getStringOperator(),
|
expr = new RsRegularExpression::PathExpression(exprCondElem->getStringOperator(),
|
||||||
wordList,
|
wordList,
|
||||||
exprParamElem->ignoreCase());
|
exprParamElem->ignoreCase());
|
||||||
break;
|
break;
|
||||||
case ExtSearch:
|
case ExtSearch:
|
||||||
expr = new ExtExpression(exprCondElem->getStringOperator(),
|
expr = new RsRegularExpression::ExtExpression(exprCondElem->getStringOperator(),
|
||||||
wordList,
|
wordList,
|
||||||
exprParamElem->ignoreCase());
|
exprParamElem->ignoreCase());
|
||||||
break;
|
break;
|
||||||
case HashSearch:
|
case HashSearch:
|
||||||
expr = new HashExpression(exprCondElem->getStringOperator(),
|
expr = new RsRegularExpression::HashExpression(exprCondElem->getStringOperator(),
|
||||||
wordList);
|
wordList);
|
||||||
break;
|
break;
|
||||||
case DateSearch:
|
case DateSearch:
|
||||||
if (inRangedConfig) {
|
if (inRangedConfig) {
|
||||||
expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
|
expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
|
||||||
} else {
|
} else {
|
||||||
expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
|
expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PopSearch:
|
case PopSearch:
|
||||||
if (inRangedConfig) {
|
if (inRangedConfig) {
|
||||||
expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
|
expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
|
||||||
} else {
|
} else {
|
||||||
expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
|
expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SizeSearch:
|
case SizeSearch:
|
||||||
if (inRangedConfig)
|
if (inRangedConfig)
|
||||||
{
|
{
|
||||||
if(lowVal >= (uint64_t)(1024*1024*1024) || highVal >= (uint64_t)(1024*1024*1024))
|
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
|
else
|
||||||
expr = new SizeExpression(exprCondElem->getRelOperator(), lowVal, highVal);
|
expr = new RsRegularExpression::SizeExpression(exprCondElem->getRelOperator(), lowVal, highVal);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint64_t s = exprParamElem->getIntValue() ;
|
uint64_t s = exprParamElem->getIntValue() ;
|
||||||
|
|
||||||
if(s >= (uint64_t)(1024*1024*1024))
|
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
|
else
|
||||||
expr = new SizeExpression(exprCondElem->getRelOperator(), (int)s) ;
|
expr = new RsRegularExpression::SizeExpression(exprCondElem->getRelOperator(), (int)s) ;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
@ -45,11 +45,11 @@ public:
|
|||||||
/** delivers the expression represented by this widget
|
/** delivers the expression represented by this widget
|
||||||
the operator to join this expression with any previous
|
the operator to join this expression with any previous
|
||||||
expressions is provided by the getOperator method */
|
expressions is provided by the getOperator method */
|
||||||
Expression* getRsExpression();
|
RsRegularExpression::Expression* getRsExpression();
|
||||||
|
|
||||||
/** supplies the operator to be used when joining this expression
|
/** supplies the operator to be used when joining this expression
|
||||||
to the whole query */
|
to the whole query */
|
||||||
LogicalOperator getOperator();
|
RsRegularExpression::LogicalOperator getOperator();
|
||||||
|
|
||||||
QString toString();
|
QString toString();
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ QStringList GuiExprElement::relOptionsList;
|
|||||||
|
|
||||||
QMap<int, ExprSearchType> GuiExprElement::TermsIndexMap;
|
QMap<int, ExprSearchType> GuiExprElement::TermsIndexMap;
|
||||||
|
|
||||||
QMap<int, LogicalOperator> GuiExprElement::logicalOpIndexMap;
|
QMap<int, RsRegularExpression::LogicalOperator> GuiExprElement::logicalOpIndexMap;
|
||||||
QMap<int, StringOperator> GuiExprElement::strConditionIndexMap;
|
QMap<int, RsRegularExpression::StringOperator> GuiExprElement::strConditionIndexMap;
|
||||||
QMap<int, RelOperator> GuiExprElement::relConditionIndexMap;
|
QMap<int, RsRegularExpression::RelOperator> GuiExprElement::relConditionIndexMap;
|
||||||
|
|
||||||
QMap<int, QString> GuiExprElement::logicalOpStrMap;
|
QMap<int, QString> GuiExprElement::logicalOpStrMap;
|
||||||
QMap<int, QString> GuiExprElement::termsStrMap;
|
QMap<int, QString> GuiExprElement::termsStrMap;
|
||||||
@ -141,9 +141,9 @@ void GuiExprElement::initialiseOptionsLists()
|
|||||||
GuiExprElement::relOptionsList.append(RANGE);
|
GuiExprElement::relOptionsList.append(RANGE);
|
||||||
|
|
||||||
// now the maps
|
// now the maps
|
||||||
GuiExprElement::logicalOpIndexMap[GuiExprElement::AND_INDEX] = AndOp;
|
GuiExprElement::logicalOpIndexMap[GuiExprElement::AND_INDEX] = RsRegularExpression::AndOp;
|
||||||
GuiExprElement::logicalOpIndexMap[GuiExprElement::OR_INDEX] = OrOp;
|
GuiExprElement::logicalOpIndexMap[GuiExprElement::OR_INDEX] = RsRegularExpression::OrOp;
|
||||||
GuiExprElement::logicalOpIndexMap[GuiExprElement::XOR_INDEX] = XorOp;
|
GuiExprElement::logicalOpIndexMap[GuiExprElement::XOR_INDEX] = RsRegularExpression::XorOp;
|
||||||
|
|
||||||
GuiExprElement::TermsIndexMap[GuiExprElement::NAME_INDEX] = NameSearch;
|
GuiExprElement::TermsIndexMap[GuiExprElement::NAME_INDEX] = NameSearch;
|
||||||
GuiExprElement::TermsIndexMap[GuiExprElement::PATH_INDEX] = PathSearch;
|
GuiExprElement::TermsIndexMap[GuiExprElement::PATH_INDEX] = PathSearch;
|
||||||
@ -153,9 +153,9 @@ void GuiExprElement::initialiseOptionsLists()
|
|||||||
GuiExprElement::TermsIndexMap[GuiExprElement::SIZE_INDEX] = SizeSearch;
|
GuiExprElement::TermsIndexMap[GuiExprElement::SIZE_INDEX] = SizeSearch;
|
||||||
GuiExprElement::TermsIndexMap[GuiExprElement::POP_INDEX] = PopSearch;
|
GuiExprElement::TermsIndexMap[GuiExprElement::POP_INDEX] = PopSearch;
|
||||||
|
|
||||||
GuiExprElement::strConditionIndexMap[GuiExprElement::CONTAINS_INDEX] = ContainsAnyStrings;
|
GuiExprElement::strConditionIndexMap[GuiExprElement::CONTAINS_INDEX] = RsRegularExpression::ContainsAnyStrings;
|
||||||
GuiExprElement::strConditionIndexMap[GuiExprElement::CONTALL_INDEX] = ContainsAllStrings;
|
GuiExprElement::strConditionIndexMap[GuiExprElement::CONTALL_INDEX] = RsRegularExpression::ContainsAllStrings;
|
||||||
GuiExprElement::strConditionIndexMap[GuiExprElement::IS_INDEX] = EqualsString;
|
GuiExprElement::strConditionIndexMap[GuiExprElement::IS_INDEX] = RsRegularExpression::EqualsString;
|
||||||
|
|
||||||
/* W A R N I N G !!!!
|
/* 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
|
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
|
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.
|
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::LT_INDEX] = RsRegularExpression::GreaterEquals;
|
||||||
GuiExprElement::relConditionIndexMap[GuiExprElement::LTE_INDEX] = Greater;
|
GuiExprElement::relConditionIndexMap[GuiExprElement::LTE_INDEX] = RsRegularExpression::Greater;
|
||||||
GuiExprElement::relConditionIndexMap[GuiExprElement::EQUAL_INDEX] = Equals;
|
GuiExprElement::relConditionIndexMap[GuiExprElement::EQUAL_INDEX] = RsRegularExpression::Equals;
|
||||||
GuiExprElement::relConditionIndexMap[GuiExprElement::GTE_INDEX] = Smaller;
|
GuiExprElement::relConditionIndexMap[GuiExprElement::GTE_INDEX] = RsRegularExpression::Smaller;
|
||||||
GuiExprElement::relConditionIndexMap[GuiExprElement::GT_INDEX] = SmallerEquals;
|
GuiExprElement::relConditionIndexMap[GuiExprElement::GT_INDEX] = RsRegularExpression::SmallerEquals;
|
||||||
GuiExprElement::relConditionIndexMap[GuiExprElement::RANGE_INDEX] = InRange;
|
GuiExprElement::relConditionIndexMap[GuiExprElement::RANGE_INDEX] = RsRegularExpression::InRange;
|
||||||
|
|
||||||
// the string to index map
|
// the string to index map
|
||||||
GuiExprElement::termsStrMap[GuiExprElement::NAME_INDEX] = NAME;
|
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()];
|
return GuiExprElement::logicalOpIndexMap[cb->currentIndex()];
|
||||||
}
|
}
|
||||||
@ -313,12 +313,12 @@ QString ExprConditionElement::toString()
|
|||||||
return GuiExprElement::relConditionStrMap[cb->currentIndex()];
|
return GuiExprElement::relConditionStrMap[cb->currentIndex()];
|
||||||
}
|
}
|
||||||
|
|
||||||
RelOperator ExprConditionElement::getRelOperator()
|
RsRegularExpression::RelOperator ExprConditionElement::getRelOperator()
|
||||||
{
|
{
|
||||||
return GuiExprElement::relConditionIndexMap[cb->currentIndex()];
|
return GuiExprElement::relConditionIndexMap[cb->currentIndex()];
|
||||||
}
|
}
|
||||||
|
|
||||||
StringOperator ExprConditionElement::getStringOperator()
|
RsRegularExpression::StringOperator ExprConditionElement::getStringOperator()
|
||||||
{
|
{
|
||||||
return GuiExprElement::strConditionIndexMap[cb->currentIndex()];
|
return GuiExprElement::strConditionIndexMap[cb->currentIndex()];
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ protected:
|
|||||||
static QStringList relOptionsList;
|
static QStringList relOptionsList;
|
||||||
|
|
||||||
// provides a mapping of condition operators to RSExpr reloperators
|
// provides a mapping of condition operators to RSExpr reloperators
|
||||||
static QMap<int, LogicalOperator> logicalOpIndexMap;
|
static QMap<int, RsRegularExpression::LogicalOperator> logicalOpIndexMap;
|
||||||
static QMap<int, StringOperator> strConditionIndexMap;
|
static QMap<int, RsRegularExpression::StringOperator> strConditionIndexMap;
|
||||||
static QMap<int, RelOperator> relConditionIndexMap;
|
static QMap<int, RsRegularExpression::RelOperator> relConditionIndexMap;
|
||||||
|
|
||||||
// provides a mapping of indexes to translatable strings
|
// provides a mapping of indexes to translatable strings
|
||||||
static QMap<int, QString> logicalOpStrMap;
|
static QMap<int, QString> logicalOpStrMap;
|
||||||
@ -134,7 +134,7 @@ class ExprOpElement : public GuiExprElement
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ExprOpElement(QWidget * parent = 0);
|
ExprOpElement(QWidget * parent = 0);
|
||||||
LogicalOperator getLogicalOperator();
|
RsRegularExpression::LogicalOperator getLogicalOperator();
|
||||||
QString toString();
|
QString toString();
|
||||||
private:
|
private:
|
||||||
QComboBox * cb;
|
QComboBox * cb;
|
||||||
@ -148,8 +148,8 @@ class ExprTermsElement : public GuiExprElement
|
|||||||
public:
|
public:
|
||||||
ExprTermsElement(QWidget * parent = 0);
|
ExprTermsElement(QWidget * parent = 0);
|
||||||
int getTermsIndex();
|
int getTermsIndex();
|
||||||
RelOperator getRelOperator();
|
RsRegularExpression::RelOperator getRelOperator();
|
||||||
StringOperator getStringOperator();
|
RsRegularExpression::StringOperator getStringOperator();
|
||||||
void set(int i) {cb->setCurrentIndex(i);}
|
void set(int i) {cb->setCurrentIndex(i);}
|
||||||
QString toString();
|
QString toString();
|
||||||
|
|
||||||
@ -167,8 +167,8 @@ class ExprConditionElement : public GuiExprElement
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ExprConditionElement(ExprSearchType, QWidget * parent = 0);
|
ExprConditionElement(ExprSearchType, QWidget * parent = 0);
|
||||||
RelOperator getRelOperator();
|
RsRegularExpression::RelOperator getRelOperator();
|
||||||
StringOperator getStringOperator();
|
RsRegularExpression::StringOperator getStringOperator();
|
||||||
void adjustForSearchType(ExprSearchType);
|
void adjustForSearchType(ExprSearchType);
|
||||||
void set(int i) {cb->setCurrentIndex(i);}
|
void set(int i) {cb->setCurrentIndex(i);}
|
||||||
QString toString();
|
QString toString();
|
||||||
|
Loading…
Reference in New Issue
Block a user