mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replaced SmallVector::Include() with include()
parent
2bc2de9034
commit
297fd3dda3
|
@ -43,7 +43,7 @@ void DeleteAnimatedTile(TileIndex tile)
|
||||||
void AddAnimatedTile(TileIndex tile)
|
void AddAnimatedTile(TileIndex tile)
|
||||||
{
|
{
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
_animated_tiles.Include(tile);
|
include(_animated_tiles, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,6 +17,24 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#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.
|
* Simple vector template class.
|
||||||
*
|
*
|
||||||
|
@ -66,19 +84,6 @@ public:
|
||||||
|
|
||||||
~SmallVector() = default;
|
~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)
|
* 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;
|
if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue;
|
||||||
|
|
||||||
/* Insert the industry into _cargo_delivery_destinations, if not yet contained */
|
/* 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]);
|
uint amount = min(num_pieces, 0xFFFFU - ind->incoming_cargo_waiting[cargo_index]);
|
||||||
ind->incoming_cargo_waiting[cargo_index] += amount;
|
ind->incoming_cargo_waiting[cargo_index] += amount;
|
||||||
|
|
|
@ -706,7 +706,7 @@ public:
|
||||||
|
|
||||||
FioFCloseFile(f);
|
FioFCloseFile(f);
|
||||||
|
|
||||||
this->Include(id);
|
include(*this, id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -968,7 +968,7 @@ static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mo
|
||||||
if (topleft <= clicked && clicked <= bottomright) {
|
if (topleft <= clicked && clicked <= bottomright) {
|
||||||
uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
|
uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
|
||||||
if (offset < (uint)bp.width) {
|
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)
|
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) :
|
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]);
|
this->ReverseLookupDependency(parents, tree[i]);
|
||||||
|
|
||||||
for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
|
for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
|
||||||
tree.Include(*piter);
|
include(tree, *piter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public:
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
/** Add a callback to this class */
|
/** 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 */
|
/** Remove a callback */
|
||||||
void RemoveCallback(ContentCallback *cb) { this->callbacks.erase(std::find(this->callbacks.begin(), this->callbacks.end(), cb)); }
|
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
|
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
|
||||||
{
|
{
|
||||||
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
|
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
|
||||||
this->receivedTypes.Include(ci->type);
|
include(this->receivedTypes, ci->type);
|
||||||
|
|
||||||
/* When downloading is finished change cancel in ok */
|
/* When downloading is finished change cancel in ok */
|
||||||
if (this->downloaded_bytes == this->total_bytes) {
|
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;
|
if (v->type != VEH_TRAIN) return NULL;
|
||||||
|
|
||||||
TrainList *affected_trains = static_cast<TrainList*>(data);
|
TrainList *affected_trains = static_cast<TrainList*>(data);
|
||||||
affected_trains->Include(Train::From(v)->First());
|
include(*affected_trains, Train::From(v)->First());
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1614,7 +1614,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
|
||||||
|
|
||||||
DeallocateSpecFromStation(st, specindex);
|
DeallocateSpecFromStation(st, specindex);
|
||||||
|
|
||||||
affected_stations.Include(st);
|
include(affected_stations, st);
|
||||||
|
|
||||||
if (v != NULL) RestoreTrainReservation(v);
|
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) {
|
for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
|
||||||
if (!IsTileType(tile, MP_HOUSE)) continue;
|
if (!IsTileType(tile, MP_HOUSE)) continue;
|
||||||
const Town *t = Town::GetByTile(tile);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2899,10 +2899,10 @@ void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
|
||||||
for (; u != NULL && num_vehicles > 0; num_vehicles--) {
|
for (; u != NULL && num_vehicles > 0; num_vehicles--) {
|
||||||
do {
|
do {
|
||||||
/* Include current vehicle in the selection. */
|
/* 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 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();
|
u = u->Next();
|
||||||
} while (u != NULL && u->IsArticulatedPart());
|
} 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) {
|
for (; v_from != NULL; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : NULL) {
|
||||||
const Engine *e_from = v_from->GetEngine();
|
const Engine *e_from = v_from->GetEngine();
|
||||||
if (!e_from->CanCarryCargo() || !HasBit(e_from->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue;
|
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;
|
byte ret_refit_cyc = 0;
|
||||||
|
@ -470,7 +470,7 @@ struct RefitWindow : public Window {
|
||||||
option.cargo = cid;
|
option.cargo = cid;
|
||||||
option.subtype = refit_cyc;
|
option.subtype = refit_cyc;
|
||||||
option.string = subtype;
|
option.string = subtype;
|
||||||
this->list[current_index].Include(option);
|
include(this->list[current_index], option);
|
||||||
} else {
|
} else {
|
||||||
/* Intersect the subtypes of earlier vehicles with the subtypes of this vehicle */
|
/* Intersect the subtypes of earlier vehicles with the subtypes of this vehicle */
|
||||||
if (subtype == STR_EMPTY) {
|
if (subtype == STR_EMPTY) {
|
||||||
|
|
Loading…
Reference in New Issue