00001 /* inmemory_positionlist.cc 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2003 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 #include <config.h> 00023 00024 #include "omassert.h" 00025 #include "omdebug.h" 00026 #include "inmemory_positionlist.h" 00027 00028 InMemoryPositionList::InMemoryPositionList(const OmDocumentTerm::term_positions & positions_) 00029 : positions(positions_), mypos(positions.begin()), 00030 iterating_in_progress(false) 00031 { 00032 } 00033 00034 void 00035 InMemoryPositionList::set_data(const OmDocumentTerm::term_positions & positions_) 00036 { 00037 positions = positions_; 00038 mypos = positions.begin(); 00039 iterating_in_progress = false; 00040 } 00041 00042 Xapian::termcount 00043 InMemoryPositionList::get_size() const 00044 { 00045 return positions.size(); 00046 } 00047 00048 Xapian::termpos 00049 InMemoryPositionList::get_position() const 00050 { 00051 Assert(iterating_in_progress); 00052 Assert(!at_end()); 00053 return *mypos; 00054 } 00055 00056 void 00057 InMemoryPositionList::next() 00058 { 00059 if (iterating_in_progress) { 00060 Assert(!at_end()); 00061 mypos++; 00062 } else { 00063 iterating_in_progress = true; 00064 } 00065 } 00066 00067 void 00068 InMemoryPositionList::skip_to(Xapian::termpos termpos) 00069 { 00070 if (!iterating_in_progress) iterating_in_progress = true; 00071 while (!at_end() && *mypos < termpos) mypos++; 00072 } 00073 00074 bool 00075 InMemoryPositionList::at_end() const 00076 { 00077 return(mypos == positions.end()); 00078 }