aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-06 18:22:17 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-08 10:53:06 +0100
commit9f3154c1979e28b6f26a584bf0454c85f173fc29 (patch)
tree43ccf15d3c0598cb7dcce7ddb728b7243022f968
parent040928cc089b2bb4d607243a5822d3f24d158f30 (diff)
downloadpaludis-9f3154c1979e28b6f26a584bf0454c85f173fc29.tar.gz
paludis-9f3154c1979e28b6f26a584bf0454c85f173fc29.tar.xz
Add PackageDepSpecCollection
-rw-r--r--paludis/package_dep_spec_collection-fwd.hh28
-rw-r--r--paludis/package_dep_spec_collection.cc76
-rw-r--r--paludis/package_dep_spec_collection.hh51
3 files changed, 155 insertions, 0 deletions
diff --git a/paludis/package_dep_spec_collection-fwd.hh b/paludis/package_dep_spec_collection-fwd.hh
new file mode 100644
index 0000000..cd70806
--- /dev/null
+++ b/paludis/package_dep_spec_collection-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_PACKAGE_DEP_SPEC_COLLECTION_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_PACKAGE_DEP_SPEC_COLLECTION_FWD_HH 1
+
+namespace paludis
+{
+ struct PackageDepSpecCollection;
+}
+
+#endif
diff --git a/paludis/package_dep_spec_collection.cc b/paludis/package_dep_spec_collection.cc
new file mode 100644
index 0000000..d652218
--- /dev/null
+++ b/paludis/package_dep_spec_collection.cc
@@ -0,0 +1,76 @@
+/* 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/package_dep_spec_collection.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/package_id.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/match_package.hh>
+#include <list>
+#include <map>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Imp<PackageDepSpecCollection>
+ {
+ std::multimap<QualifiedPackageName, PackageDepSpec> by_name;
+ std::list<PackageDepSpec> unnamed;
+ };
+}
+
+PackageDepSpecCollection::PackageDepSpecCollection() :
+ Pimp<PackageDepSpecCollection>()
+{
+}
+
+PackageDepSpecCollection::~PackageDepSpecCollection() = default;
+
+void
+PackageDepSpecCollection::insert(const PackageDepSpec & spec)
+{
+ if (spec.package_ptr())
+ _imp->by_name.insert(std::make_pair(*spec.package_ptr(), spec));
+ else
+ _imp->unnamed.push_back(spec);
+}
+
+bool
+PackageDepSpecCollection::match_any(
+ const Environment * const env,
+ const std::shared_ptr<const PackageID> & id,
+ const MatchPackageOptions & opts) const
+{
+ auto named(_imp->by_name.equal_range(id->name()));
+ for ( ; named.first != named.second ; ++named.first)
+ if (match_package(*env, named.first->second, *id, opts))
+ return true;
+
+ for (auto u(_imp->unnamed.begin()), u_end(_imp->unnamed.end()) ;
+ u != u_end ; ++u)
+ if (match_package(*env, *u, *id, opts))
+ return true;
+
+ return false;
+}
+
+template class Pimp<PackageDepSpecCollection>;
+
diff --git a/paludis/package_dep_spec_collection.hh b/paludis/package_dep_spec_collection.hh
new file mode 100644
index 0000000..7ce3beb
--- /dev/null
+++ b/paludis/package_dep_spec_collection.hh
@@ -0,0 +1,51 @@
+/* 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_PACKAGE_DEP_SPEC_COLLECTION_HH
+#define PALUDIS_GUARD_PALUDIS_PACKAGE_DEP_SPEC_COLLECTION_HH 1
+
+#include <paludis/package_dep_spec_collection-fwd.hh>
+#include <paludis/util/pimp.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/match_package-fwd.hh>
+#include <memory>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE PackageDepSpecCollection :
+ private Pimp<PackageDepSpecCollection>
+ {
+ public:
+ PackageDepSpecCollection();
+ ~PackageDepSpecCollection();
+
+ void insert(const PackageDepSpec &);
+
+ bool match_any(
+ const Environment * const,
+ const std::shared_ptr<const PackageID> & id,
+ const MatchPackageOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ extern template class Pimp<PackageDepSpecCollection>;
+}
+
+#endif