Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / solver / detail / SolverQueueItemDelete.cc
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/IdString.h"
29 #include "zypp/Resolver.h"
30 #include "zypp/solver/detail/SolverQueueItemDelete.h"
31
32 /////////////////////////////////////////////////////////////////////////
33 namespace zypp
34 { ///////////////////////////////////////////////////////////////////////
35   ///////////////////////////////////////////////////////////////////////
36   namespace solver
37   { /////////////////////////////////////////////////////////////////////
38     /////////////////////////////////////////////////////////////////////
39     namespace detail
40     { ///////////////////////////////////////////////////////////////////
41
42 using namespace std;
43
44 IMPL_PTR_TYPE(SolverQueueItemDelete);
45
46 //---------------------------------------------------------------------------
47
48 std::ostream &
49 SolverQueueItemDelete::dumpOn( std::ostream & os ) const
50 {
51     os << "[" << (_soft?"Soft":"") << "Delete: "
52        << _name << "]";
53
54     return os;
55 }
56
57 //---------------------------------------------------------------------------
58
59 SolverQueueItemDelete::SolverQueueItemDelete (const ResPool & pool, std::string name, bool soft)
60     : SolverQueueItem (QUEUE_ITEM_TYPE_DELETE, pool)
61     , _name (name)
62     , _soft (soft)
63 {
64 }
65
66
67 SolverQueueItemDelete::~SolverQueueItemDelete()
68 {
69 }
70
71 //---------------------------------------------------------------------------
72
73 bool SolverQueueItemDelete::addRule (sat::detail::CQueue & q)
74 {
75 #define MAYBE_CLEANDEPS (pool().resolver().cleandepsOnRemove()?SOLVER_CLEANDEPS:0)
76
77     ::Id id = IdString(_name).id();
78     if (_soft) {
79         queue_push( &(q), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | SOLVER_WEAK | MAYBE_CLEANDEPS );
80     } else {
81         queue_push( &(q), SOLVER_ERASE | SOLVER_SOLVABLE_NAME | MAYBE_CLEANDEPS );
82     }
83     queue_push( &(q), id);
84
85     MIL << "Delete " << _name << (_soft ? "(soft)" : "")
86         << " with SAT-Pool: " << id << endl;
87     return true;
88 }
89
90 SolverQueueItem_Ptr
91 SolverQueueItemDelete::copy (void) const
92 {
93     SolverQueueItemDelete_Ptr new_delete = new SolverQueueItemDelete (pool(), _name);
94     new_delete->SolverQueueItem::copy(this);
95
96     new_delete->_soft = _soft;
97     return new_delete;
98 }
99
100 int
101 SolverQueueItemDelete::cmp (SolverQueueItem_constPtr item) const
102 {
103     int cmp = this->compare (item);
104     if (cmp != 0)
105         return cmp;
106     SolverQueueItemDelete_constPtr del = dynamic_pointer_cast<const SolverQueueItemDelete>(item);
107     if (_name != del->_name) {
108         return _name.compare(del->_name);
109     }
110     return 0;
111 }
112
113 //---------------------------------------------------------------------------
114
115
116 ///////////////////////////////////////////////////////////////////
117     };// namespace detail
118     /////////////////////////////////////////////////////////////////////
119     /////////////////////////////////////////////////////////////////////
120   };// namespace solver
121   ///////////////////////////////////////////////////////////////////////
122   ///////////////////////////////////////////////////////////////////////
123 };// namespace zypp
124 /////////////////////////////////////////////////////////////////////////