aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-24 13:13:15 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-24 13:13:15 +0100
commit4fc32662efa9448e750621cba697a40818c6827b (patch)
treea6fcbf568eb67b4e605bc7db7a427e01550c8774
parent637a8d521b304dec1ec4db201d5d71d509efb6c1 (diff)
downloadpaludis-4fc32662efa9448e750621cba697a40818c6827b.tar.gz
paludis-4fc32662efa9448e750621cba697a40818c6827b.tar.xz
Factor out common code
-rw-r--r--src/clients/cave/Makefile.am1
-rw-r--r--src/clients/cave/cmd_show.cc40
-rw-r--r--src/clients/cave/not_strongly_masked.cc68
-rw-r--r--src/clients/cave/not_strongly_masked.hh35
4 files changed, 106 insertions, 38 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index ad45fb0..bff79f9 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -156,6 +156,7 @@ libcave_a_SOURCES = \
script_command.cc script_command.hh \
select_format_for_spec.cc select_format_for_spec.hh \
match_qpns.cc match_qpns.hh \
+ not_strongly_masked.cc not_strongly_masked.hh \
owner_common.cc owner_common.hh \
resolve_common.cc resolve_common.hh \
resume_data.cc resume_data.hh
diff --git a/src/clients/cave/cmd_show.cc b/src/clients/cave/cmd_show.cc
index 854cfe8..c1a0e92 100644
--- a/src/clients/cave/cmd_show.cc
+++ b/src/clients/cave/cmd_show.cc
@@ -23,6 +23,7 @@
#include "formats.hh"
#include "exceptions.hh"
#include "select_format_for_spec.hh"
+#include "not_strongly_masked.hh"
#include <paludis/args/args.hh>
#include <paludis/args/do_help.hh>
#include <paludis/name.hh>
@@ -863,34 +864,6 @@ namespace
}
}
- struct WeakMask
- {
- bool visit(const UnacceptedMask &) const
- {
- return true;
- }
-
- bool visit(const UserMask &) const
- {
- return false;
- }
-
- bool visit(const RepositoryMask &) const
- {
- return true;
- }
-
- bool visit(const UnsupportedMask &) const
- {
- return false;
- }
-
- bool visit(const AssociationMask &) const
- {
- return false;
- }
- };
-
void do_one_package(
const ShowCommandLine & cmdline,
const std::shared_ptr<Environment> & env,
@@ -915,16 +888,7 @@ namespace
{
if ((*i)->masked())
{
- bool weak_masked(true);
- for (PackageID::MasksConstIterator m((*i)->begin_masks()), m_end((*i)->end_masks()) ;
- m != m_end ; ++m)
- if (! (*m)->accept_returning<bool>(WeakMask()))
- {
- weak_masked = false;
- break;
- }
-
- if (weak_masked)
+ if (not_strongly_masked(*i))
best_weak_masked_installable = *i;
else
best_masked_installable = *i;
diff --git a/src/clients/cave/not_strongly_masked.cc b/src/clients/cave/not_strongly_masked.cc
new file mode 100644
index 0000000..0374f31
--- /dev/null
+++ b/src/clients/cave/not_strongly_masked.cc
@@ -0,0 +1,68 @@
+/* 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 "not_strongly_masked.hh"
+#include <paludis/package_id.hh>
+#include <paludis/mask.hh>
+
+using namespace paludis;
+using namespace cave;
+
+namespace
+{
+ struct WeakMask
+ {
+ bool visit(const UnacceptedMask &) const
+ {
+ return true;
+ }
+
+ bool visit(const UserMask &) const
+ {
+ return false;
+ }
+
+ bool visit(const RepositoryMask &) const
+ {
+ return true;
+ }
+
+ bool visit(const UnsupportedMask &) const
+ {
+ return false;
+ }
+
+ bool visit(const AssociationMask &) const
+ {
+ return false;
+ }
+ };
+}
+
+bool
+paludis::cave::not_strongly_masked(const std::shared_ptr<const PackageID> & id)
+{
+ for (auto m(id->begin_masks()), m_end(id->end_masks()) ;
+ m != m_end ; ++m)
+ if (! (*m)->accept_returning<bool>(WeakMask()))
+ return false;
+
+ return true;
+}
+
diff --git a/src/clients/cave/not_strongly_masked.hh b/src/clients/cave/not_strongly_masked.hh
new file mode 100644
index 0000000..97f4d33
--- /dev/null
+++ b/src/clients/cave/not_strongly_masked.hh
@@ -0,0 +1,35 @@
+/* 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_SRC_CLIENTS_CAVE_NOT_STRONGLY_MASKED_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_NOT_STRONGLY_MASKED_HH 1
+
+#include <paludis/package_id-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <memory>
+
+namespace paludis
+{
+ namespace cave
+ {
+ bool not_strongly_masked(const std::shared_ptr<const PackageID> &) PALUDIS_ATTRIBUTE((warn_unused_result));
+ }
+}
+
+#endif