#include <vector>
#include <sstream>
#include <algorithm>
#include <dvutil/tostring.h>
#include <dvutil/date.h>
#include <config.h>
#include "index.h"
#include "word.h"
#include "wordstreamiterator.h"
Go to the source code of this file.
Functions | |
ostream & | operator<< (ostream &os, const Index &index) |
istream & | operator>> (istream &is, Index &index) throw (runtime_error) |
|
Format: #textindexer VERSION -- do not edit this file time_t filename ... empty line word fileid .. Definition at line 24 of file index.C. References Index::begin(), Index::dates_, Index::end(), Index::Files, and Index::iterator.
00024 { 00025 // Write first line: MAGIC version# 00026 os << MAGIC << " " << VERSION << " -- do not edit this file" << endl; 00027 // Write pool contents & remember the position of each pointer. 00028 os << index.dates_.size() << endl; 00029 map<const string*,int> file_nrs; 00030 size_t n(0); 00031 for (Index::Dates::const_iterator i = index.dates_.begin(); 00032 i!=index.dates_.end(); ++i) { 00033 os << (*i).second << ' ' << *((*i).first) << "\n"; 00034 file_nrs[(*i).first] = n++; 00035 } 00036 for (Index::iterator i=index.begin(); i!= index.end(); ++i) { 00037 os << (*i).first; 00038 const Index::Files& files((*i).second); 00039 for (Index::Files::const_iterator j = files.begin(); j!=files.end(); ++j) 00040 os << " " << file_nrs[*j]; 00041 os << "\n"; 00042 } 00043 return os; 00044 } |
|
Definition at line 47 of file index.C. References Word::str().
00047 { 00048 // Read first line: MAGIC version junk 00049 // Normally, we would use ignore(numeric_limits<int>::max(), '\n') 00050 // but #include <limits> does not work in this g++ version. 00051 string magic; 00052 string junk; 00053 double version; 00054 is >> magic >> version; 00055 getline(is,junk); 00056 if (magic!=MAGIC) 00057 throw runtime_error("Bad magic in textindexer index file"); 00058 // Perhaps a test on version should come here. 00059 vector<const string*> files; 00060 StringPool& pool(index.pool()); 00061 size_t n; 00062 is >> n; 00063 string filename; 00064 time_t t; 00065 for (size_t i=0; i<n; ++i) { 00066 is >> t; 00067 if (t==0) 00068 throw runtime_error("Index reader: time == 0"); 00069 is.ignore(); 00070 getline(is, filename); 00071 if (filename.size()==0) 00072 throw runtime_error("Index reader: empty filename "); 00073 const string* pfn(pool[filename]); 00074 files.push_back(pfn); 00075 index.dates_[pfn] = t; 00076 } 00077 string line; 00078 while (getline(is,line)) { 00079 istringstream iss(line); 00080 Word w; 00081 iss >> w; 00082 size_t i; 00083 while (iss>>i) { 00084 if (i>=files.size()) 00085 throw runtime_error(Dv::Util::tostring(i) + ": illegal file#"); 00086 index.map_[w.str()].insert(files[i]); 00087 } 00088 } 00089 return is; 00090 } |
textindexer-0.2 | [27 March, 2002] |