libzypp 17.37.10

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>
28#include <zypp/solver/detail/SolverQueueItemInstallOneOf.h>
29#include <zypp/sat/Pool.h>
30
31#include <utility>
32
33 using std::endl;
34
36 namespace zypp
37{
39 namespace solver
40 {
42 namespace detail
43 {
44
45
46 IMPL_PTR_TYPE(SolverQueueItemInstallOneOf);
47
48//---------------------------------------------------------------------------
49
50std::ostream &
51 SolverQueueItemInstallOneOf::dumpOn( std::ostream & os ) const
52{
53 os << "[" << (_soft?"Soft":"") << "InstallOneOf: ";
54 for (PoolItemList::const_iterator iter = _oneOfList.begin();
55 iter != _oneOfList.end();
56 iter++)
57 os << *iter;
58 os << "]";
59
60 return os;
61}
62
63//---------------------------------------------------------------------------
64
65 SolverQueueItemInstallOneOf::SolverQueueItemInstallOneOf (const ResPool & pool, PoolItemList itemList,
66 bool soft)
67 : SolverQueueItem (QUEUE_ITEM_TYPE_INSTALL_ONE_OF, pool)
68 , _oneOfList (std::move(itemList))
69 , _soft (soft)
70{
71}
72
73
74 SolverQueueItemInstallOneOf::~SolverQueueItemInstallOneOf()
75{
76}
77
78//---------------------------------------------------------------------------
79
80 bool SolverQueueItemInstallOneOf::addRule (sat::detail::CQueue & q)
81{
82 bool ret = true;
83 MIL << "Install one of " << (_soft ? "(soft):" : ":")<< endl;
84 Queue qs;
85
86 if (_soft) {
87 queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF | SOLVER_WEAK);
88 } else {
89 queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE_ONE_OF );
90 }
91
92 queue_init(&qs);
93 for (PoolItemList::const_iterator iter = _oneOfList.begin(); iter != _oneOfList.end(); iter++) {
94 Id id = (*iter)->satSolvable().id();
95 if (id == ID_NULL) {
96 ERR << *iter << " not found" << endl;
97 ret = false;
98 } else {
99 MIL << " candidate:" << *iter << " with the SAT-Pool ID: " << id << endl;
100 queue_push( &(qs), id );
101 }
102 }
103 sat::Pool satPool( sat::Pool::instance() );
104 queue_push( &(q), pool_queuetowhatprovides(satPool.get(), &qs));
105 queue_free(&qs);
106
107 return ret;
108}
109
110SolverQueueItem_Ptr
111 SolverQueueItemInstallOneOf::copy (void) const
112{
113 SolverQueueItemInstallOneOf_Ptr new_installOneOf = new SolverQueueItemInstallOneOf (pool(), _oneOfList);
114 new_installOneOf->SolverQueueItem::copy(this);
115 new_installOneOf->_soft = _soft;
116
117 return new_installOneOf;
118}
119
120 int
121 SolverQueueItemInstallOneOf::cmp (SolverQueueItem_constPtr item) const
122{
123 int cmp = this->compare (item);
124 if (cmp != 0)
125 return cmp;
126 SolverQueueItemInstallOneOf_constPtr install = dynamic_pointer_cast<const SolverQueueItemInstallOneOf>(item);
127
128 return (_oneOfList == install->_oneOfList) ? 0 : -1; // more evaluation would be not useful
129}
130
131
132//---------------------------------------------------------------------------
133
134
136 };// namespace detail
139 };// namespace solver
142};// namespace zypp
Pool.h
SolverQueueItemInstallOneOf.h
SolverQueueItem
zypp::ResPool
Global ResObject pool.
Definition ResPool.h:62
zypp::sat::Pool
Global sat-pool.
Definition Pool.h:47
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition Pool.h:55
zypp::sat::Pool::get
detail::CPool * get() const
Expert backdoor.
Definition Pool.cc:49
zypp::solver::detail::SolverQueueItemInstallOneOf
Definition SolverQueueItemInstallOneOf.h:43
zypp::solver::detail::SolverQueueItemInstallOneOf::addRule
virtual bool addRule(sat::detail::CQueue &q)
Definition SolverQueueItemInstallOneOf.cc:80
zypp::solver::detail::SolverQueueItemInstallOneOf::~SolverQueueItemInstallOneOf
virtual ~SolverQueueItemInstallOneOf()
Definition SolverQueueItemInstallOneOf.cc:74
zypp::solver::detail::SolverQueueItemInstallOneOf::cmp
virtual int cmp(SolverQueueItem_constPtr item) const
Definition SolverQueueItemInstallOneOf.cc:121
zypp::solver::detail::SolverQueueItemInstallOneOf::_soft
bool _soft
Definition SolverQueueItemInstallOneOf.h:51
zypp::solver::detail::SolverQueueItemInstallOneOf::PoolItemList
std::list< PoolItem > PoolItemList
Definition SolverQueueItemInstallOneOf.h:46
zypp::solver::detail::SolverQueueItemInstallOneOf::copy
virtual SolverQueueItem_Ptr copy(void) const
Definition SolverQueueItemInstallOneOf.cc:111
zypp::solver::detail::SolverQueueItemInstallOneOf::SolverQueueItemInstallOneOf
SolverQueueItemInstallOneOf(const ResPool &pool, PoolItemList itemList, bool soft=false)
Definition SolverQueueItemInstallOneOf.cc:65
zypp::solver::detail::SolverQueueItemInstallOneOf::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Definition SolverQueueItemInstallOneOf.cc:51
zypp::solver::detail::SolverQueueItemInstallOneOf::_oneOfList
PoolItemList _oneOfList
Definition SolverQueueItemInstallOneOf.h:50
std
Definition Arch.h:364
zypp::pool
Definition ByIdent.h:24
zypp::sat::detail::CQueue
::s_Queue CQueue
Wrapped libsolv C data type exposed as backdoor.
Definition PoolMember.h:62
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
MIL
#define MIL
Definition Logger.h:100
ERR
#define ERR
Definition Logger.h:102
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137
Logger.h