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