1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Easy-to use interface to the ZYPP dependency resolver
6 * Copyright (C) 2000-2002 Ximian, Inc.
7 * Copyright (C) 2005 SUSE Linux Products GmbH
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.
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.
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
24 #include "zypp/base/LogTools.h"
26 #include "zypp/ResolverProblem.h"
27 #include "zypp/ProblemSolution.h"
31 /////////////////////////////////////////////////////////////////////////
34 IMPL_PTR_TYPE(ResolverProblem);
36 /////////////////////////////////////////////////////////////////////////
39 // HACK for bsc#985674: filter duplicate solutions
41 inline bool solutionInList( const ProblemSolutionList & solutions_r, const ProblemSolution_Ptr & solution_r )
43 for ( const ProblemSolution_Ptr & solution : solutions_r )
45 if ( solution->description() == solution_r->description()
46 && solution->details() == solution_r->details()
47 && solution->actions().size() == solution_r->actions().size() )
53 /////////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////
56 /// \class ResolverProblem::Impl
57 /// \brief ResolverProblem implementation.
58 ///////////////////////////////////////////////////////////////////
59 struct ResolverProblem::Impl
64 Impl( std::string && description )
65 : _description( std::move(description) )
68 Impl( std::string && description, std::string && details )
69 : _description( std::move(description) )
70 , _details( std::move(details) )
73 Impl( std::string && description, std::string && details, std::vector<std::string> &&completeProblemInfo )
74 : _description( std::move(description) )
75 , _details( std::move(details) )
76 , _completeProblemInfo ( std::move(completeProblemInfo) )
79 std::string _description;
81 ProblemSolutionList _solutions;
82 std::vector<std::string> _completeProblemInfo;
85 friend Impl * rwcowClone<Impl>( const Impl * rhs );
86 /** clone for RWCOW_pointer */
88 { return new Impl( *this ); }
90 ///////////////////////////////////////////////////////////////////
92 ResolverProblem::ResolverProblem()
93 : _pimpl( new Impl() )
96 ResolverProblem::ResolverProblem( std::string description )
97 : _pimpl( new Impl( std::move(description) ) )
100 ResolverProblem::ResolverProblem( std::string description, std::string details )
101 : _pimpl( new Impl( std::move(description), std::move(details) ) )
104 ResolverProblem::ResolverProblem( std::string description, std::string details, std::vector<std::string> &&completeProblemInfo )
105 : _pimpl( new Impl( std::move(description), std::move(details), std::move(completeProblemInfo) ) )
108 ResolverProblem::~ResolverProblem()
112 const std::string & ResolverProblem::description() const
113 { return _pimpl->_description; }
115 const std::string & ResolverProblem::details() const
116 { return _pimpl->_details; }
118 const ProblemSolutionList & ResolverProblem::solutions() const
119 { return _pimpl->_solutions; }
121 const std::vector<std::string> & ResolverProblem::completeProblemInfo() const
122 { return _pimpl->_completeProblemInfo; }
124 void ResolverProblem::setDescription( std::string description )
125 { _pimpl->_description = std::move(description); }
127 void ResolverProblem::setDetails( std::string details )
128 { _pimpl->_details = std::move(details); }
130 void ResolverProblem::addSolution( ProblemSolution_Ptr solution, bool inFront )
132 if ( ! solutionInList( _pimpl->_solutions, solution ) ) // bsc#985674: filter duplicate solutions
135 { _pimpl->_solutions.push_front( solution ); }
137 { _pimpl->_solutions.push_back( solution ); }
142 std::ostream & operator<<( std::ostream & os, const ResolverProblem & obj )
144 os << "Problem:" << endl;
145 os << "==============================" << endl;
146 os << obj.description() << endl;
147 os << obj.details() << endl;
148 os << "------------------------------" << endl;
149 os << obj.solutions();
150 os << "==============================" << endl;
154 std::ostream & operator<<( std::ostream & os, const ResolverProblemList & obj )
155 { return dumpRange( os, obj.begin(), obj.end(), "", "", ", ", "", "" ); }
158 /////////////////////////////////////////////////////////////////////////