Beispiel #1
0
pair<QueueItem::StringMap::const_iterator, bool> FileQueue::add(QueueItemPtr& qi) noexcept {
	dcassert(queueSize >= 0);
	auto ret = pathQueue.emplace(const_cast<string*>(&qi->getTarget()), qi);
	if (ret.second) {
		tthIndex.emplace(const_cast<TTHValue*>(&qi->getTTH()), qi);
		if (!qi->isSet(QueueItem::FLAG_USER_LIST) && !qi->isSet(QueueItem::FLAG_CLIENT_VIEW) && !qi->isSet(QueueItem::FLAG_FINISHED)) {
			dcassert(qi->getSize() >= 0);
			queueSize += qi->getSize();
		}

		tokenQueue.emplace(qi->getToken(), qi);
	}
	return ret;
}
Beispiel #2
0
void FileQueue::remove(QueueItemPtr& qi) noexcept {
	//TargetMap
	auto f = pathQueue.find(const_cast<string*>(&qi->getTarget()));
	if (f != pathQueue.end()) {
		pathQueue.erase(f);
		if (!qi->isSet(QueueItem::FLAG_USER_LIST) && (!qi->isSet(QueueItem::FLAG_FINISHED) || !qi->getBundle()) && !qi->isSet(QueueItem::FLAG_CLIENT_VIEW)) {
			dcassert(qi->getSize() >= 0);
			queueSize -= qi->getSize();
		}
	}
	dcassert(queueSize >= 0);

	//TTHIndex
	auto s = tthIndex.equal_range(const_cast<TTHValue*>(&qi->getTTH()));
	dcassert(s.first != s.second);

	auto k = find(s | map_values, qi);
	if (k.base() != s.second) {
		tthIndex.erase(k.base());
	}

	// Tokens
	tokenQueue.erase(qi->getToken());
}