Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / solver / detail / SolutionAction.h
1 /*
2  *
3  * Easy-to use interface to the ZYPP dependency resolver
4  *
5  * Author: Stefan Hundhammer <sh@suse.de>
6  *
7  **/
8
9 #ifndef ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
10 #define ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
11 #ifndef ZYPP_USE_RESOLVER_INTERNALS
12 #error Do not directly include this file!
13 #else
14
15 #include <list>
16 #include <string>
17
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/PtrTypes.h"
20
21 #include "zypp/PoolItem.h"
22
23 /////////////////////////////////////////////////////////////////////////
24 namespace zypp
25 { ///////////////////////////////////////////////////////////////////////
26   ///////////////////////////////////////////////////////////////////////
27   namespace solver
28   { /////////////////////////////////////////////////////////////////////
29     /////////////////////////////////////////////////////////////////////
30     namespace detail
31     { ///////////////////////////////////////////////////////////////////
32
33       class Resolver;
34
35       DEFINE_PTR_TYPE(SolverQueueItem);
36
37       DEFINE_PTR_TYPE(SolutionAction);
38       typedef std::list<SolutionAction_Ptr> SolutionActionList;
39
40         /**
41          * Abstract base class for one action of a problem solution.
42          **/
43         class SolutionAction : public base::ReferenceCounted
44         {
45         protected:
46             typedef Resolver ResolverInternal;
47             SolutionAction ();
48         public:
49             virtual ~SolutionAction();
50
51             // ---------------------------------- I/O
52             virtual std::ostream & dumpOn( std::ostream & str ) const;
53             friend std::ostream& operator<<(std::ostream & str, const SolutionAction & action)
54                 { return action.dumpOn (str); }
55             friend std::ostream& operator<<(std::ostream & str, const SolutionActionList & actionlist);
56
57             // ---------------------------------- methods
58             /**
59              * Execute this action.
60              * Returns 'true' on success, 'false' on error.
61              **/
62             virtual bool execute (ResolverInternal & resolver) const = 0;
63         };
64
65
66         /**
67          * A problem solution action that performs a transaction
68          * (installs, removes, keep ...)  one resolvable
69          * (package, patch, pattern, product).
70          **/
71         typedef enum
72         {
73             KEEP,
74             INSTALL,
75             REMOVE,
76             UNLOCK,
77             LOCK,
78             REMOVE_EXTRA_REQUIRE,
79             REMOVE_EXTRA_CONFLICT,
80             ADD_SOLVE_QUEUE_ITEM,
81             REMOVE_SOLVE_QUEUE_ITEM,
82         } TransactionKind;
83
84
85         class TransactionSolutionAction: public SolutionAction
86         {
87         public:
88             TransactionSolutionAction( PoolItem item,
89                                        TransactionKind action )
90                 : SolutionAction(),
91                   _item( item ), _action( action ) {}
92
93             TransactionSolutionAction( Capability capability,
94                                        TransactionKind action )
95                 : SolutionAction(),
96                   _capability( capability ), _action( action ) {}
97
98
99             TransactionSolutionAction( SolverQueueItem_Ptr item,
100                                        TransactionKind action )
101                 : SolutionAction(),
102                   _solverQueueItem( item ), _action( action ) {}
103
104             TransactionSolutionAction( TransactionKind action )
105                 : SolutionAction(),
106                   _item(), _action( action ) {}
107
108           // ---------------------------------- I/O
109           virtual std::ostream & dumpOn( std::ostream & str ) const;
110           friend std::ostream& operator<<(std::ostream& str, const TransactionSolutionAction & action)
111                 { return action.dumpOn (str); }
112
113           // ---------------------------------- accessors
114
115           const PoolItem item() const { return _item; }
116           const Capability capability() const { return _capability; }
117           TransactionKind action() const { return _action; }
118
119           // ---------------------------------- methods
120             virtual bool execute(ResolverInternal & resolver) const;
121
122         protected:
123
124             PoolItem _item;
125             Capability _capability;
126             SolverQueueItem_Ptr _solverQueueItem;
127
128             const TransactionKind _action;
129         };
130
131
132         /**
133          * Type of ignoring; currently only WEAK
134          **/
135
136         typedef enum
137         {
138             WEAK
139         } InjectSolutionKind;
140
141
142         /**
143          * A problem solution action that injects an artificial "provides" to
144          * the pool to satisfy open requirements or remove the conflict of
145          * concerning resolvable
146          *
147          * This is typically used by "ignore" (user override) solutions.
148          **/
149         class InjectSolutionAction: public SolutionAction
150         {
151         public:
152
153             InjectSolutionAction( PoolItem item,
154                                   const InjectSolutionKind & kind)
155                 : SolutionAction(),
156                   _item( item ),
157                   _kind( kind ) {}
158
159           // ---------------------------------- I/O
160           virtual std::ostream & dumpOn( std::ostream & str ) const;
161           friend std::ostream& operator<<(std::ostream& str, const InjectSolutionAction & action)
162                 { return action.dumpOn (str); }
163
164           // ---------------------------------- accessors
165             const PoolItem item() const { return _item; }
166
167           // ---------------------------------- methods
168             virtual bool execute(ResolverInternal & resolver) const;
169
170         protected:
171             PoolItem _item;
172             const InjectSolutionKind _kind;
173         };
174
175
176       ///////////////////////////////////////////////////////////////////
177     };// namespace detail
178     /////////////////////////////////////////////////////////////////////
179     /////////////////////////////////////////////////////////////////////
180   };// namespace solver
181   ///////////////////////////////////////////////////////////////////////
182   ///////////////////////////////////////////////////////////////////////
183 };// namespace zypp
184 /////////////////////////////////////////////////////////////////////////
185 #endif // ZYPP_USE_RESOLVER_INTERNALS
186 #endif // ZYPP_SOLVER_DETAIL_SOLUTIONACTION_H
187