aboutsummaryrefslogtreecommitdiff
path: root/paludis/resolver/labels_classifier.cc
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/resolver/labels_classifier.cc')
-rw-r--r--paludis/resolver/labels_classifier.cc236
1 files changed, 151 insertions, 85 deletions
diff --git a/paludis/resolver/labels_classifier.cc b/paludis/resolver/labels_classifier.cc
index 3606c7196..5497b8bd9 100644
--- a/paludis/resolver/labels_classifier.cc
+++ b/paludis/resolver/labels_classifier.cc
@@ -23,6 +23,8 @@
#include <paludis/util/accept_visitor.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/pool-impl.hh>
+#include <paludis/util/singleton-impl.hh>
#include <paludis/dep_label.hh>
#include <paludis/serialise-impl.hh>
#include <algorithm>
@@ -33,142 +35,201 @@ using namespace paludis::resolver;
namespace paludis
{
template <>
- struct Imp<LabelsClassifier>
+ struct Imp<LabelsClassifierBuilder>
{
const Environment * const env;
const std::shared_ptr<const PackageID> package_id;
+ bool any_enabled;
+
+ bool includes_buildish;
+ bool includes_compile_against;
+ bool includes_fetch;
+ bool includes_non_post_runish;
+ bool includes_non_test_buildish;
+ bool includes_post;
+ bool includes_postish;
+
+ bool is_recommendation;
+ bool is_requirement;
+ bool is_suggestion;
+
Imp(const Environment * const e, const std::shared_ptr<const PackageID> & i) :
env(e),
- package_id(i)
+ package_id(i),
+ any_enabled(false),
+ includes_buildish(false),
+ includes_compile_against(false),
+ includes_fetch(false),
+ includes_non_post_runish(false),
+ includes_non_test_buildish(false),
+ includes_post(false),
+ includes_postish(false),
+ is_recommendation(false),
+ is_requirement(false),
+ is_suggestion(false)
{
}
};
}
-LabelsClassifier::LabelsClassifier(const Environment * const env, const std::shared_ptr<const PackageID> & id) :
- _imp(env, id),
- any_enabled(false),
- includes_buildish(false),
- includes_compile_against(false),
- includes_fetch(false),
- includes_non_post_runish(false),
- includes_non_test_buildish(false),
- includes_post(false),
- includes_postish(false),
- is_recommendation(false),
- is_requirement(false),
- is_suggestion(false)
+LabelsClassifierBuilder::LabelsClassifierBuilder(const Environment * const env, const std::shared_ptr<const PackageID> & id) :
+ _imp(env, id)
{
}
-LabelsClassifier::~LabelsClassifier() = default;
+LabelsClassifierBuilder::~LabelsClassifierBuilder() = default;
void
-LabelsClassifier::visit(const DependenciesBuildLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesBuildLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_buildish = true;
- includes_non_test_buildish = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_buildish = true;
+ _imp->includes_non_test_buildish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesTestLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesTestLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_buildish = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_buildish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesFetchLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesFetchLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_buildish = true;
- includes_non_test_buildish = true;
- includes_fetch = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_buildish = true;
+ _imp->includes_non_test_buildish = true;
+ _imp->includes_fetch = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesRunLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesRunLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_non_post_runish = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_non_post_runish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesPostLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesPostLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_postish = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_postish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesInstallLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesInstallLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_buildish = true;
- includes_non_test_buildish = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_buildish = true;
+ _imp->includes_non_test_buildish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesCompileAgainstLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesCompileAgainstLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_requirement = true;
- includes_non_post_runish = true;
- includes_buildish = true;
- includes_non_test_buildish = true;
- any_enabled = true;
+ _imp->is_requirement = true;
+ _imp->includes_non_post_runish = true;
+ _imp->includes_buildish = true;
+ _imp->includes_non_test_buildish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesRecommendationLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesRecommendationLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_recommendation = true;
- includes_postish = true;
- any_enabled = true;
+ _imp->is_recommendation = true;
+ _imp->includes_postish = true;
+ _imp->any_enabled = true;
}
}
void
-LabelsClassifier::visit(const DependenciesSuggestionLabel & l)
+LabelsClassifierBuilder::visit(const DependenciesSuggestionLabel & l)
{
if (l.enabled(_imp->env, _imp->package_id))
{
- is_suggestion = true;
- includes_postish = true;
- any_enabled = true;
+ _imp->is_suggestion = true;
+ _imp->includes_postish = true;
+ _imp->any_enabled = true;
}
}
+const std::shared_ptr<const LabelsClassifier>
+LabelsClassifierBuilder::create() const
+{
+ return Pool<LabelsClassifier>::get_instance()->create(
+ _imp->any_enabled,
+ _imp->includes_buildish,
+ _imp->includes_compile_against,
+ _imp->includes_fetch,
+ _imp->includes_non_post_runish,
+ _imp->includes_non_test_buildish,
+ _imp->includes_post,
+ _imp->includes_postish,
+ _imp->is_recommendation,
+ _imp->is_requirement,
+ _imp->is_suggestion
+ );
+}
+
+LabelsClassifier::LabelsClassifier(
+ bool any_enabled_v,
+ bool includes_buildish_v,
+ bool includes_compile_against_v,
+ bool includes_fetch_v,
+ bool includes_non_post_runish_v,
+ bool includes_non_test_buildish_v,
+ bool includes_post_v,
+ bool includes_postish_v,
+ bool is_recommendation_v,
+ bool is_requirement_v,
+ bool is_suggestion_v
+ ) :
+ any_enabled(any_enabled_v),
+ includes_buildish(includes_buildish_v),
+ includes_compile_against(includes_compile_against_v),
+ includes_fetch(includes_fetch_v),
+ includes_non_post_runish(includes_non_post_runish_v),
+ includes_non_test_buildish(includes_non_test_buildish_v),
+ includes_post(includes_post_v),
+ includes_postish(includes_postish_v),
+ is_recommendation(is_recommendation_v),
+ is_requirement(is_requirement_v),
+ is_suggestion(is_suggestion_v)
+{
+}
+
void
LabelsClassifier::serialise(Serialiser & s) const
{
@@ -187,25 +248,24 @@ LabelsClassifier::serialise(Serialiser & s) const
;
}
-const std::shared_ptr<LabelsClassifier>
+const std::shared_ptr<const LabelsClassifier>
LabelsClassifier::deserialise(
Deserialisation & d)
{
Deserialisator v(d, "LabelsClassifier");
- auto result(std::make_shared<LabelsClassifier>(static_cast<const Environment *>(0), std::shared_ptr<const PackageID>()));
- result->any_enabled = v.member<bool>("any_enabled");
- result->includes_buildish = v.member<bool>("includes_buildish");
- result->includes_compile_against = v.member<bool>("includes_compile_against");
- result->includes_fetch = v.member<bool>("includes_fetch");
- result->includes_non_post_runish = v.member<bool>("includes_non_post_runish");
- result->includes_non_test_buildish = v.member<bool>("includes_non_test_buildish");
- result->includes_post = v.member<bool>("includes_post");
- result->includes_postish = v.member<bool>("includes_postish");
- result->is_recommendation = v.member<bool>("is_recommendation");
- result->is_requirement = v.member<bool>("is_requirement");
- result->is_suggestion = v.member<bool>("is_suggestion");
-
- return result;
+ return Pool<LabelsClassifier>::get_instance()->create(
+ v.member<bool>("any_enabled"),
+ v.member<bool>("includes_buildish"),
+ v.member<bool>("includes_compile_against"),
+ v.member<bool>("includes_fetch"),
+ v.member<bool>("includes_non_post_runish"),
+ v.member<bool>("includes_non_test_buildish"),
+ v.member<bool>("includes_post"),
+ v.member<bool>("includes_postish"),
+ v.member<bool>("is_recommendation"),
+ v.member<bool>("is_requirement"),
+ v.member<bool>("is_suggestion")
+ );
}
bool
@@ -214,11 +274,12 @@ paludis::resolver::is_suggestion(const Environment * const env, const std::share
if (dep.active_dependency_labels()->empty())
return false;
- LabelsClassifier v(env, id);
+ LabelsClassifierBuilder v(env, id);
std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()),
indirect_iterator(dep.active_dependency_labels()->end()),
accept_visitor(v));
- return v.is_suggestion && (! v.is_recommendation) && (! v.is_requirement);
+ auto c(v.create());
+ return c->is_suggestion && (! c->is_recommendation) && (! c->is_requirement);
}
bool
@@ -227,11 +288,12 @@ paludis::resolver::is_recommendation(const Environment * const env, const std::s
if (dep.active_dependency_labels()->empty())
return false;
- LabelsClassifier v(env, id);
+ LabelsClassifierBuilder v(env, id);
std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()),
indirect_iterator(dep.active_dependency_labels()->end()),
accept_visitor(v));
- return v.is_recommendation && (! v.is_requirement);
+ auto c(v.create());
+ return c->is_recommendation && (! c->is_requirement);
}
bool
@@ -240,11 +302,12 @@ paludis::resolver::is_just_build_dep(const Environment * const env, const std::s
if (dep.active_dependency_labels()->empty())
throw InternalError(PALUDIS_HERE, "not implemented");
- LabelsClassifier v(env, id);
+ LabelsClassifierBuilder v(env, id);
std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()),
indirect_iterator(dep.active_dependency_labels()->end()),
accept_visitor(v));
- return v.includes_buildish && ! v.includes_non_post_runish && ! v.includes_postish;
+ auto c(v.create());
+ return c->includes_buildish && ! c->includes_non_post_runish && ! c->includes_postish;
}
bool
@@ -253,11 +316,12 @@ paludis::resolver::is_compiled_against_dep(const Environment * const env, const
if (dep.active_dependency_labels()->empty())
throw InternalError(PALUDIS_HERE, "not implemented");
- LabelsClassifier v(env, id);
+ LabelsClassifierBuilder v(env, id);
std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()),
indirect_iterator(dep.active_dependency_labels()->end()),
accept_visitor(v));
- return v.includes_compile_against;
+ auto c(v.create());
+ return c->includes_compile_against;
}
bool
@@ -266,11 +330,12 @@ paludis::resolver::is_enabled_dep(const Environment * const env, const std::shar
if (dep.active_dependency_labels()->empty())
throw InternalError(PALUDIS_HERE, "not implemented");
- LabelsClassifier v(env, id);
+ LabelsClassifierBuilder v(env, id);
std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()),
indirect_iterator(dep.active_dependency_labels()->end()),
accept_visitor(v));
- return v.any_enabled;
+ auto c(v.create());
+ return c->any_enabled;
}
bool
@@ -279,10 +344,11 @@ paludis::resolver::is_run_or_post_dep(const Environment * const env, const std::
if (dep.active_dependency_labels()->empty())
throw InternalError(PALUDIS_HERE, "not implemented");
- LabelsClassifier v(env, id);
+ LabelsClassifierBuilder v(env, id);
std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()),
indirect_iterator(dep.active_dependency_labels()->end()),
accept_visitor(v));
- return v.includes_non_post_runish || v.includes_postish;
+ auto c(v.create());
+ return c->includes_non_post_runish || c->includes_postish;
}