bool CQueueItem::TryRemoveAll() { const int oldVisibleOffspring = m_visibleOffspring; std::vector<CQueueItem*>::iterator iter; std::vector<CQueueItem*> keepChildren; m_visibleOffspring = 0; for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++) { CQueueItem* pItem = *iter; if (pItem->TryRemoveAll()) delete pItem; else { keepChildren.push_back(pItem); m_visibleOffspring++; m_visibleOffspring += pItem->GetChildrenCount(true); } } m_children = keepChildren; m_maxCachedIndex = -1; m_removed_at_front = 0; CQueueItem* parent = GetParent(); while (parent) { parent->m_maxCachedIndex = -1; parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring; parent = parent->GetParent(); } return m_children.empty(); }
bool CServerItem::TryRemoveAll() { wxASSERT(!GetParent()); const int oldVisibleOffspring = m_visibleOffspring; std::vector<CQueueItem*>::iterator iter; std::vector<CQueueItem*> keepChildren; m_visibleOffspring = 0; for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); ++iter) { CQueueItem* pItem = *iter; if (pItem->TryRemoveAll()) { if (pItem->GetType() == QueueItemType::File || pItem->GetType() == QueueItemType::Folder) { CFileItem* pFileItem = static_cast<CFileItem*>(pItem); RemoveFileItemFromList(pFileItem, true); } delete pItem; } else { keepChildren.push_back(pItem); m_visibleOffspring++; m_visibleOffspring += pItem->GetChildrenCount(true); } } std::swap(m_children, keepChildren); m_removed_at_front = 0; m_maxCachedIndex = -1; wxASSERT(oldVisibleOffspring >= m_visibleOffspring); wxASSERT(m_visibleOffspring >= static_cast<int>(m_children.size())); (void)oldVisibleOffspring; return m_children.empty(); }
bool CServerItem::TryRemoveAll() { const int oldVisibleOffspring = m_visibleOffspring; std::vector<CQueueItem*>::iterator iter; std::vector<CQueueItem*> keepChildren; m_visibleOffspring = 0; for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++) { CQueueItem* pItem = *iter; if (pItem->TryRemoveAll()) { if (pItem->GetType() == QueueItemType_File || pItem->GetType() == QueueItemType_Folder) { CFileItem* pFileItem = reinterpret_cast<CFileItem*>(pItem); RemoveFileItemFromList(pFileItem); } delete pItem; } else { keepChildren.push_back(pItem); m_visibleOffspring++; m_visibleOffspring += pItem->GetChildrenCount(true); } } m_children = keepChildren; m_removed_at_front = 0; CQueueItem* parent = GetParent(); while (parent) { parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring; parent = parent->GetParent(); } return m_children.empty(); }