[Debtags-commits] [svn] r883 - in libdebtags1/trunk: . debian debtags swig
Enrico Zini
debtags-commits@lists.alioth.debian.org
Thu, 16 Jun 2005 13:51:08 +0000
Author: enrico
Date: Thu Jun 16 13:51:07 2005
New Revision: 883
Modified:
libdebtags1/trunk/TODO
libdebtags1/trunk/configure.ac
libdebtags1/trunk/debian/changelog
libdebtags1/trunk/debtags/DebtagsFilters.cc
libdebtags1/trunk/debtags/DebtagsFilters.h
libdebtags1/trunk/debtags/DebtagsSerializer.cc
libdebtags1/trunk/debtags/DebtagsSerializer.h
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/Update.cc
libdebtags1/trunk/debtags/instantiations.cc
libdebtags1/trunk/swig/libdebtags.i
Log:
Unified all the various serializers using template specialization
Modified: libdebtags1/trunk/TODO
==============================================================================
--- libdebtags1/trunk/TODO (original)
+++ libdebtags1/trunk/TODO Thu Jun 16 13:51:07 2005
@@ -1,5 +1,8 @@
*** TODO for libdebtags
+ - Generalise everything on the package type, allowing to use both a string and
+ a Package
+
The Debtags::Matcher is a good candidate for this one, having the same
implementation like the match function. With this the code in
TagSet::getFiltered could be implemented using a the copy_if() algorithm.
Modified: libdebtags1/trunk/configure.ac
==============================================================================
--- libdebtags1/trunk/configure.ac (original)
+++ libdebtags1/trunk/configure.ac Thu Jun 16 13:51:07 2005
@@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT(libdebtags1, 1.0.1, [enrico@debian.org])
+AC_INIT(libdebtags1, 1.0.2, [enrico@debian.org])
AC_CONFIG_SRCDIR([configure.ac])
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)
Modified: libdebtags1/trunk/debian/changelog
==============================================================================
--- libdebtags1/trunk/debian/changelog (original)
+++ libdebtags1/trunk/debian/changelog Thu Jun 16 13:51:07 2005
@@ -1,3 +1,13 @@
+libdebtags1 (1.0.2) experimental; urgency=low
+
+ * Reenabled outputSystem and outputPatched without conversion to Package or
+ Tag
+ * Fixed a segfault in DebtagsSimple when asking for the tags of non-existing
+ packages
+ * Renamed Debtags.h in DebtagsSimple.h
+
+ -- Enrico Zini <enrico@debian.org> Sat, 11 Jun 2005 18:16:22 +0200
+
libdebtags1 (1.0.1) experimental; urgency=low
* Improved the simplified interface
Modified: libdebtags1/trunk/debtags/DebtagsFilters.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsFilters.cc (original)
+++ libdebtags1/trunk/debtags/DebtagsFilters.cc Thu Jun 16 13:51:07 2005
@@ -13,7 +13,8 @@
using namespace Debtags;
ExpressionFilter::ExpressionFilter(const std::string& expression) throw (ConsistencyCheckException)
- : ser(Debtags::Environment::get().serializer()), expr(0)
+ : ser(Debtags::Environment::get().vocabulary(),
+ Debtags::Environment::get().packageDB()), expr(0)
{
expr = Tagcoll::TagexprParser::instance()->parse(expression);
if (expr == 0)
@@ -22,7 +23,9 @@
ExpressionFilter::ExpressionFilter(const std::string& expression, Tagcoll::TagcollConsumer<Package, Tag>* cons)
throw (ConsistencyCheckException)
- : Tagcoll::TagcollFilter<Package, Tag>(cons), ser(Debtags::Environment::get().serializer()), expr(0)
+ : Tagcoll::TagcollFilter<Package, Tag>(cons),
+ ser(Debtags::Environment::get().vocabulary(),
+ Debtags::Environment::get().packageDB()), expr(0)
{
expr = Tagcoll::TagexprParser::instance()->parse(expression);
if (expr == 0)
@@ -42,7 +45,7 @@
}
void ExpressionFilter::consume(const Package& item, const Tagcoll::OpSet<Tag>& tags) throw ()
{
- if (expr->eval(ser.tagToString(tags)))
+ if (expr->eval(ser.tagsToStrings(tags)))
consumer->consume(item, tags);
}
void ExpressionFilter::consume(const Tagcoll::OpSet<Debtags::Package>& items) throw ()
@@ -52,7 +55,7 @@
}
void ExpressionFilter::consume(const Tagcoll::OpSet<Debtags::Package>& items, const Tagcoll::OpSet<Debtags::Tag>& tags) throw ()
{
- if (expr->eval(ser.tagToString(tags)))
+ if (expr->eval(ser.tagsToStrings(tags)))
consumer->consume(items, tags);
}
Modified: libdebtags1/trunk/debtags/DebtagsFilters.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsFilters.h (original)
+++ libdebtags1/trunk/debtags/DebtagsFilters.h Thu Jun 16 13:51:07 2005
@@ -25,6 +25,7 @@
#include <tagcoll/Exception.h>
#include <tagcoll/TagcollFilter.h>
+#include <debtags/DebtagsSerializer.h>
#include <string>
namespace Tagcoll
@@ -34,7 +35,6 @@
namespace Debtags
{
-class DebtagsSerializer;
class Package;
class Tag;
@@ -44,7 +44,7 @@
class ExpressionFilter : public Tagcoll::TagcollFilter<Package, Tag>
{
protected:
- Debtags::DebtagsSerializer& ser;
+ Tagcoll::Serializer<Package, Tag> ser;
Tagcoll::Tagexpr* expr;
public:
Modified: libdebtags1/trunk/debtags/DebtagsSerializer.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSerializer.cc (original)
+++ libdebtags1/trunk/debtags/DebtagsSerializer.cc Thu Jun 16 13:51:07 2005
@@ -29,19 +29,22 @@
using namespace std;
using namespace Debtags;
-std::string DebtagsSerializer::tagToString(const Tag& tag) throw ()
+namespace Tagcoll
+{
+
+std::string Serializer<Debtags::Package, Debtags::Tag>::tagToString(const Debtags::Tag& tag) throw ()
{
return tag.fullname();
}
-std::string DebtagsSerializer::itemToString(const Package& item) throw ()
+std::string Serializer<Debtags::Package, Debtags::Tag>::itemToString(const Debtags::Package& item) throw ()
{
return item.name();
}
-Debtags::Tag DebtagsSerializer::stringToTag(const std::string& tag) throw ()
+Debtags::Tag Serializer<Debtags::Package, Debtags::Tag>::stringToTag(const std::string& tag) throw ()
{
- Tag t = voc.getTag(tag);
+ Debtags::Tag t = voc.getTag(tag);
if (!t)
{
//fprintf(stderr, "DebtagsSerializer::stringToTag: string %.*s gave null Tag.\n", PFSTR(tag));
@@ -50,7 +53,7 @@
return t;
}
-Package DebtagsSerializer::stringToItem(const std::string& item) throw ()
+Debtags::Package Serializer<Debtags::Package, Debtags::Tag>::stringToItem(const std::string& item) throw ()
{
return pkg.getPackage(item);
#if 0
@@ -61,15 +64,105 @@
#endif
}
-std::string DebtagsPartialSerializer::tagToString(const Tag& tag) throw ()
+OpSet<std::string> Serializer<Package, Tag>::tagsToStrings(const OpSet<Tag>& tags) throw ()
+{
+ OpSet<std::string> res;
+
+ for (OpSet<Tag>::const_iterator i = tags.begin();
+ i != tags.end(); i++)
+ if (*i != Tag())
+ res += tagToString(*i);
+
+ return res;
+}
+
+OpSet<std::string> Serializer<Package, Tag>::itemsToStrings(const OpSet<Package>& items) throw ()
+{
+ OpSet<std::string> res;
+
+ for (OpSet<Package>::const_iterator i = items.begin();
+ i != items.end(); i++)
+ if (*i != Package())
+ res += itemToString(*i);
+
+ return res;
+}
+
+OpSet<Tag> Serializer<Package, Tag>::stringsToTags(const OpSet<std::string>& tags) throw ()
+{
+ OpSet<Tag> res;
+
+ for (OpSet<std::string>::const_iterator i = tags.begin();
+ i != tags.end(); i++)
+ {
+ Tag t = stringToTag(*i);
+ if (t != Tag())
+ res += t;
+ }
+
+ return res;
+}
+
+OpSet<Package> Serializer<Package, Tag>::stringsToItems(const OpSet<std::string>& items) throw ()
+{
+ OpSet<Package> res;
+
+ for (OpSet<std::string>::const_iterator i = items.begin();
+ i != items.end(); i++)
+ {
+ Package it = stringToItem(*i);
+ if (it != Package())
+ res += it;
+ }
+
+ return res;
+}
+
+
+std::string Serializer<string, Debtags::Tag>::tagToString(const Debtags::Tag& tag) throw ()
{
- return ser.tagToString(tag);
+ return tag.fullname();
}
-Debtags::Tag DebtagsPartialSerializer::stringToTag(const std::string& tag) throw ()
+Debtags::Tag Serializer<string, Debtags::Tag>::stringToTag(const std::string& tag) throw ()
{
- return ser.stringToTag(tag);
+ Debtags::Tag t = voc.getTag(tag);
+ if (!t)
+ {
+ //fprintf(stderr, "DebtagsSerializer::stringToTag: string %.*s gave null Tag.\n", PFSTR(tag));
+ return voc.getTag("special::invalid-tag");
+ }
+ return t;
}
+OpSet<std::string> Serializer<string, Debtags::Tag>::tagsToStrings(const OpSet<Debtags::Tag>& tags) throw ()
+{
+ OpSet<std::string> res;
+
+ for (OpSet<Debtags::Tag>::const_iterator i = tags.begin();
+ i != tags.end(); i++)
+ if (*i != Debtags::Tag())
+ res += tagToString(*i);
+
+ return res;
+}
+
+OpSet<Debtags::Tag> Serializer<string, Debtags::Tag>::stringsToTags(const OpSet<std::string>& tags) throw ()
+{
+ OpSet<Debtags::Tag> res;
+
+ for (OpSet<std::string>::const_iterator i = tags.begin();
+ i != tags.end(); i++)
+ {
+ Debtags::Tag t = stringToTag(*i);
+ if (t != Debtags::Tag())
+ res += t;
+ }
+
+ return res;
+}
+
+};
+
// vim:set ts=4 sw=4:
Modified: libdebtags1/trunk/debtags/DebtagsSerializer.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSerializer.h (original)
+++ libdebtags1/trunk/debtags/DebtagsSerializer.h Thu Jun 16 13:51:07 2005
@@ -32,90 +32,118 @@
class Tag;
class Vocabulary;
class PackageDB;
+};
+
+namespace Tagcoll
+{
/**
* Serialize Packages and Tags to and from Strings
*/
-class DebtagsSerializer : public Tagcoll::Serializer<Package, Tag>
+template<>
+class Serializer<Debtags::Package, Debtags::Tag>
{
protected:
- const Vocabulary& voc;
- const PackageDB& pkg;
+ const Debtags::Vocabulary& voc;
+ const Debtags::PackageDB& pkg;
public:
- DebtagsSerializer(const Vocabulary& voc, const PackageDB& pkg) throw () : voc(voc), pkg(pkg) {}
+ Serializer(const Debtags::Vocabulary& voc, const Debtags::PackageDB& pkg) throw ()
+ : voc(voc), pkg(pkg) {}
/**
* Convert a TAG to a string
*/
- virtual std::string tagToString(const Tag& tag) throw ();
+ std::string tagToString(const Debtags::Tag& tag) throw ();
/**
* Convert an ITEM to a string
*/
- virtual std::string itemToString(const Package& item) throw ();
+ std::string itemToString(const Debtags::Package& item) throw ();
/**
* Convert a string to a TAG
*/
- virtual Tag stringToTag(const std::string& tag) throw ();
+ Debtags::Tag stringToTag(const std::string& tag) throw ();
/**
* Convert a string to an ITEM
*/
- virtual Package stringToItem(const std::string& item) throw ();
+ Debtags::Package stringToItem(const std::string& item) throw ();
/**
* Convert TAGs to strings
*/
- virtual Tagcoll::OpSet<std::string> tagToString(const Tagcoll::OpSet<Tag>& tag) throw ()
- {
- return Tagcoll::Serializer<Package, Tag>::tagToString(tag);
- }
+ OpSet<std::string> tagsToStrings(const OpSet<Debtags::Tag>& tag) throw ();
+
+ /**
+ * Convert ITEMs to strings
+ */
+ OpSet<std::string> itemsToStrings(const OpSet<Debtags::Package>& item) throw ();
- friend class DebtagsPartialSerializer;
+ /**
+ * Convert strings to TAGs
+ */
+ OpSet<Debtags::Tag> stringsToTags(const OpSet<std::string>& tag) throw ();
+
+ /**
+ * Convert strings to ITEMs
+ */
+ OpSet<Debtags::Package> stringsToItems(const OpSet<std::string>& item) throw ();
};
/**
* Serialize only Tags to and from Strings
*/
-class DebtagsPartialSerializer : public Tagcoll::Serializer<std::string, Tag>
+template<>
+class Serializer<std::string, Debtags::Tag>
{
protected:
- Tagcoll::Serializer<Debtags::Package, Tag>& ser;
+ const Debtags::Vocabulary& voc;
public:
- DebtagsPartialSerializer(Tagcoll::Serializer<Debtags::Package, Tag>& ser) throw ()
- : ser(ser) {}
+ Serializer(const Debtags::Vocabulary& voc) throw ()
+ : voc(voc) {}
/**
* Convert a TAG to a string
*/
- virtual std::string tagToString(const Tag& tag) throw ();
+ std::string tagToString(const Debtags::Tag& tag) throw ();
/**
* Convert an ITEM to a string
*/
- virtual std::string itemToString(const std::string& item) throw () { return item; }
+ std::string itemToString(const std::string& item) throw () { return item; }
/**
* Convert a string to a TAG
*/
- virtual Tag stringToTag(const std::string& tag) throw ();
+ Debtags::Tag stringToTag(const std::string& tag) throw ();
/**
* Convert a string to an ITEM
*/
- virtual std::string stringToItem(const std::string& item) throw () { return item; }
+ std::string stringToItem(const std::string& item) throw () { return item; }
/**
* Convert TAGs to strings
*/
- virtual Tagcoll::OpSet<std::string> tagToString(const Tagcoll::OpSet<Tag>& tag) throw ()
- {
- return Tagcoll::Serializer<std::string, Tag>::tagToString(tag);
- }
+ OpSet<std::string> tagsToStrings(const OpSet<Debtags::Tag>& tag) throw ();
+ /**
+ * Convert ITEMs to strings
+ */
+ OpSet<std::string> itemsToStrings(const OpSet<std::string>& items) throw () { return items; }
+
+ /**
+ * Convert strings to TAGs
+ */
+ OpSet<Debtags::Tag> stringsToTags(const OpSet<std::string>& tags) throw ();
+
+ /**
+ * Convert strings to ITEMs
+ */
+ OpSet<std::string> stringsToItems(const OpSet<std::string>& items) throw () { return items; }
};
};
Modified: libdebtags1/trunk/debtags/DebtagsSimple.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.cc (original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.cc Thu Jun 16 13:51:07 2005
@@ -14,8 +14,7 @@
DebtagsSimple::DebtagsSimple(bool editable) :
_vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
- _serializer(_vocab, _packagedb),
- _tagDB(_serializer, editable)
+ _tagDB(_vocab, _packagedb, editable)
{
}
Modified: libdebtags1/trunk/debtags/DebtagsSimple.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.h (original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.h Thu Jun 16 13:51:07 2005
@@ -48,7 +48,7 @@
Vocabulary _vocab;
// Debtags serializer
- DebtagsSerializer _serializer;
+ //DebtagsSerializer _serializer;
// Debtags database
TagDB _tagDB;
Modified: libdebtags1/trunk/debtags/Environment.cc
==============================================================================
--- libdebtags1/trunk/debtags/Environment.cc (original)
+++ libdebtags1/trunk/debtags/Environment.cc Thu Jun 16 13:51:07 2005
@@ -51,7 +51,7 @@
Vocabulary _vocab;
// Serializer
- DebtagsSerializer _serializer;
+ Tagcoll::Serializer<Package, Tag> _serializer;
// Debtags database
TagDB _tagDB;
@@ -99,7 +99,7 @@
const PackageDB& packageDB() const throw () { return _packagedb; }
// Return the Debtags serializer
- DebtagsSerializer& serializer() throw () { return _serializer; }
+ Serializer<Package, Tag>& serializer() throw () { return _serializer; }
// Return the Debtags Database access class
const TagDB& tagDB() const throw ()
@@ -185,7 +185,7 @@
facet_only(facet_only),
_vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
_serializer(_vocab, _packagedb),
- _tagDB(_serializer, editable)//,
+ _tagDB(_vocab, _packagedb, editable)//,
//availableLoaded(false)
{
}
Modified: libdebtags1/trunk/debtags/Environment.h
==============================================================================
--- libdebtags1/trunk/debtags/Environment.h (original)
+++ libdebtags1/trunk/debtags/Environment.h Thu Jun 16 13:51:07 2005
@@ -6,6 +6,7 @@
#include <tagcoll/Exception.h>
#include <tagcoll/ParserBase.h>
#include <tagcoll/TagcollConsumer.h>
+#include <tagcoll/Serializer.h>
#include <debtags/Consumer.h>
class pkgAcquireStatus;
@@ -18,7 +19,6 @@
class Package;
class PackageMatcher;
class TagDB;
-class DebtagsSerializer;
class PackageImpl;
class PackageSet;
class Maintainer;
@@ -64,7 +64,7 @@
virtual const PackageDB& packageDB() const throw () = 0;
// Return the Debtags serializer
- virtual DebtagsSerializer& serializer() throw () = 0;
+ virtual Tagcoll::Serializer<Package, Tag>& serializer() throw () = 0;
// Return the Debtags Database access class
virtual const TagDB& tagDB() const throw () = 0;
Modified: libdebtags1/trunk/debtags/TagDB.cc
==============================================================================
--- libdebtags1/trunk/debtags/TagDB.cc (original)
+++ libdebtags1/trunk/debtags/TagDB.cc Thu Jun 16 13:51:07 2005
@@ -221,8 +221,9 @@
}
-TagDB::TagDB(DebtagsSerializer& serializer, bool editable) throw (SystemException, ConsistencyCheckException)
- : TDBReadonlyDiskIndex<Package, Tag>(Paths::path_tagdb_index, serializer)
+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)
{
if (rcdir.empty())
@@ -409,14 +410,14 @@
void TagDB::outputSystem(TagcollConsumer<std::string, std::string>& cons)
{
StdioParserInput in(Paths::path_tagdb);
- TrivialSerializer ser;
+ Serializer<string, string> ser;
TextFormat<string, string>::parse(in, ser, cons);
}
void TagDB::outputSystem(TagcollConsumer<std::string, Tag>& cons)
{
StdioParserInput in(Paths::path_tagdb);
- DebtagsPartialSerializer ser(serializer);
+ Serializer<string, Tag> ser(voc);
TextFormat<string, Tag>::parse(in, ser, cons);
}
@@ -502,7 +503,7 @@
void TagDB::outputPatched(TagcollConsumer<std::string, std::string>& cons)
{
const string patchFile = rcdir + "/patch";
- TrivialSerializer ser;
+ Serializer<string, string> ser;
if (access(patchFile.c_str(), F_OK) == 0)
{
StdioParserInput inpatch(patchFile);
@@ -519,7 +520,7 @@
void TagDB::outputPatched(TagcollConsumer<std::string, Debtags::Tag>& cons)
{
const string patchFile = rcdir + "/patch";
- DebtagsPartialSerializer ser(serializer);
+ Serializer<string, Tag> ser(voc);
if (access(patchFile.c_str(), F_OK) == 0)
{
StdioParserInput inpatch(patchFile);
Modified: libdebtags1/trunk/debtags/TagDB.h
==============================================================================
--- libdebtags1/trunk/debtags/TagDB.h (original)
+++ libdebtags1/trunk/debtags/TagDB.h Thu Jun 16 13:51:07 2005
@@ -45,6 +45,11 @@
*/
class TagDB : public TDBReadonlyDiskIndex<Package, Tag>
{
+protected:
+ const Vocabulary& voc;
+ const PackageDB& pdb;
+ Tagcoll::Serializer<Package, Tag> debtagsSerializer;
+
public:
/** Create a new TagDB
*
@@ -54,7 +59,8 @@
* If editable is true, then the local state directory will be
* created when the object is instantiated
*/
- TagDB(DebtagsSerializer& serializer, bool editable = false) throw (SystemException, ConsistencyCheckException);
+ TagDB(const Vocabulary& voc, const PackageDB& pdb, bool editable = false)
+ throw (SystemException, ConsistencyCheckException);
~TagDB() throw ();
/**
Modified: libdebtags1/trunk/debtags/Update.cc
==============================================================================
--- libdebtags1/trunk/debtags/Update.cc (original)
+++ libdebtags1/trunk/debtags/Update.cc Thu Jun 16 13:51:07 2005
@@ -217,7 +217,7 @@
filters.setConsumer(&merger);
// Read the collection
- TrivialSerializer serializer;
+ Serializer<string, string> serializer;
TextFormat<string, string>::parse(in, serializer, filters);
// Add packages only in APT as untagged
@@ -622,7 +622,7 @@
string tmpdbidx = tagdbidx + ".tmp";
FILE* out = fopen(tmpdb.c_str(), "wt");
if (!out) throw FileException(errno, "opening " + tmpdb);
- TrivialSerializer serializer;
+ Serializer<string, string> serializer;
TextFormat<string, string> writer(serializer, out);
grouper.output(writer);
fclose(out);
Modified: libdebtags1/trunk/debtags/instantiations.cc
==============================================================================
--- libdebtags1/trunk/debtags/instantiations.cc (original)
+++ libdebtags1/trunk/debtags/instantiations.cc Thu Jun 16 13:51:07 2005
@@ -3,6 +3,7 @@
#include <debtags/Package.h>
#include <debtags/Maintainer.h>
#include <debtags/Tag.h>
+#include <debtags/DebtagsSerializer.h>
#include <tagcoll/FilterChain.cc>
#include <tagcoll/InputMerger.cc>
Modified: libdebtags1/trunk/swig/libdebtags.i
==============================================================================
--- libdebtags1/trunk/swig/libdebtags.i (original)
+++ libdebtags1/trunk/swig/libdebtags.i Thu Jun 16 13:51:07 2005
@@ -91,7 +91,6 @@
%include "debtags/Vocabulary.h"
%include "debtags/TagSet.h"
-%include "debtags/DebtagsSerializer.h"
%include "debtags/TagDB.h"
%include "debtags/DebtagsSimple.h"
%include "debtags/PackageSet.h"