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