2 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
5 * Easy-to use interface to the ZYPP dependency resolver
7 * Copyright (C) 2000-2002 Ximian, Inc.
8 * Copyright (C) 2005 SUSE Linux Products GmbH
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.
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.
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
25 #define ZYPP_USE_RESOLVER_INTERNALS
27 #include "zypp/base/Gettext.h"
28 #include "zypp/solver/detail/SolutionAction.h"
29 #include "zypp/ProblemSolution.h"
30 #include "zypp/base/Logger.h"
31 #include "zypp/solver/detail/Resolver.h"
35 /////////////////////////////////////////////////////////////////////////
38 IMPL_PTR_TYPE(ProblemSolution);
40 ///////////////////////////////////////////////////////////////////
41 /// \class ProblemSolution::Impl
42 /// \brief ProblemSolution implementation.
43 ///////////////////////////////////////////////////////////////////
44 struct ProblemSolution::Impl
49 Impl( std::string && description )
50 : _description( std::move(description) )
53 Impl( std::string && description, std::string && details )
54 : _description( std::move(description) )
55 , _details( std::move(details) )
58 std::string _description;
60 SolutionActionList _actions;
63 friend Impl * rwcowClone<Impl>( const Impl * rhs );
64 /** clone for RWCOW_pointer */
66 { return new Impl( *this ); }
68 ///////////////////////////////////////////////////////////////////
70 ProblemSolution::ProblemSolution()
71 : _pimpl( new Impl() )
74 ProblemSolution::ProblemSolution( std::string description )
75 : _pimpl( new Impl( std::move(description) ) )
78 ProblemSolution::ProblemSolution( std::string description, std::string details )
79 : _pimpl( new Impl( std::move(description), std::move(details) ) )
82 ProblemSolution::~ProblemSolution()
86 const std::string & ProblemSolution::description() const
87 { return _pimpl->_description; }
89 const std::string & ProblemSolution::details() const
90 { return _pimpl->_details; }
92 const ProblemSolution::SolutionActionList & ProblemSolution::actions() const
93 { return _pimpl->_actions; }
96 void ProblemSolution::setDescription( std::string description )
97 { _pimpl->_description = std::move(description); }
99 void ProblemSolution::setDetails( std::string details )
100 { _pimpl->_details += "\n"; _pimpl->_details += std::move(details); }
102 void ProblemSolution::pushDescriptionDetail( std::string description, bool front )
104 if ( _pimpl->_details.empty() )
106 if ( _pimpl->_description.empty() ) // first entry
108 _pimpl->_description = std::move(description);
111 else // second entry: form headline in _description
113 _pimpl->_description.swap( _pimpl->_details );
114 _pimpl->_description = _("Following actions will be done:");
118 { _pimpl->_details.swap( description ); }
119 _pimpl->_details += "\n";
120 _pimpl->_details += std::move(description);
123 void ProblemSolution::addAction( solver::detail::SolutionAction_Ptr action )
124 { _pimpl->_actions.push_back( action ); }
128 std::ostream & operator<<( std::ostream & os, const ProblemSolution & obj )
130 os << "Solution:" << endl;
131 os << obj.description() << endl;
132 if ( ! obj.details().empty() )
133 os << obj.details() << endl;
138 std::ostream & operator<<( std::ostream & os, const ProblemSolutionList & obj )
140 for ( const auto & ptr: obj )
146 /////////////////////////////////////////////////////////////////////////