aboutsummaryrefslogtreecommitdiff
path: root/doc/api/cplusplus/examples/example_dep_spec.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-12-29 23:48:09 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-12-29 23:48:09 +0000
commita9f4540c2ab1d7f6704c2bf7bdb41f8c9e18ae4a (patch)
tree9f88a8dcf7d81e2614c6fc39add69793f8e99d92 /doc/api/cplusplus/examples/example_dep_spec.cc
parent5c955c37d351d0a64d566d9316b704c4676fc44e (diff)
downloadpaludis-a9f4540c2ab1d7f6704c2bf7bdb41f8c9e18ae4a.tar.gz
paludis-a9f4540c2ab1d7f6704c2bf7bdb41f8c9e18ae4a.tar.xz
[use?] deps in paludis-1, exheres-0. Change how we handle UseRequirements to support this. FIxes: ticket:312
Diffstat (limited to 'doc/api/cplusplus/examples/example_dep_spec.cc')
-rw-r--r--doc/api/cplusplus/examples/example_dep_spec.cc51
1 files changed, 36 insertions, 15 deletions
diff --git a/doc/api/cplusplus/examples/example_dep_spec.cc b/doc/api/cplusplus/examples/example_dep_spec.cc
index f21bdb840..9be91eb5d 100644
--- a/doc/api/cplusplus/examples/example_dep_spec.cc
+++ b/doc/api/cplusplus/examples/example_dep_spec.cc
@@ -23,6 +23,7 @@
#include <cstdlib>
#include <list>
#include <map>
+#include <sstream>
using namespace paludis;
using namespace examples;
@@ -32,6 +33,36 @@ using std::endl;
using std::setw;
using std::left;
+namespace
+{
+ /* Used to print out more information about a UseRequirement. */
+ struct UseRequirementPrinter :
+ ConstVisitor<UseRequirementVisitorTypes>
+ {
+ std::ostringstream s;
+
+ void visit(const EnabledUseRequirement & r)
+ {
+ s << "[" << r.flag() << "]";
+ }
+
+ void visit(const DisabledUseRequirement & r)
+ {
+ s << "[!" << r.flag() << "]";
+ }
+
+ void visit(const EqualUseRequirement & r)
+ {
+ s << "[" << r.flag() << "?] (using '" << *r.package_id() << "')";
+ }
+
+ void visit(const NotEqualUseRequirement & r)
+ {
+ s << "[!" << r.flag() << "?] (using '" << *r.package_id() << "')";
+ }
+ };
+}
+
int main(int argc, char * argv[])
{
try
@@ -113,21 +144,11 @@ int main(int argc, char * argv[])
if (need_join)
cout << " and ";
- switch (u->second)
- {
- case use_enabled:
- case use_unspecified:
- break;
-
- case use_disabled:
- cout << "-";
- break;
-
- case last_use:
- throw InternalError(PALUDIS_HERE, "Bad use requirements");
- }
- cout << u->first;
-
+ /* A UseRequirement could be one of various subclasses. We
+ * use a visitor to do the right thing. */
+ UseRequirementPrinter p;
+ (*u)->accept(p);
+ cout << p.s.str();
need_join = true;
}
cout << endl;