strigi/src/streams
archiveentrycache.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "archiveentrycache.h"
00021 #include <iostream>
00022
00023 using namespace std;
00024
00025 ArchiveEntryCache::SubEntry::~SubEntry() {
00026 SubEntryMap::iterator i;
00027 for (i=entries.begin(); i!=entries.end(); ++i) {
00028 delete i->second;
00029 }
00030 }
00031 map<string, ArchiveEntryCache::RootSubEntry*>::const_iterator
00032 ArchiveEntryCache::findRootEntry(const string& url) const {
00033 string n(url);
00034 size_t p = n.size();
00035 do {
00036 map<string, RootSubEntry*>::const_iterator i = cache.find(n);
00037 if (i != cache.end()) {
00038
00039 return i;
00040 }
00041
00042 p = n.rfind('/');
00043 if (p != string::npos) {
00044 n.resize(p);
00045 }
00046 } while (p != string::npos);
00047
00048 return cache.end();
00049 }
00053 const ArchiveEntryCache::SubEntry*
00054 ArchiveEntryCache::findEntry(const string& url) const {
00055
00056 map<string, RootSubEntry*>::const_iterator ei = findRootEntry(url);
00057 if (ei == cache.end()) return 0;
00058 if (ei->first == url) {
00059
00060 return ei->second;
00061 }
00062 return ei->second->findEntry(ei->first, url);
00063 }
00064 const ArchiveEntryCache::SubEntry*
00065 ArchiveEntryCache::RootSubEntry::findEntry(const std::string& rootpath,
00066 const std::string& url) const {
00067
00068 const SubEntry* e = this;
00069 size_t p = rootpath.length();
00070 string name;
00071 do {
00072 size_t np = url.find('/', p+1);
00073 if (np == string::npos) {
00074 name.assign(url, p+1, url.size());
00075 } else {
00076 name.assign(url, p+1, np-p-1);
00077 }
00078 SubEntryMap::const_iterator i = e->entries.find(name);
00079 if (i == e->entries.end()) {
00080 e = 0;
00081 } else {
00082 e = i->second;
00083 p = np;
00084 }
00085 if (p == url.length()) {
00086 return e;
00087 }
00088 } while(e && p != string::npos);
00089
00090 return e;
00091 }