libzypp 17.37.17
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>
31#include <zypp/base/Logger.h>
33
34using std::endl;
35
37namespace zypp
38{
40
46 {
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 };
88
89
93
95 : _pimpl( new Impl( std::move(description) ) )
96 {}
97
99 : _pimpl( new Impl( std::move(description), std::move(details) ) )
100 {}
101
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
117 { _pimpl->_description = std::move(description); }
118
119 void ProblemSolution::setDetails( const std::string& details )
120 { _pimpl->_details += "\n"; _pimpl->_details += details; }
121
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 {
133 _pimpl->_description.swap( _pimpl->_details );
134 _pimpl->_description = _("Following actions will be done:");
135 }
136 }
137 if ( front )
138 { _pimpl->_details.swap( description ); }
139 _pimpl->_details += "\n";
140 _pimpl->_details += description;
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
Class representing one possible solution to a problem found during resolving.
void setDescription(std::string description)
Set description of the solution.
void setDetails(const std::string &details)
Set detail description of the solution.
RWCOW_pointer< Impl > _pimpl
bool skipsPatchesOnly() const
The solution contains only 'do not install patch:' actions.
const std::string & description() const
Return a one-line text description of this solution.
solver::detail::SolutionAction_Ptr SolutionAction_Ptr
ProblemSolution()
Constructor.
const SolutionActionList & actions() const
Return the list of actions forming this solution.
solver::detail::SolutionActionList SolutionActionList
void pushDescriptionDetail(std::string description, bool front=false)
Collect multiple action descriptions in details (NL separated)
const std::string & details() const
Return a (possibly multi-line) detailed description of this solution or an empty string if there are ...
void addAction(const SolutionAction_Ptr &action)
Add an action to the actions list.
~ProblemSolution() override
Destructor.
Definition Arch.h:364
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
Definition functional.h:32
Easy-to use interface to the ZYPP dependency resolver.
std::list< ProblemSolution_Ptr > ProblemSolutionList
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
ProblemSolution implementation.
Impl * clone() const
clone for RWCOW_pointer
std::set< PoolItem > collectActionItems() const
friend Impl * rwcowClone(const Impl *rhs)
bool allActionsMatch(Predicate &&predicate) const
Impl(std::string &&description, std::string &&details)
Impl(std::string &&description)
#define _(MSG)
Definition Gettext.h:39
#define IMPL_PTR_TYPE(NAME)
Interface to gettext.