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 
00066 //
00067 //      CLASS NAME : QueueItem
00068 
00069 class QueueItem : public base::ReferenceCounted, private base::NonCopyable {
00070     
00071   private:
00072 
00073     QueueItemType _type;
00074     ResPool _pool;
00075 
00076     int _priority;
00077     size_t _size;
00078     ResolverInfoList _pending_info;
00079 
00080   protected:
00081 
00082     QueueItem (QueueItemType type, const ResPool & pool);
00083 
00084   public:
00085 
00086     virtual ~QueueItem();
00087 
00088     // ---------------------------------- I/O
00089 
00090     virtual std::ostream & dumpOn( std::ostream & str ) const;
00091 
00092     friend std::ostream& operator<<(std::ostream & str, const QueueItem & obj)
00093     { return obj.dumpOn (str); }
00094     friend std::ostream& operator<<(std::ostream & str, const QueueItemList & itemlist);
00095 
00096     // ---------------------------------- accessors
00097 
00098     ResPool pool (void) const { return _pool; }
00099     int priority (void) const { return _priority; }
00100     void setPriority (int priority) { _priority = priority; }
00101     int size (void) const { return _size; }
00102 
00103     // ---------------------------------- methods
00104 
00105     void copy (const QueueItem *from);
00106 
00107     bool isBranch (void) const { return _type == QUEUE_ITEM_TYPE_BRANCH; }
00108     bool isConflict (void) const { return _type == QUEUE_ITEM_TYPE_CONFLICT; }
00109     bool isGroup (void) const { return _type == QUEUE_ITEM_TYPE_GROUP; }
00110     bool isInstall (void) const { return _type == QUEUE_ITEM_TYPE_INSTALL; }
00111     bool isRequire (void) const { return _type == QUEUE_ITEM_TYPE_REQUIRE; }
00112     bool isUninstall (void) const { return _type == QUEUE_ITEM_TYPE_UNINSTALL; }
00113     bool isEstablish (void) const { return _type == QUEUE_ITEM_TYPE_ESTABLISH; }
00114 
00115     virtual bool process (ResolverContext_Ptr context, QueueItemList & qil) = 0;
00116     virtual QueueItem_Ptr copy (void) const = 0;
00117     virtual int cmp (QueueItem_constPtr item) const = 0;
00118     int compare (QueueItem_constPtr item) const { return CMP(_type, item->_type); }
00119 
00120     //   isRedundant true == can be dropped from any branch
00121     virtual bool isRedundant (ResolverContext_Ptr context) const = 0;
00122 
00123     //   isSatisfied true == can be dropped from any queue, and any
00124     //   branch containing it can also be dropped
00125     virtual bool isSatisfied (ResolverContext_Ptr context) const = 0;
00126 
00127     void addInfo (ResolverInfo_Ptr);
00128     void logInfo (ResolverContext_Ptr);
00129 };
00130 
00132     };// namespace detail
00135   };// namespace solver
00138 };// namespace zypp
00140 
00141 #endif // ZYPP_SOLVER_DETAIL_QUEUEITEM_H

Generated on Thu Jul 6 00:07:23 2006 for zypp by  doxygen 1.4.6