aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-01 23:57:02 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-01 23:57:02 +0000
commit9f496dd5300d95cb31eaeed085168e7a493b458a (patch)
tree9694e6b7fd599dfbc963623277cf097edd53b65b
parent619fe2d966f91ad6db69138f3ffb8b148327576e (diff)
downloadpaludis-9f496dd5300d95cb31eaeed085168e7a493b458a.tar.gz
paludis-9f496dd5300d95cb31eaeed085168e7a493b458a.tar.xz
Unify various things into match_package_in_heirarchy. Fixes: ticket:39
-rw-r--r--paludis/dep_list/dep_list.cc74
-rw-r--r--paludis/dep_list/uninstall_list.cc75
-rw-r--r--paludis/environment/default/default_environment.cc88
-rw-r--r--paludis/match_package.cc80
-rw-r--r--paludis/match_package.hh10
5 files changed, 101 insertions, 226 deletions
diff --git a/paludis/dep_list/dep_list.cc b/paludis/dep_list/dep_list.cc
index cdc4ab7..0675ca6 100644
--- a/paludis/dep_list/dep_list.cc
+++ b/paludis/dep_list/dep_list.cc
@@ -1524,85 +1524,13 @@ DepList::end() const
return Iterator(_imp->merge_list.end());
}
-namespace
-{
- struct IsTopLevelTarget :
- DepAtomVisitorTypes::ConstVisitor,
- std::unary_function<PackageDatabaseEntry, bool>
- {
- const Environment * const env;
- std::tr1::shared_ptr<const DepAtom> target;
- const PackageDatabaseEntry * dbe;
- bool matched;
-
- IsTopLevelTarget(const Environment * const e, std::tr1::shared_ptr<const DepAtom> t) :
- env(e),
- target(t),
- matched(false)
- {
- }
-
- bool operator() (const PackageDatabaseEntry & e)
- {
- dbe = &e;
- matched = false;
- target->accept(this);
- return matched;
- }
-
- void visit(const AllDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const PackageDepAtom * const a)
- {
- if (matched)
- return;
-
- if (match_package(*env, *a, *dbe))
- matched = true;
- }
-
- void visit(const UseDepAtom * const u)
- {
- if (matched)
- return;
-
- std::for_each(u->begin(), u->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom * const)
- {
- }
-
- void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn))
- {
- throw InternalError(PALUDIS_HERE, "Got PlainTextDepAtom?");
- }
- };
-
-}
-
bool
DepList::is_top_level_target(const PackageDatabaseEntry & e) const
{
if (! _imp->current_top_level_target)
throw InternalError(PALUDIS_HERE, "current_top_level_target not set?");
- IsTopLevelTarget t(_imp->env, _imp->current_top_level_target);
- return t(e);
+ return match_package_in_heirarchy(*_imp->env, *_imp->current_top_level_target, e);
}
namespace
diff --git a/paludis/dep_list/uninstall_list.cc b/paludis/dep_list/uninstall_list.cc
index f928033..ac91104 100644
--- a/paludis/dep_list/uninstall_list.cc
+++ b/paludis/dep_list/uninstall_list.cc
@@ -87,73 +87,6 @@ namespace
return f.package == e;
}
};
-
- struct IsWorld :
- DepAtomVisitorTypes::ConstVisitor,
- std::unary_function<PackageDatabaseEntry, bool>
- {
- const Environment * const env;
- std::tr1::shared_ptr<const DepAtom> world;
- const PackageDatabaseEntry * dbe;
- bool matched;
-
- IsWorld(const Environment * const e) :
- env(e),
- world(e->package_set(SetName("world"))),
- matched(false)
- {
- }
-
- bool operator() (const PackageDatabaseEntry & e)
- {
- dbe = &e;
- matched = false;
- world->accept(this);
- return matched;
- }
-
- void visit(const AllDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const PackageDepAtom * const a)
- {
- if (matched)
- return;
-
- if (match_package(*env, *a, *dbe))
- matched = true;
- }
-
- void visit(const UseDepAtom * const u)
- {
- if (matched)
- return;
-
- std::for_each(u->begin(), u->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom * const)
- {
- }
-
- void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn))
- {
- throw InternalError(PALUDIS_HERE, "Got PlainTextDepAtom?");
- }
- };
}
UninstallList::UninstallList(const Environment * const env, const UninstallListOptions & o) :
@@ -428,11 +361,11 @@ UninstallList::add_unused_dependencies()
ArbitrarilyOrderedPackageDatabaseEntryCollectionComparator());
/* if any of them aren't already on the list, and aren't in world, add them and recurse */
- IsWorld w(_imp->env);
+ std::tr1::shared_ptr<DepAtom> world(_imp->env->package_set(SetName("world")));
for (PackageDatabaseEntryCollection::Iterator i(unused_dependencies->begin()),
i_end(unused_dependencies->end()) ; i != i_end ; ++i)
{
- if (w(*i))
+ if (match_package_in_heirarchy(*_imp->env, *world, *i))
continue;
if (_imp->uninstall_list.end() != std::find_if(_imp->uninstall_list.begin(),
@@ -495,10 +428,10 @@ UninstallList::collect_world() const
new ArbitrarilyOrderedPackageDatabaseEntryCollection::Concrete);
std::tr1::shared_ptr<const ArbitrarilyOrderedPackageDatabaseEntryCollection> everything(collect_all_installed());
- IsWorld w(_imp->env);
+ std::tr1::shared_ptr<DepAtom> world(_imp->env->package_set(SetName("world")));
for (PackageDatabaseEntryCollection::Iterator i(everything->begin()),
i_end(everything->end()) ; i != i_end ; ++i)
- if (w(*i))
+ if (match_package_in_heirarchy(*_imp->env, *world, *i))
result->insert(*i);
return result;
diff --git a/paludis/environment/default/default_environment.cc b/paludis/environment/default/default_environment.cc
index a0c3aaf..2f8c0e5 100644
--- a/paludis/environment/default/default_environment.cc
+++ b/paludis/environment/default/default_environment.cc
@@ -52,76 +52,6 @@ DefaultEnvironment::~DefaultEnvironment()
{
}
-namespace
-{
- struct IsInSet :
- DepAtomVisitorTypes::ConstVisitor,
- std::unary_function<PackageDatabaseEntry, bool>
- {
- const Environment * const env;
- std::tr1::shared_ptr<const DepAtom> set;
- const PackageDatabaseEntry * dbe;
- bool matched;
-
- IsInSet(const Environment * const e, std::tr1::shared_ptr<const DepAtom> s) :
- env(e),
- set(s),
- matched(false)
- {
- }
-
- bool operator() (const PackageDatabaseEntry & e)
- {
- dbe = &e;
- matched = false;
- set->accept(this);
- return matched;
- }
-
- void visit(const AllDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const PackageDepAtom * const a)
- {
- if (matched)
- return;
-
- if (match_package(*env, *a, *dbe))
- matched = true;
- }
-
- void visit(const UseDepAtom * const u)
- {
- if (matched)
- return;
-
- std::for_each(u->begin(), u->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom * const)
- {
- }
-
- void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn))
- {
- throw InternalError(PALUDIS_HERE, "Got PlainTextDepAtom?");
- }
- };
-}
-
bool
DefaultEnvironment::query_use(const UseFlagName & f, const PackageDatabaseEntry * e) const
{
@@ -231,8 +161,7 @@ DefaultEnvironment::query_use(const UseFlagName & f, const PackageDatabaseEntry
if (f != u->flag_name)
continue;
- IsInSet q(this, u->dep_atom);
- if (! q(*e))
+ if (! match_package_in_heirarchy(*this, *u->dep_atom, *e))
continue;
switch (u->flag_state)
@@ -274,8 +203,7 @@ DefaultEnvironment::query_use(const UseFlagName & f, const PackageDatabaseEntry
i_end(DefaultConfig::get_instance()->end_set_use_prefixes_with_minus_star()) ;
i != i_end ; ++i)
{
- IsInSet q(this, i->dep_atom);
- if (! q(*e))
+ if (! match_package_in_heirarchy(*this, *i->dep_atom, *e))
continue;
if (0 == i->prefix.compare(0, i->prefix.length(), stringify(f), 0, i->prefix.length()))
@@ -392,8 +320,7 @@ DefaultEnvironment::accept_keyword(const KeywordName & keyword, const PackageDat
k_end(DefaultConfig::get_instance()->end_set_keywords()) ;
k != k_end ; ++k)
{
- IsInSet q(this, k->dep_atom);
- if (! q(*d))
+ if (! match_package_in_heirarchy(*this, *k->dep_atom, *d))
continue;
if (k->keyword == minus_star_keyword)
@@ -460,8 +387,7 @@ DefaultEnvironment::accept_license(const std::string & license, const PackageDat
k_end(DefaultConfig::get_instance()->end_set_licenses()) ;
k != k_end ; ++k)
{
- IsInSet q(this, k->dep_atom);
- if (! q(*d))
+ if (! match_package_in_heirarchy(*this, *k->dep_atom, *d))
continue;
if (k->license == "-*")
@@ -513,8 +439,7 @@ DefaultEnvironment::query_user_masks(const PackageDatabaseEntry & d) const
k_end(DefaultConfig::get_instance()->end_user_masks_sets()) ;
k != k_end ; ++k)
{
- IsInSet q(this, k->dep_atom);
- if (! q(d))
+ if (! match_package_in_heirarchy(*this, *k->dep_atom, d))
continue;
return true;
@@ -542,8 +467,7 @@ DefaultEnvironment::query_user_unmasks(const PackageDatabaseEntry & d) const
k_end(DefaultConfig::get_instance()->end_user_unmasks_sets()) ;
k != k_end ; ++k)
{
- IsInSet q(this, k->dep_atom);
- if (! q(d))
+ if (! match_package_in_heirarchy(*this, *k->dep_atom, d))
continue;
return true;
diff --git a/paludis/match_package.cc b/paludis/match_package.cc
index d4dc04c..67094df 100644
--- a/paludis/match_package.cc
+++ b/paludis/match_package.cc
@@ -108,3 +108,83 @@ paludis::match_package(
return true;
}
+namespace
+{
+ struct IsInHeirarchy :
+ DepAtomVisitorTypes::ConstVisitor,
+ std::unary_function<PackageDatabaseEntry, bool>
+ {
+ const Environment & env;
+ const DepAtom & target;
+ const PackageDatabaseEntry * dbe;
+ bool matched;
+
+ IsInHeirarchy(const Environment & e, const DepAtom & t) :
+ env(e),
+ target(t),
+ matched(false)
+ {
+ }
+
+ bool operator() (const PackageDatabaseEntry & e)
+ {
+ dbe = &e;
+ matched = false;
+ target.accept(this);
+ return matched;
+ }
+
+ void visit(const AllDepAtom * const a)
+ {
+ if (matched)
+ return;
+
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const PackageDepAtom * const a)
+ {
+ if (matched)
+ return;
+
+ if (match_package(env, *a, *dbe))
+ matched = true;
+ }
+
+ void visit(const UseDepAtom * const u)
+ {
+ if (matched)
+ return;
+
+ std::for_each(u->begin(), u->end(), accept_visitor(this));
+ }
+
+ void visit(const AnyDepAtom * const a)
+ {
+ if (matched)
+ return;
+
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const BlockDepAtom * const)
+ {
+ }
+
+ void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw InternalError(PALUDIS_HERE, "Got PlainTextDepAtom?");
+ }
+ };
+}
+
+bool
+paludis::match_package_in_heirarchy(
+ const Environment & env,
+ const DepAtom & atom,
+ const PackageDatabaseEntry & entry)
+{
+ IsInHeirarchy h(env, atom);
+ return h(entry);
+}
+
diff --git a/paludis/match_package.hh b/paludis/match_package.hh
index c244a42..cdc97a3 100644
--- a/paludis/match_package.hh
+++ b/paludis/match_package.hh
@@ -28,6 +28,16 @@ namespace paludis
const Environment & env,
const PackageDepAtom & atom,
const PackageDatabaseEntry & target);
+
+ /**
+ * Return whether the specified atom matches the specified target, for heirarchies.
+ *
+ * \ingroup grpmatchpackage
+ */
+ bool match_package_in_heirarchy(
+ const Environment & env,
+ const DepAtom & atom,
+ const PackageDatabaseEntry & target);
}
#endif