/* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace paludis; namespace paludis { template <> struct Imp { std::shared_ptr annotations; }; } DepSpec::DepSpec() : _imp() { } DepSpec::~DepSpec() { } const std::shared_ptr DepSpec::maybe_annotations() const { return _imp->annotations; } void DepSpec::set_annotations(const std::shared_ptr & a) { _imp->annotations = a; } AnyDepSpec::AnyDepSpec() { } std::shared_ptr AnyDepSpec::clone() const { std::shared_ptr result(std::make_shared()); result->set_annotations(maybe_annotations()); return result; } AllDepSpec::AllDepSpec() { } std::shared_ptr AllDepSpec::clone() const { std::shared_ptr result(std::make_shared()); result->set_annotations(maybe_annotations()); return result; } ExactlyOneDepSpec::ExactlyOneDepSpec() { } std::shared_ptr ExactlyOneDepSpec::clone() const { std::shared_ptr result(std::make_shared()); result->set_annotations(maybe_annotations()); return result; } namespace paludis { template <> struct Imp { const std::shared_ptr data; Imp(const std::shared_ptr & d) : data(d) { } }; } ConditionalDepSpec::ConditionalDepSpec(const std::shared_ptr & d) : _imp(d) { } namespace { template const ConditionalDepSpec & horrible_hack_to_force_key_copy(const ConditionalDepSpec & spec) { (spec.*f_)(); return spec; } } ConditionalDepSpec::ConditionalDepSpec(const ConditionalDepSpec & other) : Cloneable(), DepSpec(), CloneUsingThis(other), _imp(other._imp->data) { set_annotations(other.maybe_annotations()); } ConditionalDepSpec::~ConditionalDepSpec() { } bool ConditionalDepSpec::condition_met(const Environment * const env, const std::shared_ptr & id) const { return _imp->data->condition_met(env, id); } bool ConditionalDepSpec::condition_would_be_met_when( const Environment * const env, const std::shared_ptr & id, const ChangedChoices & c) const { return _imp->data->condition_would_be_met_when(env, id, c); } bool ConditionalDepSpec::condition_meetable(const Environment * const env, const std::shared_ptr & id) const { return _imp->data->condition_meetable(env, id); } const std::shared_ptr ConditionalDepSpec::data() const { return _imp->data; } std::string ConditionalDepSpec::_as_string() const { return _imp->data->as_string(); } std::string StringDepSpec::text() const { return _str; } NamedSetDepSpec::NamedSetDepSpec(const SetName & n) : StringDepSpec(stringify(n)), _name(n) { } const SetName NamedSetDepSpec::name() const { return _name; } std::shared_ptr NamedSetDepSpec::clone() const { std::shared_ptr result(std::make_shared(_name)); result->set_annotations(maybe_annotations()); return result; } BlockDepSpec::BlockDepSpec(const std::string & s, const PackageDepSpec & p) : StringDepSpec(s), _spec(p) { } BlockDepSpec::BlockDepSpec(const BlockDepSpec & other) : StringDepSpec(other.text()), _spec(other._spec) { set_annotations(other.maybe_annotations()); } std::ostream & paludis::operator<< (std::ostream & s, const PlainTextDepSpec & a) { s << a.text(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const LicenseDepSpec & a) { s << a.text(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const NamedSetDepSpec & a) { s << a.name(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const BlockDepSpec & a) { s << a.text(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const FetchableURIDepSpec & p) { if (! p.renamed_url_suffix().empty()) s << p.original_url() << " -> " << p.renamed_url_suffix(); else s << p.original_url(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const SimpleURIDepSpec & p) { s << p.text(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const PackageDepSpec & a) { s << a._as_string(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const ConditionalDepSpec & a) { s << a._as_string(); return s; } std::ostream & paludis::operator<< (std::ostream & s, const URILabelsDepSpec & l) { s << join(indirect_iterator(l.begin()), indirect_iterator(l.end()), "+") << ":"; return s; } std::ostream & paludis::operator<< (std::ostream & s, const DependenciesLabelsDepSpec & l) { s << join(indirect_iterator(l.begin()), indirect_iterator(l.end()), "+") << ":"; return s; } std::ostream & paludis::operator<< (std::ostream & s, const PlainTextLabelDepSpec & l) { s << l.label() << ":"; return s; } PackageDepSpecError::PackageDepSpecError(const std::string & msg) throw () : Exception(msg) { } StringDepSpec::StringDepSpec(const std::string & s) : _str(s) { } StringDepSpec::~StringDepSpec() { } PlainTextDepSpec::PlainTextDepSpec(const std::string & s) : StringDepSpec(s) { } std::shared_ptr PlainTextDepSpec::clone() const { std::shared_ptr result(std::make_shared(text())); result->set_annotations(maybe_annotations()); return result; } PlainTextLabelDepSpec::PlainTextLabelDepSpec(const std::string & s) : StringDepSpec(s) { } PlainTextLabelDepSpec::~PlainTextLabelDepSpec() { } std::shared_ptr PlainTextLabelDepSpec::clone() const { std::shared_ptr result(std::make_shared(text())); result->set_annotations(maybe_annotations()); return result; } const std::string PlainTextLabelDepSpec::label() const { return text().substr(0, text().length() - 1); } LicenseDepSpec::LicenseDepSpec(const std::string & s) : StringDepSpec(s) { } std::shared_ptr LicenseDepSpec::clone() const { std::shared_ptr result(std::make_shared(text())); result->set_annotations(maybe_annotations()); return result; } SimpleURIDepSpec::SimpleURIDepSpec(const std::string & s) : StringDepSpec(s) { } std::shared_ptr SimpleURIDepSpec::clone() const { std::shared_ptr result(std::make_shared(text())); result->set_annotations(maybe_annotations()); return result; } const PackageDepSpec BlockDepSpec::blocking() const { return _spec; } std::shared_ptr BlockDepSpec::clone() const { std::shared_ptr result(std::make_shared(*this)); result->set_annotations(maybe_annotations()); return result; } FetchableURIDepSpec::FetchableURIDepSpec(const std::string & s) : StringDepSpec(s) { } std::string FetchableURIDepSpec::original_url() const { std::string::size_type p(text().find(" -> ")); if (std::string::npos == p) return text(); else return text().substr(0, p); } std::string FetchableURIDepSpec::renamed_url_suffix() const { std::string::size_type p(text().find(" -> ")); if (std::string::npos == p) return ""; else return text().substr(p + 4); } std::string FetchableURIDepSpec::filename() const { std::string rus = renamed_url_suffix(); if (! rus.empty()) return rus; std::string orig = original_url(); std::string::size_type p(orig.rfind('/')); if (std::string::npos == p) return orig; return orig.substr(p+1); } std::shared_ptr FetchableURIDepSpec::clone() const { std::shared_ptr result(std::make_shared(text())); result->set_annotations(maybe_annotations()); return result; } namespace paludis { template struct Imp > { std::list > items; }; template <> struct WrappedForwardIteratorTraits { typedef std::list >::const_iterator UnderlyingIterator; }; template <> struct WrappedForwardIteratorTraits { typedef std::list >::const_iterator UnderlyingIterator; }; } template LabelsDepSpec::LabelsDepSpec() : _imp() { } template LabelsDepSpec::~LabelsDepSpec() { } template std::shared_ptr LabelsDepSpec::clone() const { using namespace std::placeholders; std::shared_ptr > my_clone(std::make_shared>()); my_clone->set_annotations(maybe_annotations()); std::for_each(begin(), end(), std::bind(std::mem_fn(&LabelsDepSpec::add_label), my_clone.get(), _1)); return my_clone; } template typename LabelsDepSpec::ConstIterator LabelsDepSpec::begin() const { return ConstIterator(_imp->items.begin()); } template typename LabelsDepSpec::ConstIterator LabelsDepSpec::end() const { return ConstIterator(_imp->items.end()); } template void LabelsDepSpec::add_label(const std::shared_ptr & item) { _imp->items.push_back(item); } namespace paludis { template <> struct Imp { const std::shared_ptr data; Imp(const std::shared_ptr & d) : data(d) { } }; } PackageDepSpec::PackageDepSpec(const std::shared_ptr & d) : Cloneable(), StringDepSpec(d->as_string()), _imp(d) { } PackageDepSpec::~PackageDepSpec() { } PackageDepSpec::PackageDepSpec(const PackageDepSpec & d) : Cloneable(d), StringDepSpec(d._imp->data->as_string()), CloneUsingThis(d), _imp(d._imp->data) { set_annotations(d.maybe_annotations()); } std::shared_ptr PackageDepSpec::package_ptr() const { return _imp->data->package_ptr(); } std::shared_ptr PackageDepSpec::package_name_part_ptr() const { return _imp->data->package_name_part_ptr(); } std::shared_ptr PackageDepSpec::category_name_part_ptr() const { return _imp->data->category_name_part_ptr(); } std::shared_ptr PackageDepSpec::version_requirements_ptr() const { return _imp->data->version_requirements_ptr(); } VersionRequirementsMode PackageDepSpec::version_requirements_mode() const { return _imp->data->version_requirements_mode(); } std::shared_ptr PackageDepSpec::slot_requirement_ptr() const { return _imp->data->slot_requirement_ptr(); } std::shared_ptr PackageDepSpec::in_repository_ptr() const { return _imp->data->in_repository_ptr(); } std::shared_ptr PackageDepSpec::installable_to_repository_ptr() const { return _imp->data->installable_to_repository_ptr(); } std::shared_ptr PackageDepSpec::from_repository_ptr() const { return _imp->data->from_repository_ptr(); } std::shared_ptr PackageDepSpec::installed_at_path_ptr() const { return _imp->data->installed_at_path_ptr(); } std::shared_ptr PackageDepSpec::installable_to_path_ptr() const { return _imp->data->installable_to_path_ptr(); } std::shared_ptr PackageDepSpec::additional_requirements_ptr() const { return _imp->data->additional_requirements_ptr(); } std::string PackageDepSpec::_as_string() const { return _imp->data->as_string(); } std::shared_ptr PackageDepSpec::data() const { return _imp->data; } namespace paludis { template class LabelsDepSpec; template class LabelsDepSpec; template class Cloneable; template class Pimp; template class CloneUsingThis; template class Pimp; template class CloneUsingThis; template class Pimp; template class Pimp; template class WrappedForwardIterator >; template class WrappedForwardIterator >; }