Codechange: Replaced SmallVector::Include() with include()

pull/82/head
Henry Wilson 5 years ago committed by PeterN
parent 2bc2de9034
commit 297fd3dda3

@ -43,7 +43,7 @@ void DeleteAnimatedTile(TileIndex tile)
void AddAnimatedTile(TileIndex tile)
{
MarkTileDirtyByTile(tile);
_animated_tiles.Include(tile);
include(_animated_tiles, tile);
}
/**

@ -17,6 +17,24 @@
#include <vector>
#include <algorithm>
/**
* Helper function to append an item to a vector if it is not already contained
* Consider using std::set, std::unordered_set or std::flat_set in new code
*
* @param vec A reference to the vector to be extended
* @param item Reference to the item to be copy-constructed if not found
*
* @return Whether the item was already present
*/
template <typename T>
inline bool include(std::vector<T>& vec, const T &item)
{
const bool is_member = std::find(vec.begin(), vec.end(), item) != vec.end();
if (!is_member) vec.emplace_back(item);
return is_member;
}
/**
* Simple vector template class.
*
@ -66,19 +84,6 @@ public:
~SmallVector() = default;
/**
* Tests whether a item is present in the vector, and appends it to the end if not.
* The '!=' operator of T is used for comparison.
* @param item Item to test for
* @return true iff the item is was already present
*/
inline bool Include(const T &item)
{
bool is_member = std::find(std::vector<T>::begin(), std::vector<T>::end(), item) != std::vector<T>::end();
if (!is_member) std::vector<T>::emplace_back(item);
return is_member;
}
/**
* Get the pointer to the first item (const)
*

@ -1058,7 +1058,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue;
/* Insert the industry into _cargo_delivery_destinations, if not yet contained */
_cargo_delivery_destinations.Include(ind);
include(_cargo_delivery_destinations, ind);
uint amount = min(num_pieces, 0xFFFFU - ind->incoming_cargo_waiting[cargo_index]);
ind->incoming_cargo_waiting[cargo_index] += amount;

@ -706,7 +706,7 @@ public:
FioFCloseFile(f);
this->Include(id);
include(*this, id);
return true;
}
};

@ -968,7 +968,7 @@ static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mo
if (topleft <= clicked && clicked <= bottomright) {
uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
if (offset < (uint)bp.width) {
_newgrf_debug_sprite_picker.sprites.Include(sprite_id);
include(_newgrf_debug_sprite_picker.sprites, sprite_id);
}
}
}

@ -248,7 +248,7 @@ Hotkey::Hotkey(const uint16 *default_keycodes, const char *name, int num) :
*/
void Hotkey::AddKeycode(uint16 keycode)
{
this->keycodes.Include(keycode);
include(this->keycodes, keycode);
}
HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :

@ -930,7 +930,7 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
this->ReverseLookupDependency(parents, tree[i]);
for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
tree.Include(*piter);
include(tree, *piter);
}
}
}

@ -140,7 +140,7 @@ public:
void Clear();
/** Add a callback to this class */
void AddCallback(ContentCallback *cb) { this->callbacks.Include(cb); }
void AddCallback(ContentCallback *cb) { include(this->callbacks, cb); }
/** Remove a callback */
void RemoveCallback(ContentCallback *cb) { this->callbacks.erase(std::find(this->callbacks.begin(), this->callbacks.end(), cb)); }
};

@ -274,7 +274,7 @@ public:
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
{
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
this->receivedTypes.Include(ci->type);
include(this->receivedTypes, ci->type);
/* When downloading is finished change cancel in ok */
if (this->downloaded_bytes == this->total_bytes) {

@ -1534,7 +1534,7 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
if (v->type != VEH_TRAIN) return NULL;
TrainList *affected_trains = static_cast<TrainList*>(data);
affected_trains->Include(Train::From(v)->First());
include(*affected_trains, Train::From(v)->First());
return NULL;
}

@ -1614,7 +1614,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
DeallocateSpecFromStation(st, specindex);
affected_stations.Include(st);
include(affected_stations, st);
if (v != NULL) RestoreTrainReservation(v);
}

@ -577,7 +577,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
if (!IsTileType(tile, MP_HOUSE)) continue;
const Town *t = Town::GetByTile(tile);
if (t->cache.part_of_subsidy & POS_DST) towns_near.Include(t);
if (t->cache.part_of_subsidy & POS_DST) include(towns_near, t);
}
break;
}

@ -2899,10 +2899,10 @@ void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
for (; u != NULL && num_vehicles > 0; num_vehicles--) {
do {
/* Include current vehicle in the selection. */
set.Include(u->index);
include(set, u->index);
/* If the vehicle is multiheaded, add the other part too. */
if (u->IsMultiheaded()) set.Include(u->other_multiheaded_part->index);
if (u->IsMultiheaded()) include(set, u->other_multiheaded_part->index);
u = u->Next();
} while (u != NULL && u->IsArticulatedPart());

@ -238,7 +238,7 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_t
for (; v_from != NULL; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : NULL) {
const Engine *e_from = v_from->GetEngine();
if (!e_from->CanCarryCargo() || !HasBit(e_from->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
subtypes.Include(GetCargoSubtypeText(v_from));
include(subtypes, GetCargoSubtypeText(v_from));
}
byte ret_refit_cyc = 0;
@ -470,7 +470,7 @@ struct RefitWindow : public Window {
option.cargo = cid;
option.subtype = refit_cyc;
option.string = subtype;
this->list[current_index].Include(option);
include(this->list[current_index], option);
} else {
/* Intersect the subtypes of earlier vehicles with the subtypes of this vehicle */
if (subtype == STR_EMPTY) {

Loading…
Cancel
Save