libzypp  10.5.0
InstallOrder.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* InstallOrder.h
00003  *
00004  * Copyright (C) 2005 SUSE Linux Products GmbH
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License,
00008  * version 2, as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018  * 02111-1307, USA.
00019  */
00020 
00021 // stolen from yast2-packagemanager
00022 /*
00023    File:       InstallOrder.h
00024    Purpose:    Determine order for installing packages
00025    Author:     Ludwig Nussel <lnussel@suse.de>
00026    Maintainer: Ludwig Nussel <lnussel@suse.de>
00027 
00028 /-*/
00029 
00030 #ifndef ZYPP_SOLVER_DETAIL_INSTALLORDER_H
00031 #define ZYPP_SOLVER_DETAIL_INSTALLORDER_H
00032 
00033 #include <string>
00034 #include <list>
00035 #include <map>
00036 #include <set>
00037 
00038 #include "zypp/PoolItem.h"
00039 #include "zypp/ResPool.h"
00040 #include "zypp/Capabilities.h"
00041 
00042 #include "zypp/solver/detail/Types.h"
00043 
00045 namespace zypp
00046 { 
00047 
00048   namespace solver
00049   { 
00050 
00051     namespace detail
00052     { 
00053 
00062 class InstallOrder
00063 {
00064     private:
00065         const ResPool & _pool;
00066         PoolItemSet _toinstall;
00067         PoolItemSet _installed;
00068 
00070         typedef std::map<PoolItem, PoolItemList> Graph;
00071 
00073         Graph _graph;
00074 
00076         Graph _rgraph;
00077 
00078         struct NodeInfo
00079         {
00080             unsigned begintime;
00081             unsigned endtime;
00082             bool visited;
00083             int order; // number of incoming edges in reverse graph
00084 
00085             PoolItem item;
00086 
00087             NodeInfo() : begintime(0), endtime(0), visited(false), order(0) {}
00088             NodeInfo(PoolItem item) : begintime(0), endtime(0), visited(false), order(0), item(item) {}
00089         };
00090 
00091         typedef std::map<PoolItem, NodeInfo> Nodes;
00092 
00093         Nodes _nodes;
00094 
00095         unsigned _rdfstime;
00096 
00097         PoolItemList _topsorted;
00098 
00099         bool _dirty;
00100 
00101         unsigned _numrun;
00102 
00103         std::set<std::string> _logset;
00104 
00105     private:
00106         void rdfsvisit (PoolItem item);
00107 
00108         PoolItem findProviderInSet( const Capability requirement, const PoolItemSet & candidates ) const;
00109         bool doesProvide( const Capability requirement, PoolItem item ) const;
00110 
00111     public:
00112 
00119         InstallOrder( const ResPool & pool, const PoolItemSet & toinstall, const PoolItemSet & installed);
00120 
00125         PoolItemList computeNextSet();
00126 
00131         void setInstalled( PoolItem item );
00132 
00136         void setInstalled( const PoolItemList & list );
00137 
00141         void startrdfs();
00142 
00147         void init() { startrdfs(); }
00148 
00154         const PoolItemList getTopSorted() const;
00155 
00156         void printAdj (std::ostream & os, bool reversed = false) const;
00157 };
00158 
00160     };// namespace detail
00163   };// namespace solver
00166 };// namespace zypp
00168 
00169 #endif // ZYPP_SOLVER_DETAIL_INSTALLORDER_H