libzypp  17.31.31
ProblemSolution.cc
Go to the documentation of this file.
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 
25 #define ZYPP_USE_RESOLVER_INTERNALS
26 #include <functional>
27 
28 #include <zypp/base/Gettext.h>
30 #include <zypp/ProblemSolution.h>
31 #include <zypp/base/Logger.h>
32 #include <zypp/solver/detail/Resolver.h>
33 
34 using std::endl;
35 
37 namespace zypp
38 {
39  IMPL_PTR_TYPE(ProblemSolution);
40 
46  {
47  Impl()
48  {}
49 
50  Impl( std::string && description )
51  : _description( std::move(description) )
52  {}
53 
54  Impl( std::string && description, std::string && details )
55  : _description( std::move(description) )
56  , _details( std::move(details) )
57  {}
58 
59  std::string _description;
60  std::string _details;
62 
63  template <typename Predicate>
64  bool allActionsMatch( Predicate && predicate ) const
65  {
66  if ( _actions.empty() )
67  return false;
68  for ( const auto & aptr : _actions )
69  if ( not std::invoke( std::forward<Predicate>(predicate), aptr ) )
70  return false;
71  return true;
72  }
73 
74  private:
75  friend Impl * rwcowClone<Impl>( const Impl * rhs );
77  Impl * clone() const
78  { return new Impl( *this ); }
79  };
81 
83  : _pimpl( new Impl() )
84  {}
85 
86  ProblemSolution::ProblemSolution( std::string description )
87  : _pimpl( new Impl( std::move(description) ) )
88  {}
89 
90  ProblemSolution::ProblemSolution( std::string description, std::string details )
91  : _pimpl( new Impl( std::move(description), std::move(details) ) )
92  {}
93 
95  {}
96 
97 
98  const std::string & ProblemSolution::description() const
99  { return _pimpl->_description; }
100 
101  const std::string & ProblemSolution::details() const
102  { return _pimpl->_details; }
103 
105  { return _pimpl->_actions; }
106 
107 
108  void ProblemSolution::setDescription( std::string description )
109  { _pimpl->_description = std::move(description); }
110 
111  void ProblemSolution::setDetails( std::string details )
112  { _pimpl->_details += "\n"; _pimpl->_details += std::move(details); }
113 
114  void ProblemSolution::pushDescriptionDetail( std::string description, bool front )
115  {
116  if ( _pimpl->_details.empty() )
117  {
118  if ( _pimpl->_description.empty() ) // first entry
119  {
120  _pimpl->_description = std::move(description);
121  return;
122  }
123  else // second entry: form headline in _description
124  {
126  _pimpl->_description = _("Following actions will be done:");
127  }
128  }
129  if ( front )
130  { _pimpl->_details.swap( description ); }
131  _pimpl->_details += "\n";
132  _pimpl->_details += std::move(description);
133  }
134 
135  void ProblemSolution::addAction( solver::detail::SolutionAction_Ptr action )
136  { _pimpl->_actions.push_back( action ); }
137 
138 
140  {
141  return _pimpl->allActionsMatch( []( const SolutionAction_Ptr & aptr ) -> bool {
142  return aptr->skipsPatchesOnly();
143  } );
144  }
145 
146 
147  std::ostream & operator<<( std::ostream & os, const ProblemSolution & obj )
148  {
149  os << "Solution:" << endl;
150  os << obj.description() << endl;
151  if ( ! obj.details().empty() )
152  os << obj.details() << endl;
153  os << obj.actions();
154  return os;
155  }
156 
157  std::ostream & operator<<( std::ostream & os, const ProblemSolutionList & obj )
158  {
159  for ( const auto & ptr: obj )
160  { os << ptr; }
161  return os;
162  }
163 
164 } // namespace zypp
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
#define _(MSG)
Definition: Gettext.h:37
const SolutionActionList & actions() const
Return the list of actions forming this solution.
RWCOW_pointer< Impl > _pimpl
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
Definition: Arch.h:363
ProblemSolution()
Constructor.
void setDetails(std::string details)
Set detail description of the solution.
const std::string & details() const
Return a (possibly multi-line) detailed description of this solution or an empty string if there are ...
Impl(std::string &&description, std::string &&details)
Impl * clone() const
clone for RWCOW_pointer
void addAction(SolutionAction_Ptr action)
Add an action to the actions list.
Impl(std::string &&description)
IMPL_PTR_TYPE(Application)
SolutionActionList _actions
bool allActionsMatch(Predicate &&predicate) const
solver::detail::SolutionAction_Ptr SolutionAction_Ptr
Predicate predicate
Definition: PoolQuery.cc:313
solver::detail::SolutionActionList SolutionActionList
void setDescription(std::string description)
Set description of the solution.
bool skipsPatchesOnly() const
The solution contains only &#39;do not install patch:&#39; actions.
ProblemSolution implementation.
const std::string & description() const
Return a one-line text description of this solution.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void pushDescriptionDetail(std::string description, bool front=false)
Collect multiple action descriptions in details (NL separated)
Class representing one possible solution to a problem found during resolving.
virtual ~ProblemSolution()
Destructor.