ca4002e2db7dfe96d87e8fc5ded39613ef179bc9
[platform/upstream/libzypp.git] / zypp / solver / detail / SolverQueueItem.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* QueueItem.h
3  *
4  * Copyright (C) 2008 SUSE Linux Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20
21 #ifndef ZYPP_SOLVER_DETAIL_QUEUEITEM_H
22 #define ZYPP_SOLVER_DETAIL_QUEUEITEM_H
23
24 #include <iosfwd>
25 #include <list>
26 #include <string>
27
28 #include "zypp/solver/detail/Types.h"
29 #include "zypp/base/ReferenceCounted.h"
30 #include "zypp/base/NonCopyable.h"
31 #include "zypp/base/PtrTypes.h"
32 #include "zypp/ResPool.h"
33
34 /////////////////////////////////////////////////////////////////////////
35 namespace zypp
36 { ///////////////////////////////////////////////////////////////////////
37   ///////////////////////////////////////////////////////////////////////
38   namespace solver
39   { /////////////////////////////////////////////////////////////////////
40     /////////////////////////////////////////////////////////////////////
41     namespace detail
42     { ///////////////////////////////////////////////////////////////////
43
44 typedef enum {
45     QUEUE_ITEM_TYPE_UNKNOWN = 0,
46     QUEUE_ITEM_TYPE_UPDATE,
47     QUEUE_ITEM_TYPE_INSTALL,
48     QUEUE_ITEM_TYPE_DELETE,
49     QUEUE_ITEM_TYPE_INSTALL_ONE_OF,
50     QUEUE_ITEM_TYPE_LOCK
51 } SolverQueueItemType;
52
53
54 typedef std::list<SolverQueueItem_Ptr> SolverQueueItemList;
55
56 #define CMP(a,b) (((a) < (b)) - ((b) < (a)))
57
58 ///////////////////////////////////////////////////////////////////
59 //
60 //      CLASS NAME : SolverQueueItem
61
62 class SolverQueueItem : public base::ReferenceCounted, private base::NonCopyable {
63
64   private:
65
66     SolverQueueItemType _type;
67     ResPool _pool;
68
69   protected:
70
71     SolverQueueItem (SolverQueueItemType type, const ResPool & pool);
72
73   public:
74
75     virtual ~SolverQueueItem();
76
77     // ---------------------------------- I/O
78
79     virtual std::ostream & dumpOn( std::ostream & str ) const;
80
81     friend std::ostream& operator<<(std::ostream & str, const SolverQueueItem & obj)
82     { return obj.dumpOn (str); }
83     friend std::ostream& operator<<(std::ostream & str, const SolverQueueItemList & itemlist);
84
85     // ---------------------------------- accessors
86
87     ResPool pool (void) const { return _pool; }
88
89     // ---------------------------------- methods
90
91     void copy (const SolverQueueItem *from);
92
93     bool isDelete (void) const { return _type == QUEUE_ITEM_TYPE_DELETE; }
94     bool isInstall (void) const { return _type == QUEUE_ITEM_TYPE_INSTALL; }
95     bool isUpdate (void) const { return _type == QUEUE_ITEM_TYPE_UPDATE; }
96     bool isLock (void) const { return _type == QUEUE_ITEM_TYPE_LOCK; }
97     bool isInstallOneOf (void) const { return _type == QUEUE_ITEM_TYPE_INSTALL_ONE_OF; }
98
99
100     virtual SolverQueueItem_Ptr copy (void) const = 0;
101     virtual bool addRule (sat::detail::CQueue & q) =0 ;
102     virtual int cmp (SolverQueueItem_constPtr item) const = 0;
103     int compare (SolverQueueItem_constPtr item) const { return CMP(_type, item->_type); }
104
105 };
106
107 ///////////////////////////////////////////////////////////////////
108     };// namespace detail
109     /////////////////////////////////////////////////////////////////////
110     /////////////////////////////////////////////////////////////////////
111   };// namespace solver
112   ///////////////////////////////////////////////////////////////////////
113   ///////////////////////////////////////////////////////////////////////
114 };// namespace zypp
115 /////////////////////////////////////////////////////////////////////////
116
117 #endif // ZYPP_SOLVER_DETAIL_QUEUEITEM_H