problem solution moved to toplevel; setTransacts --> setTransact
[platform/upstream/libzypp.git] / zypp / ResolverProblem.cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* ResolverProblem.cc
3  *
4  * Easy-to use interface to the ZYPP dependency resolver
5  *
6  * Copyright (C) 2000-2002 Ximian, Inc.
7  * Copyright (C) 2005 SUSE Linux Products GmbH
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License,
11  * version 2, as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307, USA.
22  */
23
24 #include "zypp/ResolverProblem.h"
25 #include "zypp/ProblemSolution.h"
26
27 using namespace std;
28
29 /////////////////////////////////////////////////////////////////////////
30 namespace zypp
31 { ///////////////////////////////////////////////////////////////////////
32
33 IMPL_PTR_TYPE(ResolverProblem);
34
35 //---------------------------------------------------------------------------
36
37 ostream&
38 operator<<( ostream& os, const ResolverProblem & problem)
39 {
40     os << "Problem:" << endl;
41     os << problem._description << endl;
42     os << problem._details << endl;
43     os << problem._solutions;
44     return os;
45 }
46
47
48 ostream&
49 operator<<( ostream& os, const ResolverProblemList & problemlist)
50 {
51     for (ResolverProblemList::const_iterator iter = problemlist.begin(); iter != problemlist.end(); ++iter) {
52         if (iter != problemlist.begin())
53             os << ", ";
54         os << (*iter);
55     }
56     return os;
57 }
58
59 //---------------------------------------------------------------------------
60
61 /**
62  * Constructor.
63  **/
64 ResolverProblem::ResolverProblem( const string & description, const string & details )
65     : _description (description)
66     , _details (details)
67 {
68 }
69
70 /**
71  * Destructor.
72  **/
73 ResolverProblem::~ResolverProblem()
74 {
75 }
76
77 /**
78  * Return the possible solutions to this problem.
79  * All problems should have at least 2-3 (mutually exclusive) solutions:
80  *
81  *        -  Undo: Do not perform the offending transaction
82  *       (do not install the package that had unsatisfied requirements,
83  *        do not remove  the package that would break other packages' requirements)
84  *
85  *        - Remove referrers: Remove all packages that would break because
86  *      they depend on the package that is requested to be removed
87  *
88  *        - Ignore: Inject artificial "provides" for a missing requirement
89  *      (pretend that requirement is satisfied)
90  **/
91
92 ProblemSolutionList
93 ResolverProblem::solutions() const
94 {
95     return _solutions;
96 }
97
98 /**
99  * Add a solution to this problem. This class takes over ownership of
100  * the problem and will delete it when neccessary.
101  **/
102
103 void
104 ResolverProblem::addSolution( ProblemSolution_Ptr solution )
105 {
106     _solutions.push_back (solution);
107 }
108
109 void
110 ResolverProblem::clear()
111 {
112     _solutions.clear();
113 }
114
115   ///////////////////////////////////////////////////////////////////////
116 };// namespace zypp
117 /////////////////////////////////////////////////////////////////////////