De-duplicate cargo masking boilerplate using C++11.

This commit is contained in:
Jonathan G Rennison
2016-09-04 23:58:17 +01:00
parent 72a386abe5
commit e90b266af1
3 changed files with 28 additions and 39 deletions

View File

@@ -388,6 +388,19 @@ public:
void FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first = NULL, uint hops = 0);
};
template <typename T, typename F> T CargoMaskValueFilter(uint32 &cargo_mask, F filter_func)
{
CargoID first_cargo_id = FindFirstBit(cargo_mask);
T value = filter_func(first_cargo_id);
uint32 other_cargo_mask = cargo_mask;
ClrBit(other_cargo_mask, first_cargo_id);
CargoID cargo;
FOR_EACH_SET_BIT(cargo, other_cargo_mask) {
if (value != filter_func(cargo)) ClrBit(cargo_mask, cargo);
}
return value;
}
/**
* Shared order list linking together the linked list of orders and the list
* of vehicles sharing this order list.