Exemplo n.º 1
0
//Filter normal objects
bool ObjectSelection::FilterNonQualifierObjects(LPRDATA rdPtr, short Oi, bool negate, bool (*filterFunction)(LPRDATA, LPRO))
{
	LPOIL pObjectInfo = GetOILFromOI(Oi);
	bool hasSelected = false;

	if(pObjectInfo->oilEventCount != rhPtr->rh2.rh2EventCount)
		SelectAll(Oi);	//The SOL is invalid, must reset.

	//If SOL is empty
	if(pObjectInfo->oilNumOfSelected <= 0)
		return false;

	int firstSelected = -1;
	int count = 0;
	int current = pObjectInfo->oilListSelected;
	LPHO previous = NULL;

	while(current >= 0)
	{
		LPHO pObject = ObjectList[current].oblOffset;
		bool useObject = filterFunction(rdPtr, (LPRO)pObject) ^ negate;
		hasSelected |= useObject;

		if(useObject)
		{
			if(firstSelected == -1)
				firstSelected = current;

			if(previous != NULL)
				previous->hoNextSelected = current;
			
			previous = pObject;
			count++;
		}
		current = pObject->hoNextSelected;
	}
	if(previous != NULL)
		previous->hoNextSelected = -1;

	pObjectInfo->oilListSelected = firstSelected;
	pObjectInfo->oilNumOfSelected = count;

	return hasSelected;
}
Exemplo n.º 2
0
std::unique_ptr<A> filter(const A & collection, const F & filterFunction) {
	if (collection.empty()) {
		return std::unique_ptr<A>(new A());
	}
	else {

		A* filteredCollection = new A();

		const auto startI = collection.begin();
		const auto endI = collection.end();

		for (auto i = startI; i != endI; i++) {
			if (filterFunction(*i)) { //Max.
				filteredCollection->push_back(*i);
			}
		}

		return std::unique_ptr<A>(filteredCollection);
	}
}