1 /** @file 2 * @brief PositionList from an InMemory DB or a Document object 3 */ 4 /* Copyright 1999,2000,2001 BrightStation PLC 5 * Copyright 2003,2008,2009,2011 Olly Betts 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 20 * USA 21 */ 22 23 #ifndef OM_HGUARD_INMEMORY_POSITIONLIST_H 24 #define OM_HGUARD_INMEMORY_POSITIONLIST_H 25 26 #include <xapian/types.h> 27 #include <xapian/error.h> 28 29 #include <vector> 30 #include "backends/positionlist.h" 31 #include "api/documentterm.h" 32 33 using namespace std; 34 35 /** A position list in a inmemory database. */ 36 class InMemoryPositionList : public PositionList 37 { 38 private: 39 /// The list of positions. 40 vector<Xapian::termpos> positions; 41 42 /// Position of iteration through positions 43 vector<Xapian::termpos>::const_iterator mypos; 44 45 /// True if we have started iterating 46 bool iterating_in_progress; 47 48 /// Copying is not allowed. 49 InMemoryPositionList(const InMemoryPositionList &); 50 51 /// Assignment is not allowed. 52 void operator=(const InMemoryPositionList &); 53 54 public: 55 /// Default constructor. InMemoryPositionList()56 InMemoryPositionList() : iterating_in_progress(false) { } 57 58 /// Construct an empty InMemoryPositionList. InMemoryPositionList(bool)59 explicit InMemoryPositionList(bool) 60 : mypos(positions.begin()), iterating_in_progress(false) { } 61 62 /// Construct, fill list with data, and move the position to the start. 63 explicit 64 InMemoryPositionList(const OmDocumentTerm::term_positions & positions_); 65 66 /// Fill list with data, and move the position to the start. 67 void set_data(const OmDocumentTerm::term_positions & positions_); 68 69 /// Gets size of position list. 70 Xapian::termcount get_approx_size() const; 71 72 /// Gets current position. 73 Xapian::termpos get_position() const; 74 75 /** Move to the next item in the list. 76 * Either next() or skip_to() must be called before any other 77 * methods. 78 */ 79 bool next(); 80 81 /** Move to the next item in the list. 82 * Either next() or skip_to() must be called before any other 83 * methods. 84 */ 85 bool skip_to(Xapian::termpos termpos); 86 }; 87 88 #endif /* OM_HGUARD_INMEMORY_POSITIONLIST_H */ 89