aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-03 15:19:28 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-04 19:01:03 +0100
commit2d1137e5b4c0b29670dbf50d23d1001265745815 (patch)
tree47f2c00536daebacac14dc09893b50ca7bdec0fe
parent205e8218a25fdabbdb4091c81fffd865171c8238 (diff)
downloadpaludis-2d1137e5b4c0b29670dbf50d23d1001265745815.tar.gz
paludis-2d1137e5b4c0b29670dbf50d23d1001265745815.tar.xz
ChangedChoices, ConditionalDepSpec::condition_would_be_met_when
-rw-r--r--paludis/changed_choices-fwd.hh28
-rw-r--r--paludis/changed_choices.cc101
-rw-r--r--paludis/changed_choices.hh55
-rw-r--r--paludis/dep_spec.cc6
-rw-r--r--paludis/dep_spec.hh11
-rw-r--r--paludis/elike_conditional_dep_spec.cc14
-rw-r--r--paludis/files.m41
7 files changed, 216 insertions, 0 deletions
diff --git a/paludis/changed_choices-fwd.hh b/paludis/changed_choices-fwd.hh
new file mode 100644
index 0000000..71c551a
--- /dev/null
+++ b/paludis/changed_choices-fwd.hh
@@ -0,0 +1,28 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_CHANGED_CHOICES_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_CHANGED_CHOICES_FWD_HH 1
+
+namespace paludis
+{
+ struct ChangedChoices;
+}
+
+#endif
diff --git a/paludis/changed_choices.cc b/paludis/changed_choices.cc
new file mode 100644
index 0000000..462d110
--- /dev/null
+++ b/paludis/changed_choices.cc
@@ -0,0 +1,101 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/changed_choices.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/tribool.hh>
+#include <paludis/choice.hh>
+#include <paludis/serialise-impl.hh>
+#include <map>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Imp<ChangedChoices>
+ {
+ std::map<ChoiceNameWithPrefix, bool> overrides;
+ };
+}
+
+ChangedChoices::ChangedChoices() :
+ Pimp<ChangedChoices>()
+{
+}
+
+ChangedChoices::~ChangedChoices() = default;
+
+bool
+ChangedChoices::add_override_if_possible(const ChoiceNameWithPrefix & c, const bool v)
+{
+ auto r(_imp->overrides.insert(std::make_pair(c, v)));
+ return r.second || (r.first->second == v);
+}
+
+bool
+ChangedChoices::empty() const
+{
+ return _imp->overrides.empty();
+}
+
+Tribool
+ChangedChoices::overridden_value(const ChoiceNameWithPrefix & c) const
+{
+ auto i(_imp->overrides.find(c));
+ if (i == _imp->overrides.end())
+ return Tribool(indeterminate);
+ else
+ return Tribool(i->second);
+}
+
+void
+ChangedChoices::serialise(Serialiser & s) const
+{
+ auto ss(s.object("ChangedChoices"));
+
+ ss.member(SerialiserFlags<>(), "count", stringify(_imp->overrides.size()));
+
+ int n(0);
+ for (auto o(_imp->overrides.begin()), o_end(_imp->overrides.end()) ;
+ o != o_end ; ++o)
+ {
+ ++n;
+ ss.member(SerialiserFlags<>(), stringify(n) + "a" , stringify(o->first));
+ ss.member(SerialiserFlags<>(), stringify(n) + "b" , stringify(o->second));
+ }
+}
+
+const std::shared_ptr<ChangedChoices>
+ChangedChoices::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "ChangedChoices");
+ auto result(std::make_shared<ChangedChoices>());
+
+ for (int n(1), n_end(v.member<int>("count") + 1) ; n != n_end ; ++n)
+ result->add_override_if_possible(
+ ChoiceNameWithPrefix(v.member<std::string>(stringify(n) + "a")),
+ v.member<bool>(stringify(n) + "b")
+ );
+
+ return result;
+}
+
+template class Pimp<ChangedChoices>;
+
diff --git a/paludis/changed_choices.hh b/paludis/changed_choices.hh
new file mode 100644
index 0000000..18bd479
--- /dev/null
+++ b/paludis/changed_choices.hh
@@ -0,0 +1,55 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_CHANGED_CHOICES_HH
+#define PALUDIS_GUARD_PALUDIS_CHANGED_CHOICES_HH 1
+
+#include <paludis/changed_choices-fwd.hh>
+#include <paludis/util/pimp.hh>
+#include <paludis/util/tribool-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/choice-fwd.hh>
+#include <paludis/serialise-fwd.hh>
+#include <memory>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE ChangedChoices :
+ private Pimp<ChangedChoices>
+ {
+ public:
+ ChangedChoices();
+ ~ChangedChoices();
+
+ bool add_override_if_possible(const ChoiceNameWithPrefix &, const bool);
+
+ Tribool overridden_value(const ChoiceNameWithPrefix &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ bool empty() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ void serialise(Serialiser &) const;
+
+ static const std::shared_ptr<ChangedChoices> deserialise(
+ Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ extern template class Pimp<ChangedChoices>;
+}
+
+#endif
diff --git a/paludis/dep_spec.cc b/paludis/dep_spec.cc
index 6a0e8e2..749ea9d 100644
--- a/paludis/dep_spec.cc
+++ b/paludis/dep_spec.cc
@@ -198,6 +198,12 @@ ConditionalDepSpec::condition_met() const
}
bool
+ConditionalDepSpec::condition_would_be_met_when(const ChangedChoices & c) const
+{
+ return _imp->data->condition_would_be_met_when(c);
+}
+
+bool
ConditionalDepSpec::condition_meetable() const
{
return _imp->data->condition_meetable();
diff --git a/paludis/dep_spec.hh b/paludis/dep_spec.hh
index 30bf6bd..2b3b434 100644
--- a/paludis/dep_spec.hh
+++ b/paludis/dep_spec.hh
@@ -27,6 +27,7 @@
#include <paludis/util/fs_entry.hh>
#include <paludis/util/named_value.hh>
+#include <paludis/changed_choices-fwd.hh>
#include <paludis/dep_label.hh>
#include <paludis/dep_spec-fwd.hh>
#include <paludis/dep_tag-fwd.hh>
@@ -190,6 +191,11 @@ namespace paludis
bool condition_met() const PALUDIS_ATTRIBUTE((warn_unused_result));
/**
+ * Would our condition met, if certain choices were changed?
+ */
+ bool condition_would_be_met_when(const ChangedChoices &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ /**
* Is our condition meetable?
*
* This takes into account inverses, masks, forces etc.
@@ -233,6 +239,11 @@ namespace paludis
virtual bool condition_met() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
/**
+ * Fetch the result for condition_would_be_met_when.
+ */
+ virtual bool condition_would_be_met_when(const ChangedChoices &) const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
+ /**
* Fetch the result for condition_meetable.
*/
virtual bool condition_meetable() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
diff --git a/paludis/elike_conditional_dep_spec.cc b/paludis/elike_conditional_dep_spec.cc
index 70cac0f..0898e82 100644
--- a/paludis/elike_conditional_dep_spec.cc
+++ b/paludis/elike_conditional_dep_spec.cc
@@ -23,8 +23,10 @@
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/simple_visitor_cast.hh>
#include <paludis/util/destringify.hh>
+#include <paludis/util/tribool.hh>
#include <paludis/util/log.hh>
#include <paludis/dep_spec.hh>
+#include <paludis/changed_choices.hh>
#include <paludis/name.hh>
#include <paludis/literal_metadata_key.hh>
#include <paludis/environment.hh>
@@ -138,6 +140,18 @@ namespace
return condition_met() || ! icky_use_query_locked(flag, *id, no_warning_for_unlisted);
}
+ virtual bool condition_would_be_met_when(const ChangedChoices & changes) const
+ {
+ Tribool overridden(changes.overridden_value(flag));
+
+ if (overridden.is_indeterminate())
+ return condition_met();
+ else if (! condition_meetable())
+ return condition_met();
+ else
+ return overridden.is_true() ^ inverse;
+ }
+
virtual void need_keys_added() const
{
}
diff --git a/paludis/files.m4 b/paludis/files.m4
index d152924..2046c88 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -15,6 +15,7 @@ add(`action_names', `hh', `cc', `fwd')
add(`broken_linkage_configuration', `hh', `cc', `test', `testscript')
add(`broken_linkage_finder', `hh', `cc')
add(`buffer_output_manager', `hh', `cc', `fwd')
+add(`changed_choices', `hh', `cc', `fwd')
add(`choice', `hh', `cc', `fwd')
add(`comma_separated_dep_parser', `hh', `cc', `test')
add(`comma_separated_dep_printer', `hh', `cc')