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>
31#include <zypp/base/Logger.h>
32#include <zypp/solver/detail/Resolver.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 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
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 {
125 _pimpl->_description.swap( _pimpl->_details );
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
Predicate predicate
Definition PoolQuery.cc:313
Class representing one possible solution to a problem found during resolving.
void setDescription(std::string description)
Set description of the solution.
RWCOW_pointer< Impl > _pimpl
bool skipsPatchesOnly() const
The solution contains only 'do not install patch:' actions.
solver::detail::SolutionAction_Ptr SolutionAction_Ptr
void addAction(SolutionAction_Ptr action)
Add an action to the actions list.
solver::detail::SolutionActionList SolutionActionList
const std::string & description() const
Return a one-line text description of this solution.
ProblemSolution()
Constructor.
virtual ~ProblemSolution()
Destructor.
const SolutionActionList & actions() const
Return the list of actions forming this solution.
void pushDescriptionDetail(std::string description, bool front=false)
Collect multiple action descriptions in details (NL separated)
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 ...
Definition Arch.h:364
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
std::list< ProblemSolution_Ptr > ProblemSolutionList
ProblemSolution implementation.
Impl * clone() const
clone for RWCOW_pointer
bool allActionsMatch(Predicate &&predicate) const
Impl(std::string &&description, std::string &&details)
Impl(std::string &&description)
#define _(MSG)
Definition Gettext.h:37
#define IMPL_PTR_TYPE(NAME)