[Debtags-commits] [svn] r1717 - in tagcoll/2.0: . tools

Enrico Zini enrico at costa.debian.org
Tue May 9 00:13:18 UTC 2006


Author: enrico
Date: Tue May  9 00:13:17 2006
New Revision: 1717

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tools/tagcoll.cc
Log:
 r2604 at viaza:  enrico | 2006-05-07 11:50:47 -0500
 More refactoring of tagcoll.cc


Modified: tagcoll/2.0/tools/tagcoll.cc
==============================================================================
--- tagcoll/2.0/tools/tagcoll.cc	(original)
+++ tagcoll/2.0/tools/tagcoll.cc	Tue May  9 00:13:17 2006
@@ -40,6 +40,7 @@
 #include <wibble/operators.h>
 
 #include <tagcoll/filters.h>
+#include <tagcoll/sink.h>
 
 #include <tagcoll/CardinalityStore.h>
 #include <tagcoll/SmartHierarchy.h>
@@ -471,11 +472,11 @@
 	~Tagcoll()
 	{
 		if (!grouper.empty())
-			grouper.output(forwarder(textformat::StdioWriter(stdout)));
+			grouper.output(textformat::StdioWriter(stdout));
 	}
 
 	template<typename OUT>
-	void outputFile(const string& file, const OUT& out)
+	void readFile(const string& file, const OUT& out)
 	{
 		FilterStepManager m;
 		FilterStep* reader =
@@ -487,7 +488,7 @@
 	}
 
 	template<typename OUT>
-	void outputAll(const OUT& out)
+	void readAll(const OUT& out)
 	{
 		FilterStepManager m;
 		FilterStep* reader =
@@ -538,14 +539,13 @@
 		// If the parser took care of the action, we can exit just fine.
 		if (opts.parse(argc, argv))
 			return 0;
-
-		Reader reader(opts);
+		Tagcoll tagcoll(opts);
 		
 		// Perform the correct operation
 		if (opts.foundCommand() == opts.implications)
 		{
 			CardinalityStore<string, string> coll;
-			reader.output(opts, coll);
+			tagcoll.readAll(consumer(coll));
 
 			Implications<string> newImpls;
 
@@ -575,7 +575,7 @@
 				flattenThreshold = opts.hie_flatten->intValue();
 
 			CardinalityStore<string, string> coll;
-			reader.output(opts, coll);
+			tagcoll.readAll(coll);
 
 			if (opts.hie_filter->boolValue())
 				coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
@@ -592,7 +592,7 @@
 				flattenThreshold = opts.hie_flatten->intValue();
 
 			CardinalityStore<string, string> coll;
-			reader.output(opts, coll);
+			tagcoll.readAll(coll);
 
 			if (opts.hie_filter->boolValue())
 				coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
@@ -604,10 +604,10 @@
 		else if (opts.foundCommand() == opts.diff)
 		{
 			InputMerger<string, string> merger1;
-			reader.output(opts.next(), merger1);
+			tagcoll.readFile(opts.next(), merger1);
 
 			InputMerger<string, string> merger2;
-			reader.output(opts.next(), merger2);
+			tagcoll.readFile(opts.next(), merger2);
 
 			PatchList<string, string> newpatches;
 			newpatches.addPatch(merger1, merger2);
@@ -619,7 +619,7 @@
 		{
 			string item = opts.next();
 			InputMerger<string, string> merger;
-			reader.output(opts, merger);
+			tagcoll.readAll(merger);
 
 			int maxdist = 0;
 			if (opts.misc_distance->boolValue())
@@ -634,7 +634,7 @@
 				{
 					if (!merger.hasItem(splititem))
 					{
-						fprintf(stderr, "Item \"%.*s\" does not exist in the collection\n", PFSTR(splititem));
+						cerr << "Item \"" << splititem << "\" does not exist in the collection" << endl;
 						return 1;
 					}
 					splititems.insert(splititem);
@@ -643,7 +643,7 @@
 					splititem += *c;
 			if (!merger.hasItem(splititem))
 			{
-				fprintf(stderr, "Item \"%.*s\" does not exist in the collection\n", PFSTR(splititem));
+				cerr << "Item \"" << splititem << "\" does not exist in the collection" << endl;
 				return 1;
 			}
 			splititems.insert(splititem);
@@ -652,14 +652,14 @@
 			set<string>::const_iterator i = splititems.begin();
 			std::set<string> ts = merger.getTags(*i);
 			for (++i; i != splititems.end(); i++)
-				ts = ts ^ merger.getTags(*i);
+				ts = ts & merger.getTags(*i);
 
 			if (ts.empty())
 			{
 				if (splititems.size() > 1)
-					fprintf(stderr, "The items %.*s are unrelated: cannot find a barycenter to start computing relationships from.\n", PFSTR(item));
+					cerr << "The items " << item << " are unrelated: cannot find a barycenter to start computing relationships from." << endl;
 				else
-					fprintf(stderr, "The items %.*s has no tags attached.\n", PFSTR(item));
+					cerr << "The items " << item << " has no tags attached." << endl;
 				return 1;
 			}
 
@@ -695,8 +695,7 @@
 		}
 		else if (opts.foundCommand() == opts.copy)
 		{
-			Writer writer(opts);
-			reader.output(opts, writer);
+			tagcoll.readAll(tagcoll.writer());
 		}
 		else if (opts.foundCommand() == opts.findspecials)
 		{
@@ -705,7 +704,7 @@
 				flattenThreshold = opts.hie_flatten->intValue();
 
 			CardinalityStore<string, string> coll;
-			reader.output(opts, coll);
+			tagcoll.readAll(consumer(coll));
 
 			if (opts.hie_filter->boolValue())
 				coll.removeTagsWithCardinalityLessThan(opts.hie_filter->intValue());
@@ -727,39 +726,40 @@
 					for (std::set<string>::const_iterator j = items.begin();
 							j != items.end(); j++)
 					{
-						std::set<string> tags = coll.getTags(*j) ^ seen;
+						std::set<string> tags = coll.getTags(*j) & seen;
 						if (tags.empty())
-							newItems += *j;
+							newItems |= *j;
 					}
 
-					printf("%.*s: %d items, %d special items:\n",
-							PFSTR((*i)->tag()), items.size(), newItems.size());
+					cout << (*i)->tag() << ": " << items.size() << " items, " <<
+						newItems.size() << " special items:" << endl;
 
 					int indent = (*i)->tag().size() + 2;
 					for (std::set<string>::const_iterator j = newItems.begin(); j != newItems.end(); j++)
-						printf("%*s%.*s\n", indent, "", PFSTR(*j));
+					{
+						for (int ind = 0; ind < indent; ++ind)
+							cout << ' ';
+						cout << *j << endl;
+					}
 				}
 
-				seen += (*i)->tag();
+				seen |= (*i)->tag();
 			}
 		}
 		else if (opts.foundCommand() == opts.grep)
 		{
-			Writer writer(opts);
-			Sink<string, string> sink;
-
-			FilterItemsByExpression<string, string> filter(opts.next());
-			if (opts.misc_invert->boolValue())
-				filter.setMatchType(FilterItemsByExpression<string, string>::INVERTED);
+			int count = 0;
+			ExpressionFilter::MatchType type =
+				opts.misc_invert->boolValue() ?
+					ExpressionFilter::INVERTED : ExpressionFilter::PLAIN;
 
 			if (opts.misc_quiet->boolValue())
-				filter.setConsumer(sink);
+				tagcoll.readAll(filterItemsByExpression(opts.next(), type, countingSink(count)));
 			else
-				filter.setConsumer(writer);
-
-			reader.output(opts, filter);
+				tagcoll.readAll(filterItemsByExpression(opts.next(), type,
+							teeFilter(tagcoll.writer(), countingSink(count))));
 
-			return filter.countMatched() > 0 ? 0 : 1;
+			return count > 0 ? 0 : 1;
 		}
 		else
 			throw wibble::exception::BadOption(string("unhandled command ") +



More information about the Debtags-commits mailing list