TDBIndexer.h

Go to the documentation of this file.
00001 #ifndef TDB_INDEXER_H
00002 #define TDB_INDEXER_H
00003 
00008 /*
00009  * Copyright (C) 2005  Enrico Zini <enrico@debian.org>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #include <tagcoll/Collection.h>
00027 #include <tagcoll/Serializer.h>
00028 #include <tagcoll/Exception.h>
00029 #include <map>
00030 
00031 namespace Tagcoll
00032 {
00033 
00044 template<class ITEM, class TAG>
00045 class TDBIndexer : public Collection<ITEM, TAG>
00046 {
00047 protected:
00048     std::map<ITEM, OpSet<TAG> > items;
00049     std::map<TAG, OpSet<ITEM> > tags;
00050 
00051     virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags);
00052     virtual void consumeItems(const OpSet<ITEM>& items, const OpSet<TAG>& tags);
00053 
00054     virtual OpSet<ITEM> getItemsHavingTag(const TAG& tag) const;
00055     virtual OpSet<TAG> getTagsOfItem(const ITEM& item) const;
00056 
00057 public:
00058     virtual ~TDBIndexer() {}
00059 
00060     virtual bool hasItem(const ITEM& item) const { return items.find(item) != items.end(); }
00061     virtual bool hasTag(const TAG& tag) const { return tags.find(tag) != tags.end(); }
00062     virtual OpSet<ITEM> getTaggedItems() const;
00063     virtual OpSet<TAG> getAllTags() const;
00064     virtual void output(Consumer<ITEM, TAG>& consumer) const;
00065     virtual void applyChange(const PatchList<ITEM, TAG>& change);
00066 
00079     void writeIndex(
00080             Converter<ITEM, std::string>& itemconv,
00081             Converter<TAG, std::string>& tagconv,
00082             const std::string& pkgidx,
00083             const std::string& tagidx) const;
00084 };
00085 
00086 };
00087 
00088 // vim:set ts=4 sw=4:
00089 #endif

Generated on Fri Mar 24 23:00:30 2006 for libtagcoll by  doxygen 1.4.6