libzypp
10.5.0
|
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ 00002 /* SolverQueueItem.cc 00003 * 00004 * Copyright (C) 2008 SUSE Linux Products GmbH 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License, 00008 * version 2, as published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00018 * 02111-1307, USA. 00019 */ 00020 extern "C" 00021 { 00022 #include <solv/solver.h> 00023 } 00024 00025 #include "zypp/base/Logger.h" 00026 #include "zypp/solver/detail/SolverQueueItemInstallOneOf.h" 00027 #include "zypp/sat/Pool.h" 00028 00030 namespace zypp 00031 { 00032 00033 namespace solver 00034 { 00035 00036 namespace detail 00037 { 00038 00039 using namespace std; 00040 00041 IMPL_PTR_TYPE(SolverQueueItemInstallOneOf); 00042 00043 //--------------------------------------------------------------------------- 00044 00045 std::ostream & 00046 SolverQueueItemInstallOneOf::dumpOn( std::ostream & os ) const 00047 { 00048 os << "[" << (_soft?"Soft":"") << "InstallOneOf: "; 00049 for (PoolItemList::const_iterator iter = _oneOfList.begin(); 00050 iter != _oneOfList.end(); 00051 iter++) 00052 os << *iter; 00053 os << "]"; 00054 00055 return os; 00056 } 00057 00058 //--------------------------------------------------------------------------- 00059 00060 SolverQueueItemInstallOneOf::SolverQueueItemInstallOneOf (const ResPool & pool, const PoolItemList & itemList, 00061 bool soft) 00062 : SolverQueueItem (QUEUE_ITEM_TYPE_INSTALL_ONE_OF, pool) 00063 , _oneOfList (itemList) 00064 , _soft (soft) 00065 { 00066 } 00067 00068 00069 SolverQueueItemInstallOneOf::~SolverQueueItemInstallOneOf() 00070 { 00071 } 00072 00073 //--------------------------------------------------------------------------- 00074 00075 bool SolverQueueItemInstallOneOf::addRule (_Queue & q) 00076 { 00077 bool ret = true; 00078 MIL << "Install one of " << (_soft ? "(soft):" : ":")<< endl; 00079 Queue qs; 00080 00081 if (_soft) { 00082 queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF | SOLVER_WEAK); 00083 } else { 00084 queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF ); 00085 } 00086 00087 queue_init(&qs); 00088 for (PoolItemList::const_iterator iter = _oneOfList.begin(); iter != _oneOfList.end(); iter++) { 00089 Id id = (*iter)->satSolvable().id(); 00090 if (id == ID_NULL) { 00091 ERR << *iter << " not found" << endl; 00092 ret = false; 00093 } else { 00094 MIL << " candidate:" << *iter << " with the SAT-Pool ID: " << id << endl; 00095 queue_push( &(qs), id ); 00096 } 00097 } 00098 sat::Pool satPool( sat::Pool::instance() ); 00099 queue_push( &(q), pool_queuetowhatprovides(satPool.get(), &qs)); 00100 queue_free(&qs); 00101 00102 return ret; 00103 } 00104 00105 SolverQueueItem_Ptr 00106 SolverQueueItemInstallOneOf::copy (void) const 00107 { 00108 SolverQueueItemInstallOneOf_Ptr new_installOneOf = new SolverQueueItemInstallOneOf (pool(), _oneOfList); 00109 new_installOneOf->SolverQueueItem::copy(this); 00110 new_installOneOf->_soft = _soft; 00111 00112 return new_installOneOf; 00113 } 00114 00115 int 00116 SolverQueueItemInstallOneOf::cmp (SolverQueueItem_constPtr item) const 00117 { 00118 int cmp = this->compare (item); 00119 if (cmp != 0) 00120 return cmp; 00121 SolverQueueItemInstallOneOf_constPtr install = dynamic_pointer_cast<const SolverQueueItemInstallOneOf>(item); 00122 00123 return (_oneOfList == install->_oneOfList) ? 0 : -1; // more evaluation would be not useful 00124 } 00125 00126 00127 //--------------------------------------------------------------------------- 00128 00129 00131 };// namespace detail 00134 };// namespace solver 00137 };// namespace zypp