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