common/vectortermlist.h

Go to the documentation of this file.
00001 /* vectortermlist.h
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002,2003,2005,2006,2007 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00019  * USA
00020  */
00021 
00022 #ifndef OM_HGUARD_VECTORTERMLIST_H
00023 #define OM_HGUARD_VECTORTERMLIST_H
00024 
00025 #include <xapian/error.h>
00026 #include "omassert.h"
00027 #include "termlist.h"
00028 
00029 #include <list>
00030 #include <vector>
00031 
00032 using namespace std;
00033 
00034 class VectorTermList : public TermList {
00035     private:
00036         vector<string> terms;
00037         vector<string>::size_type offset;
00038         bool before_start;
00039 
00040     public:
00041         VectorTermList(vector<string>::const_iterator begin,
00042                        vector<string>::const_iterator end)
00043             : terms(begin, end), offset(0), before_start(true)
00044         {
00045         }
00046 
00047         VectorTermList(list<string>::const_iterator begin,
00048                        list<string>::const_iterator end)
00049             : terms(begin, end), offset(0), before_start(true)
00050         {
00051         }
00052 
00053         // Gets size of termlist
00054         Xapian::termcount get_approx_size() const {
00055             return terms.size();
00056         }
00057 
00058         // Gets current termname
00059         string get_termname() const {
00060             Assert(!before_start && offset < terms.size());
00061             return terms[offset];
00062         }
00063 
00064         // Get wdf of current term
00065         Xapian::termcount get_wdf() const {
00066             Assert(!before_start && offset < terms.size());
00067             return 1; // FIXME: or is Xapian::InvalidOperationError better?
00068         }
00069 
00070         // Get num of docs indexed by term
00071         Xapian::doccount get_termfreq() const {
00072             throw Xapian::InvalidOperationError("VectorTermList::get_termfreq() not supported");
00073         }
00074 
00082         TermList * next() {
00083             Assert(!at_end());
00084             if (before_start)
00085                 before_start = false;
00086             else
00087                 offset++;
00088             return NULL;
00089         }
00090 
00091         TermList *skip_to(const string &/*tname*/) {
00092             Assert(!at_end());
00093             // termlist not ordered
00094             Assert(false);
00095             throw Xapian::InvalidOperationError("VectorTermList::skip_to() not supported");
00096         }
00097 
00098         // True if we're off the end of the list
00099         bool at_end() const {
00100             return !before_start && offset == terms.size();
00101         }
00102 
00103         Xapian::PositionIterator positionlist_begin() const {
00104             throw Xapian::InvalidOperationError("VectorTermList::positionlist_begin() isn't meaningful");
00105         }
00106 
00107         Xapian::termcount positionlist_count() const {
00108             throw Xapian::InvalidOperationError("VectorTermList::positionlist_count() isn't meaningful");
00109         }
00110 };
00111 
00112 #endif // OM_HGUARD_VECTORTERMLIST_H

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.