Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / ProblemSolution.cc
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"
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"
32
33 using std::endl;
34
35 /////////////////////////////////////////////////////////////////////////
36 namespace zypp
37 {
38   IMPL_PTR_TYPE(ProblemSolution);
39
40   ///////////////////////////////////////////////////////////////////
41   /// \class ProblemSolution::Impl
42   /// \brief ProblemSolution implementation.
43   ///////////////////////////////////////////////////////////////////
44   struct ProblemSolution::Impl
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;
60     SolutionActionList  _actions;
61
62   private:
63     friend Impl * rwcowClone<Impl>( const Impl * rhs );
64     /** clone for RWCOW_pointer */
65     Impl * clone() const
66     { return new Impl( *this ); }
67   };
68   ///////////////////////////////////////////////////////////////////
69
70   ProblemSolution::ProblemSolution()
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
82   ProblemSolution::~ProblemSolution()
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
92   const ProblemSolution::SolutionActionList & ProblemSolution::actions() const
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       {
113         _pimpl->_description.swap( _pimpl->_details );
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
146 /////////////////////////////////////////////////////////////////////////