• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE Support
  • Sitemap
  • Contact Us
 

strigi/src/streams

archiveentrycache.cpp

Go to the documentation of this file.
00001 /* This file is part of Strigi Desktop Search
00002  *
00003  * Copyright (C) 2006,2009 Jos van den Oever <jos@vandenoever.info>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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             // the root entry is in the cache - we're done
00039             return i;
00040         }
00041         // remove the last element in the path, and look for that
00042         p = n.rfind('/');
00043         if (p != string::npos) {
00044             n.resize(p);
00045         }
00046     } while (p != string::npos);
00047     // couldn't find it
00048     return cache.end();
00049 }
00053 const ArchiveEntryCache::SubEntry*
00054 ArchiveEntryCache::findEntry(const string& url) const {
00055     // find the root entry that should contain the wanted entry
00056     map<string, RootSubEntry*>::const_iterator ei = findRootEntry(url);
00057     if (ei == cache.end()) return 0; // no root could be find
00058     if (ei->first == url) {
00059         // the requested entry is a root entry: we are done
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     // use the path components as keys to find the entry
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 }

strigi/src/streams

Skip menu "strigi/src/streams"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDE Support

Skip menu "KDE Support"
  • akonadi
  • Decibel
  • grantlee
  • kdewin
  • phonon
  •     Backend
  • polkit-qt
  • qca
  • qimageblitz
  • soprano
  • strigi
  •     searchclient
  •     streamanalyzer
  •     streams
Generated for KDE Support by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal