aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-02-14 09:43:03 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-02-14 09:43:03 +0000
commit3f23bc84239efb3917f47ff84fa43bca3aacd049 (patch)
tree0cc7ad113b0c50d081a5b8a5cda9e1b9d7fa0391
parent13fd474a32135f52536d2a1a14c89be9bd9ed089 (diff)
downloadpaludis-3f23bc84239efb3917f47ff84fa43bca3aacd049.tar.gz
paludis-3f23bc84239efb3917f47ff84fa43bca3aacd049.tar.xz
Move common metadata key code into a base class
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/metadata_key_holder-fwd.hh28
-rw-r--r--paludis/metadata_key_holder.cc100
-rw-r--r--paludis/metadata_key_holder.hh78
-rw-r--r--paludis/package_id.cc48
-rw-r--r--paludis/package_id.hh34
-rw-r--r--paludis/repository.cc56
-rw-r--r--paludis/repository.hh39
8 files changed, 225 insertions, 159 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 3785fcc..d428ed2 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -39,6 +39,7 @@ add(`match_package', `hh', `cc')
add(`merger', `hh', `cc', `fwd', `se', `sr', `test', `testscript')
add(`merger_entry_type', `hh', `cc', `se')
add(`metadata_key', `hh', `cc', `se', `fwd')
+add(`metadata_key_holder', `hh', `cc', `fwd')
add(`name', `hh', `cc', `fwd', `test', `sr', `se')
add(`ndbam', `hh', `cc', `fwd', `sr')
add(`ndbam_merger', `hh', `cc', `sr')
diff --git a/paludis/metadata_key_holder-fwd.hh b/paludis/metadata_key_holder-fwd.hh
new file mode 100644
index 0000000..5c6c219
--- /dev/null
+++ b/paludis/metadata_key_holder-fwd.hh
@@ -0,0 +1,28 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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_METADATA_KEY_HOLDER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_METADATA_KEY_HOLDER_FWD_HH 1
+
+namespace paludis
+{
+ class MetadataKeyHolder;
+}
+
+#endif
diff --git a/paludis/metadata_key_holder.cc b/paludis/metadata_key_holder.cc
new file mode 100644
index 0000000..77086c0
--- /dev/null
+++ b/paludis/metadata_key_holder.cc
@@ -0,0 +1,100 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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/metadata_key_holder.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/tr1_functional.hh>
+#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/exception.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/metadata_key.hh>
+#include <list>
+#include <algorithm>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<MetadataKeyHolder>
+ {
+ mutable std::list<tr1::shared_ptr<const MetadataKey> > keys;
+ };
+}
+
+MetadataKeyHolder::MetadataKeyHolder() :
+ PrivateImplementationPattern<MetadataKeyHolder>(new Implementation<MetadataKeyHolder>)
+{
+}
+
+MetadataKeyHolder::~MetadataKeyHolder()
+{
+}
+
+void
+MetadataKeyHolder::add_metadata_key(const tr1::shared_ptr<const MetadataKey> & k) const
+{
+ using namespace tr1::placeholders;
+
+ if (indirect_iterator(_imp->keys.end()) != std::find_if(indirect_iterator(_imp->keys.begin()), indirect_iterator(_imp->keys.end()),
+ tr1::bind(std::equal_to<std::string>(), k->raw_name(), tr1::bind(tr1::mem_fn(&MetadataKey::raw_name), _1))))
+ throw ConfigurationError("Tried to add duplicate key '" + k->raw_name() + "'");
+
+ _imp->keys.push_back(k);
+}
+
+MetadataKeyHolder::MetadataConstIterator
+MetadataKeyHolder::begin_metadata() const
+{
+ need_keys_added();
+ return MetadataConstIterator(_imp->keys.begin());
+}
+
+MetadataKeyHolder::MetadataConstIterator
+MetadataKeyHolder::end_metadata() const
+{
+ need_keys_added();
+ return MetadataConstIterator(_imp->keys.end());
+}
+
+MetadataKeyHolder::MetadataConstIterator
+MetadataKeyHolder::find_metadata(const std::string & s) const
+{
+ using namespace tr1::placeholders;
+
+ need_keys_added();
+
+ // tr1::mem_fn on a sptr doesn't work with boost
+ // return std::find_if(begin_metadata(), end_metadata(),
+ // tr1::bind(std::equal_to<std::string>(), s, tr1::bind(tr1::mem_fn(&MetadataKey::raw_name), _1)));
+
+ for (MetadataConstIterator i(begin_metadata()), i_end(end_metadata()) ;
+ i != i_end ; ++i)
+ if ((*i)->raw_name() == s)
+ return i;
+ return end_metadata();
+}
+
+void
+MetadataKeyHolder::clear_metadata_keys() const
+{
+ _imp->keys.clear();
+}
+
diff --git a/paludis/metadata_key_holder.hh b/paludis/metadata_key_holder.hh
new file mode 100644
index 0000000..2128e97
--- /dev/null
+++ b/paludis/metadata_key_holder.hh
@@ -0,0 +1,78 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 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_METADATA_KEY_HOLDER_HH
+#define PALUDIS_GUARD_PALUDIS_METADATA_KEY_HOLDER_HH 1
+
+#include <paludis/metadata_key_holder-fwd.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/wrapped_forward_iterator-fwd.hh>
+#include <paludis/util/tr1_memory.hh>
+#include <paludis/metadata_key-fwd.hh>
+
+namespace paludis
+{
+ /**
+ * Generic interface for any class that holds a number of MetadataKey
+ * instances.
+ *
+ * \since 0.26
+ * \ingroup g_metadata_key
+ */
+ class PALUDIS_VISIBLE MetadataKeyHolder :
+ private PrivateImplementationPattern<MetadataKeyHolder>
+ {
+ protected:
+ /**
+ * Add a new MetadataKey, which must not use the same raw name as
+ * any previous MetadataKey added to this ID.
+ */
+ virtual void add_metadata_key(const tr1::shared_ptr<const MetadataKey> &) const;
+
+ /**
+ * Clear all MetadataKey instances added using add_metadata_key.
+ */
+ virtual void clear_metadata_keys() const;
+
+ /**
+ * This method will be called before any of the metadata key
+ * iteration methods does its work. It can be used by subclasses to
+ * implement as-needed loading of keys.
+ */
+ virtual void need_keys_added() const = 0;
+
+ public:
+ MetadataKeyHolder();
+ virtual ~MetadataKeyHolder() = 0;
+
+ ///\name Finding and iterating over metadata keys
+ ///\{
+
+ struct MetadataConstIteratorTag;
+ typedef WrappedForwardIterator<MetadataConstIteratorTag, tr1::shared_ptr<const MetadataKey> > MetadataConstIterator;
+
+ MetadataConstIterator begin_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ MetadataConstIterator end_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ MetadataConstIterator find_metadata(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ ///\}
+ };
+}
+
+#endif
diff --git a/paludis/package_id.cc b/paludis/package_id.cc
index f5aa643..2d0b6de 100644
--- a/paludis/package_id.cc
+++ b/paludis/package_id.cc
@@ -64,13 +64,13 @@ namespace paludis
template <>
struct Implementation<PackageID>
{
- mutable std::list<tr1::shared_ptr<const MetadataKey> > keys;
mutable std::list<tr1::shared_ptr<const Mask> > masks;
};
}
PackageID::PackageID() :
- PrivateImplementationPattern<PackageID>(new Implementation<PackageID>)
+ PrivateImplementationPattern<PackageID>(new Implementation<PackageID>),
+ _imp(PrivateImplementationPattern<PackageID>::_imp)
{
}
@@ -79,32 +79,6 @@ PackageID::~PackageID()
}
void
-PackageID::add_metadata_key(const tr1::shared_ptr<const MetadataKey> & k) const
-{
- using namespace tr1::placeholders;
-
- if (indirect_iterator(_imp->keys.end()) != std::find_if(indirect_iterator(_imp->keys.begin()), indirect_iterator(_imp->keys.end()),
- tr1::bind(std::equal_to<std::string>(), k->raw_name(), tr1::bind(tr1::mem_fn(&MetadataKey::raw_name), _1))))
- throw ConfigurationError("Tried to add duplicate key '" + k->raw_name() + "' to ID '" + stringify(*this) + "'");
-
- _imp->keys.push_back(k);
-}
-
-PackageID::MetadataConstIterator
-PackageID::begin_metadata() const
-{
- need_keys_added();
- return MetadataConstIterator(_imp->keys.begin());
-}
-
-PackageID::MetadataConstIterator
-PackageID::end_metadata() const
-{
- need_keys_added();
- return MetadataConstIterator(_imp->keys.end());
-}
-
-void
PackageID::add_mask(const tr1::shared_ptr<const Mask> & k) const
{
_imp->masks.push_back(k);
@@ -136,24 +110,6 @@ PackageID::invalidate_masks() const
_imp->masks.clear();
}
-PackageID::MetadataConstIterator
-PackageID::find_metadata(const std::string & s) const
-{
- using namespace tr1::placeholders;
-
- need_keys_added();
-
- // tr1::mem_fn on a sptr doesn't work with boost
- // return std::find_if(begin_metadata(), end_metadata(),
- // tr1::bind(std::equal_to<std::string>(), s, tr1::bind(tr1::mem_fn(&MetadataKey::raw_name), _1)));
-
- for (MetadataConstIterator i(begin_metadata()), i_end(end_metadata()) ;
- i != i_end ; ++i)
- if ((*i)->raw_name() == s)
- return i;
- return end_metadata();
-}
-
std::ostream &
paludis::operator<< (std::ostream & s, const PackageID & i)
{
diff --git a/paludis/package_id.hh b/paludis/package_id.hh
index 822fedb..96f9797 100644
--- a/paludis/package_id.hh
+++ b/paludis/package_id.hh
@@ -23,7 +23,6 @@
#include <paludis/package_id-fwd.hh>
#include <paludis/util/attributes.hh>
-#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/operators.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/tr1_memory.hh>
@@ -34,6 +33,7 @@
#include <paludis/dep_tree-fwd.hh>
#include <paludis/mask-fwd.hh>
#include <paludis/metadata_key-fwd.hh>
+#include <paludis/metadata_key_holder.hh>
#include <paludis/name-fwd.hh>
#include <paludis/repository-fwd.hh>
#include <paludis/version_spec-fwd.hh>
@@ -86,30 +86,20 @@ namespace paludis
* via an Action subclass instance.
*/
class PALUDIS_VISIBLE PackageID :
- private InstantiationPolicy<PackageID, instantiation_method::NonCopyableTag>,
private PrivateImplementationPattern<PackageID>,
- public equality_operators::HasEqualityOperators
+ public equality_operators::HasEqualityOperators,
+ public MetadataKeyHolder
{
- protected:
- /**
- * Add a new MetadataKey, which must not use the same raw name as
- * any previous MetadataKey added to this ID.
- */
- virtual void add_metadata_key(const tr1::shared_ptr<const MetadataKey> &) const;
+ private:
+ PrivateImplementationPattern<PackageID>::ImpPtr & _imp;
+ protected:
/**
* Add a new Mask.
*/
virtual void add_mask(const tr1::shared_ptr<const Mask> &) const;
/**
- * This method will be called before any of the metadata key
- * iteration methods does its work. It can be used by subclasses to
- * implement as-needed loading of keys.
- */
- virtual void need_keys_added() const = 0;
-
- /**
* This method will be called before any of the mask iteration
* methods does its work. It can be used by subclasses to implement
* as-needed loading of masks.
@@ -297,18 +287,6 @@ namespace paludis
///\}
- ///\name Finding and iterating over metadata keys
- ///\{
-
- struct MetadataConstIteratorTag;
- typedef WrappedForwardIterator<MetadataConstIteratorTag, tr1::shared_ptr<const MetadataKey> > MetadataConstIterator;
-
- MetadataConstIterator begin_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
- MetadataConstIterator end_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
- MetadataConstIterator find_metadata(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result));
-
- ///\}
-
///\name Actions
///\{
diff --git a/paludis/repository.cc b/paludis/repository.cc
index 89e7374..44473b7 100644
--- a/paludis/repository.cc
+++ b/paludis/repository.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 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
@@ -100,7 +100,6 @@ namespace paludis
template <>
struct Implementation<Repository>
{
- mutable std::list<tr1::shared_ptr<const MetadataKey> > keys;
const RepositoryName name;
Implementation(const RepositoryName & n) :
@@ -114,7 +113,8 @@ Repository::Repository(
const RepositoryName & our_name,
const RepositoryCapabilities & caps) :
PrivateImplementationPattern<Repository>(new Implementation<Repository>(our_name)),
- RepositoryCapabilities(caps)
+ RepositoryCapabilities(caps),
+ _imp(PrivateImplementationPattern<Repository>::_imp)
{
std::map<std::string, std::string>::const_iterator i(
RepositoryBlacklist::get_instance()->items.find(stringify(name())));
@@ -133,56 +133,6 @@ Repository::name() const
return _imp->name;
}
-void
-Repository::add_metadata_key(const tr1::shared_ptr<const MetadataKey> & k) const
-{
- using namespace tr1::placeholders;
-
- if (indirect_iterator(_imp->keys.end()) != std::find_if(indirect_iterator(_imp->keys.begin()), indirect_iterator(_imp->keys.end()),
- tr1::bind(std::equal_to<std::string>(), k->raw_name(), tr1::bind(tr1::mem_fn(&MetadataKey::raw_name), _1))))
- throw ConfigurationError("Tried to add duplicate key '" + k->raw_name() + "' to Repository '" + stringify(name()) + "'");
-
- _imp->keys.push_back(k);
-}
-
-void
-Repository::clear_metadata_keys() const
-{
- _imp->keys.clear();
-}
-
-Repository::MetadataConstIterator
-Repository::begin_metadata() const
-{
- need_keys_added();
- return MetadataConstIterator(_imp->keys.begin());
-}
-
-Repository::MetadataConstIterator
-Repository::end_metadata() const
-{
- need_keys_added();
- return MetadataConstIterator(_imp->keys.end());
-}
-
-Repository::MetadataConstIterator
-Repository::find_metadata(const std::string & s) const
-{
- using namespace tr1::placeholders;
-
- need_keys_added();
-
- // tr1::mem_fn on a sptr doesn't work with boost
- // return std::find_if(begin_metadata(), end_metadata(),
- // tr1::bind(std::equal_to<std::string>(), s, tr1::bind(tr1::mem_fn(&MetadataKey::raw_name), _1)));
-
- for (MetadataConstIterator i(begin_metadata()), i_end(end_metadata()) ;
- i != i_end ; ++i)
- if ((*i)->raw_name() == s)
- return i;
- return end_metadata();
-}
-
tr1::shared_ptr<const CategoryNamePartSet>
Repository::category_names_containing_package(const PackageNamePart & p) const
{
diff --git a/paludis/repository.hh b/paludis/repository.hh
index a78239b..5d0d8f9 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008 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
@@ -36,6 +36,7 @@
#include <paludis/util/options.hh>
#include <paludis/version_spec.hh>
#include <paludis/metadata_key-fwd.hh>
+#include <paludis/metadata_key_holder.hh>
#include <paludis/merger-fwd.hh>
#include <string>
@@ -132,8 +133,12 @@ namespace paludis
class PALUDIS_VISIBLE Repository :
private InstantiationPolicy<Repository, instantiation_method::NonCopyableTag>,
private PrivateImplementationPattern<Repository>,
- public RepositoryCapabilities
+ public RepositoryCapabilities,
+ public MetadataKeyHolder
{
+ private:
+ PrivateImplementationPattern<Repository>::ImpPtr & _imp;
+
protected:
///\name Basic operations
///\{
@@ -142,24 +147,6 @@ namespace paludis
///\}
- /**
- * Add a new MetadataKey, which must not use the same raw name as
- * any previous MetadataKey added to this repository.
- */
- virtual void add_metadata_key(const tr1::shared_ptr<const MetadataKey> &) const;
-
- /**
- * Clear all MetadataKey instances added using add_metadata_key.
- */
- virtual void clear_metadata_keys() const;
-
- /**
- * This method will be called before any of the metadata key
- * iteration methods does its work. It can be used by subclasses to
- * implement as-needed loading of keys.
- */
- virtual void need_keys_added() const = 0;
-
public:
///\name Basic operations
///\{
@@ -205,18 +192,6 @@ namespace paludis
///\}
- ///\name Finding and iterating over metadata keys
- ///\{
-
- struct MetadataConstIteratorTag;
- typedef WrappedForwardIterator<MetadataConstIteratorTag, tr1::shared_ptr<const MetadataKey> > MetadataConstIterator;
-
- MetadataConstIterator begin_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
- MetadataConstIterator end_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
- MetadataConstIterator find_metadata(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result));
-
- ///\}
-
///\name Repository content queries
///\{