libzypp  17.35.19
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>
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  std::set<PoolItem> collectActionItems() const
64  {
65  std::set<PoolItem> ret;
66  for ( const auto & aptr : _actions )
67  ret.insert( aptr->item() );
68  return ret;
69  }
70 
71  template <typename Predicate>
72  bool allActionsMatch( Predicate && predicate ) const
73  {
74  if ( _actions.empty() )
75  return false;
76  for ( const auto & aptr : _actions )
77  if ( not std::invoke( std::forward<Predicate>(predicate), aptr ) )
78  return false;
79  return true;
80  }
81 
82  private:
83  friend Impl * rwcowClone<Impl>( const Impl * rhs );
85  Impl * clone() const
86  { return new Impl( *this ); }
87  };
89 
91  : _pimpl( new Impl() )
92  {}
93 
94  ProblemSolution::ProblemSolution( std::string description )
95  : _pimpl( new Impl( std::move(description) ) )
96  {}
97 
98  ProblemSolution::ProblemSolution( std::string description, std::string details )
99  : _pimpl( new Impl( std::move(description), std::move(details) ) )
100  {}
101 
103  {}
104 
105 
106  const std::string & ProblemSolution::description() const
107  { return _pimpl->_description; }
108 
109  const std::string & ProblemSolution::details() const
110  { return _pimpl->_details; }
111 
113  { return _pimpl->_actions; }
114 
115 
116  void ProblemSolution::setDescription( std::string description )
117  { _pimpl->_description = std::move(description); }
118 
119  void ProblemSolution::setDetails( const std::string& details )
120  { _pimpl->_details += "\n"; _pimpl->_details += details; }
121 
122  void ProblemSolution::pushDescriptionDetail( std::string description, bool front )
123  {
124  if ( _pimpl->_details.empty() )
125  {
126  if ( _pimpl->_description.empty() ) // first entry
127  {
128  _pimpl->_description = std::move(description);
129  return;
130  }
131  else // second entry: form headline in _description
132  {
134  _pimpl->_description = _("Following actions will be done:");
135  }
136  }
137  if ( front )
138  { _pimpl->_details.swap( description ); }
139  _pimpl->_details += "\n";
141  }
142 
143  void ProblemSolution::addAction( const solver::detail::SolutionAction_Ptr& action )
144  { _pimpl->_actions.push_back( action ); }
145 
147  {
148  return _pimpl->allActionsMatch( []( const SolutionAction_Ptr & aptr ) -> bool {
149  return aptr->skipsPatchesOnly();
150  } );
151  }
152 
153  std::optional<std::set<PoolItem>> ProblemSolution::getIfSkipsPatchesOnly() const
154  {
155  if ( not skipsPatchesOnly() )
156  return std::nullopt;
157  return _pimpl->collectActionItems();
158  }
159 
160 
161  std::ostream & operator<<( std::ostream & os, const ProblemSolution & obj )
162  {
163  os << "Solution:" << endl;
164  os << obj.description() << endl;
165  if ( ! obj.details().empty() )
166  os << obj.details() << endl;
167  os << obj.actions();
168  return os;
169  }
170 
171  std::ostream & operator<<( std::ostream & os, const ProblemSolutionList & obj )
172  {
173  for ( const auto & ptr: obj )
174  { os << ptr; }
175  return os;
176  }
177 
178 } // namespace zypp
std::set< PoolItem > collectActionItems() const
Interface to gettext.
#define _(MSG)
Definition: Gettext.h:39
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.
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)
std::enable_if< std::is_member_pointer< typename std::decay< Functor >::type >::value, typename std::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
Definition: functional.h:32
Impl * clone() const
clone for RWCOW_pointer
solver::detail::SolutionAction_Ptr SolutionAction_Ptr
Impl(std::string &&description)
solver::detail::SolutionActionList SolutionActionList
IMPL_PTR_TYPE(Application)
void setDetails(const std::string &details)
Set detail description of the solution.
SolutionActionList _actions
bool allActionsMatch(Predicate &&predicate) const
Predicate predicate
Definition: PoolQuery.cc:314
void addAction(const SolutionAction_Ptr &action)
Add an action to the actions list.
~ProblemSolution() override
Destructor.
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: Application.cc:19
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.
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43