diff options
author | 2010-12-19 01:19:21 +0000 | |
---|---|---|
committer | 2010-12-19 01:19:21 +0000 | |
commit | 7d994ad210d8fc308a506ad9c2cd3eeed4607a65 (patch) | |
tree | a85245d7592cdd3fc289998e4b863268825c0f3e | |
parent | b990aeda2d842664cb12aa75c5cb48142779af82 (diff) | |
download | paludis-7d994ad210d8fc308a506ad9c2cd3eeed4607a65.tar.gz paludis-7d994ad210d8fc308a506ad9c2cd3eeed4607a65.tar.xz |
Do annotations differently
25 files changed, 286 insertions, 601 deletions
diff --git a/paludis/dep_spec.cc b/paludis/dep_spec.cc index 602646997..6085ad1b1 100644 --- a/paludis/dep_spec.cc +++ b/paludis/dep_spec.cc @@ -34,7 +34,6 @@ #include <paludis/util/iterator_funcs.hh> #include <paludis/util/indirect_iterator-impl.hh> #include <paludis/util/options.hh> -#include <paludis/metadata_key.hh> #include <paludis/additional_package_dep_spec_requirement.hh> #include <paludis/dep_spec_data.hh> @@ -52,22 +51,12 @@ namespace paludis template <> struct Imp<DepSpec> { - std::shared_ptr<const MetadataSectionKey> annotations_key; - - Imp() - { - } - - Imp(const std::shared_ptr<const MetadataSectionKey> & k) : - annotations_key(k) - { - } + std::shared_ptr<const DepSpecAnnotations> annotations; }; } DepSpec::DepSpec() : - Pimp<DepSpec>(), - _imp(Pimp<DepSpec>::_imp) + Pimp<DepSpec>() { } @@ -75,19 +64,16 @@ DepSpec::~DepSpec() { } -const std::shared_ptr<const MetadataSectionKey> -DepSpec::annotations_key() const +const std::shared_ptr<const DepSpecAnnotations> +DepSpec::maybe_annotations() const { - return _imp->annotations_key; + return _imp->annotations; } void -DepSpec::set_annotations_key(const std::shared_ptr<const MetadataSectionKey> & k) +DepSpec::set_annotations(const std::shared_ptr<const DepSpecAnnotations> & a) { - clear_metadata_keys(); - _imp->annotations_key = k; - if (_imp->annotations_key) - add_metadata_key(_imp->annotations_key); + _imp->annotations = a; } AnyDepSpec::AnyDepSpec() @@ -98,30 +84,19 @@ std::shared_ptr<DepSpec> AnyDepSpec::clone() const { std::shared_ptr<AnyDepSpec> result(std::make_shared<AnyDepSpec>()); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } -void -AnyDepSpec::need_keys_added() const -{ -} - - AllDepSpec::AllDepSpec() { } -void -AllDepSpec::need_keys_added() const -{ -} - std::shared_ptr<DepSpec> AllDepSpec::clone() const { std::shared_ptr<AllDepSpec> result(std::make_shared<AllDepSpec>()); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } @@ -129,16 +104,11 @@ ExactlyOneDepSpec::ExactlyOneDepSpec() { } -void -ExactlyOneDepSpec::need_keys_added() const -{ -} - std::shared_ptr<DepSpec> ExactlyOneDepSpec::clone() const { std::shared_ptr<ExactlyOneDepSpec> result(std::make_shared<ExactlyOneDepSpec>()); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } @@ -148,12 +118,9 @@ namespace paludis struct Imp<ConditionalDepSpec> { const std::shared_ptr<const ConditionalDepSpecData> data; - Mutex mutex; - bool added_keys; Imp(const std::shared_ptr<const ConditionalDepSpecData> & d) : - data(d), - added_keys(false) + data(d) { } }; @@ -182,34 +149,13 @@ ConditionalDepSpec::ConditionalDepSpec(const ConditionalDepSpec & other) : CloneUsingThis<DepSpec, ConditionalDepSpec>(other), _imp(Pimp<ConditionalDepSpec>::_imp) { - set_annotations_key(other.annotations_key()); + set_annotations(other.maybe_annotations()); } ConditionalDepSpec::~ConditionalDepSpec() { } -void -ConditionalDepSpec::need_keys_added() const -{ - Lock l(_imp->mutex); - if (! _imp->added_keys) - { - _imp->added_keys = true; - using namespace std::placeholders; - std::for_each(_imp->data->begin_metadata(), _imp->data->end_metadata(), - std::bind(&ConditionalDepSpec::add_metadata_key, this, _1)); - } -} - -void -ConditionalDepSpec::clear_metadata_keys() const -{ - Lock l(_imp->mutex); - _imp->added_keys = false; - MetadataKeyHolder::clear_metadata_keys(); -} - bool ConditionalDepSpec::condition_met() const { @@ -262,15 +208,10 @@ std::shared_ptr<DepSpec> NamedSetDepSpec::clone() const { std::shared_ptr<NamedSetDepSpec> result(std::make_shared<NamedSetDepSpec>(_name)); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } -void -NamedSetDepSpec::need_keys_added() const -{ -} - BlockDepSpec::BlockDepSpec(const std::string & s, const PackageDepSpec & p, const BlockKind k) : StringDepSpec(s), _spec(p), @@ -283,7 +224,7 @@ BlockDepSpec::BlockDepSpec(const BlockDepSpec & other) : _spec(other._spec), _kind(other._kind) { - set_annotations_key(other.annotations_key()); + set_annotations(other.maybe_annotations()); } std::ostream & @@ -391,15 +332,10 @@ std::shared_ptr<DepSpec> PlainTextDepSpec::clone() const { std::shared_ptr<PlainTextDepSpec> result(std::make_shared<PlainTextDepSpec>(text())); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } -void -PlainTextDepSpec::need_keys_added() const -{ -} - PlainTextLabelDepSpec::PlainTextLabelDepSpec(const std::string & s) : StringDepSpec(s) { @@ -413,7 +349,7 @@ std::shared_ptr<DepSpec> PlainTextLabelDepSpec::clone() const { std::shared_ptr<PlainTextLabelDepSpec> result(std::make_shared<PlainTextLabelDepSpec>(text())); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } @@ -423,11 +359,6 @@ PlainTextLabelDepSpec::label() const return text().substr(0, text().length() - 1); } -void -PlainTextLabelDepSpec::need_keys_added() const -{ -} - LicenseDepSpec::LicenseDepSpec(const std::string & s) : StringDepSpec(s) { @@ -437,15 +368,10 @@ std::shared_ptr<DepSpec> LicenseDepSpec::clone() const { std::shared_ptr<LicenseDepSpec> result(std::make_shared<LicenseDepSpec>(text())); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } -void -LicenseDepSpec::need_keys_added() const -{ -} - SimpleURIDepSpec::SimpleURIDepSpec(const std::string & s) : StringDepSpec(s) { @@ -455,15 +381,10 @@ std::shared_ptr<DepSpec> SimpleURIDepSpec::clone() const { std::shared_ptr<SimpleURIDepSpec> result(std::make_shared<SimpleURIDepSpec>(text())); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } -void -SimpleURIDepSpec::need_keys_added() const -{ -} - const PackageDepSpec BlockDepSpec::blocking() const { @@ -486,26 +407,15 @@ std::shared_ptr<DepSpec> BlockDepSpec::clone() const { std::shared_ptr<BlockDepSpec> result(std::make_shared<BlockDepSpec>(*this)); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } -void -BlockDepSpec::need_keys_added() const -{ -} - FetchableURIDepSpec::FetchableURIDepSpec(const std::string & s) : StringDepSpec(s) { } -void -FetchableURIDepSpec::need_keys_added() const -{ -} - - std::string FetchableURIDepSpec::original_url() const { @@ -545,7 +455,7 @@ std::shared_ptr<DepSpec> FetchableURIDepSpec::clone() const { std::shared_ptr<FetchableURIDepSpec> result(std::make_shared<FetchableURIDepSpec>(text())); - result->set_annotations_key(annotations_key()); + result->set_annotations(maybe_annotations()); return result; } @@ -588,7 +498,7 @@ LabelsDepSpec<T_>::clone() const { using namespace std::placeholders; std::shared_ptr<LabelsDepSpec<T_> > my_clone(std::make_shared<LabelsDepSpec<T_>>()); - my_clone->set_annotations_key(annotations_key()); + my_clone->set_annotations(maybe_annotations()); std::for_each(begin(), end(), std::bind(std::mem_fn(&LabelsDepSpec<T_>::add_label), my_clone.get(), _1)); return my_clone; } @@ -614,12 +524,6 @@ LabelsDepSpec<T_>::add_label(const std::shared_ptr<const T_> & item) _imp->items.push_back(item); } -template <typename T_> -void -LabelsDepSpec<T_>::need_keys_added() const -{ -} - namespace paludis { template <> @@ -642,7 +546,6 @@ PackageDepSpec::PackageDepSpec(const std::shared_ptr<const PackageDepSpecData> & Pimp<PackageDepSpec>(d, std::shared_ptr<const DepTag>()), _imp(Pimp<PackageDepSpec>::_imp) { - set_annotations_key(d->annotations_key()); } PackageDepSpec::~PackageDepSpec() @@ -656,7 +559,7 @@ PackageDepSpec::PackageDepSpec(const PackageDepSpec & d) : CloneUsingThis<DepSpec, PackageDepSpec>(d), _imp(Pimp<PackageDepSpec>::_imp) { - set_annotations_key(d.annotations_key()); + set_annotations(d.maybe_annotations()); } std::shared_ptr<const QualifiedPackageName> @@ -755,11 +658,6 @@ PackageDepSpec::data() const return _imp->data; } -void -PackageDepSpec::need_keys_added() const -{ -} - template class LabelsDepSpec<URILabel>; template class LabelsDepSpec<DependenciesLabel>; diff --git a/paludis/dep_spec.hh b/paludis/dep_spec.hh index fc3584cf5..a9aedb8bd 100644 --- a/paludis/dep_spec.hh +++ b/paludis/dep_spec.hh @@ -32,7 +32,6 @@ #include <paludis/dep_spec-fwd.hh> #include <paludis/dep_tag-fwd.hh> #include <paludis/name.hh> -#include <paludis/metadata_key_holder.hh> #include <paludis/version_operator-fwd.hh> #include <paludis/version_requirements-fwd.hh> #include <paludis/version_spec-fwd.hh> @@ -42,6 +41,7 @@ #include <paludis/additional_package_dep_spec_requirement-fwd.hh> #include <paludis/partially_made_package_dep_spec-fwd.hh> #include <paludis/dep_spec_data-fwd.hh> +#include <paludis/dep_spec_annotations-fwd.hh> #include <memory> @@ -67,12 +67,8 @@ namespace paludis */ class PALUDIS_VISIBLE DepSpec : private Pimp<DepSpec>, - public MetadataKeyHolder, public virtual Cloneable<DepSpec> { - private: - Pimp<DepSpec>::ImpPtr & _imp; - protected: DepSpec(); @@ -87,21 +83,19 @@ namespace paludis ///\} - ///\name Upcasts - ///\{ - /** - * The annotations_key, if non-zero, contains any annotations. + * Our annotations, may be null. + * + * \since 0.58 */ - const std::shared_ptr<const MetadataSectionKey> annotations_key() const - PALUDIS_ATTRIBUTE((warn_unused_result)); + const std::shared_ptr<const DepSpecAnnotations> maybe_annotations() const PALUDIS_ATTRIBUTE((warn_unused_result)); /** - * Change the annotations key. + * Change our annotations, may be null. + * + * \since 0.58 */ - void set_annotations_key(const std::shared_ptr<const MetadataSectionKey> &); - - ///\} + void set_annotations(const std::shared_ptr<const DepSpecAnnotations> &); }; /** @@ -113,9 +107,6 @@ namespace paludis class PALUDIS_VISIBLE AnyDepSpec : public DepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -137,9 +128,6 @@ namespace paludis class PALUDIS_VISIBLE AllDepSpec : public DepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -161,9 +149,6 @@ namespace paludis class PALUDIS_VISIBLE ExactlyOneDepSpec : public DepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -195,10 +180,6 @@ namespace paludis std::string _as_string() const; - protected: - virtual void need_keys_added() const; - virtual void clear_metadata_keys() const; - public: ///\name Basic operations ///\{ @@ -332,9 +313,6 @@ namespace paludis Pimp<PackageDepSpec>::ImpPtr & _imp; - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -448,9 +426,6 @@ namespace paludis class PALUDIS_VISIBLE PlainTextDepSpec : public StringDepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -474,9 +449,6 @@ namespace paludis private: const SetName _name; - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -501,9 +473,6 @@ namespace paludis class PALUDIS_VISIBLE LicenseDepSpec : public StringDepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -529,9 +498,6 @@ namespace paludis class PALUDIS_VISIBLE FetchableURIDepSpec : public StringDepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -573,9 +539,6 @@ namespace paludis class PALUDIS_VISIBLE SimpleURIDepSpec : public StringDepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -621,9 +584,6 @@ namespace paludis PackageDepSpec _spec; BlockKind _kind; - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -679,9 +639,6 @@ namespace paludis private: typename Pimp<LabelsDepSpec>::ImpPtr & _imp; - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ @@ -711,9 +668,6 @@ namespace paludis class PALUDIS_VISIBLE PlainTextLabelDepSpec : public StringDepSpec { - protected: - virtual void need_keys_added() const; - public: ///\name Basic operations ///\{ diff --git a/paludis/elike_annotations-fwd.hh b/paludis/dep_spec_annotations-fwd.hh index d54845c38..63f5ee7e6 100644 --- a/paludis/elike_annotations-fwd.hh +++ b/paludis/dep_spec_annotations-fwd.hh @@ -17,12 +17,13 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef PALUDIS_GUARD_PALUDIS_ELIKE_ANNOTATIONS_FWD_HH -#define PALUDIS_GUARD_PALUDIS_ELIKE_ANNOTATIONS_FWD_HH 1 +#ifndef PALUDIS_GUARD_PALUDIS_DEP_SPEC_ANNOTATIONS_FWD_HH +#define PALUDIS_GUARD_PALUDIS_DEP_SPEC_ANNOTATIONS_FWD_HH 1 namespace paludis { - struct ELikeAnnotations; + class DepSpecAnnotation; + class DepSpecAnnotations; } #endif diff --git a/paludis/dep_spec_annotations.cc b/paludis/dep_spec_annotations.cc new file mode 100644 index 000000000..32603a5c9 --- /dev/null +++ b/paludis/dep_spec_annotations.cc @@ -0,0 +1,91 @@ +/* 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/dep_spec_annotations.hh> +#include <paludis/util/pimp-impl.hh> +#include <paludis/util/wrapped_forward_iterator-impl.hh> +#include <paludis/util/exception.hh> +#include <paludis/util/stringify.hh> +#include <ostream> +#include <vector> +#include <algorithm> +#include <functional> + +using namespace paludis; + +typedef std::vector<DepSpecAnnotation> Annotations; + +namespace paludis +{ + template <> + struct Imp<DepSpecAnnotations> + { + Annotations annotations; + }; + + template <> + struct WrappedForwardIteratorTraits<DepSpecAnnotations::ConstIteratorTag> + { + typedef Annotations::const_iterator UnderlyingIterator; + }; +} + +DepSpecAnnotations::DepSpecAnnotations() : + Pimp<DepSpecAnnotations>() +{ +} + +DepSpecAnnotations::~DepSpecAnnotations() = default; + +DepSpecAnnotations::ConstIterator +DepSpecAnnotations::begin() const +{ + return ConstIterator(_imp->annotations.begin()); +} + +DepSpecAnnotations::ConstIterator +DepSpecAnnotations::end() const +{ + return ConstIterator(_imp->annotations.end()); +} + +namespace +{ + bool key_is(const DepSpecAnnotation & a, const std::string & k) + { + return a.key() == k; + } +} + +DepSpecAnnotations::ConstIterator +DepSpecAnnotations::find(const std::string & s) const +{ + return ConstIterator(std::find_if(_imp->annotations.begin(), _imp->annotations.end(), + std::bind(&key_is, std::placeholders::_1, s))); +} + +void +DepSpecAnnotations::add(const DepSpecAnnotation & a) +{ + _imp->annotations.push_back(a); +} + +template class Pimp<DepSpecAnnotations>; +template class WrappedForwardIterator<DepSpecAnnotations::ConstIteratorTag, const DepSpecAnnotation>; + diff --git a/paludis/dep_spec_annotations.hh b/paludis/dep_spec_annotations.hh new file mode 100644 index 000000000..e28d4ab86 --- /dev/null +++ b/paludis/dep_spec_annotations.hh @@ -0,0 +1,64 @@ +/* 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_DEP_SPEC_ANNOTATIONS_HH +#define PALUDIS_GUARD_PALUDIS_DEP_SPEC_ANNOTATIONS_HH 1 + +#include <paludis/dep_spec_annotations-fwd.hh> +#include <paludis/util/pimp.hh> +#include <paludis/util/attributes.hh> +#include <paludis/util/named_value.hh> +#include <paludis/util/wrapped_forward_iterator.hh> + +namespace paludis +{ + namespace n + { + typedef Name<struct key_name> key; + typedef Name<struct value_name> value; + } + + struct DepSpecAnnotation + { + NamedValue<n::key, std::string> key; + NamedValue<n::value, std::string> value; + }; + + class PALUDIS_VISIBLE DepSpecAnnotations : + private Pimp<DepSpecAnnotations> + { + public: + DepSpecAnnotations(); + ~DepSpecAnnotations(); + + void add(const DepSpecAnnotation &); + + struct ConstIteratorTag; + typedef WrappedForwardIterator<ConstIteratorTag, const DepSpecAnnotation> ConstIterator; + + ConstIterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result)); + ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result)); + ConstIterator find(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result)); + }; + + extern template class Pimp<DepSpecAnnotations>; + extern template class WrappedForwardIterator<DepSpecAnnotations::ConstIteratorTag, const DepSpecAnnotation>; +} + +#endif diff --git a/paludis/dep_spec_data.hh b/paludis/dep_spec_data.hh index aff05ada6..6fe3084e1 100644 --- a/paludis/dep_spec_data.hh +++ b/paludis/dep_spec_data.hh @@ -163,11 +163,6 @@ namespace paludis virtual std::shared_ptr<const AdditionalPackageDepSpecRequirements> additional_requirements_ptr() const = 0; /** - * Fetch the annotations (may be a zero pointer). - */ - virtual std::shared_ptr<const MetadataSectionKey> annotations_key() const = 0; - - /** * Fetch options if we're being used to construct a new PartiallyMadePackageDepSpec. * * \since 0.38 diff --git a/paludis/elike_annotations.cc b/paludis/elike_annotations.cc deleted file mode 100644 index 54e984f45..000000000 --- a/paludis/elike_annotations.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* 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/elike_annotations.hh> -#include <paludis/util/pimp-impl.hh> -#include <paludis/util/map.hh> -#include <paludis/util/wrapped_forward_iterator.hh> -#include <paludis/literal_metadata_key.hh> - -using namespace paludis; - -namespace paludis -{ - template <> - struct Imp<ELikeAnnotations> - { - }; -} - -ELikeAnnotations::ELikeAnnotations(const std::shared_ptr<const Map<std::string, std::string> > & m) : - Pimp<ELikeAnnotations>() -{ - for (Map<std::string, std::string>::ConstIterator k(m->begin()), k_end(m->end()) ; - k != k_end ; ++k) - add_metadata_key(std::make_shared<LiteralMetadataValueKey<std::string>>( - k->first, k->first, mkt_normal, k->second)); -} - -ELikeAnnotations::~ELikeAnnotations() -{ -} - - -void -ELikeAnnotations::need_keys_added() const -{ -} - -const std::string -ELikeAnnotations::human_name() const -{ - return "Annotations"; -} - -const std::string -ELikeAnnotations::raw_name() const -{ - return "Annotations"; -} - -MetadataKeyType -ELikeAnnotations::type() const -{ - return mkt_normal; -} - -template class Pimp<ELikeAnnotations>; - diff --git a/paludis/elike_annotations.hh b/paludis/elike_annotations.hh deleted file mode 100644 index 781cc92c2..000000000 --- a/paludis/elike_annotations.hh +++ /dev/null @@ -1,48 +0,0 @@ -/* 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_ELIKE_ANNOTATIONS_HH -#define PALUDIS_GUARD_PALUDIS_ELIKE_ANNOTATIONS_HH 1 - -#include <paludis/elike_annotations-fwd.hh> -#include <paludis/util/pimp.hh> -#include <paludis/util/map-fwd.hh> -#include <paludis/metadata_key.hh> -#include <memory> - -namespace paludis -{ - class PALUDIS_VISIBLE ELikeAnnotations : - private Pimp<ELikeAnnotations>, - public MetadataSectionKey - { - public: - ELikeAnnotations(const std::shared_ptr<const Map<std::string, std::string> > &); - ~ELikeAnnotations(); - - void need_keys_added() const; - virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); - virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); - virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result)); - }; - - extern template class Pimp<ELikeAnnotations>; -} - -#endif diff --git a/paludis/elike_conditional_dep_spec-fwd.hh b/paludis/elike_conditional_dep_spec-fwd.hh index 01e8b1305..4b283647d 100644 --- a/paludis/elike_conditional_dep_spec-fwd.hh +++ b/paludis/elike_conditional_dep_spec-fwd.hh @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2008 Ciaran McCreesh + * Copyright (c) 2008, 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 @@ -34,10 +34,6 @@ namespace paludis ConditionalDepSpec parse_elike_conditional_dep_spec(const std::string &, const Environment * const, const std::shared_ptr<const PackageID> &, const bool no_warning_for_unlisted) PALUDIS_VISIBLE; - - bool elike_conditional_dep_spec_is_inverse(const ConditionalDepSpec & spec) PALUDIS_VISIBLE; - - ChoiceNameWithPrefix elike_conditional_dep_spec_flag(const ConditionalDepSpec & spec) PALUDIS_VISIBLE; } #endif diff --git a/paludis/elike_conditional_dep_spec.cc b/paludis/elike_conditional_dep_spec.cc index 7134dac26..0879c8192 100644 --- a/paludis/elike_conditional_dep_spec.cc +++ b/paludis/elike_conditional_dep_spec.cc @@ -167,27 +167,3 @@ paludis::parse_elike_conditional_dep_spec(const std::string & s, return ConditionalDepSpec(std::make_shared<EConditionalDepSpecData>(s, env, id, no_warning_for_unlisted)); } -ChoiceNameWithPrefix -paludis::elike_conditional_dep_spec_flag(const ConditionalDepSpec & spec) -{ - ConditionalDepSpec::MetadataConstIterator i(spec.find_metadata("Flag")); - if (i == spec.end_metadata()) - throw InternalError(PALUDIS_HERE, "Spec '" + stringify(spec) + "' has no Flag metadata"); - const MetadataValueKey<std::string> * key(simple_visitor_cast<const MetadataValueKey<std::string> >(**i)); - if (! key) - throw InternalError(PALUDIS_HERE, "Spec '" + stringify(spec) + "' has Flag metadata which is not a string"); - return ChoiceNameWithPrefix(key->value()); -} - -bool -paludis::elike_conditional_dep_spec_is_inverse(const ConditionalDepSpec & spec) -{ - ConditionalDepSpec::MetadataConstIterator i(spec.find_metadata("Inverse")); - if (i == spec.end_metadata()) - throw InternalError(PALUDIS_HERE, "Spec '" + stringify(spec) + "' has no Inverse metadata"); - const MetadataValueKey<std::string> * key(simple_visitor_cast<const MetadataValueKey<std::string> >(**i)); - if (! key) - throw InternalError(PALUDIS_HERE, "Spec '" + stringify(spec) + "' has Inverse metadata which is not a string"); - return destringify<bool>(key->value()); -} - diff --git a/paludis/files.m4 b/paludis/files.m4 index b987297de..df5c706f8 100644 --- a/paludis/files.m4 +++ b/paludis/files.m4 @@ -26,12 +26,12 @@ add(`contents', `hh', `cc', `fwd') add(`create_output_manager_info', `hh', `cc', `fwd', `se') add(`dep_label', `hh', `cc', `fwd') add(`dep_spec', `hh', `cc', `test', `fwd', `se') +add(`dep_spec_annotations', `hh', `cc', `fwd') add(`dep_spec_data', `hh', `cc', `fwd') add(`dep_spec_flattener', `hh', `cc') add(`dep_tag', `hh', `cc', `fwd') add(`distribution', `hh', `cc', `impl', `fwd') add(`elf_linkage_checker', `hh', `cc') -add(`elike_annotations', `hh', `cc', `fwd') add(`elike_choices', `hh', `cc', `fwd') add(`elike_dep_parser', `hh', `cc', `fwd', `test') add(`elike_conditional_dep_spec', `hh', `cc', `fwd') diff --git a/paludis/partially_made_package_dep_spec.cc b/paludis/partially_made_package_dep_spec.cc index 6d1360418..bd34af36a 100644 --- a/paludis/partially_made_package_dep_spec.cc +++ b/paludis/partially_made_package_dep_spec.cc @@ -59,7 +59,6 @@ namespace std::shared_ptr<const FSPath> installed_at_path; std::shared_ptr<const InstallableToPath> installable_to_path; std::shared_ptr<AdditionalPackageDepSpecRequirements> additional_requirements; - std::shared_ptr<const MetadataSectionKey> annotations; PartiallyMadePackageDepSpecOptions options_for_partially_made_package_dep_spec_v; PartiallyMadePackageDepSpecData(const PartiallyMadePackageDepSpecOptions & o) : @@ -83,7 +82,6 @@ namespace installed_at_path(other.installed_at_path_ptr()), installable_to_path(other.installable_to_path_ptr()), additional_requirements(other.additional_requirements_ptr() ? new AdditionalPackageDepSpecRequirements : 0), - annotations(other.annotations_key()), options_for_partially_made_package_dep_spec_v(other.options_for_partially_made_package_dep_spec()) { if (version_requirements) @@ -109,7 +107,6 @@ namespace installed_at_path(other.installed_at_path), installable_to_path(other.installable_to_path), additional_requirements(other.additional_requirements), - annotations(other.annotations), options_for_partially_made_package_dep_spec_v(other.options_for_partially_made_package_dep_spec_v) { } @@ -340,11 +337,6 @@ namespace return additional_requirements; } - virtual std::shared_ptr<const MetadataSectionKey> annotations_key() const - { - return annotations; - } - virtual const PartiallyMadePackageDepSpecOptions options_for_partially_made_package_dep_spec() const { return options_for_partially_made_package_dep_spec_v; @@ -560,13 +552,6 @@ PartiallyMadePackageDepSpec::clear_additional_requirements() return *this; } -PartiallyMadePackageDepSpec & -PartiallyMadePackageDepSpec::annotations(const std::shared_ptr<const MetadataSectionKey> & a) -{ - _imp->data->annotations = a; - return *this; -} - PartiallyMadePackageDepSpec::operator const PackageDepSpec() const { return PackageDepSpec(_imp->data); diff --git a/paludis/partially_made_package_dep_spec.hh b/paludis/partially_made_package_dep_spec.hh index fc034f40e..1d16547ae 100644 --- a/paludis/partially_made_package_dep_spec.hh +++ b/paludis/partially_made_package_dep_spec.hh @@ -193,12 +193,6 @@ namespace paludis PartiallyMadePackageDepSpec & clear_additional_requirements(); /** - * Add annotations - */ - PartiallyMadePackageDepSpec & annotations( - const std::shared_ptr<const MetadataSectionKey> &); - - /** * Turn ourselves into a PackageDepSpec. */ operator const PackageDepSpec() const; diff --git a/paludis/repositories/e/dep_parser.cc b/paludis/repositories/e/dep_parser.cc index b9a0e7637..ce134b257 100644 --- a/paludis/repositories/e/dep_parser.cc +++ b/paludis/repositories/e/dep_parser.cc @@ -31,7 +31,6 @@ #include <paludis/util/make_null_shared_ptr.hh> #include <paludis/util/mutex.hh> #include <paludis/util/singleton-impl.hh> -#include <paludis/elike_annotations.hh> #include <paludis/elike_dep_parser.hh> #include <paludis/elike_conditional_dep_spec.hh> #include <paludis/elike_package_dep_spec.hh> @@ -39,10 +38,10 @@ #include <paludis/environment.hh> #include <paludis/repository.hh> #include <paludis/package_id.hh> -#include <paludis/metadata_key.hh> -#include <paludis/literal_metadata_key.hh> #include <paludis/action.hh> #include <paludis/choice.hh> +#include <paludis/dep_spec_annotations.hh> +#include <paludis/metadata_key.hh> #include <map> #include <list> #include <set> @@ -343,8 +342,13 @@ namespace std::shared_ptr<DepSpec> & spec, const std::shared_ptr<const Map<std::string, std::string> > & m) { - std::shared_ptr<ELikeAnnotations> key(std::make_shared<ELikeAnnotations>(m)); - spec->set_annotations_key(key); + auto annotations(std::make_shared<DepSpecAnnotations>()); + for (auto k(m->begin()), k_end(m->end()) ; + k != k_end ; ++k) + annotations->add(make_named_values<DepSpecAnnotation>( + n::key() = k->first, + n::value() = k->second)); + spec->set_annotations(annotations); } void set_annotations_block( @@ -353,32 +357,33 @@ namespace std::shared_ptr<BlockDepSpec> & if_block_spec, const std::shared_ptr<const Map<std::string, std::string> > & m) { - std::shared_ptr<ELikeAnnotations> key(std::make_shared<ELikeAnnotations>(m)); - spec->set_annotations_key(key); + auto annotations(std::make_shared<DepSpecAnnotations>()); + for (auto k(m->begin()), k_end(m->end()) ; + k != k_end ; ++k) + annotations->add(make_named_values<DepSpecAnnotation>( + n::key() = k->first, + n::value() = k->second)); + spec->set_annotations(annotations); if (if_block_spec && (! eapi.supported()->annotations()->blocker_resolution().empty()) - && if_block_spec->annotations_key()) + && if_block_spec->maybe_annotations()) { - auto a(if_block_spec->annotations_key()->find_metadata(eapi.supported()->annotations()->blocker_resolution())); - if (a != if_block_spec->annotations_key()->end_metadata()) + auto a(if_block_spec->maybe_annotations()->find(eapi.supported()->annotations()->blocker_resolution())); + if (a != if_block_spec->maybe_annotations()->end()) { - auto k(simple_visitor_cast<const MetadataValueKey<std::string> >(**a)); - if (! k) - throw EDepParseError(stringify(*if_block_spec), "Annotation key for blocker resolution not a string"); - - if (k->value().empty()) + if (a->value().empty()) { } - else if (k->value() == eapi.supported()->annotations()->blocker_resolution_manual()) + else if (a->value() == eapi.supported()->annotations()->blocker_resolution_manual()) if_block_spec->set_block_kind(bk_manual); - else if (k->value() == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_after()) + else if (a->value() == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_after()) if_block_spec->set_block_kind(bk_uninstall_blocked_after); - else if (k->value() == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_before()) + else if (a->value() == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_before()) if_block_spec->set_block_kind(bk_uninstall_blocked_before); - else if (k->value() == eapi.supported()->annotations()->blocker_resolution_upgrade_blocked_before()) + else if (a->value() == eapi.supported()->annotations()->blocker_resolution_upgrade_blocked_before()) if_block_spec->set_block_kind(bk_upgrade_blocked_before); else - throw EDepParseError(stringify(*if_block_spec), "Unknown value '" + k->value() + "' for annotation '" + k->raw_name() + "'"); + throw EDepParseError(stringify(*if_block_spec), "Unknown value '" + a->value() + "' for annotation '" + a->key() + "'"); } } } diff --git a/paludis/repositories/e/dep_spec_pretty_printer.cc b/paludis/repositories/e/dep_spec_pretty_printer.cc index b679f1ac3..bc88ff3e0 100644 --- a/paludis/repositories/e/dep_spec_pretty_printer.cc +++ b/paludis/repositories/e/dep_spec_pretty_printer.cc @@ -18,9 +18,6 @@ */ #include <paludis/repositories/e/dep_spec_pretty_printer.hh> -#include <paludis/dep_spec.hh> -#include <paludis/metadata_key.hh> -#include <paludis/formatter.hh> #include <paludis/util/save.hh> #include <paludis/util/simple_visitor_cast.hh> #include <paludis/util/pimp-impl.hh> @@ -35,6 +32,10 @@ #include <paludis/filter.hh> #include <paludis/filtered_generator.hh> #include <paludis/action-fwd.hh> +#include <paludis/dep_spec.hh> +#include <paludis/formatter.hh> +#include <paludis/dep_spec_annotations.hh> +#include <paludis/metadata_key.hh> #include <algorithm> #include <sstream> @@ -190,7 +191,7 @@ namespace void DepSpecPrettyPrinter::visit(const GenericSpecTree::NodeType<AllDepSpec>::Type & node) { - bool need_parens(_imp->all_needs_parens || node.spec()->annotations_key() || + bool need_parens(_imp->all_needs_parens || node.spec()->maybe_annotations() || (! _imp->outer_block && indirect_iterator(node.end()) != std::find_if(indirect_iterator(node.begin()), indirect_iterator(node.end()), is_label))); @@ -587,16 +588,14 @@ DepSpecPrettyPrinter::visit(const GenericSpecTree::NodeType<DependenciesLabelsDe void DepSpecPrettyPrinter::do_annotations(const DepSpec & p) { - if (p.annotations_key() && (p.annotations_key()->begin_metadata() != p.annotations_key()->end_metadata())) + if (p.maybe_annotations() && (p.maybe_annotations()->begin() != p.maybe_annotations()->end())) { _imp->s << " [[ "; - for (MetadataSectionKey::MetadataConstIterator k(p.annotations_key()->begin_metadata()), k_end(p.annotations_key()->end_metadata()) ; - k != k_end ; ++k) + + for (auto m(p.maybe_annotations()->begin()), m_end(p.maybe_annotations()->end()) ; + m != m_end ; ++m) { - const MetadataValueKey<std::string> * r(simple_visitor_cast<const MetadataValueKey<std::string> >(**k)); - if (! r) - throw InternalError(PALUDIS_HERE, "annotations must be string keys"); - _imp->s << (*k)->raw_name() << " = [" << (r->value().empty() ? " " : " " + r->value() + " ") << "] "; + _imp->s << m->key() << " = [" << (m->value().empty() ? " " : " " + m->value() + " ") << "] "; } _imp->s << "]]"; } diff --git a/paludis/repositories/e/dependencies_rewriter.cc b/paludis/repositories/e/dependencies_rewriter.cc index 8bd7c4bd4..b0a785731 100644 --- a/paludis/repositories/e/dependencies_rewriter.cc +++ b/paludis/repositories/e/dependencies_rewriter.cc @@ -29,7 +29,7 @@ #include <paludis/util/wrapped_output_iterator.hh> #include <paludis/util/sequence.hh> #include <paludis/util/accept_visitor.hh> -#include <paludis/metadata_key.hh> +#include <paludis/dep_spec_annotations.hh> #include <list> #include <algorithm> @@ -43,18 +43,13 @@ namespace const std::string get_annotations(const DepSpec & a) { std::stringstream s; - if (a.annotations_key() && (a.annotations_key()->begin_metadata() != a.annotations_key()->end_metadata())) + if (a.maybe_annotations() && (a.maybe_annotations()->begin() != a.maybe_annotations()->end())) { s << " [[ "; - for (MetadataSectionKey::MetadataConstIterator k(a.annotations_key()->begin_metadata()), - k_end(a.annotations_key()->end_metadata()) ; - k != k_end ; ++k) - { - const MetadataValueKey<std::string> * r(simple_visitor_cast<const MetadataValueKey<std::string> >(**k)); - if (! r) - throw InternalError(PALUDIS_HERE, "annotations must be string keys"); - s << (*k)->raw_name() << " = [" << (r->value().empty() ? " " : " " + r->value() + " ") << "] "; - } + for (auto m(a.maybe_annotations()->begin()), m_end(a.maybe_annotations()->end()) ; + m != m_end ; ++m) + s << m->key() << " = [" << (m->value().empty() ? " " : " " + m->value() + " ") << "] "; + s << "]]"; } return s.str(); diff --git a/paludis/repositories/e/e_choices_key.cc b/paludis/repositories/e/e_choices_key.cc index 3b1dba704..ccd125873 100644 --- a/paludis/repositories/e/e_choices_key.cc +++ b/paludis/repositories/e/e_choices_key.cc @@ -45,6 +45,7 @@ #include <paludis/stringify_formatter-impl.hh> #include <paludis/choice.hh> #include <paludis/elike_choices.hh> +#include <paludis/dep_spec_annotations.hh> #include <list> #include <algorithm> @@ -156,23 +157,11 @@ namespace if (v == p->second.end()) v = p->second.insert(std::make_pair(n, Annotations())).first; - if (node.spec()->annotations_key()) + if (node.spec()->maybe_annotations()) { - for (MetadataSectionKey::MetadataConstIterator m(node.spec()->annotations_key()->begin_metadata()), - m_end(node.spec()->annotations_key()->end_metadata()) ; + for (auto m(node.spec()->maybe_annotations()->begin()), m_end(node.spec()->maybe_annotations()->end()) ; m != m_end ; ++m) - { - const MetadataValueKey<std::string> * mm(simple_visitor_cast<const MetadataValueKey<std::string> >(**m)); - if (! mm) - { - Log::get_instance()->message("e_key.myoptions.strange_annotation", ll_warning, lc_context) - << "Don't know how to handle annotation '" << (*m)->raw_name() << "'"; - continue; - } - - Annotations::iterator a(v->second.find(mm->raw_name())); - v->second.insert(make_pair(mm->raw_name(), mm->value())); - } + v->second.insert(make_pair(m->key(), m->value())); } } diff --git a/paludis/repositories/e/myoptions_requirements_verifier.cc b/paludis/repositories/e/myoptions_requirements_verifier.cc index 5925b4834..d78afcae4 100644 --- a/paludis/repositories/e/myoptions_requirements_verifier.cc +++ b/paludis/repositories/e/myoptions_requirements_verifier.cc @@ -32,6 +32,7 @@ #include <paludis/util/accept_visitor.hh> #include <paludis/choice.hh> #include <paludis/metadata_key.hh> +#include <paludis/dep_spec_annotations.hh> #include <algorithm> #include <list> @@ -110,8 +111,10 @@ namespace } void -MyOptionsRequirementsVerifier::verify_one(const ChoicePrefixName & spec_prefix, - const std::string & spec_text, const std::shared_ptr<const MetadataSectionKey> & annotations_key) +MyOptionsRequirementsVerifier::verify_one( + const ChoicePrefixName & spec_prefix, + const std::string & spec_text, + const std::shared_ptr<const DepSpecAnnotations> & annotations) { std::pair<UnprefixedChoiceName, bool> active_myoption(parse_myoption(spec_text)); ChoiceNameWithPrefix active_flag(( @@ -135,18 +138,10 @@ MyOptionsRequirementsVerifier::verify_one(const ChoicePrefixName & spec_prefix, } } - for (MetadataSectionKey::MetadataConstIterator m(annotations_key->begin_metadata()), m_end(annotations_key->end_metadata()) ; + for (auto m(annotations->begin()), m_end(annotations->end()) ; m != m_end ; ++m) { - const MetadataValueKey<std::string> * mm(simple_visitor_cast<const MetadataValueKey<std::string> >(**m)); - if (! mm) - { - Log::get_instance()->message("e_key.myoptions.strange_annotation", ll_warning, lc_context) - << "Don't know how to handle annotation '" << (*m)->raw_name() << "'"; - continue; - } - - std::string a_key(mm->raw_name()), a_value(mm->value()); + std::string a_key(m->key()), a_value(m->value()); if (a_key == _imp->id->eapi()->supported()->annotations()->myoptions_description()) { @@ -251,10 +246,10 @@ MyOptionsRequirementsVerifier::visit(const PlainTextSpecTree::NodeType<PlainText ++*l; } - if ((! node.spec()->annotations_key()) || (node.spec()->annotations_key()->begin_metadata() == node.spec()->annotations_key()->end_metadata())) + if ((! node.spec()->maybe_annotations()) || (node.spec()->maybe_annotations()->begin() == node.spec()->maybe_annotations()->end())) return; - verify_one(*_imp->current_prefix_stack.begin(), node.spec()->text(), node.spec()->annotations_key()); + verify_one(*_imp->current_prefix_stack.begin(), node.spec()->text(), node.spec()->maybe_annotations()); } void @@ -282,25 +277,17 @@ MyOptionsRequirementsVerifier::visit(const PlainTextSpecTree::NodeType<AllDepSpe _imp->number_enabled_stack.push_front(0); std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this)); - if (node.spec()->annotations_key() && (node.spec()->annotations_key()->begin_metadata() != node.spec()->annotations_key()->end_metadata())) + if (node.spec()->maybe_annotations() && (node.spec()->maybe_annotations()->begin() != node.spec()->maybe_annotations()->end())) { for (ChildrenList::const_iterator i(_imp->current_children_stack.begin()->begin()), i_end(_imp->current_children_stack.begin()->end()) ; i != i_end ; ++i) - verify_one(i->first, i->second, node.spec()->annotations_key()); + verify_one(i->first, i->second, node.spec()->maybe_annotations()); - for (MetadataSectionKey::MetadataConstIterator m(node.spec()->annotations_key()->begin_metadata()), m_end(node.spec()->annotations_key()->end_metadata()) ; + for (auto m(node.spec()->maybe_annotations()->begin()), m_end(node.spec()->maybe_annotations()->end()) ; m != m_end ; ++m) { - const MetadataValueKey<std::string> * mm(simple_visitor_cast<const MetadataValueKey<std::string> >(**m)); - if (! mm) - { - Log::get_instance()->message("e_key.myoptions.strange_annotation", ll_warning, lc_context) - << "Don't know how to handle annotation '" << (*m)->raw_name() << "'"; - continue; - } - - std::string a_key(mm->raw_name()), a_value(mm->value()); + std::string a_key(m->key()), a_value(m->value()); if (a_key == _imp->id->eapi()->supported()->annotations()->myoptions_number_selected()) { diff --git a/paludis/repositories/e/myoptions_requirements_verifier.hh b/paludis/repositories/e/myoptions_requirements_verifier.hh index 6c81f6c26..728c4b9b5 100644 --- a/paludis/repositories/e/myoptions_requirements_verifier.hh +++ b/paludis/repositories/e/myoptions_requirements_verifier.hh @@ -37,7 +37,7 @@ namespace paludis { private: void verify_one(const ChoicePrefixName &, const std::string &, - const std::shared_ptr<const MetadataSectionKey> &); + const std::shared_ptr<const DepSpecAnnotations> &); public: MyOptionsRequirementsVerifier(const std::shared_ptr<const ERepositoryID> &); diff --git a/paludis/repositories/e/pipe_command_handler.cc b/paludis/repositories/e/pipe_command_handler.cc index 72ba2d79d..1314c1926 100644 --- a/paludis/repositories/e/pipe_command_handler.cc +++ b/paludis/repositories/e/pipe_command_handler.cc @@ -47,6 +47,7 @@ #include <paludis/filter.hh> #include <paludis/filtered_generator.hh> #include <paludis/choice.hh> +#include <paludis/dep_spec_annotations.hh> #include <vector> #include <limits> #include <sstream> @@ -117,10 +118,9 @@ namespace { bool seen_description(false), done_brackets(false); - if (p.annotations_key()) - for (MetadataSectionKey::MetadataConstIterator k(p.annotations_key()->begin_metadata()), - k_end(p.annotations_key()->end_metadata()) ; - k != k_end ; ++k) + if (p.maybe_annotations()) + for (auto m(p.maybe_annotations()->begin()), m_end(p.maybe_annotations()->end()) ; + m != m_end ; ++m) { if (! done_brackets) { @@ -128,13 +128,9 @@ namespace done_brackets = true; } - const MetadataValueKey<std::string> * r( - simple_visitor_cast<const MetadataValueKey<std::string> >(**k)); - if (! r) - throw InternalError(PALUDIS_HERE, "annotations must be string keys"); - str << (*k)->raw_name() << " = [" << (r->value().empty() ? " " : " " + r->value() + " ") << "] "; + str << m->key() << " = [" << (m->value().empty() ? " " : " " + m->value() + " ") << "] "; - if ((*k)->raw_name() == description_annotation) + if (m->key() == description_annotation) seen_description = true; } diff --git a/paludis/repositories/e/vdb_repository.cc b/paludis/repositories/e/vdb_repository.cc index 7f4ae5f5f..657e5d373 100644 --- a/paludis/repositories/e/vdb_repository.cc +++ b/paludis/repositories/e/vdb_repository.cc @@ -56,6 +56,7 @@ #include <paludis/filter.hh> #include <paludis/output_manager.hh> #include <paludis/partially_made_package_dep_spec.hh> +#include <paludis/dep_spec_annotations.hh> #include <paludis/util/accept_visitor.hh> #include <paludis/util/fast_unique_copy.hh> @@ -1205,19 +1206,12 @@ namespace void do_annotations(const DepSpec & p) { - if (p.annotations_key() && (p.annotations_key()->begin_metadata() != p.annotations_key()->end_metadata())) + if (p.maybe_annotations() && (p.maybe_annotations()->begin() != p.maybe_annotations()->end())) { str << " [[ "; - for (MetadataSectionKey::MetadataConstIterator k(p.annotations_key()->begin_metadata()), - k_end(p.annotations_key()->end_metadata()) ; - k != k_end ; ++k) - { - const MetadataValueKey<std::string> * r( - simple_visitor_cast<const MetadataValueKey<std::string> >(**k)); - if (! r) - throw InternalError(PALUDIS_HERE, "annotations must be string keys"); - str << (*k)->raw_name() << " = [" << (r->value().empty() ? " " : " " + r->value() + " ") << "] "; - } + for (auto m(p.maybe_annotations()->begin()), m_end(p.maybe_annotations()->end()) ; + m != m_end ; ++m) + str << m->key() << " = [" << (m->value().empty() ? " " : " " + m->value() + " ") << "] "; str << "]] "; } } diff --git a/paludis/resolver/package_or_block_dep_spec.cc b/paludis/resolver/package_or_block_dep_spec.cc index 576ec5755..23ad5349b 100644 --- a/paludis/resolver/package_or_block_dep_spec.cc +++ b/paludis/resolver/package_or_block_dep_spec.cc @@ -24,10 +24,10 @@ #include <paludis/util/sequence-impl.hh> #include <paludis/util/wrapped_forward_iterator-impl.hh> #include <paludis/util/make_null_shared_ptr.hh> +#include <paludis/util/make_named_values.hh> #include <paludis/serialise-impl.hh> -#include <paludis/metadata_key.hh> +#include <paludis/dep_spec_annotations.hh> #include <paludis/elike_package_dep_spec.hh> -#include <paludis/elike_annotations.hh> #include <ostream> using namespace paludis; @@ -79,26 +79,16 @@ PackageOrBlockDepSpec::serialise(Serialiser & s) const ; } - if (! spec->annotations_key()) + if (! spec->maybe_annotations()) w.member(SerialiserFlags<>(), "annotations_count", 0); else { int n(0); - for (MetadataSectionKey::MetadataConstIterator m(spec->annotations_key()->begin_metadata()), - m_end(spec->annotations_key()->end_metadata()) ; + for (auto m(spec->maybe_annotations()->begin()), m_end(spec->maybe_annotations()->end()) ; m != m_end ; ++m) { - const MetadataValueKey<std::string> * k( - simple_visitor_cast<const MetadataValueKey<std::string> >(**m)); - if (! k) - { - Log::get_instance()->message("resolver.sanitised_dependencies.not_a_string", ll_warning, lc_context) - << "Annotation '" << (*m)->raw_name() << "' not a string. This is probably a bug."; - continue; - } - - w.member(SerialiserFlags<>(), "annotations_k_" + stringify(n), k->human_name()); - w.member(SerialiserFlags<>(), "annotations_v_" + stringify(n), k->value()); + w.member(SerialiserFlags<>(), "annotations_k_" + stringify(n), m->key()); + w.member(SerialiserFlags<>(), "annotations_v_" + stringify(n), m->value()); ++n; } @@ -124,33 +114,31 @@ PackageOrBlockDepSpec::deserialise(Deserialisation & d, const std::shared_ptr<co vso_letters_anywhere, vso_dotted_suffixes }, for_id)); - std::shared_ptr<MetadataSectionKey> annotations; - - std::shared_ptr<Map<std::string, std::string> > m(std::make_shared<Map<std::string, std::string>>()); + auto annotations(std::make_shared<DepSpecAnnotations>()); for (int a(0), a_end(v.member<int>("annotations_count")) ; a != a_end ; ++a) { std::string key(v.member<std::string>("annotations_k_" + stringify(a))); std::string value(v.member<std::string>("annotations_v_" + stringify(a))); - m->insert(key, value); + annotations->add(make_named_values<DepSpecAnnotation>( + n::key() = key, + n::value() = value + )); } - if (! m->empty()) - annotations = std::make_shared<ELikeAnnotations>(m); - if (block) { BlockKind kind(destringify<BlockKind>(v.member<std::string>("block_kind"))); std::string text(v.member<std::string>("text")); BlockDepSpec b_spec(text, spec, kind); - if (annotations) - b_spec.set_annotations_key(annotations); + if (annotations->begin() != annotations->end()) + b_spec.set_annotations(annotations); return PackageOrBlockDepSpec(b_spec); } else { - if (annotations) - spec.set_annotations_key(annotations); + if (annotations->begin() != annotations->end()) + spec.set_annotations(annotations); return PackageOrBlockDepSpec(spec); } } diff --git a/paludis/resolver/sanitised_dependencies.cc b/paludis/resolver/sanitised_dependencies.cc index 139605d92..e12fc94e7 100644 --- a/paludis/resolver/sanitised_dependencies.cc +++ b/paludis/resolver/sanitised_dependencies.cc @@ -40,7 +40,6 @@ #include <paludis/metadata_key.hh> #include <paludis/package_id.hh> #include <paludis/elike_package_dep_spec.hh> -#include <paludis/elike_annotations.hh> #include <paludis/serialise-impl.hh> #include <paludis/environment.hh> #include <paludis/repository.hh> diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc index 0350e8222..530003009 100644 --- a/ruby/dep_spec.cc +++ b/ruby/dep_spec.cc @@ -660,93 +660,6 @@ namespace /* * call-seq: - * each_metadata {|key| block } -> Nil - * - * Our metadata. - */ - VALUE - dep_spec_each_metadata(VALUE self) - { - std::shared_ptr<WrappedSpecBase> * ptr; - Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr); - try - { - for (DepSpec::MetadataConstIterator it((*ptr)->base_spec()->begin_metadata()), - it_end((*ptr)->base_spec()->end_metadata()); it_end != it; ++it) - { - VALUE val(metadata_key_to_value(*it)); - if (Qnil != val) - rb_yield(val); - } - } - catch (const std::exception & e) - { - exception_to_ruby_exception(e); - } - - return Qnil; - } - - /* - * call-seq: - * [String] -> MetadataKey or Nil - * - * The named metadata key. - */ - VALUE - dep_spec_subscript(VALUE self, VALUE raw_name) - { - std::shared_ptr<WrappedSpecBase> * ptr; - Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr); - try - { - DepSpec::MetadataConstIterator it((*ptr)->base_spec()->find_metadata(StringValuePtr(raw_name))); - if ((*ptr)->base_spec()->end_metadata() == it) - return Qnil; - return metadata_key_to_value(*it); - } - catch (const std::exception & e) - { - exception_to_ruby_exception(e); - } - - return Qnil; - } - - /* - * Document-method: choices_key - * - * call-seq: - * annotations_key -> MetadataSectionKey - * - * Our annotations - */ - template <typename T_, const std::shared_ptr<const T_> (DepSpec::* m_) () const> - struct KeyValue - { - static VALUE - fetch(VALUE self) - { - std::shared_ptr<WrappedSpecBase> * ptr; - Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr); - std::shared_ptr<const T_> key(((*(*ptr)->base_spec()).*m_)()); - - try - { - if (key) - return metadata_key_to_value(key); - } - catch (const std::exception & e) - { - exception_to_ruby_exception(e); - } - - return Qnil; - } - }; - - /* - * call-seq: * text -> String * * Fetch our text. @@ -1103,10 +1016,6 @@ namespace */ c_dep_spec = rb_define_class_under(paludis_module(), "DepSpec", rb_cObject); rb_funcall(c_dep_spec, rb_intern("private_class_method"), 1, rb_str_new2("new")); - rb_define_method(c_dep_spec, "each_metadata", RUBY_FUNC_CAST(&dep_spec_each_metadata), 0); - rb_define_method(c_dep_spec, "[]", RUBY_FUNC_CAST(&dep_spec_subscript), 1); - rb_define_method(c_dep_spec, "annotations_key", - RUBY_FUNC_CAST((&KeyValue<MetadataSectionKey, &DepSpec::annotations_key>::fetch)), 0); /* * Document-class: Paludis::AllDepSpec diff --git a/src/clients/cave/cmd_display_resolution.cc b/src/clients/cave/cmd_display_resolution.cc index 18652f6e9..14d45cd00 100755 --- a/src/clients/cave/cmd_display_resolution.cc +++ b/src/clients/cave/cmd_display_resolution.cc @@ -78,6 +78,7 @@ #include <paludis/output_manager.hh> #include <paludis/changed_choices.hh> #include <paludis/mask_utils.hh> +#include <paludis/dep_spec_annotations.hh> #include <set> #include <iterator> @@ -134,23 +135,14 @@ namespace }; std::string get_annotation( - const std::shared_ptr<const MetadataSectionKey> & section, + const std::shared_ptr<const DepSpecAnnotations> & annotations, const std::string & name) { - MetadataSectionKey::MetadataConstIterator i(section->find_metadata(name)); - if (i == section->end_metadata()) + auto i(annotations->find(name)); + if (i == annotations->end()) return ""; - const MetadataValueKey<std::string> * value( - simple_visitor_cast<const MetadataValueKey<std::string> >(**i)); - if (! value) - { - Log::get_instance()->message("cave.get_annotation.not_a_string", ll_warning, lc_context) - << "Annotation '" << (*i)->raw_name() << "' not a string. This is probably a bug."; - return ""; - } - - return value->value(); + return i->value(); } std::string stringify_change_by_resolvent(const ChangeByResolvent & r) @@ -170,7 +162,7 @@ namespace } std::pair<std::string, Tribool> annotate( - const std::shared_ptr<const MetadataSectionKey> & key, + const std::shared_ptr<const DepSpecAnnotations> & key, const std::pair<std::string, Tribool> unannotated, const bool annotate_regardless) const { @@ -192,7 +184,7 @@ namespace std::pair<std::string, Tribool> visit(const DependencyReason & r) const { if (r.sanitised_dependency().spec().if_block()) - return annotate(r.sanitised_dependency().spec().if_block()->annotations_key(), + return annotate(r.sanitised_dependency().spec().if_block()->maybe_annotations(), std::make_pair(stringify(*r.sanitised_dependency().spec().if_block()) + " from " + (verbose ? stringify(*r.from_id()) : stringify(r.from_id()->name())), false), true); @@ -204,7 +196,7 @@ namespace if (! r.sanitised_dependency().original_specs_as_string().empty()) as = " (originally " + r.sanitised_dependency().original_specs_as_string() + ")"; - return annotate(r.sanitised_dependency().spec().if_package()->annotations_key(), + return annotate(r.sanitised_dependency().spec().if_package()->maybe_annotations(), std::make_pair(stringify(*r.sanitised_dependency().spec().if_package()) + " from " + stringify(*r.from_id()) + ", key '" + r.sanitised_dependency().metadata_key_human_name() + "'" @@ -223,7 +215,7 @@ namespace ! cs.includes_non_test_buildish) ts = " (test)"; - return annotate(r.sanitised_dependency().spec().if_package()->annotations_key(), + return annotate(r.sanitised_dependency().spec().if_package()->maybe_annotations(), std::make_pair(stringify(r.from_id()->name()) + ts, false), false); } } |