libzypp  13.10.6
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 #include "zypp/base/Logger.h"
27 #include "zypp/sat/Pool.h"
28 
30 namespace zypp
31 {
32  namespace solver
34  {
35  namespace detail
37  {
38 
39 using namespace std;
40 
41 IMPL_PTR_TYPE(SolverQueueItemInstallOneOf);
42 
43 //---------------------------------------------------------------------------
44 
45 std::ostream &
46 SolverQueueItemInstallOneOf::dumpOn( std::ostream & os ) const
47 {
48  os << "[" << (_soft?"Soft":"") << "InstallOneOf: ";
49  for (PoolItemList::const_iterator iter = _oneOfList.begin();
50  iter != _oneOfList.end();
51  iter++)
52  os << *iter;
53  os << "]";
54 
55  return os;
56 }
57 
58 //---------------------------------------------------------------------------
59 
61  bool soft)
63  , _oneOfList (itemList)
64  , _soft (soft)
65 {
66 }
67 
68 
70 {
71 }
72 
73 //---------------------------------------------------------------------------
74 
76 {
77  bool ret = true;
78  MIL << "Install one of " << (_soft ? "(soft):" : ":")<< endl;
79  Queue qs;
80 
81  if (_soft) {
82  queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF | SOLVER_WEAK);
83  } else {
84  queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF );
85  }
86 
87  queue_init(&qs);
88  for (PoolItemList::const_iterator iter = _oneOfList.begin(); iter != _oneOfList.end(); iter++) {
89  Id id = (*iter)->satSolvable().id();
90  if (id == ID_NULL) {
91  ERR << *iter << " not found" << endl;
92  ret = false;
93  } else {
94  MIL << " candidate:" << *iter << " with the SAT-Pool ID: " << id << endl;
95  queue_push( &(qs), id );
96  }
97  }
98  sat::Pool satPool( sat::Pool::instance() );
99  queue_push( &(q), pool_queuetowhatprovides(satPool.get(), &qs));
100  queue_free(&qs);
101 
102  return ret;
103 }
104 
105 SolverQueueItem_Ptr
107 {
108  SolverQueueItemInstallOneOf_Ptr new_installOneOf = new SolverQueueItemInstallOneOf (pool(), _oneOfList);
109  new_installOneOf->SolverQueueItem::copy(this);
110  new_installOneOf->_soft = _soft;
111 
112  return new_installOneOf;
113 }
114 
115 int
116 SolverQueueItemInstallOneOf::cmp (SolverQueueItem_constPtr item) const
117 {
118  int cmp = this->compare (item);
119  if (cmp != 0)
120  return cmp;
121  SolverQueueItemInstallOneOf_constPtr install = dynamic_pointer_cast<const SolverQueueItemInstallOneOf>(item);
122 
123  return (_oneOfList == install->_oneOfList) ? 0 : -1; // more evaluation would be not useful
124 }
125 
126 
127 //---------------------------------------------------------------------------
128 
129 
131  };// namespace detail
134  };// namespace solver
137 };// namespace zypp
::_Pool * get() const
Expert backdoor.
Definition: Pool.cc:36
#define MIL
Definition: Logger.h:47
#define ERR
Definition: Logger.h:49
static Pool instance()
Singleton ctor.
Definition: Pool.h:51
SolverQueueItemInstallOneOf(const ResPool &pool, const PoolItemList &itemList, bool soft=false)
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream &amp; operator&lt;&lt;.
Global ResObject pool.
Definition: ResPool.h:48
IMPL_PTR_TYPE(ProblemSolutionCombi)
Global sat-pool.
Definition: Pool.h:42
virtual int cmp(SolverQueueItem_constPtr item) const
int compare(SolverQueueItem_constPtr item) const