libzypp  17.1.1
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/base/LogTools.h"
25 
26 #include "zypp/ResolverProblem.h"
27 #include "zypp/ProblemSolution.h"
28 
29 using std::endl;
30 
32 namespace 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 
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  std::string _description;
74  std::string _details;
76 
77  private:
78  friend Impl * rwcowClone<Impl>( const Impl * rhs );
80  Impl * clone() const
81  { return new Impl( *this ); }
82  };
84 
86  : _pimpl( new Impl() )
87  {}
88 
90  : _pimpl( new Impl( std::move(description) ) )
91  {}
92 
94  : _pimpl( new Impl( std::move(description), std::move(details) ) )
95  {}
96 
98  {}
99 
100 
101  const std::string & ResolverProblem::description() const
102  { return _pimpl->_description; }
103 
104  const std::string & ResolverProblem::details() const
105  { return _pimpl->_details; }
106 
108  { return _pimpl->_solutions; }
109 
110 
112  { _pimpl->_description = std::move(description); }
113 
115  { _pimpl->_details = std::move(details); }
116 
117  void ResolverProblem::addSolution( ProblemSolution_Ptr solution, bool inFront )
118  {
119  if ( ! solutionInList( _pimpl->_solutions, solution ) ) // bsc#985674: filter duplicate solutions
120  {
121  if (inFront)
122  { _pimpl->_solutions.push_front( solution ); }
123  else
124  { _pimpl->_solutions.push_back( solution ); }
125  }
126  }
127 
128 
129  std::ostream & operator<<( std::ostream & os, const ResolverProblem & obj )
130  {
131  os << "Problem:" << endl;
132  os << "==============================" << endl;
133  os << obj.description() << endl;
134  os << obj.details() << endl;
135  os << "------------------------------" << endl;
136  os << obj.solutions();
137  os << "==============================" << endl;
138  return os;
139  }
140 
141  std::ostream & operator<<( std::ostream & os, const ResolverProblemList & obj )
142  { return dumpRange( os, obj.begin(), obj.end(), "", "", ", ", "", "" ); }
143 
144 } // namespace zypp
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
void addSolution(ProblemSolution_Ptr solution, bool inFront=false)
Add a solution to this problem.
~ResolverProblem()
Destructor.
const ProblemSolutionList & solutions() const
Return the possible solutions to this problem.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\ ", const std::string &sep="\ ", const std::string &sfx="\, const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition: LogTools.h:91
Definition: Arch.h:344
Impl(std::string &&description, std::string &&details)
ResolverProblem implementation.
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
void setDetails(std::string details)
Set detail description of the problem.
IMPL_PTR_TYPE(Application)
Impl * clone() const
clone for RWCOW_pointer
const std::string & details() const
Return a (possibly muti-line) detailed description of the problem or an empty string if there are no ...
RWCOW_pointer< Impl > _pimpl
ProblemSolutionList _solutions
Impl(std::string &&description)
Describe a solver problem and offer solutions.
std::ostream & operator<<(std::ostream &, const ResolverProblem &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
ResolverProblem()
Constructor.
const std::string & description() const
Return a one-line description of the problem.
void setDescription(std::string description)
Set description of the problem.