[Debtags-commits] [svn] r884 - in libdebtags1/trunk: debtags swig tests

Enrico Zini debtags-commits@lists.alioth.debian.org
Thu, 16 Jun 2005 18:39:01 +0000


Author: enrico
Date: Thu Jun 16 18:38:59 2005
New Revision: 884

Modified:
   libdebtags1/trunk/debtags/DebtagsSimple.cc
   libdebtags1/trunk/debtags/DebtagsSimple.h
   libdebtags1/trunk/debtags/Environment.cc
   libdebtags1/trunk/debtags/Environment.h
   libdebtags1/trunk/debtags/TagDB.cc
   libdebtags1/trunk/debtags/TagDB.h
   libdebtags1/trunk/debtags/instantiations.cc
   libdebtags1/trunk/swig/libdebtags.i
   libdebtags1/trunk/tests/test-packages.cc
Log:
Templatized TagDB

Modified: libdebtags1/trunk/debtags/DebtagsSimple.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.cc	(original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.cc	Thu Jun 16 18:38:59 2005
@@ -14,7 +14,8 @@
 
 DebtagsSimple::DebtagsSimple(bool editable) :
 		_vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
-		_tagDB(_vocab, _packagedb, editable)
+		_serializer(_vocab, _packagedb),
+		_tagDB(_vocab, _serializer, editable)
 {
 }
 

Modified: libdebtags1/trunk/debtags/DebtagsSimple.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.h	(original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.h	Thu Jun 16 18:38:59 2005
@@ -48,10 +48,10 @@
 	Vocabulary _vocab;
 
 	// Debtags serializer
-	//DebtagsSerializer _serializer;
+	Tagcoll::Serializer<Package, Tag> _serializer;
 	
 	// Debtags database
-	TagDB _tagDB;
+	TagDB<Debtags::Package> _tagDB;
 
 public:
 	DebtagsSimple(bool editable);
@@ -63,8 +63,8 @@
 	Vocabulary& vocabulary() throw () { return _vocab; }
 	const Vocabulary& vocabulary() const throw () { return _vocab; }
 
-	TagDB& tagDB() throw () { return _tagDB; }
-	const TagDB& tagDB() const throw () { return _tagDB; }
+	TagDB<Debtags::Package>& tagDB() throw () { return _tagDB; }
+	const TagDB<Debtags::Package>& tagDB() const throw () { return _tagDB; }
 
 	TagSet getTags(const std::string& package) const;
 	PackageSet getPackages(const Tag& tag) const;

Modified: libdebtags1/trunk/debtags/Environment.cc
==============================================================================
--- libdebtags1/trunk/debtags/Environment.cc	(original)
+++ libdebtags1/trunk/debtags/Environment.cc	Thu Jun 16 18:38:59 2005
@@ -54,7 +54,7 @@
 	Tagcoll::Serializer<Package, Tag> _serializer;
 
 	// Debtags database
-	TagDB _tagDB;
+	TagDB<Debtags::Package> _tagDB;
 
 #if 0
 	// Packages repository
@@ -102,13 +102,13 @@
 	Serializer<Package, Tag>& serializer() throw () { return _serializer; }
 
 	// Return the Debtags Database access class
-	const TagDB& tagDB() const throw ()
+	const TagDB<Debtags::Package>& tagDB() const throw ()
 	{
 		return _tagDB;
 	}
 
 	// Return the Debtags Database access class
-	TagDB& tagDB() throw ()
+	TagDB<Debtags::Package>& tagDB() throw ()
 	{
 		return _tagDB;
 	}
@@ -185,14 +185,14 @@
 		facet_only(facet_only),
 		_vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
 		_serializer(_vocab, _packagedb),
-		_tagDB(_vocab, _packagedb, editable)//,
+		_tagDB(_vocab, _serializer, editable)//,
 		//availableLoaded(false)
 {
 }
 
 bool StandardEnvironment::hasTagDatabase() throw ()
 {
-	return TagDB::hasTagDatabase();
+	return TagDB<Debtags::Package>::hasTagDatabase();
 }
 
 #if 0

Modified: libdebtags1/trunk/debtags/Environment.h
==============================================================================
--- libdebtags1/trunk/debtags/Environment.h	(original)
+++ libdebtags1/trunk/debtags/Environment.h	Thu Jun 16 18:38:59 2005
@@ -8,6 +8,7 @@
 #include <tagcoll/TagcollConsumer.h>
 #include <tagcoll/Serializer.h>
 #include <debtags/Consumer.h>
+#include <debtags/TagDB.h>
 
 class pkgAcquireStatus;
 
@@ -18,7 +19,6 @@
 class PackageDB;
 class Package;
 class PackageMatcher;
-class TagDB;
 class PackageImpl;
 class PackageSet;
 class Maintainer;
@@ -67,8 +67,8 @@
 	virtual Tagcoll::Serializer<Package, Tag>& serializer() throw () = 0;
 
 	// Return the Debtags Database access class
-	virtual const TagDB& tagDB() const throw () = 0;
-	virtual TagDB& tagDB() throw () = 0;
+	virtual const TagDB<Debtags::Package>& tagDB() const throw () = 0;
+	virtual TagDB<Debtags::Package>& tagDB() throw () = 0;
 
 	// Return the Debtags Vocabulary access class
 	virtual const Vocabulary& vocabulary() const throw () = 0;

Modified: libdebtags1/trunk/debtags/TagDB.cc
==============================================================================
--- libdebtags1/trunk/debtags/TagDB.cc	(original)
+++ libdebtags1/trunk/debtags/TagDB.cc	Thu Jun 16 18:38:59 2005
@@ -23,7 +23,6 @@
 #include <debtags/TagDB.h>
 #include <debtags/Paths.h>
 #include <debtags/Vocabulary.h>
-#include <debtags/Environment.h>
 #include <debtags/Package.h>
 
 #include <tagcoll/StdioParserInput.h>
@@ -221,10 +220,11 @@
 }
 
 
-TagDB::TagDB(const Vocabulary& voc, const PackageDB& pdb, bool editable) throw (SystemException, ConsistencyCheckException)
-	: TDBReadonlyDiskIndex<Package, Tag>(Paths::path_tagdb_index, debtagsSerializer),
-			voc(voc), pdb(pdb), debtagsSerializer(voc, pdb)
-
+template<class ITEM>
+TagDB<ITEM>::TagDB(const Vocabulary& voc, Tagcoll::Serializer<ITEM, Tag>& ser, bool editable)
+	throw (SystemException, ConsistencyCheckException)
+	: TDBReadonlyDiskIndex<ITEM, Tag>(Paths::path_tagdb_index, ser),
+			voc(voc)
 {
 	if (rcdir.empty())
 		init_rcdir(editable);
@@ -233,18 +233,20 @@
 	if (access(patchFile.c_str(), F_OK) == 0)
 	{
 		StdioParserInput in(patchFile);
-		PatchList<Package, Tag> patch = TextFormat<Package, Tag>::parsePatch(in, serializer);
+		PatchList<ITEM, Tag> patch = TextFormat<ITEM, Tag>::parsePatch(in, serializer);
 		setChanges(patch);
 	}
 }
 
-TagDB::~TagDB() throw ()
+template<class ITEM>
+TagDB<ITEM>::~TagDB() throw ()
 {
 }
 
-const std::string& TagDB::statedir() throw () { return rcdir; }
+//const std::string& TagDB::statedir() throw () { return rcdir; }
 	
-bool TagDB::hasTagDatabase() throw ()
+template<class ITEM>
+bool TagDB<ITEM>::hasTagDatabase() throw ()
 {
 	if (   access(Paths::path_tagdb, R_OK) == -1
 		|| access(Paths::path_vocabulary, R_OK) == -1)
@@ -260,13 +262,15 @@
 */
 
 
-void TagDB::savePatch()
+template<class ITEM>
+void TagDB<ITEM>::savePatch()
 	throw (FileException, ParserException, SystemException)
 {
 	savePatch(getChanges());
 }
 
-void TagDB::savePatch(const PatchList<Debtags::Package, Debtags::Tag>& patch)
+template<class ITEM>
+void TagDB<ITEM>::savePatch(const PatchList<ITEM, Debtags::Tag>& patch)
 	throw (FileException, ParserException, SystemException)
 {
 	string patchFile = rcdir + "/patch";
@@ -281,7 +285,7 @@
 		if (out == 0)
 			throw SystemException(errno, "Can't write to " + patchFile);
 		
-		TextFormat<Package, Tag>::outputPatch(patch, serializer, out);
+		TextFormat<ITEM, Tag>::outputPatch(patch, serializer, out);
 
 		fclose(out);
 	} catch (Exception& e) {
@@ -291,15 +295,17 @@
 	}
 }
 
-void TagDB::sendPatch()
+template<class ITEM>
+void TagDB<ITEM>::sendPatch()
 	throw (FileException, ParserException, SystemException, ConsistencyCheckException)
 {
-	PatchList<Package, Tag> patch = getChanges();
+	PatchList<ITEM, Tag> patch = getChanges();
 	if (!patch.empty())
 		sendPatch(getChanges());
 }
 
-void TagDB::sendPatch(const PatchList<Debtags::Package, Debtags::Tag>& patch)
+template<class ITEM>
+void TagDB<ITEM>::sendPatch(const PatchList<ITEM, Debtags::Tag>& patch)
 	throw (FileException, ParserException, SystemException, ConsistencyCheckException)
 {
 	static const char* cmd = "/usr/sbin/sendmail -t";
@@ -323,7 +329,7 @@
 			"Content-Disposition: inline\n\n"
 			"-- DEBTAGS DIFF V0.1 --\n", udata->pw_name);
 
-	TextFormat<Package, Tag>::outputPatch(patch, serializer, out);
+	TextFormat<ITEM, Tag>::outputPatch(patch, serializer, out);
 
 	fprintf(out, "\n--9amGYk9869ThD9tj\n");
 
@@ -407,24 +413,29 @@
 }
 #endif
 
-void TagDB::outputSystem(TagcollConsumer<std::string, std::string>& cons)
+template<class ITEM>
+void TagDB<ITEM>::outputSystem(TagcollConsumer<std::string, std::string>& cons)
 {
 	StdioParserInput in(Paths::path_tagdb);
 	Serializer<string, string> ser;
 	TextFormat<string, string>::parse(in, ser, cons);
 }
 
-void TagDB::outputSystem(TagcollConsumer<std::string, Tag>& cons)
+/*
+template<class ITEM>
+void TagDB<ITEM>::outputSystem(TagcollConsumer<std::string, Tag>& cons)
 {
 	StdioParserInput in(Paths::path_tagdb);
 	Serializer<string, Tag> ser(voc);
 	TextFormat<string, Tag>::parse(in, ser, cons);
 }
+*/
 
-void TagDB::outputSystem(TagcollConsumer<Package, Tag>& cons)
+template<class ITEM>
+void TagDB<ITEM>::outputSystem(TagcollConsumer<ITEM, Tag>& cons)
 {
 	StdioParserInput in(Paths::path_tagdb);
-	TextFormat<Package, Tag>::parse(in, serializer, cons);
+	TextFormat<ITEM, Tag>::parse(in, serializer, cons);
 }
 
 #if 0
@@ -500,7 +511,8 @@
 }
 #endif
 
-void TagDB::outputPatched(TagcollConsumer<std::string, std::string>& cons)
+template<class ITEM>
+void TagDB<ITEM>::outputPatched(TagcollConsumer<std::string, std::string>& cons)
 {
 	const string patchFile = rcdir + "/patch";
 	Serializer<string, string> ser;
@@ -517,7 +529,9 @@
 		outputSystem(cons);
 }
 
-void TagDB::outputPatched(TagcollConsumer<std::string, Debtags::Tag>& cons)
+/*
+template<class ITEM>
+void TagDB<ITEM>::outputPatched(TagcollConsumer<std::string, Debtags::Tag>& cons)
 {
 	const string patchFile = rcdir + "/patch";
 	Serializer<string, Tag> ser(voc);
@@ -533,19 +547,21 @@
 	} else
 		outputSystem(cons);
 }
+*/
 
-void TagDB::outputPatched(TagcollConsumer<Debtags::Package, Debtags::Tag>& cons)
+template<class ITEM>
+void TagDB<ITEM>::outputPatched(TagcollConsumer<ITEM, Debtags::Tag>& cons)
 {
 	string patchFile = rcdir + "/patch";
 	if (access(patchFile.c_str(), F_OK) == 0)
 	{
 		StdioParserInput inpatch(patchFile);
-		PatchList<Package, Tag> patch = TextFormat<Package, Tag>::parsePatch(inpatch, serializer);
+		PatchList<ITEM, Tag> patch = TextFormat<ITEM, Tag>::parsePatch(inpatch, serializer);
 
 		patch.setConsumer(&cons);
 
 		StdioParserInput in(Paths::path_tagdb);
-		TextFormat<Package, Tag>::parse(in, serializer, patch);
+		TextFormat<ITEM, Tag>::parse(in, serializer, patch);
 	} else
 		outputSystem(cons);
 }

Modified: libdebtags1/trunk/debtags/TagDB.h
==============================================================================
--- libdebtags1/trunk/debtags/TagDB.h	(original)
+++ libdebtags1/trunk/debtags/TagDB.h	Thu Jun 16 18:38:59 2005
@@ -43,12 +43,11 @@
  * TadDB provides read access to the local Debtags tag database via its various
  * output* methods.
  */
-class TagDB : public TDBReadonlyDiskIndex<Package, Tag>
+template<class ITEM>
+class TagDB : public TDBReadonlyDiskIndex<ITEM, Tag>
 {
 protected:
 	const Vocabulary& voc;
-	const PackageDB& pdb;
-	Tagcoll::Serializer<Package, Tag> debtagsSerializer;
 
 public:
 	/** Create a new TagDB
@@ -59,7 +58,7 @@
 	 *        If editable is true, then the local state directory will be
 	 *        created when the object is instantiated
 	 */
-	TagDB(const Vocabulary& voc, const PackageDB& pdb, bool editable = false)
+	TagDB(const Vocabulary& voc, Tagcoll::Serializer<ITEM, Tag>& ser, bool editable = false)
 		throw (SystemException, ConsistencyCheckException);
 	~TagDB() throw ();
 
@@ -90,7 +89,7 @@
 	 * Save in the state storage directory a patch to turn the system database
 	 * into the collection given
 	 */
-	void savePatch(const PatchList<Package, Tag>& patch)
+	void savePatch(const PatchList<ITEM, Tag>& patch)
 		throw (FileException, ParserException, SystemException);
 
 	/**
@@ -103,42 +102,21 @@
 	/**
 	 * Send the given patch to the central archive
 	 */
-	void sendPatch(const PatchList<Package, Tag>& patch)
+	void sendPatch(const PatchList<ITEM, Tag>& patch)
 		throw (FileException, ParserException, SystemException, ConsistencyCheckException);
 	
 
-	/// Return the full path of the state storage directory (usually ~/.debtags)
-	static const std::string& statedir() throw ();
-
-	/// Returns the path to the current tag database (usually /var/lib/debtags/package-tags)
-	//static const std::string& path_tagdb() throw ();
-
-	/// Returns the path to the current indexed tag database (usually /var/lib/debtags/package-tags.idx)
-	//static const std::string& path_tagdb_idx() throw ();
-	
-	/// Check if the tag database has been created (i.e. if something
-	/// equivalend to debtags update has been run)
-	static bool hasTagDatabase() throw ();
-
-#if 0
-	/** Output the database in the given file to a TagcollConsumer
-	 * @note The collection is sent to 'cons' without merging repeated items
+	/**
+	 * Return the full path of the state storage directory (usually ~/.debtags)
 	 */
-	static void outputFile(const std::string& name, TagcollConsumer<std::string, std::string>& cons, bool facet_only = true)
-		throw (FileException, ParserException);
+	//static const std::string& statedir() throw ();
 
-	/** Output the database in the given file to a TagcollConsumer
-	 * @note The collection is sent to 'cons' without merging repeated items
+	/**
+	 * Check if the tag database has been created (i.e. if something
+	 * equivalend to debtags update has been run)
 	 */
-	static void outputFile(const std::string& name, TagcollConsumer<std::string, Tag>& cons, bool facet_only = true)
-		throw (FileException, ParserException);
+	static bool hasTagDatabase() throw ();
 
-	/** Output the database in the given file to a TagcollConsumer
-	 * @note The collection is sent to 'cons' without merging repeated items
-	 */
-	static void outputFile(const std::string& name, TagcollConsumer<Package, Tag>& cons, bool facet_only = true)
-		throw (FileException, ParserException);
-#endif
 
 	/** Output the current Debian tags database to a TagcollConsumer
 	 * @note The collection is sent to 'cons' without merging repeated items
@@ -148,12 +126,12 @@
 	/** Output the current Debian tags database to a TagcollConsumer
 	 * @note The collection is sent to 'cons' without merging repeated items
 	 */
-	void outputSystem(TagcollConsumer<std::string, Tag>& cons);
+	//void outputSystem(TagcollConsumer<std::string, Tag>& cons);
 
 	/** Output the current Debian tags database to a TagcollConsumer
 	 * @note The collection is sent to 'cons' without merging repeated items
 	 */
-	void outputSystem(TagcollConsumer<Package, Tag>& cons);
+	void outputSystem(TagcollConsumer<ITEM, Tag>& cons);
 
 	/**
 	 * Output the current Debian tags database, patched with local patch, to a TagcollConsumer
@@ -165,21 +143,18 @@
 	 * Output the current Debian tags database, patched with local patch, to a TagcollConsumer
 	 * @note The collection is sent to 'cons' without merging repeated items
 	 */
-	void outputPatched(TagcollConsumer<std::string, Tag>& cons);
+	//void outputPatched(TagcollConsumer<std::string, Tag>& cons);
 
 	/**
 	 * Output the current Debian tags database, patched with local patch, to a TagcollConsumer
 	 * @note The collection is sent to 'cons' without merging repeated items
 	 */
-	void outputPatched(TagcollConsumer<Package, Tag>& cons);
-
-	//using TDBReadonlyDiskIndex<Package, Tag>::getItems;
-	//using TDBReadonlyDiskIndex<Package, Tag>::getTags;
+	void outputPatched(TagcollConsumer<ITEM, Tag>& cons);
 
 	// Oh, dear gcc, why, why, why do I have to do this?
-	OpSet<Package> getItems(const OpSet<Tag>& tagset) const throw ()
+	OpSet<ITEM> getItems(const OpSet<Tag>& tagset) const throw ()
 	{
-		return TDBReadonlyDiskIndex<Package, Tag>::getItems(tagset);
+		return TDBReadonlyDiskIndex<ITEM, Tag>::getItems(tagset);
 	}
 };
 

Modified: libdebtags1/trunk/debtags/instantiations.cc
==============================================================================
--- libdebtags1/trunk/debtags/instantiations.cc	(original)
+++ libdebtags1/trunk/debtags/instantiations.cc	Thu Jun 16 18:38:59 2005
@@ -4,6 +4,7 @@
 #include <debtags/Maintainer.h>
 #include <debtags/Tag.h>
 #include <debtags/DebtagsSerializer.h>
+#include <debtags/TagDB.h>
 
 #include <tagcoll/FilterChain.cc>
 #include <tagcoll/InputMerger.cc>
@@ -21,6 +22,7 @@
 #include <tagcoll/DiskIndex.cc>
 #include <tagcoll/TDBDiskIndex.cc>
 #include <tagcoll/TDBReadonlyDiskIndex.cc>
+#include <debtags/TagDB.cc>
 
 // Instantiate tagcoll template for Debtags::Package items
 
@@ -46,5 +48,7 @@
 template class DiskIndex<Debtags::Package, Debtags::Tag>;
 template class TDBDiskIndex<Debtags::Package, Debtags::Tag>;
 template class TDBReadonlyDiskIndex<Debtags::Package, Debtags::Tag>;
+template class Debtags::TagDB<std::string>;
+template class Debtags::TagDB<Debtags::Package>;
 
 // vim:set ts=4 sw=4:

Modified: libdebtags1/trunk/swig/libdebtags.i
==============================================================================
--- libdebtags1/trunk/swig/libdebtags.i	(original)
+++ libdebtags1/trunk/swig/libdebtags.i	Thu Jun 16 18:38:59 2005
@@ -93,6 +93,7 @@
 %include "debtags/TagSet.h"
 %include "debtags/TagDB.h"
 %include "debtags/DebtagsSimple.h"
+%include "debtags/DebtagsSerializer.h"
 %include "debtags/PackageSet.h"
 %include "debtags/PackageDB.h"
 

Modified: libdebtags1/trunk/tests/test-packages.cc
==============================================================================
--- libdebtags1/trunk/tests/test-packages.cc	(original)
+++ libdebtags1/trunk/tests/test-packages.cc	Thu Jun 16 18:38:59 2005
@@ -150,7 +150,7 @@
 		}
 
 		// Compare two methods of getting tags
-		TagDB first = Debtags::Environment::get().tagDB();
+		TagDB<Debtags::Package> first = Debtags::Environment::get().tagDB();
 		InputMerger<Package, Tag> second;
 		first.outputPatched(second);