From 3d694175391c6650f71339d0deb5d307228c502d Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 15 Jan 2009 14:37:08 +0000 Subject: [PATCH] refactor operations delegated to subsequence by sortseq and filtspec into superclass --- src/query/docseq.h | 33 ++++++++++++++++++++++++++++++++- src/query/filtseq.cpp | 2 +- src/query/filtseq.h | 8 +------- src/query/sortseq.cpp | 2 +- src/query/sortseq.h | 8 +------- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/query/docseq.h b/src/query/docseq.h index 4d2c52b0..167c70b3 100644 --- a/src/query/docseq.h +++ b/src/query/docseq.h @@ -27,6 +27,7 @@ using std::vector; #endif #include "rcldoc.h" +#include "refcntr.h" // A result list entry. struct ResListEntry { @@ -120,7 +121,7 @@ class DocSequence { { terms.clear(); groups.clear(); gslks.clear(); return true; } - virtual list expand(Rcl::Doc &) {list e; return e;} + virtual list expand(Rcl::Doc &) {return list();} /** Optional functionality. Yeah, not nice */ virtual bool canFilter() {return false;} @@ -132,4 +133,34 @@ class DocSequence { string m_title; }; +/** A modifier has a child sequence which does the real work and does + * something with the results. Some operations are just delegated + */ +class DocSeqModifier : public DocSequence { +public: + DocSeqModifier(const string &t, RefCntr iseq) + : DocSequence(t), m_seq(iseq) + {} + virtual ~DocSeqModifier() {} + + virtual string getAbstract(Rcl::Doc& doc) + { + return m_seq->getAbstract(doc); + } + virtual string getDescription() + { + return m_seq->getDescription(); + } + virtual bool getTerms(vector& terms, + vector >& groups, + vector& gslks) + { + return m_seq->getTerms(terms, groups, gslks); + } + +protected: + RefCntr m_seq; +}; + + #endif /* _DOCSEQ_H_INCLUDED_ */ diff --git a/src/query/filtseq.cpp b/src/query/filtseq.cpp index 79b3a637..e346bea5 100644 --- a/src/query/filtseq.cpp +++ b/src/query/filtseq.cpp @@ -43,7 +43,7 @@ static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x) DocSeqFiltered::DocSeqFiltered(RefCntr iseq, DocSeqFiltSpec &filtspec, const std::string &t) - : DocSequence(t), m_seq(iseq), m_spec(filtspec) + : DocSeqModifier(t, iseq), m_spec(filtspec) { } diff --git a/src/query/filtseq.h b/src/query/filtseq.h index ae07eb30..5845e3f3 100644 --- a/src/query/filtseq.h +++ b/src/query/filtseq.h @@ -29,7 +29,7 @@ * A filtered sequence is created from another one by selecting entries * according to the given criteria. */ -class DocSeqFiltered : public DocSequence { +class DocSeqFiltered : public DocSeqModifier { public: DocSeqFiltered(RefCntr iseq, DocSeqFiltSpec &filtspec, const std::string &t); @@ -38,13 +38,7 @@ class DocSeqFiltered : public DocSequence { virtual bool setFiltSpec(DocSeqFiltSpec &filtspec); virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0); virtual int getResCnt() {return m_seq->getResCnt();} - virtual string getAbstract(Rcl::Doc& doc) { - return m_seq->getAbstract(doc); - } - virtual string getDescription() {return m_seq->getDescription();} - private: - RefCntr m_seq; DocSeqFiltSpec m_spec; vector m_dbindices; }; diff --git a/src/query/sortseq.cpp b/src/query/sortseq.cpp index 9bd6eeb6..217a34d1 100644 --- a/src/query/sortseq.cpp +++ b/src/query/sortseq.cpp @@ -70,7 +70,7 @@ public: DocSeqSorted::DocSeqSorted(RefCntr iseq, DocSeqSortSpec &sortspec, const std::string &t) - : DocSequence(t), m_seq(iseq) + : DocSeqModifier(t, iseq) { setSortSpec(sortspec); } diff --git a/src/query/sortseq.h b/src/query/sortseq.h index 8c9a98e6..b067d5cc 100644 --- a/src/query/sortseq.h +++ b/src/query/sortseq.h @@ -28,7 +28,7 @@ * A sorted sequence is created from the first N documents of another one, * and sorts them according to the given criteria. */ -class DocSeqSorted : public DocSequence { +class DocSeqSorted : public DocSeqModifier { public: DocSeqSorted(RefCntr iseq, DocSeqSortSpec &sortspec, const std::string &t); @@ -37,13 +37,7 @@ class DocSeqSorted : public DocSequence { virtual bool setSortSpec(DocSeqSortSpec &sortspec); virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0); virtual int getResCnt() {return m_spec.sortdepth;} - virtual string getAbstract(Rcl::Doc& doc) { - return m_seq->getAbstract(doc); - } - virtual string getDescription() {return m_seq->getDescription();} - private: - RefCntr m_seq; DocSeqSortSpec m_spec; std::vector m_docs; std::vector m_docsp;