libzypp 17.37.10

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>
29#include <zypp/solver/detail/SolutionAction.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
45 struct ProblemSolution::Impl
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;
61 SolutionActionList _actions;
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
90 ProblemSolution::ProblemSolution()
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
102 ProblemSolution::~ProblemSolution()
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
112 const ProblemSolution::SolutionActionList & ProblemSolution::actions() const
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 {
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
146 bool ProblemSolution::skipsPatchesOnly() const
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
ProblemSolution.h
SolutionAction.h
zypp::ProblemSolution
Class representing one possible solution to a problem found during resolving.
Definition ProblemSolution.h:41
zypp::ProblemSolution::setDescription
void setDescription(std::string description)
Set description of the solution.
Definition ProblemSolution.cc:116
zypp::ProblemSolution::setDetails
void setDetails(const std::string &details)
Set detail description of the solution.
Definition ProblemSolution.cc:119
zypp::ProblemSolution::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition ProblemSolution.h:107
zypp::ProblemSolution::skipsPatchesOnly
bool skipsPatchesOnly() const
The solution contains only 'do not install patch:' actions.
Definition ProblemSolution.cc:146
zypp::ProblemSolution::description
const std::string & description() const
Return a one-line text description of this solution.
Definition ProblemSolution.cc:106
zypp::ProblemSolution::SolutionAction_Ptr
solver::detail::SolutionAction_Ptr SolutionAction_Ptr
Definition ProblemSolution.h:43
zypp::ProblemSolution::ProblemSolution
ProblemSolution()
Constructor.
Definition ProblemSolution.cc:90
zypp::ProblemSolution::actions
const SolutionActionList & actions() const
Return the list of actions forming this solution.
Definition ProblemSolution.cc:112
zypp::ProblemSolution::SolutionActionList
solver::detail::SolutionActionList SolutionActionList
Definition ProblemSolution.h:44
zypp::ProblemSolution::pushDescriptionDetail
void pushDescriptionDetail(std::string description, bool front=false)
Collect multiple action descriptions in details (NL separated)
Definition ProblemSolution.cc:122
zypp::ProblemSolution::details
const std::string & details() const
Return a (possibly multi-line) detailed description of this solution or an empty string if there are ...
Definition ProblemSolution.cc:109
zypp::ProblemSolution::addAction
void addAction(const SolutionAction_Ptr &action)
Add an action to the actions list.
Definition ProblemSolution.cc:143
zypp::ProblemSolution::~ProblemSolution
~ProblemSolution() override
Destructor.
Definition ProblemSolution.cc:102
std
Definition Arch.h:364
std::invoke
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
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ProblemSolutionList
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition ProblemTypes.h:43
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
Resolver.h
zypp::ProblemSolution::Impl
ProblemSolution implementation.
Definition ProblemSolution.cc:46
zypp::ProblemSolution::Impl::_details
std::string _details
Definition ProblemSolution.cc:60
zypp::ProblemSolution::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition ProblemSolution.cc:85
zypp::ProblemSolution::Impl::collectActionItems
std::set< PoolItem > collectActionItems() const
Definition ProblemSolution.cc:63
zypp::ProblemSolution::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::ProblemSolution::Impl::allActionsMatch
bool allActionsMatch(Predicate &&predicate) const
Definition ProblemSolution.cc:72
zypp::ProblemSolution::Impl::_description
std::string _description
Definition ProblemSolution.cc:59
zypp::ProblemSolution::Impl::Impl
Impl()
Definition ProblemSolution.cc:47
zypp::ProblemSolution::Impl::Impl
Impl(std::string &&description, std::string &&details)
Definition ProblemSolution.cc:54
zypp::ProblemSolution::Impl::Impl
Impl(std::string &&description)
Definition ProblemSolution.cc:50
zypp::ProblemSolution::Impl::_actions
SolutionActionList _actions
Definition ProblemSolution.cc:61
_
#define _(MSG)
Definition Gettext.h:39
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137
Gettext.h
Interface to gettext.
Logger.h