refactor operations delegated to subsequence by sortseq and filtspec into superclass

This commit is contained in:
dockes 2009-01-15 14:37:08 +00:00
parent 5b879ea0e7
commit 3d69417539
5 changed files with 36 additions and 17 deletions

View File

@ -27,6 +27,7 @@ using std::vector;
#endif #endif
#include "rcldoc.h" #include "rcldoc.h"
#include "refcntr.h"
// A result list entry. // A result list entry.
struct ResListEntry { struct ResListEntry {
@ -120,7 +121,7 @@ class DocSequence {
{ {
terms.clear(); groups.clear(); gslks.clear(); return true; terms.clear(); groups.clear(); gslks.clear(); return true;
} }
virtual list<string> expand(Rcl::Doc &) {list<string> e; return e;} virtual list<string> expand(Rcl::Doc &) {return list<string>();}
/** Optional functionality. Yeah, not nice */ /** Optional functionality. Yeah, not nice */
virtual bool canFilter() {return false;} virtual bool canFilter() {return false;}
@ -132,4 +133,34 @@ class DocSequence {
string m_title; 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<DocSequence> 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<string>& terms,
vector<vector<string> >& groups,
vector<int>& gslks)
{
return m_seq->getTerms(terms, groups, gslks);
}
protected:
RefCntr<DocSequence> m_seq;
};
#endif /* _DOCSEQ_H_INCLUDED_ */ #endif /* _DOCSEQ_H_INCLUDED_ */

View File

@ -43,7 +43,7 @@ static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
DocSeqFiltered::DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltered::DocSeqFiltered(RefCntr<DocSequence> iseq,
DocSeqFiltSpec &filtspec, DocSeqFiltSpec &filtspec,
const std::string &t) const std::string &t)
: DocSequence(t), m_seq(iseq), m_spec(filtspec) : DocSeqModifier(t, iseq), m_spec(filtspec)
{ {
} }

View File

@ -29,7 +29,7 @@
* A filtered sequence is created from another one by selecting entries * A filtered sequence is created from another one by selecting entries
* according to the given criteria. * according to the given criteria.
*/ */
class DocSeqFiltered : public DocSequence { class DocSeqFiltered : public DocSeqModifier {
public: public:
DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltSpec &filtspec, DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltSpec &filtspec,
const std::string &t); const std::string &t);
@ -38,13 +38,7 @@ class DocSeqFiltered : public DocSequence {
virtual bool setFiltSpec(DocSeqFiltSpec &filtspec); virtual bool setFiltSpec(DocSeqFiltSpec &filtspec);
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0); virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
virtual int getResCnt() {return m_seq->getResCnt();} 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: private:
RefCntr<DocSequence> m_seq;
DocSeqFiltSpec m_spec; DocSeqFiltSpec m_spec;
vector<int> m_dbindices; vector<int> m_dbindices;
}; };

View File

@ -70,7 +70,7 @@ public:
DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec, DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
const std::string &t) const std::string &t)
: DocSequence(t), m_seq(iseq) : DocSeqModifier(t, iseq)
{ {
setSortSpec(sortspec); setSortSpec(sortspec);
} }

View File

@ -28,7 +28,7 @@
* A sorted sequence is created from the first N documents of another one, * A sorted sequence is created from the first N documents of another one,
* and sorts them according to the given criteria. * and sorts them according to the given criteria.
*/ */
class DocSeqSorted : public DocSequence { class DocSeqSorted : public DocSeqModifier {
public: public:
DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec, DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
const std::string &t); const std::string &t);
@ -37,13 +37,7 @@ class DocSeqSorted : public DocSequence {
virtual bool setSortSpec(DocSeqSortSpec &sortspec); virtual bool setSortSpec(DocSeqSortSpec &sortspec);
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0); virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
virtual int getResCnt() {return m_spec.sortdepth;} 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: private:
RefCntr<DocSequence> m_seq;
DocSeqSortSpec m_spec; DocSeqSortSpec m_spec;
std::vector<Rcl::Doc> m_docs; std::vector<Rcl::Doc> m_docs;
std::vector<Rcl::Doc *> m_docsp; std::vector<Rcl::Doc *> m_docsp;