backup
[platform/upstream/libzypp.git] / zypp / ProblemSolution.cc
1
2 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 /* ProblemSolution.cc
4  *
5  * Easy-to use interface to the ZYPP dependency resolver
6  *
7  * Copyright (C) 2000-2002 Ximian, Inc.
8  * Copyright (C) 2005 SUSE Linux Products GmbH
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License,
12  * version 2, as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22  * 02111-1307, USA.
23  */
24 #include "zypp/solver/detail/Types.h"
25 #include "zypp/solver/detail/SolutionAction.h"
26 #include "zypp/ProblemSolution.h"
27 #include "zypp/base/Logger.h"
28 #include "zypp/solver/detail/Resolver.h"
29
30 using namespace std;
31
32 /////////////////////////////////////////////////////////////////////////
33 namespace zypp
34 { ///////////////////////////////////////////////////////////////////////
35
36 IMPL_PTR_TYPE(ProblemSolution);
37
38 //---------------------------------------------------------------------------
39
40 ostream&
41 operator<<( ostream& os, const ProblemSolution & solution)
42 {
43     os << "Solution:" << endl;
44     os << solution._description << endl;
45     os << solution._details << endl;
46     os << solution._actions;
47     return os;
48 }
49
50 ostream&
51 operator<<( ostream& os, const ProblemSolutionList & solutionlist)
52 {
53     for (ProblemSolutionList::const_iterator iter = solutionlist.begin(); iter != solutionlist.end(); ++iter) {
54         os << *(*iter) << endl;
55     }
56     return os;
57 }
58
59 ostream&
60 operator<<( ostream& os, const CProblemSolutionList & solutionlist)
61 {
62     for (CProblemSolutionList::const_iterator iter = solutionlist.begin(); iter != solutionlist.end(); ++iter) {
63         os << *(*iter) << endl;
64     }
65     return os;
66 }
67
68 //---------------------------------------------------------------------------
69
70 ProblemSolution::ProblemSolution( ResolverProblem_Ptr parent, const string & description, const string & details )
71     : _problem (parent)
72     , _description (description)
73     , _details (details)
74 {
75 }
76
77
78 ProblemSolution::~ProblemSolution()
79 {
80 }
81
82
83 /**
84  * Apply this solution, i.e. execute all of its actions.
85  *
86  * Returns 'true' on success, 'false' if actions could not be performed.
87  **/
88
89 bool
90 ProblemSolution::apply (solver::detail::Resolver & resolver)
91 {
92     DBG << "apply solution " << *this << endl;
93     bool ret = true;
94     for (solver::detail::CSolutionActionList::const_iterator iter = _actions.begin();
95          iter != _actions.end(); ++iter) {
96         solver::detail::SolutionAction_constPtr action = *iter;
97         if (! action->execute (resolver))
98         {
99             ret = false;
100             break;
101         }
102     }
103     return true;
104 }
105
106
107 /**
108  * Add an action to the actions list.
109  **/ 
110 void
111 ProblemSolution::addAction (solver::detail::SolutionAction_constPtr action)
112 {
113     _actions.push_back (action);
114 }
115
116
117 void
118 ProblemSolution::clear()
119 {
120     _actions.clear();
121 }
122
123   ///////////////////////////////////////////////////////////////////////
124 };// namespace zypp
125 /////////////////////////////////////////////////////////////////////////