libzypp: zypp/ResolverProblem.cc Source File

libzypp 17.38.13

ResolverProblem.cc
Go to the documentation of this file.
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-core/base/LogTools.h>
25
26#include <zypp/ResolverProblem.h>
27#include <zypp/ProblemSolution.h>
28
29using std::endl;
30
32namespace zypp
33{
34 IMPL_PTR_TYPE(ResolverProblem);
35
37 namespace
38 {
39 // HACK for bsc#985674: filter duplicate solutions
40 //
41 inline bool solutionInList( const ProblemSolutionList & solutions_r, const ProblemSolution_Ptr & solution_r )
42 {
43 for ( const ProblemSolution_Ptr & solution : solutions_r )
44 {
45 if ( solution->description() == solution_r->description()
46 && solution->details() == solution_r->details()
47 && solution->actions().size() == solution_r->actions().size() )
48 return true;
49 }
50 return false;
51 }
52 } // namespace
54
59 struct ResolverProblem::Impl
60 {
61 Impl()
62 {}
63
64 Impl( std::string && description )
65 : _description( std::move(description) )
66 {}
67
68 Impl( std::string && description, std::string && details )
69 : _description( std::move(description) )
70 , _details( std::move(details) )
71 {}
72
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) )
77 {}
78
79 std::string _description;
80 std::string _details;
81 ProblemSolutionList _solutions;
82 std::vector<std::string> _completeProblemInfo;
83
84 private:
85 friend Impl * rwcowClone<Impl>( const Impl * rhs );
87 Impl * clone() const
88 { return new Impl( *this ); }
89 };
90
91
92 ResolverProblem::ResolverProblem()
93 : _pimpl( new Impl() )
94 {}
95
96 ResolverProblem::ResolverProblem( std::string description )
97 : _pimpl( new Impl( std::move(description) ) )
98 {}
99
100 ResolverProblem::ResolverProblem( std::string description, std::string details )
101 : _pimpl( new Impl( std::move(description), std::move(details) ) )
102 {}
103
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) ) )
106 {}
107
108 ResolverProblem::~ResolverProblem()
109 {}
110
111
112 const std::string & ResolverProblem::description() const
113 { return _pimpl->_description; }
114
115 const std::string & ResolverProblem::details() const
116 { return _pimpl->_details; }
117
118 const ProblemSolutionList & ResolverProblem::solutions() const
119 { return _pimpl->_solutions; }
120
121 const std::vector<std::string> & ResolverProblem::completeProblemInfo() const
122 { return _pimpl->_completeProblemInfo; }
123
124 void ResolverProblem::setDescription( std::string description )
125 { _pimpl->_description = std::move(description); }
126
127 void ResolverProblem::setDetails( std::string details )
128 { _pimpl->_details = std::move(details); }
129
130 void ResolverProblem::addSolution( const ProblemSolution_Ptr& solution, bool inFront )
131 {
132 if ( ! solutionInList( _pimpl->_solutions, solution ) ) // bsc#985674: filter duplicate solutions
133 {
134 if (inFront)
135 { _pimpl->_solutions.push_front( solution ); }
136 else
137 { _pimpl->_solutions.push_back( solution ); }
138 }
139 }
140
141
142 std::ostream & operator<<( std::ostream & os, const ResolverProblem & obj )
143 {
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;
151 return os;
152 }
153
154 std::ostream & operator<<( std::ostream & os, const ResolverProblemList & obj )
155 { return dumpRange( os, obj.begin(), obj.end(), "", "", ", ", "", "" ); }
156
157} // namespace zypp
LogTools.h
ProblemSolution.h
ResolverProblem.h
zypp::ResolverProblem
Describe a solver problem and offer solutions.
Definition ResolverProblem.h:27
zypp::ResolverProblem::completeProblemInfo
const std::vector< std::string > & completeProblemInfo() const
Return a one-line description for each problematic rule in the problem tree.
Definition ResolverProblem.cc:121
zypp::ResolverProblem::setDetails
void setDetails(std::string details)
Set detail description of the problem.
Definition ResolverProblem.cc:127
zypp::ResolverProblem::description
const std::string & description() const
Return a one-line description of the problem.
Definition ResolverProblem.cc:112
zypp::ResolverProblem::ResolverProblem
ResolverProblem()
Constructor.
Definition ResolverProblem.cc:92
zypp::ResolverProblem::~ResolverProblem
~ResolverProblem() override
Destructor.
Definition ResolverProblem.cc:108
zypp::ResolverProblem::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition ResolverProblem.h:93
zypp::ResolverProblem::solutions
const ProblemSolutionList & solutions() const
Return the possible solutions to this problem.
Definition ResolverProblem.cc:118
zypp::ResolverProblem::addSolution
void addSolution(const ProblemSolution_Ptr &solution, bool inFront=false)
Add a solution to this problem.
Definition ResolverProblem.cc:130
zypp::ResolverProblem::details
const std::string & details() const
Return a (possibly muti-line) detailed description of the problem or an empty string if there are no ...
Definition ResolverProblem.cc:115
zypp::ResolverProblem::setDescription
void setDescription(std::string description)
Set description of the problem.
Definition ResolverProblem.cc:124
std
Definition ansi.h:855
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ProblemSolutionList
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition ProblemTypes.h:43
zypp::dumpRange
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition LogTools.h:419
zypp::ResolverProblemList
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition ProblemTypes.h:46
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::ResolverProblem::Impl
ResolverProblem implementation.
Definition ResolverProblem.cc:60
zypp::ResolverProblem::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition ResolverProblem.cc:87
zypp::ResolverProblem::Impl::_completeProblemInfo
std::vector< std::string > _completeProblemInfo
Definition ResolverProblem.cc:82
zypp::ResolverProblem::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::ResolverProblem::Impl::_details
std::string _details
Definition ResolverProblem.cc:80
zypp::ResolverProblem::Impl::Impl
Impl(std::string &&description, std::string &&details, std::vector< std::string > &&completeProblemInfo)
Definition ResolverProblem.cc:73
zypp::ResolverProblem::Impl::Impl
Impl()
Definition ResolverProblem.cc:61
zypp::ResolverProblem::Impl::Impl
Impl(std::string &&description)
Definition ResolverProblem.cc:64
zypp::ResolverProblem::Impl::_description
std::string _description
Definition ResolverProblem.cc:79
zypp::ResolverProblem::Impl::_solutions
ProblemSolutionList _solutions
Definition ResolverProblem.cc:81
zypp::ResolverProblem::Impl::Impl
Impl(std::string &&description, std::string &&details)
Definition ResolverProblem.cc:68
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137