libzypp  15.21.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 
41  {
42  Impl()
43  {}
44 
45  Impl( std::string && description )
46  : _description( std::move(description) )
47  {}
48 
49  Impl( std::string && description, std::string && details )
50  : _description( std::move(description) )
51  , _details( std::move(details) )
52  {}
53 
54  std::string _description;
55  std::string _details;
57 
58  private:
59  friend Impl * rwcowClone<Impl>( const Impl * rhs );
61  Impl * clone() const
62  { return new Impl( *this ); }
63  };
65 
67  : _pimpl( new Impl() )
68  {}
69 
70  ResolverProblem::ResolverProblem( std::string description )
71  : _pimpl( new Impl( std::move(description) ) )
72  {}
73 
74  ResolverProblem::ResolverProblem( std::string description, std::string details )
75  : _pimpl( new Impl( std::move(description), std::move(details) ) )
76  {}
77 
79  {}
80 
81 
82  const std::string & ResolverProblem::description() const
83  { return _pimpl->_description; }
84 
85  const std::string & ResolverProblem::details() const
86  { return _pimpl->_details; }
87 
89  { return _pimpl->_solutions; }
90 
91 
92  void ResolverProblem::setDescription( std::string description )
93  { _pimpl->_description = std::move(description); }
94 
95  void ResolverProblem::setDetails( std::string details )
96  { _pimpl->_details = std::move(details); }
97 
98  void ResolverProblem::addSolution( ProblemSolution_Ptr solution, bool inFront )
99  {
100  if (inFront)
101  { _pimpl->_solutions.push_front( solution ); }
102  else
103  { _pimpl->_solutions.push_back( solution ); }
104  }
105 
106 
107  std::ostream & operator<<( std::ostream & os, const ResolverProblem & obj )
108  {
109  os << "Problem:" << endl;
110  os << "==============================" << endl;
111  os << obj.description() << endl;
112  os << obj.details() << endl;
113  os << "------------------------------" << endl;
114  os << obj.solutions();
115  os << "==============================" << endl;
116  return os;
117  }
118 
119  std::ostream & operator<<( std::ostream & os, const ResolverProblemList & obj )
120  { return dumpRange( os, obj.begin(), obj.end(), "", "", ", ", "", "" ); }
121 
122 } // 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 std::string & description() const
Return a one-line description of the problem.
Impl(std::string &&description, std::string &&details)
ResolverProblem implementation.
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
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:91
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
void setDetails(std::string details)
Set detail description of the problem.
IMPL_PTR_TYPE(Application)
const std::string & details() const
Return a (possibly muti-line) detailed description of the problem or an empty string if there are no ...
Impl * clone() const
clone for RWCOW_pointer
RWCOW_pointer< Impl > _pimpl
ProblemSolutionList _solutions
Impl(std::string &&description)
Describe a solver problem and offer solutions.
ResolverProblem()
Constructor.
const ProblemSolutionList & solutions() const
Return the possible solutions to this problem.
void setDescription(std::string description)
Set description of the problem.