libzypp  17.8.0
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 
27 #include "zypp/base/Gettext.h"
29 #include "zypp/ProblemSolution.h"
30 #include "zypp/base/Logger.h"
32 
33 using std::endl;
34 
36 namespace zypp
37 {
38  IMPL_PTR_TYPE(ProblemSolution);
39 
45  {
46  Impl()
47  {}
48 
49  Impl( std::string && description )
50  : _description( std::move(description) )
51  {}
52 
53  Impl( std::string && description, std::string && details )
54  : _description( std::move(description) )
55  , _details( std::move(details) )
56  {}
57 
58  std::string _description;
59  std::string _details;
61 
62  private:
63  friend Impl * rwcowClone<Impl>( const Impl * rhs );
65  Impl * clone() const
66  { return new Impl( *this ); }
67  };
69 
71  : _pimpl( new Impl() )
72  {}
73 
74  ProblemSolution::ProblemSolution( std::string description )
75  : _pimpl( new Impl( std::move(description) ) )
76  {}
77 
78  ProblemSolution::ProblemSolution( std::string description, std::string details )
79  : _pimpl( new Impl( std::move(description), std::move(details) ) )
80  {}
81 
83  {}
84 
85 
86  const std::string & ProblemSolution::description() const
87  { return _pimpl->_description; }
88 
89  const std::string & ProblemSolution::details() const
90  { return _pimpl->_details; }
91 
93  { return _pimpl->_actions; }
94 
95 
96  void ProblemSolution::setDescription( std::string description )
97  { _pimpl->_description = std::move(description); }
98 
99  void ProblemSolution::setDetails( std::string details )
100  { _pimpl->_details += "\n"; _pimpl->_details += std::move(details); }
101 
102  void ProblemSolution::pushDescriptionDetail( std::string description, bool front )
103  {
104  if ( _pimpl->_details.empty() )
105  {
106  if ( _pimpl->_description.empty() ) // first entry
107  {
108  _pimpl->_description = std::move(description);
109  return;
110  }
111  else // second entry: form headline in _description
112  {
114  _pimpl->_description = _("Following actions will be done:");
115  }
116  }
117  if ( front )
118  { _pimpl->_details.swap( description ); }
119  _pimpl->_details += "\n";
120  _pimpl->_details += std::move(description);
121  }
122 
123  void ProblemSolution::addAction( solver::detail::SolutionAction_Ptr action )
124  { _pimpl->_actions.push_back( action ); }
125 
126 
127 
128  std::ostream & operator<<( std::ostream & os, const ProblemSolution & obj )
129  {
130  os << "Solution:" << endl;
131  os << obj.description() << endl;
132  if ( ! obj.details().empty() )
133  os << obj.details() << endl;
134  os << obj.actions();
135  return os;
136  }
137 
138  std::ostream & operator<<( std::ostream & os, const ProblemSolutionList & obj )
139  {
140  for ( const auto & ptr: obj )
141  { os << ptr; }
142  return os;
143  }
144 
145 } // namespace zypp
Interface to gettext.
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
const SolutionActionList & actions() const
Return the list of actions forming this solution.
RWCOW_pointer< Impl > _pimpl
Definition: Arch.h:344
ProblemSolution()
Constructor.
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 ...
Impl(std::string &&description, std::string &&details)
Impl * clone() const
clone for RWCOW_pointer
void addAction(SolutionAction_Ptr action)
Add an action to the actions list.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
Impl(std::string &&description)
IMPL_PTR_TYPE(Application)
SolutionActionList _actions
#define _(MSG)
Definition: Gettext.h:37
solver::detail::SolutionActionList SolutionActionList
void setDescription(std::string description)
Set description of the solution.
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: CodePitfalls.doc:1
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.
virtual ~ProblemSolution()
Destructor.