Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / solver / detail / SolverQueueItemUpdate.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 #include "zypp/base/Logger.h"
26 #include "zypp/solver/detail/SolverQueueItemUpdate.h"
27
28 /////////////////////////////////////////////////////////////////////////
29 namespace zypp
30 { ///////////////////////////////////////////////////////////////////////
31   ///////////////////////////////////////////////////////////////////////
32   namespace solver
33   { /////////////////////////////////////////////////////////////////////
34     /////////////////////////////////////////////////////////////////////
35     namespace detail
36     { ///////////////////////////////////////////////////////////////////
37
38 using namespace std;
39
40 IMPL_PTR_TYPE(SolverQueueItemUpdate);
41
42 //---------------------------------------------------------------------------
43
44 std::ostream &
45 SolverQueueItemUpdate::dumpOn( std::ostream & os ) const
46 {
47     os << "[" << (_soft?"Soft":"") << "Update: " <<
48         _item << "]";
49
50     return os;
51 }
52
53 //---------------------------------------------------------------------------
54
55 SolverQueueItemUpdate::SolverQueueItemUpdate (const ResPool & pool,
56                                               const PoolItem & item, bool soft)
57     : SolverQueueItem (QUEUE_ITEM_TYPE_UPDATE, pool)
58     , _item (item)
59     , _soft (soft)
60 {
61 }
62
63
64 SolverQueueItemUpdate::~SolverQueueItemUpdate()
65 {
66 }
67
68 //---------------------------------------------------------------------------
69
70 bool SolverQueueItemUpdate::addRule (_Queue & q)
71 {
72     ::Id id = _item.satSolvable().id();
73     if (id == ID_NULL) {
74         ERR << "Update explicit: " << _item << " not found" << endl;
75         return false;
76     }
77     MIL << "Update explicit " << _item << " with the SAT-Pool ID: " << id << endl;
78     queue_push( &(q), SOLVER_UPDATE | SOLVER_SOLVABLE );
79     queue_push( &(q), id );
80     return true;
81 }
82
83 SolverQueueItem_Ptr
84 SolverQueueItemUpdate::copy (void) const
85 {
86     SolverQueueItemUpdate_Ptr new_update = new SolverQueueItemUpdate (pool(), _item);
87     new_update->SolverQueueItem::copy(this);
88
89     new_update->_soft = _soft;
90     return new_update;
91 }
92
93 int
94 SolverQueueItemUpdate::cmp (SolverQueueItem_constPtr item) const
95 {
96     int cmp = this->compare (item);
97     if (cmp != 0)
98         return cmp;
99     SolverQueueItemUpdate_constPtr update = dynamic_pointer_cast<const SolverQueueItemUpdate>(item);
100     return compareByNVRA (_item.resolvable(), update->_item.resolvable());
101 }
102
103
104 //---------------------------------------------------------------------------
105
106
107 ///////////////////////////////////////////////////////////////////
108     };// namespace detail
109     /////////////////////////////////////////////////////////////////////
110     /////////////////////////////////////////////////////////////////////
111   };// namespace solver
112   ///////////////////////////////////////////////////////////////////////
113   ///////////////////////////////////////////////////////////////////////
114 };// namespace zypp
115 /////////////////////////////////////////////////////////////////////////