00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ 00002 /* QueueItemGroup.cc 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 #include "zypp/solver/detail/QueueItemGroup.h" 00023 #include "zypp/solver/detail/QueueItem.h" 00024 #include "zypp/base/Logger.h" 00025 00027 namespace zypp 00028 { 00029 00030 namespace solver 00031 { 00032 00033 namespace detail 00034 { 00035 00036 using namespace std; 00037 00038 IMPL_PTR_TYPE(QueueItemGroup); 00039 00040 //--------------------------------------------------------------------------- 00041 00042 std::ostream & 00043 QueueItemGroup::dumpOn( std::ostream & os ) const 00044 { 00045 os << "[Group: "; 00046 os << _subitems; 00047 os << "]"; 00048 return os; 00049 } 00050 00051 //--------------------------------------------------------------------------- 00052 00053 QueueItemGroup::QueueItemGroup (const ResPool & pool) 00054 : QueueItem (QUEUE_ITEM_TYPE_GROUP, pool) 00055 { 00056 } 00057 00058 00059 QueueItemGroup::~QueueItemGroup() 00060 { 00061 } 00062 00063 //--------------------------------------------------------------------------- 00064 00065 bool 00066 QueueItemGroup::process (ResolverContext_Ptr context, QueueItemList & new_items) 00067 { 00068 _DEBUG( "QueueItemGroup::process" ); 00069 00070 bool did_something = false; 00071 00072 // Just move all of the group's subitems onto the new_items list. 00073 00074 for (QueueItemList::const_iterator iter = _subitems.begin(); iter != _subitems.end(); iter++) { 00075 new_items.push_front (*iter); 00076 did_something = true; 00077 } 00078 00079 _subitems.clear(); 00080 00081 return did_something; 00082 } 00083 00084 00085 QueueItem_Ptr 00086 QueueItemGroup::copy (void) const 00087 { 00088 QueueItemGroup_Ptr new_group = new QueueItemGroup (pool()); 00089 new_group->QueueItem::copy(this); 00090 00091 for (QueueItemList::const_iterator iter = _subitems.begin(); iter != _subitems.end(); iter++) { 00092 new_group->_subitems.push_back ((*iter)->copy()); 00093 } 00094 return new_group; 00095 } 00096 00097 00098 int 00099 QueueItemGroup::cmp (QueueItem_constPtr item) const 00100 { 00101 int cmp = this->compare (item); // assures equal type 00102 if (cmp != 0) 00103 return cmp; 00104 00105 QueueItemGroup_constPtr group = dynamic_pointer_cast<const QueueItemGroup>(item); 00106 00107 // First, sort by # of subitems 00108 00109 cmp = CMP(_subitems.size(), group->_subitems.size()); 00110 if (cmp) 00111 return cmp; 00112 00113 // We can do a by-item cmp since the possible items are kept in sorted order. 00114 QueueItemList::const_iterator iter2; 00115 for (QueueItemList::const_iterator iter = _subitems.begin(), iter2 = group->_subitems.begin(); 00116 iter != _subitems.end() && iter2 != group->_subitems.end(); iter++, iter2++) { 00117 cmp = (*iter)->cmp (*iter2); 00118 if (cmp) { 00119 return cmp; 00120 } 00121 } 00122 00123 return 0; 00124 } 00125 00126 00127 void 00128 QueueItemGroup::addItem (QueueItem_Ptr subitem) 00129 { 00130 // We need to keep the list sorted for comparison purposes. 00131 _subitems.push_back (subitem); 00132 // FIXME _subitems.sort(cmp) 00133 } 00134 00136 };// namespace detail 00139 };// namespace solver 00142 };// namespace zypp 00144