[Debtags-commits] [svn] r1718 - in tagcoll/2.0: . tools
Enrico Zini
enrico at costa.debian.org
Tue May 9 00:14:08 UTC 2006
Author: enrico
Date: Tue May 9 00:14:07 2006
New Revision: 1718
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tools/tagcoll.cc
Log:
r2605 at viaza: enrico | 2006-05-07 12:22:41 -0500
More tagcoll.cc work
Modified: tagcoll/2.0/tools/tagcoll.cc
==============================================================================
--- tagcoll/2.0/tools/tagcoll.cc (original)
+++ tagcoll/2.0/tools/tagcoll.cc Tue May 9 00:14:07 2006
@@ -251,7 +251,7 @@
// Break filtering into generic steps that are abstracted by a virtual function
-class FilterStep : public wibble::mixin::OutputIterator<FilterStep>
+class FilterStep
{
public:
virtual ~FilterStep() {}
@@ -259,6 +259,8 @@
virtual FilterStep& operator=(const pair< wibble::Singleton<string>, set<string> >& data) = 0;
virtual FilterStep& operator=(const pair< set<string>, wibble::Empty<string> >& data) = 0;
virtual FilterStep& operator=(const pair< wibble::Singleton<string>, wibble::Empty<string> >& data) = 0;
+ FilterStep& operator++() { return *this; }
+ FilterStep& operator*() { return *this; }
};
template<typename OUT>
@@ -511,24 +513,43 @@
wman.manage(makeWriterTail())));
return FilterForwarder(m_writer);
}
-};
-#if 0
-TODO:
- - output the grouped data
+ void diff(const std::string& input1, const std::string& input2)
+ {
+ InputMerger<string, string> merger1;
+ readFile(input1, consumer(merger1));
-public:
- ~Writer()
+ InputMerger<string, string> merger2;
+ readFile(input2, consumer(merger2));
+
+ PatchList<string, string> newpatches;
+ newpatches.addPatch(merger1, merger2);
+
+ TrivialConverter<string, string> conv;
+ TextFormat<string, string>::outputPatch(conv, conv, newpatches, stdout);
+ }
+
+ void copy()
{
- // Flush output if needed
- if (grouper)
- {
- grouper->output(output);
- delete grouper;
- }
+ readAll(writer());
+ }
+
+ int grep(const std::string& expr)
+ {
+ int count = 0;
+ ExpressionFilter::MatchType type =
+ opts.misc_invert->boolValue() ?
+ ExpressionFilter::INVERTED : ExpressionFilter::PLAIN;
+
+ if (opts.misc_quiet->boolValue())
+ readAll(filterItemsByExpression(expr, type, countingSink(count)));
+ else
+ readAll(filterItemsByExpression(expr, type,
+ teeFilter(writer(), countingSink(count))));
+
+ return count > 0 ? 0 : 1;
}
};
-#endif
int main(int argc, const char* argv[])
{
@@ -575,7 +596,7 @@
flattenThreshold = opts.hie_flatten->intValue();
CardinalityStore<string, string> coll;
- tagcoll.readAll(coll);
+ tagcoll.readAll(consumer(coll));
if (opts.hie_filter->boolValue())
coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
@@ -592,7 +613,7 @@
flattenThreshold = opts.hie_flatten->intValue();
CardinalityStore<string, string> coll;
- tagcoll.readAll(coll);
+ tagcoll.readAll(consumer(coll));
if (opts.hie_filter->boolValue())
coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
@@ -603,17 +624,7 @@
}
else if (opts.foundCommand() == opts.diff)
{
- InputMerger<string, string> merger1;
- tagcoll.readFile(opts.next(), merger1);
-
- InputMerger<string, string> merger2;
- tagcoll.readFile(opts.next(), merger2);
-
- PatchList<string, string> newpatches;
- newpatches.addPatch(merger1, merger2);
-
- TrivialConverter<string, string> conv;
- TextFormat<string, string>::outputPatch(conv, conv, newpatches, stdout);
+ tagcoll.diff(opts.next(), opts.next());
}
else if (opts.foundCommand() == opts.related)
{
@@ -688,14 +699,14 @@
InputMerger<string, string> reversed;
Reverser<string, string> reverser(reversed, revnull);
- reader.output(opts, reverser);
+ tagcoll.readAll(reverser);
Writer writer(opts);
reversed.output(writer);
}
else if (opts.foundCommand() == opts.copy)
{
- tagcoll.readAll(tagcoll.writer());
+ tagcoll.copy();
}
else if (opts.foundCommand() == opts.findspecials)
{
@@ -748,18 +759,7 @@
}
else if (opts.foundCommand() == opts.grep)
{
- int count = 0;
- ExpressionFilter::MatchType type =
- opts.misc_invert->boolValue() ?
- ExpressionFilter::INVERTED : ExpressionFilter::PLAIN;
-
- if (opts.misc_quiet->boolValue())
- tagcoll.readAll(filterItemsByExpression(opts.next(), type, countingSink(count)));
- else
- tagcoll.readAll(filterItemsByExpression(opts.next(), type,
- teeFilter(tagcoll.writer(), countingSink(count))));
-
- return count > 0 ? 0 : 1;
+ return tagcoll.grep(opts.next());
}
else
throw wibble::exception::BadOption(string("unhandled command ") +
More information about the Debtags-commits
mailing list