/* vim: set sw=4 sts=4 et foldmethod=syntax : *//* * Copyright (c) 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<paludis/repositories/unavailable/unavailable_package_id.hh>#include<paludis/repositories/unavailable/unavailable_repository.hh>#include<paludis/util/pimp-impl.hh>#include<paludis/util/stringify.hh>#include<paludis/util/simple_visitor_cast.hh>#include<paludis/util/set.hh>#include<paludis/util/hashes.hh>#include<paludis/util/wrapped_forward_iterator.hh>#include<paludis/util/make_null_shared_ptr.hh>#include<paludis/name.hh>#include<paludis/version_spec.hh>#include<paludis/metadata_key.hh>#include<paludis/literal_metadata_key.hh>#include<paludis/action.hh>#include<paludis/unchoices_key.hh>#include<paludis/user_dep_spec.hh>usingnamespacepaludis;usingnamespacepaludis::unavailable_repository;namespacepaludis{template<>structImp<UnavailablePackageID>{constEnvironment*constenv;constQualifiedPackageNamename;constVersionSpecversion;constRepositoryNamerepository_name;conststd::shared_ptr<constMetadataValueKey<SlotName>>slot_key;conststd::shared_ptr<constMetadataValueKey<std::string>>description_key;conststd::shared_ptr<constMetadataValueKey<std::string>>repository_homepage_key,repository_description_key;conststd::shared_ptr<constMetadataCollectionKey<Set<std::string>>>from_repositories_key;conststd::shared_ptr<constMetadataValueKey<std::shared_ptr<constChoices>>>choices_key;conststd::shared_ptr<constMask>mask;Imp(constUnavailablePackageIDParams&e):env(e.environment()),name(e.name()),version(e.version()),repository_name(e.repository()),slot_key(std::make_shared<LiteralMetadataValueKey<SlotName>>("SLOT","Slot",mkt_internal,e.slot())),description_key(e.description()),repository_homepage_key(e.repository_homepage()),repository_description_key(e.repository_description()),from_repositories_key(e.from_repositories()),choices_key(unchoices_key()),mask(e.mask()){}};}UnavailablePackageID::UnavailablePackageID(constUnavailablePackageIDParams&entry):_imp(entry){add_metadata_key(_imp->slot_key);add_metadata_key(_imp->description_key);add_metadata_key(_imp->from_repositories_key);if(_imp->repository_homepage_key)add_metadata_key(_imp->repository_homepage_key);if(_imp->repository_description_key)add_metadata_key(_imp->repository_description_key);add_mask(_imp->mask);}UnavailablePackageID::~UnavailablePackageID(){}voidUnavailablePackageID::need_keys_added()const{}voidUnavailablePackageID::need_masks_added()const{}conststd::stringUnavailablePackageID::canonical_form(constPackageIDCanonicalFormf)const{switch(f){caseidcf_full:returnstringify(_imp->name)+"-"+stringify(_imp->version)+":"+stringify(_imp->slot_key->value())+"::"+stringify(_imp->repository_name)+" (in ::"+*_imp->from_repositories_key->value()->begin()+")";caseidcf_no_version:returnstringify(_imp->name)+":"+stringify(_imp->slot_key->value())+"::"+stringify(_imp->repository_name)+" (in ::"+*_imp->from_repositories_key->value()->begin()+")";caseidcf_version:returnstringify(_imp->version)+" (in ::"+*_imp->from_repositories_key->value()->begin()+")";caseidcf_no_name:returnstringify(_imp->version)+":"+stringify(_imp->slot_key->value())+"::"+stringify(_imp->repository_name)+" (in ::"+*_imp->from_repositories_key->value()->begin()+")";caselast_idcf:break;}throwInternalError(PALUDIS_HERE,"Bad PackageIDCanonicalForm");}PackageDepSpecUnavailablePackageID::uniquely_identifying_spec()const{returnparse_user_package_dep_spec("="+stringify(name())+"-"+stringify(version())+(slot_key()?":"+stringify(slot_key()->value()):"")+"::"+stringify(repository_name())+"[."+_imp->from_repositories_key->raw_name()+"="+*_imp->from_repositories_key->value()->begin()+"]",_imp->env,{});}constQualifiedPackageNameUnavailablePackageID::name()const{return_imp->name;}constVersionSpecUnavailablePackageID::version()const{return_imp->version;}constRepositoryNameUnavailablePackageID::repository_name()const{return_imp->repository_name;}boolUnavailablePackageID::supports_action(constSupportsActionTestBase&a)const{returnsimple_visitor_cast<constSupportsActionTest<InstallAction>>(a);}voidUnavailablePackageID::perform_action(Action&a)const{throwActionFailedError("Unsupported action: "+a.simple_name());}std::shared_ptr<constSet<std::string>>UnavailablePackageID::breaks_portage()const{returnstd::make_shared<Set<std::string>>();}boolUnavailablePackageID::arbitrary_less_than_comparison(constPackageID&other)const{if(!other.slot_key())returnfalse;if(slot_key()->value()<other.slot_key()->value())returntrue;if(slot_key()->value()>other.slot_key()->value())returnfalse;std::shared_ptr<constMetadataCollectionKey<Set<std::string>>>k(other.from_repositories_key());if(!k)throwInternalError(PALUDIS_HERE,"other has no from_repositories_key()");if(1!=k->value()->size())throwInternalError(PALUDIS_HERE,"other has bad from_repositories_key");return*_imp->from_repositories_key->value()->begin()<*k->value()->begin();}std::size_tUnavailablePackageID::extra_hash_value()const{returnHash<std::pair<SlotName,std::string>>()(std::make_pair(slot_key()->value(),*_imp->from_repositories_key->value()->begin()));}conststd::shared_ptr<constMetadataCollectionKey<PackageIDSequence>>UnavailablePackageID::contains_key()const{returnstd::shared_ptr<constMetadataCollectionKey<PackageIDSequence>>();}conststd::shared_ptr<constMetadataValueKey<std::shared_ptr<constPackageID>>>UnavailablePackageID::contained_in_key()const{returnstd::shared_ptr<constMetadataValueKey<std::shared_ptr<constPackageID>>>();}conststd::shared_ptr<constMetadataValueKey<FSPath>>UnavailablePackageID::fs_location_key()const{returnstd::shared_ptr<constMetadataValueKey<FSPath>>();}conststd::shared_ptr<constMetadataCollectionKey<Set<std::string>>>UnavailablePackageID::behaviours_key()const{returnmake_null_shared_ptr();}conststd::shared_ptr<constMetadataValueKey<std::shared_ptr<constPackageID>>>UnavailablePackageID::virtual_for_key()const{returnstd::shared_ptr<constMetadataValueKey<std::shared_ptr<constPackageID>>>();}conststd::shared_ptr<constMetadataCollectionKey<KeywordNameSet>>UnavailablePackageID::keywords_key()const{returnstd::shared_ptr<constMetadataCollectionKey<KeywordNameSet>>();}conststd::shared_ptr<constMetadataSpecTreeKey<ProvideSpecTree>>UnavailablePackageID::provide_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<ProvideSpecTree>>();}conststd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>UnavailablePackageID::dependencies_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>();}conststd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>UnavailablePackageID::build_dependencies_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>();}conststd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>UnavailablePackageID::run_dependencies_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>();}conststd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>UnavailablePackageID::post_dependencies_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>();}conststd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>UnavailablePackageID::suggested_dependencies_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<DependencySpecTree>>();}conststd::shared_ptr<constMetadataValueKey<std::string>>UnavailablePackageID::short_description_key()const{return_imp->description_key;}conststd::shared_ptr<constMetadataValueKey<std::string>>UnavailablePackageID::long_description_key()const{returnstd::shared_ptr<constMetadataValueKey<std::string>>();}conststd::shared_ptr<constMetadataSpecTreeKey<FetchableURISpecTree>>UnavailablePackageID::fetches_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<FetchableURISpecTree>>();}conststd::shared_ptr<constMetadataSpecTreeKey<SimpleURISpecTree>>UnavailablePackageID::homepage_key()const{returnstd::shared_ptr<constMetadataSpecTreeKey<SimpleURISpecTree>>();}conststd::shared_ptr<constMetadataValueKey<std::shared_ptr<constContents>>>UnavailablePackageID::contents_key()const{returnstd::shared_ptr<constMetadataValueKey<std::shared_ptr<constContents>>>();}conststd::shared_ptr<constMetadataTimeKey>UnavailablePackageID::installed_time_key()const{returnstd::shared_ptr<constMetadataTimeKey>();}conststd::shared_ptr<constMetadataCollectionKey<Set<std::string>>>UnavailablePackageID::from_repositories_key()const{return_imp->from_repositories_key;}conststd::shared_ptr<constMetadataValueKey<std::shared_ptr<constChoices>>>UnavailablePackageID::choices_key()const{return_imp->choices_key;}conststd::shared_ptr<constMetadataValueKey<SlotName>>UnavailablePackageID::slot_key()const{return_imp->slot_key;}templateclassPimp<UnavailablePackageID>;