libzypp  17.23.8
SolverQueueItemInstallOneOf.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SolverQueueItem.cc
3  *
4  * Copyright (C) 2008 SUSE Linux Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 extern "C"
21 {
22 #include <solv/solver.h>
23 }
24 
25 #define ZYPP_USE_RESOLVER_INTERNALS
26 
27 #include <zypp/base/Logger.h>
29 #include <zypp/sat/Pool.h>
30 
31 using std::endl;
32 
34 namespace zypp
35 {
36  namespace solver
38  {
39  namespace detail
41  {
42 
43 
44 IMPL_PTR_TYPE(SolverQueueItemInstallOneOf);
45 
46 //---------------------------------------------------------------------------
47 
48 std::ostream &
49 SolverQueueItemInstallOneOf::dumpOn( std::ostream & os ) const
50 {
51  os << "[" << (_soft?"Soft":"") << "InstallOneOf: ";
52  for (PoolItemList::const_iterator iter = _oneOfList.begin();
53  iter != _oneOfList.end();
54  iter++)
55  os << *iter;
56  os << "]";
57 
58  return os;
59 }
60 
61 //---------------------------------------------------------------------------
62 
64  bool soft)
65  : SolverQueueItem (QUEUE_ITEM_TYPE_INSTALL_ONE_OF, pool)
66  , _oneOfList (itemList)
67  , _soft (soft)
68 {
69 }
70 
71 
73 {
74 }
75 
76 //---------------------------------------------------------------------------
77 
79 {
80  bool ret = true;
81  MIL << "Install one of " << (_soft ? "(soft):" : ":")<< endl;
82  Queue qs;
83 
84  if (_soft) {
85  queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF | SOLVER_WEAK);
86  } else {
87  queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF );
88  }
89 
90  queue_init(&qs);
91  for (PoolItemList::const_iterator iter = _oneOfList.begin(); iter != _oneOfList.end(); iter++) {
92  Id id = (*iter)->satSolvable().id();
93  if (id == ID_NULL) {
94  ERR << *iter << " not found" << endl;
95  ret = false;
96  } else {
97  MIL << " candidate:" << *iter << " with the SAT-Pool ID: " << id << endl;
98  queue_push( &(qs), id );
99  }
100  }
101  sat::Pool satPool( sat::Pool::instance() );
102  queue_push( &(q), pool_queuetowhatprovides(satPool.get(), &qs));
103  queue_free(&qs);
104 
105  return ret;
106 }
107 
108 SolverQueueItem_Ptr
110 {
111  SolverQueueItemInstallOneOf_Ptr new_installOneOf = new SolverQueueItemInstallOneOf (pool(), _oneOfList);
112  new_installOneOf->SolverQueueItem::copy(this);
113  new_installOneOf->_soft = _soft;
114 
115  return new_installOneOf;
116 }
117 
118 int
119 SolverQueueItemInstallOneOf::cmp (SolverQueueItem_constPtr item) const
120 {
121  int cmp = this->compare (item);
122  if (cmp != 0)
123  return cmp;
124  SolverQueueItemInstallOneOf_constPtr install = dynamic_pointer_cast<const SolverQueueItemInstallOneOf>(item);
125 
126  return (_oneOfList == install->_oneOfList) ? 0 : -1; // more evaluation would be not useful
127 }
128 
129 
130 //---------------------------------------------------------------------------
131 
132 
134  };// namespace detail
137  };// namespace solver
140 };// namespace zypp
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition: Pool.h:55
zypp::solver::detail::SolverQueueItemInstallOneOf::_oneOfList
PoolItemList _oneOfList
Definition: SolverQueueItemInstallOneOf.h:50
zypp::solver::detail::SolverQueueItemInstallOneOf::~SolverQueueItemInstallOneOf
virtual ~SolverQueueItemInstallOneOf()
Definition: SolverQueueItemInstallOneOf.cc:72
zypp::solver::detail::IMPL_PTR_TYPE
IMPL_PTR_TYPE(SATResolver)
SolverQueueItemInstallOneOf.h
MIL
#define MIL
Definition: Logger.h:79
zypp::solver::detail::SolverQueueItemInstallOneOf::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Definition: SolverQueueItemInstallOneOf.cc:49
zypp::sat::Pool
Global sat-pool.
Definition: Pool.h:46
zypp::solver::detail::SolverQueueItemInstallOneOf::cmp
virtual int cmp(SolverQueueItem_constPtr item) const
Definition: SolverQueueItemInstallOneOf.cc:119
Logger.h
zypp::solver::detail::SolverQueueItemInstallOneOf::_soft
bool _soft
Definition: SolverQueueItemInstallOneOf.h:51
zypp::solver::detail::SolverQueueItemInstallOneOf::addRule
virtual bool addRule(sat::detail::CQueue &q)
Definition: SolverQueueItemInstallOneOf.cc:78
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Pool.h
zypp::solver::detail::SolverQueueItemInstallOneOf::PoolItemList
std::list< PoolItem > PoolItemList
Definition: SolverQueueItemInstallOneOf.h:46
SolverQueueItem
zypp::ResPool
Global ResObject pool.
Definition: ResPool.h:60
zypp::sat::detail::CQueue
::s_Queue CQueue
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:62
ERR
#define ERR
Definition: Logger.h:81
zypp::solver::detail::SolverQueueItemInstallOneOf::copy
virtual SolverQueueItem_Ptr copy(void) const
Definition: SolverQueueItemInstallOneOf.cc:109
zypp::solver::detail::SolverQueueItemInstallOneOf::SolverQueueItemInstallOneOf
SolverQueueItemInstallOneOf(const ResPool &pool, const PoolItemList &itemList, bool soft=false)
Definition: SolverQueueItemInstallOneOf.cc:63
zypp::sat::Pool::get
detail::CPool * get() const
Expert backdoor.
Definition: Pool.cc:49