QueueItem.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* QueueItem.h
00003  *
00004  * Copyright (C) 2000-2002 Ximian, Inc.
00005  * Copyright (C) 2005 SUSE Linux Products GmbH
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #ifndef ZYPP_SOLVER_DETAIL_QUEUEITEM_H
00023 #define ZYPP_SOLVER_DETAIL_QUEUEITEM_H
00024 
00025 #include <iosfwd>
00026 #include <list>
00027 #include <string>
00028 
00029 #include "zypp/base/ReferenceCounted.h"
00030 #include "zypp/base/NonCopyable.h"
00031 #include "zypp/base/PtrTypes.h"
00032 
00033 #include "zypp/ResPool.h"
00034 
00035 #include "zypp/solver/detail/Types.h"
00036 #include "zypp/solver/detail/ResolverInfo.h"
00037 
00039 namespace zypp
00040 { 
00041 
00042   namespace solver
00043   { 
00044 
00045     namespace detail
00046     { 
00047 
00048 typedef enum {
00049     QUEUE_ITEM_TYPE_UNKNOWN = 0,                        // ordering is important !
00050     QUEUE_ITEM_TYPE_INSTALL,
00051     QUEUE_ITEM_TYPE_REQUIRE,
00052     QUEUE_ITEM_TYPE_BRANCH,
00053     QUEUE_ITEM_TYPE_GROUP,
00054     QUEUE_ITEM_TYPE_CONFLICT,
00055     QUEUE_ITEM_TYPE_UNINSTALL,
00056     QUEUE_ITEM_TYPE_ESTABLISH,
00057     QUEUE_ITEM_TYPE_LAST
00058 } QueueItemType;
00059 
00060 
00061 typedef std::list<QueueItem_Ptr> QueueItemList;
00062 
00063 #define CMP(a,b) (((a) < (b)) - ((b) < (a)))
00064 #define DEFAULTPRIO 10
00065 
00067 //
00068 //      CLASS NAME : QueueItem
00069 
00070 class QueueItem : public base::ReferenceCounted, private base::NonCopyable {
00071     
00072   private:
00073 
00074     QueueItemType _type;
00075     ResPool _pool;
00076 
00077     int _priority;
00078     size_t _size;
00079     ResolverInfoList _pending_info;
00080 
00081   protected:
00082 
00083     QueueItem (QueueItemType type, const ResPool & pool);
00084 
00085   public:
00086 
00087     virtual ~QueueItem();
00088 
00089     // ---------------------------------- I/O
00090 
00091     virtual std::ostream & dumpOn( std::ostream & str ) const;
00092 
00093     friend std::ostream& operator<<(std::ostream & str, const QueueItem & obj)
00094     { return obj.dumpOn (str); }
00095     friend std::ostream& operator<<(std::ostream & str, const QueueItemList & itemlist);
00096 
00097     // ---------------------------------- accessors
00098 
00099     ResPool pool (void) const { return _pool; }
00100     int priority (void) const { return _priority; }
00101     void setPriority (int priority) { _priority = priority; }
00102     int size (void) const { return _size; }
00103 
00104     // ---------------------------------- methods
00105 
00106     void copy (const QueueItem *from);
00107 
00108     bool isBranch (void) const { return _type == QUEUE_ITEM_TYPE_BRANCH; }
00109     bool isConflict (void) const { return _type == QUEUE_ITEM_TYPE_CONFLICT; }
00110     bool isGroup (void) const { return _type == QUEUE_ITEM_TYPE_GROUP; }
00111     bool isInstall (void) const { return _type == QUEUE_ITEM_TYPE_INSTALL; }
00112     bool isRequire (void) const { return _type == QUEUE_ITEM_TYPE_REQUIRE; }
00113     bool isUninstall (void) const { return _type == QUEUE_ITEM_TYPE_UNINSTALL; }
00114     bool isEstablish (void) const { return _type == QUEUE_ITEM_TYPE_ESTABLISH; }
00115 
00116     virtual bool process (const QueueItemList & mainQueue, ResolverContext_Ptr context, QueueItemList & qil) = 0;
00117     virtual QueueItem_Ptr copy (void) const = 0;
00118     virtual int cmp (QueueItem_constPtr item) const = 0;
00119     int compare (QueueItem_constPtr item) const { return CMP(_type, item->_type); }
00120 
00121     //   isRedundant true == can be dropped from any branch
00122     virtual bool isRedundant (ResolverContext_Ptr context) const = 0;
00123 
00124     //   isSatisfied true == can be dropped from any queue, and any
00125     //   branch containing it can also be dropped
00126     virtual bool isSatisfied (ResolverContext_Ptr context) const = 0;
00127 
00128     void addInfo (ResolverInfo_Ptr);
00129     void logInfo (ResolverContext_Ptr);
00130 };
00131 
00133     };// namespace detail
00136   };// namespace solver
00139 };// namespace zypp
00141 
00142 #endif // ZYPP_SOLVER_DETAIL_QUEUEITEM_H

Generated on Tue Sep 25 19:23:07 2007 for libzypp by  doxygen 1.5.3