[Debtags-commits] [svn] r885 - in libdebtags1/trunk: debtags tests
Enrico Zini
debtags-commits@lists.alioth.debian.org
Thu, 16 Jun 2005 19:38:05 +0000
Author: enrico
Date: Thu Jun 16 19:38:05 2005
New Revision: 885
Modified:
libdebtags1/trunk/debtags/DebtagsSimple.cc
libdebtags1/trunk/debtags/DebtagsSimple.h
libdebtags1/trunk/debtags/DebtagsTODO.cc
libdebtags1/trunk/debtags/DebtagsTODO.h
libdebtags1/trunk/debtags/TagToFacet.h
libdebtags1/trunk/debtags/instantiations.cc
libdebtags1/trunk/tests/ex-showpkgs.cc
Log:
Parameterized DebtagsSimple as well
Modified: libdebtags1/trunk/debtags/DebtagsSimple.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.cc (original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.cc Thu Jun 16 19:38:05 2005
@@ -12,40 +12,66 @@
namespace Debtags {
-DebtagsSimple::DebtagsSimple(bool editable) :
+template<class ITEM>
+DebtagsSimple<ITEM>::DebtagsSimple(bool editable) :
_vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
- _serializer(_vocab, _packagedb),
+ _serializer(_vocab),
_tagDB(_vocab, _serializer, editable)
{
}
-TagSet DebtagsSimple::getTags(const std::string& package) const
+template<class ITEM>
+TagSet DebtagsSimple<ITEM>::getTags(const std::string& package) const
{
- Package pkg = _packagedb.getPackage(package);
+ ITEM pkg = _serializer.stringToItem(package);
if (pkg)
return _tagDB.getTags(pkg);
else
return TagSet();
}
-PackageSet DebtagsSimple::getPackages(const Tag& tag) const
+#ifndef INSTANTIATING_TEMPLATES
+template<>
+DebtagsSimple<Debtags::Package>::DebtagsSimple(bool editable) :
+ _vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
+ _serializer(_vocab, _packagedb),
+ _tagDB(_vocab, _serializer, editable)
+{
+}
+
+template<>
+TagSet DebtagsSimple<std::string>::getTags(const std::string& package) const
+{
+ return _tagDB.getTags(package);
+}
+#else
+template<>
+DebtagsSimple<Debtags::Package>::DebtagsSimple(bool editable);
+template<>
+TagSet DebtagsSimple<std::string>::getTags(const std::string& package) const;
+#endif
+
+template<class ITEM>
+OpSet<ITEM> DebtagsSimple<ITEM>::getPackages(const Tag& tag) const
{
TagSet tags;
tags += tag;
return _tagDB.getItems(tags);
}
-PackageSet DebtagsSimple::getPackages(const TagSet& tags) const
+template<class ITEM>
+OpSet<ITEM> DebtagsSimple<ITEM>::getPackages(const TagSet& tags) const
{
return _tagDB.getItems(tags);
}
-ImplicationList<Facet> DebtagsSimple::getFacetImplications() const
+template<class ITEM>
+ImplicationList<Facet> DebtagsSimple<ITEM>::getFacetImplications() const
{
- TagCollection<Package, Facet> coll;
+ TagCollection<ITEM, Facet> coll;
// Make a new collection tagged with facets instead of tags
- TagToFacet tagStripper(&coll);
+ TagToFacet<ITEM> tagStripper(&coll);
_tagDB.output(tagStripper);
ImplicationList<Facet> newImpls;
@@ -65,18 +91,19 @@
return newImpls;
}
-FacetSet DebtagsSimple::getToplevelFacets(int flattenThreshold) const
+template<class ITEM>
+FacetSet DebtagsSimple<ITEM>::getToplevelFacets(int flattenThreshold) const
{
- TagCollection<Package, Facet> coll;
+ TagCollection<ITEM, Facet> coll;
FacetSet res;
// Make a new collection tagged with facets instead of tags
- TagToFacet tagStripper(&coll);
+ TagToFacet<ITEM> tagStripper(&coll);
_tagDB.output(tagStripper);
Facet f;
- SmartHierarchyNode<Package, Facet> node(f, coll, flattenThreshold);
- for (HierarchyNode<Package, Facet>::iterator i = node.begin();
+ SmartHierarchyNode<ITEM, Facet> node(f, coll, flattenThreshold);
+ for (typename HierarchyNode<ITEM, Facet>::iterator i = node.begin();
i != node.end(); i++)
res += (*i)->tag();
Modified: libdebtags1/trunk/debtags/DebtagsSimple.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.h (original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.h Thu Jun 16 19:38:05 2005
@@ -33,6 +33,7 @@
namespace Debtags
{
+template <class ITEM>
class DebtagsSimple
{
// If true, save state to ~/.debtags
@@ -48,10 +49,10 @@
Vocabulary _vocab;
// Debtags serializer
- Tagcoll::Serializer<Package, Tag> _serializer;
+ mutable Tagcoll::Serializer<ITEM, Tag> _serializer;
// Debtags database
- TagDB<Debtags::Package> _tagDB;
+ TagDB<ITEM> _tagDB;
public:
DebtagsSimple(bool editable);
@@ -63,12 +64,12 @@
Vocabulary& vocabulary() throw () { return _vocab; }
const Vocabulary& vocabulary() const throw () { return _vocab; }
- TagDB<Debtags::Package>& tagDB() throw () { return _tagDB; }
- const TagDB<Debtags::Package>& tagDB() const throw () { return _tagDB; }
+ TagDB<ITEM>& tagDB() throw () { return _tagDB; }
+ const TagDB<ITEM>& tagDB() const throw () { return _tagDB; }
TagSet getTags(const std::string& package) const;
- PackageSet getPackages(const Tag& tag) const;
- PackageSet getPackages(const TagSet& tags) const;
+ OpSet<ITEM> getPackages(const Tag& tag) const;
+ OpSet<ITEM> getPackages(const TagSet& tags) const;
Tagcoll::ImplicationList<Debtags::Facet> getFacetImplications() const;
Modified: libdebtags1/trunk/debtags/DebtagsTODO.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsTODO.cc (original)
+++ libdebtags1/trunk/debtags/DebtagsTODO.cc Thu Jun 16 19:38:05 2005
@@ -10,11 +10,12 @@
using namespace Debtags;
using namespace Tagcoll;
-static OpSet<Package> getItems(HierarchyNode<Package, Facet>* node) throw ()
+template<class ITEM>
+static OpSet<ITEM> getItems(HierarchyNode<ITEM, Facet>* node) throw ()
{
- OpSet<Package> items = node->getItems();
+ OpSet<ITEM> items = node->getItems();
- for (HierarchyNode<Package, Facet>::iterator i = node->begin();
+ for (typename HierarchyNode<ITEM, Facet>::iterator i = node->begin();
i != node->end(); i++)
items += getItems(*i);
@@ -23,29 +24,30 @@
namespace Debtags {
-void DebtagsTODOSpecials::compute(DebtagsStatus* tracker) throw ()
+template<class ITEM>
+void DebtagsTODOSpecials<ITEM>::compute(DebtagsStatus* tracker) throw ()
{
if (computed)
return;
Facet f;
- SmartHierarchyNode<Package, Facet> node(f, coll, 0);
+ SmartHierarchyNode<ITEM, Facet> node(f, coll, 0);
if (tracker)
tracker->setTotal(node.size());
FacetSet seen;
- for (HierarchyNode<Package, Facet>::iterator i = node.begin();
+ for (typename HierarchyNode<ITEM, Facet>::iterator i = node.begin();
i != node.end(); i++)
{
- OpSet<Package> items = getItems(*i);
+ OpSet<ITEM> items = getItems(*i);
// Find the items in this branch that are not present in
// any of the previous ones
if (!seen.empty())
{
- OpSet<Package> newItems;
- for (OpSet<Package>::const_iterator j = items.begin();
+ OpSet<ITEM> newItems;
+ for (typename OpSet<ITEM>::const_iterator j = items.begin();
j != items.end() && newItems.size() <= 101; j++)
{
TagSet tags = j->tags();
@@ -61,7 +63,7 @@
}
if (!newItems.empty() && (maxPerGroup == 0 || newItems.size() <= maxPerGroup))
- specials.insert(make_pair<Facet, PackageSet>((*i)->tag(), newItems));
+ specials.insert(make_pair<Facet, OpSet<ITEM> >((*i)->tag(), newItems));
}
seen += (*i)->tag();
Modified: libdebtags1/trunk/debtags/DebtagsTODO.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsTODO.h (original)
+++ libdebtags1/trunk/debtags/DebtagsTODO.h Thu Jun 16 19:38:05 2005
@@ -45,11 +45,12 @@
* The list corresponds to those packages reported by
* debtags facetcoll | tagcoll findspecials
*/
-class DebtagsTODOSpecials : public Tagcoll::TagcollConsumer<Package, Tag>
+template <class ITEM>
+class DebtagsTODOSpecials : public Tagcoll::TagcollConsumer<ITEM, Tag>
{
protected:
- Tagcoll::TagCollection<Package, Facet> coll;
- TagToFacet tagStripper;
+ Tagcoll::TagCollection<ITEM, Facet> coll;
+ TagToFacet<ITEM> tagStripper;
unsigned int maxPerGroup;
bool computed;
@@ -58,16 +59,16 @@
tagStripper(&coll), maxPerGroup(maxPerGroup), computed(false) {}
virtual ~DebtagsTODOSpecials() throw () {}
- virtual void consume(const Package& item) { tagStripper.consume(item); }
- virtual void consume(const Package& item, const Tagcoll::OpSet<Tag>& tags) { tagStripper.consume(item, tags); }
- virtual void consume(const Tagcoll::OpSet<Package>& items) { tagStripper.consume(items); }
- virtual void consume(const Tagcoll::OpSet<Package>& items, const Tagcoll::OpSet<Tag>& tags) { tagStripper.consume(items, tags); }
+ virtual void consume(const ITEM& item) { tagStripper.consume(item); }
+ virtual void consume(const ITEM& item, const Tagcoll::OpSet<Tag>& tags) { tagStripper.consume(item, tags); }
+ virtual void consume(const Tagcoll::OpSet<ITEM>& items) { tagStripper.consume(items); }
+ virtual void consume(const Tagcoll::OpSet<ITEM>& items, const Tagcoll::OpSet<Tag>& tags) { tagStripper.consume(items, tags); }
bool isComputed() const throw () { return computed; }
void compute(DebtagsStatus* tracker = 0) throw ();
- void clear() throw () { coll = Tagcoll::TagCollection<Package, Facet>(); specials.clear(); computed = false; }
+ void clear() throw () { coll = Tagcoll::TagCollection<ITEM, Facet>(); specials.clear(); computed = false; }
- std::map<Facet, PackageSet> specials;
+ std::map<Facet, OpSet<ITEM> > specials;
};
};
Modified: libdebtags1/trunk/debtags/TagToFacet.h
==============================================================================
--- libdebtags1/trunk/debtags/TagToFacet.h (original)
+++ libdebtags1/trunk/debtags/TagToFacet.h Thu Jun 16 19:38:05 2005
@@ -9,13 +9,14 @@
{
/**
- * Convert a collection of Packages tagged with Tags to a collection of
- * Packages tagged with only the facets.
+ * Convert a collection of ITEMs tagged with Tags to a collection of
+ * ITEMs tagged with only the facets.
*/
-class TagToFacet : public Tagcoll::TagcollConsumer<Package, Tag>
+template<class ITEM>
+class TagToFacet : public Tagcoll::TagcollConsumer<ITEM, Tag>
{
protected:
- Tagcoll::TagcollConsumer<Debtags::Package, Debtags::Facet>* consumer;
+ Tagcoll::TagcollConsumer<ITEM, Debtags::Facet>* consumer;
Tagcoll::OpSet<Debtags::Facet> strip(const Tagcoll::OpSet<Debtags::Tag>& tags)
{
@@ -28,18 +29,18 @@
public:
TagToFacet() throw () : consumer(0) {}
- TagToFacet(Tagcoll::TagcollConsumer<Debtags::Package, Debtags::Facet>* consumer) throw () : consumer(consumer) {}
+ TagToFacet(Tagcoll::TagcollConsumer<ITEM, Debtags::Facet>* consumer) throw () : consumer(consumer) {}
- Tagcoll::TagcollConsumer<Debtags::Package, Debtags::Facet>* getConsumer() const throw () { return consumer; }
- void setConsumer(Tagcoll::TagcollConsumer<Debtags::Package, Debtags::Facet>* consumer) throw () { this->consumer = consumer; }
+ Tagcoll::TagcollConsumer<ITEM, Debtags::Facet>* getConsumer() const throw () { return consumer; }
+ void setConsumer(Tagcoll::TagcollConsumer<ITEM, Debtags::Facet>* consumer) throw () { this->consumer = consumer; }
- virtual void consume(const Debtags::Package& item) { consumer->consume(item); }
- virtual void consume(const Debtags::Package& item, const Tagcoll::OpSet<Debtags::Tag>& tags)
+ virtual void consume(const ITEM& item) { consumer->consume(item); }
+ virtual void consume(const ITEM& item, const Tagcoll::OpSet<Debtags::Tag>& tags)
{
consumer->consume(item, strip(tags));
}
- virtual void consume(const Tagcoll::OpSet<Debtags::Package>& items) { consumer->consume(items); }
- virtual void consume(const Tagcoll::OpSet<Debtags::Package>& items, const Tagcoll::OpSet<Debtags::Tag>& tags)
+ virtual void consume(const Tagcoll::OpSet<ITEM>& items) { consumer->consume(items); }
+ virtual void consume(const Tagcoll::OpSet<ITEM>& items, const Tagcoll::OpSet<Debtags::Tag>& tags)
{
consumer->consume(items, strip(tags));
}
Modified: libdebtags1/trunk/debtags/instantiations.cc
==============================================================================
--- libdebtags1/trunk/debtags/instantiations.cc (original)
+++ libdebtags1/trunk/debtags/instantiations.cc Thu Jun 16 19:38:05 2005
@@ -5,6 +5,7 @@
#include <debtags/Tag.h>
#include <debtags/DebtagsSerializer.h>
#include <debtags/TagDB.h>
+#include <debtags/DebtagsSimple.h>
#include <tagcoll/FilterChain.cc>
#include <tagcoll/InputMerger.cc>
@@ -23,6 +24,7 @@
#include <tagcoll/TDBDiskIndex.cc>
#include <tagcoll/TDBReadonlyDiskIndex.cc>
#include <debtags/TagDB.cc>
+#include <debtags/DebtagsSimple.cc>
// Instantiate tagcoll template for Debtags::Package items
@@ -50,5 +52,7 @@
template class TDBReadonlyDiskIndex<Debtags::Package, Debtags::Tag>;
template class Debtags::TagDB<std::string>;
template class Debtags::TagDB<Debtags::Package>;
+template class Debtags::DebtagsSimple<std::string>;
+template class Debtags::DebtagsSimple<Debtags::Package>;
// vim:set ts=4 sw=4:
Modified: libdebtags1/trunk/tests/ex-showpkgs.cc
==============================================================================
--- libdebtags1/trunk/tests/ex-showpkgs.cc (original)
+++ libdebtags1/trunk/tests/ex-showpkgs.cc Thu Jun 16 19:38:05 2005
@@ -15,7 +15,7 @@
// Install the handler for unexpected exceptions
InstallUnexpected installUnexpected;
- DebtagsSimple dt(0);
+ DebtagsSimple<Debtags::Package> dt(0);
TagSet ts;
for (int i = 1; i < argc; i++)