[Debtags-commits] [svn] r1565 - in tagcoll/trunk: . tagcoll tests
tools
Enrico Zini
enrico at costa.debian.org
Sat Feb 11 14:14:46 UTC 2006
Author: enrico
Date: Sat Feb 11 14:14:44 2006
New Revision: 1565
Added:
tagcoll/trunk/tagcoll/BasicDiskIndex.cc
tagcoll/trunk/tagcoll/BasicDiskIndex.h
Removed:
tagcoll/trunk/tools/Index.cc
tagcoll/trunk/tools/Index.h
Modified:
tagcoll/trunk/ (props changed)
tagcoll/trunk/tagcoll/IntDiskIndex.cc
tagcoll/trunk/tagcoll/ItemGrouper.h
tagcoll/trunk/tagcoll/Makefile.am
tagcoll/trunk/tests/test-tdbdiskindex.cc
tagcoll/trunk/tests/test-tdbreadonlydiskindex.cc
tagcoll/trunk/tests/test-textformat.cc
tagcoll/trunk/tools/Makefile.am
tagcoll/trunk/tools/tagidx.cc
Log:
r7225 at viaza: enrico | 2006-02-11 15:03:43 +0100
More tests needed fixing the Converter usage
Moved tools/Index into tagcoll/
Implemented tagidx cat
Modified: tagcoll/trunk/tagcoll/IntDiskIndex.cc
==============================================================================
--- tagcoll/trunk/tagcoll/IntDiskIndex.cc (original)
+++ tagcoll/trunk/tagcoll/IntDiskIndex.cc Sat Feb 11 14:14:44 2006
@@ -158,7 +158,7 @@
#include <iostream>
-void outts(const OpSet<string>& s)
+static void outts(const OpSet<string>& s)
{
for (OpSet<string>::const_iterator i = s.begin(); i != s.end(); i++)
if (i == s.begin())
Modified: tagcoll/trunk/tagcoll/ItemGrouper.h
==============================================================================
--- tagcoll/trunk/tagcoll/ItemGrouper.h (original)
+++ tagcoll/trunk/tagcoll/ItemGrouper.h Sat Feb 11 14:14:44 2006
@@ -25,6 +25,7 @@
#include <tagcoll/Collection.h>
#include <tagcoll/OpSet.h>
+#include <tagcoll/Patches.h>
#include <map>
#include <list>
Modified: tagcoll/trunk/tagcoll/Makefile.am
==============================================================================
--- tagcoll/trunk/tagcoll/Makefile.am (original)
+++ tagcoll/trunk/tagcoll/Makefile.am Sat Feb 11 14:14:44 2006
@@ -42,6 +42,7 @@
IntIndex.h \
StringIndex.h \
IntDiskIndex.h \
+ BasicDiskIndex.h \
\
Filters.h \
Implications.h \
@@ -83,6 +84,7 @@
IntIndex.cc \
StringIndex.cc \
IntDiskIndex.cc \
+ BasicDiskIndex.cc \
\
Filters.cc \
Implications.cc \
Modified: tagcoll/trunk/tests/test-tdbdiskindex.cc
==============================================================================
--- tagcoll/trunk/tests/test-tdbdiskindex.cc (original)
+++ tagcoll/trunk/tests/test-tdbdiskindex.cc Sat Feb 11 14:14:44 2006
@@ -41,7 +41,7 @@
template<> template<>
void to::test<1> ()
{
- Converter<string, string> conv;
+ TrivialConverter<string, string> conv;
try {
// An empty database should return empty sets, but not fail
Modified: tagcoll/trunk/tests/test-tdbreadonlydiskindex.cc
==============================================================================
--- tagcoll/trunk/tests/test-tdbreadonlydiskindex.cc (original)
+++ tagcoll/trunk/tests/test-tdbreadonlydiskindex.cc Sat Feb 11 14:14:44 2006
@@ -36,7 +36,7 @@
template<> template<>
void to::test<1> ()
{
- Converter<string, string> conv;
+ TrivialConverter<string, string> conv;
PatchList<string, string> changes;
try {
{
Modified: tagcoll/trunk/tests/test-textformat.cc
==============================================================================
--- tagcoll/trunk/tests/test-textformat.cc (original)
+++ tagcoll/trunk/tests/test-textformat.cc Sat Feb 11 14:14:44 2006
@@ -77,53 +77,18 @@
};
// Serializer to use for testing (can return NULL values)
-namespace Tagcoll {
-
-template<>
-class Converter<Item, string>
+class ItemConverter : public Converter<Item, string>, public Converter<string, Item>
{
public:
- string operator()(const Item& item) { return item.getData(); }
- OpSet<string> operator()(const OpSet<Item>& items)
- {
- OpSet<string> res;
- for (OpSet<Item>::const_iterator i = items.begin();
- i != items.end(); i++)
- {
- string t = (*this)(*i);
- if (!t.empty())
- res += t;
- }
- return res;
- }
-};
-
-template<>
-class Converter<string, Item>
-{
-public:
- Item operator()(const string& item)
+ string operator()(const Item& item) const { return item.getData(); }
+ Item operator()(const string& item) const
{
if (item == "null")
return Item(0);
return Item(item.c_str());
}
- OpSet<Item> operator()(const OpSet<string>& items)
- {
- OpSet<Item> res;
- for (OpSet<string>::const_iterator i = items.begin();
- i != items.end(); i++)
- {
- Item t = (*this)(*i);
- if (t)
- res += t;
- }
- return res;
- }
};
-}
-
#define INSTANTIATING_TEMPLATES
#undef COMPILE_TESTSUITE
#include <tagcoll/OpSet.cc>
@@ -186,18 +151,18 @@
template<> template<>
void to::test<1> ()
{
- Converter<string, Item> toitem;
+ ItemConverter conv;
try {
// Parse the sample collection
StringParserInput in0(testCollection);
TDBIndexer<Item, Item> coll;
ItemChecker checker;
- TextFormat<Item, Item>::parse(toitem, toitem, in0, checker);
+ TextFormat<Item, Item>::parse(conv, conv, in0, checker);
ensure_equals(checker.nullItems(), 2);
ensure_equals(checker.nullTags(), 2);
StringParserInput in1(testCollection);
- TextFormat<Item, Item>::parse(toitem, toitem, in1, coll);
+ TextFormat<Item, Item>::parse(conv, conv, in1, coll);
gen_ensure(coll.hasItem("1"));
gen_ensure(coll.hasItem("2"));
@@ -219,11 +184,11 @@
template<> template<>
void to::test<2> ()
{
- Converter<string, Item> toitem;
+ ItemConverter conv;
try {
// Parse the sample patch
StringParserInput in0(testPatch);
- PatchList<Item, Item> patch = TextFormat<Item, Item>::parsePatch(toitem, toitem, in0);
+ PatchList<Item, Item> patch = TextFormat<Item, Item>::parsePatch(conv, conv, in0);
gen_ensure(patch.find("1") != patch.end());
gen_ensure(patch.find("2") != patch.end());
Modified: tagcoll/trunk/tools/Makefile.am
==============================================================================
--- tagcoll/trunk/tools/Makefile.am (original)
+++ tagcoll/trunk/tools/Makefile.am Sat Feb 11 14:14:44 2006
@@ -8,7 +8,7 @@
taggrep_SOURCES = taggrep.cc CommandlineParser.cc
taggrep_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
-tagidx_SOURCES = Index.cc tagidx.cc CommandlineParser.cc
+tagidx_SOURCES = tagidx.cc CommandlineParser.cc
tagidx_LDADD = ../tagcoll/libtagcoll.la ../tagcoll/tagexpr/libtagexpr.la
INCLUDES = -I$(top_srcdir)
Modified: tagcoll/trunk/tools/tagidx.cc
==============================================================================
--- tagcoll/trunk/tools/tagidx.cc (original)
+++ tagcoll/trunk/tools/tagidx.cc Sat Feb 11 14:14:44 2006
@@ -35,7 +35,8 @@
#endif
#include "CommandlineParser.h"
-#include "Index.h"
+#include <tagcoll/BasicDiskIndex.h>
+#include <tagcoll/ItemGrouper.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -66,7 +67,6 @@
#include <tagcoll/Filters.h>
#include <tagcoll/Patches.h>
#include <tagcoll/DerivedTags.h>
-#include <tagcoll/ItemGrouper.h>
#include <tagcoll/Serializer.h>
#include <tagcoll/Expression.h>
@@ -354,7 +354,7 @@
}
};
-enum valid_command { CREATE /*, DIFF, RELATED, IMPLICATIONS, HIERARCHY, CLEANHIERARCHY, REVERSE, FINDSPECIALS, GREP, ITEMS */ };
+enum valid_command { CREATE, CAT /*, DIFF, RELATED, IMPLICATIONS, HIERARCHY, CLEANHIERARCHY, REVERSE, FINDSPECIALS, GREP, ITEMS */ };
#if 0
class Reader
@@ -499,8 +499,8 @@
"Access an indexed tagged collection\n\n"
"Commands are:\n"
" create create the index from a tagged collection\n"
+ " cat output the collection\n"
/*
- " copy or cat output the collection\n"
" reverse \"reverse\" the collection, outputting one with items\n"
" associated to tags\n"
" diff output a tag patch file with the differences between two files\n"
@@ -524,6 +524,7 @@
*/
opts.add("index", 'I', "index", "directory where the index files are stored", "dir");
+ opts.add("groupitems", 'g', "group-items", "group items with the same tagset in the output collection");
#if 0
opts.add("derived", 'e', "derived-tags-from", "use an external list of derived tags", "file");
opts.add("extimpl", 'i', "implications-from", "use an external list of implications", "file");
@@ -531,7 +532,6 @@
opts.add("patch", 'p', "patch-with", "apply patches from the given tag patch file", "file");
opts.add("expanded", 'x', "expanded-output", "produce full (and redundant) output data instead of compact");
- opts.add("groupitems", 'g', "group-items", "group items with the same tagset in the output collection");
opts.add("distance", 'd', "distance", "set the maximum distance to use for the \"related\" command (defaults to 0)", "num");
opts.add("flatten", 0, "flatten-threshold", "set the number of total items below which a branch is flattened when using the \"hierarchy\" command (defaults to 0, meaning \"don't flatten\")", "num");
opts.add("filter", 'f', "filter", "filter out the tags with cardinality less than the given value (defaults to not filter; currently only works when building hierarchies)", "num");
@@ -544,9 +544,9 @@
#endif
opts.addCommand("create", (int)CREATE);
+ opts.addCommand("cat", (int)CAT);
#if 0
opts.addCommand("copy", (int)COPY);
- opts.addCommand("cat", (int)COPY);
opts.addCommand("reverse", (int)REVERSE);
opts.addCommand("diff", (int)DIFF);
opts.addCommand("related", (int)RELATED);
@@ -571,10 +571,11 @@
switch (cmd)
{
case CREATE:
+ {
string dir = indexdir(opts);
mkpath(dir);
- Indexer indexer;
+ BasicDiskIndexer indexer;
if (args.hasNext())
while (args.hasNext())
@@ -585,6 +586,24 @@
indexer.write(dir);
break;
+ }
+ case CAT:
+ {
+ string dir = indexdir(opts);
+ BasicDiskIndex idx(dir);
+
+ TrivialConverter<string, string> conv;
+ TextFormat<string, string> writer(conv, conv, stdout);
+
+ if (opts.get("groupitems").defined())
+ {
+ ItemGrouper<string, string> grouper;
+ idx.output(grouper);
+ grouper.output(writer);
+ } else
+ idx.output(writer);
+ break;
+ }
#if 0
case IMPLICATIONS:
{
@@ -749,19 +768,6 @@
reverser.outputReversed(writer);
break;
}
- case COPY:
- {
- Converter<string, string> conv;
- TextFormat<string, string> writer(conv, conv, stdout);
- if (opts.get("groupitems").defined())
- {
- ItemGrouper<string, string> grouper;
- reader.output(args, grouper);
- grouper.output(writer);
- } else
- reader.output(args, writer);
- break;
- }
case FINDSPECIALS:
{
int flattenThreshold = 0;
More information about the Debtags-commits
mailing list