00001 00004 /* Copyright (C) 2008,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 USA 00019 */ 00020 00021 #include <config.h> 00022 00023 #include "documentvaluelist.h" 00024 00025 #include "document.h" 00026 #include "omassert.h" 00027 #include "str.h" 00028 00029 #include "xapian/error.h" 00030 00031 using namespace std; 00032 00033 Xapian::docid 00034 DocumentValueList::get_docid() const 00035 { 00036 throw Xapian::InvalidOperationError("get_docid() isn't valid when iterating over values in a document"); 00037 } 00038 00039 Xapian::valueno 00040 DocumentValueList::get_valueno() const 00041 { 00042 Assert(!at_end()); 00043 return it->first; 00044 } 00045 00046 string 00047 DocumentValueList::get_value() const 00048 { 00049 Assert(!at_end()); 00050 return it->second; 00051 } 00052 00053 bool 00054 DocumentValueList::at_end() const 00055 { 00056 return it == doc->values.end(); 00057 } 00058 00059 void 00060 DocumentValueList::next() 00061 { 00062 if (it == doc->values.end()) { 00063 it = doc->values.begin(); 00064 } else { 00065 ++it; 00066 } 00067 } 00068 00069 void 00070 DocumentValueList::skip_to(Xapian::docid slot) 00071 { 00072 it = doc->values.lower_bound(slot); 00073 } 00074 00075 string 00076 DocumentValueList::get_description() const 00077 { 00078 string desc = "DocumentValueList("; 00079 if (!at_end()) { 00080 desc += "slot="; 00081 desc += str(get_valueno()); 00082 desc += ", value=\""; 00083 desc += get_value(); 00084 desc += "\")"; 00085 } else { 00086 desc += "atend)"; 00087 } 00088 return desc; 00089 }