summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Wilson <m3henry@googlemail.com>2019-02-20 21:35:41 +0000
committerPeterN <peter@fuzzle.org>2019-03-26 20:15:57 +0000
commit297fd3dda3abe353ebe2fe77c67b011e24d403bc (patch)
tree916615e2c4e8eaeed982b9293bea3b76a0a29374
parent2bc2de9034d3b75a253b849cf7a703b1a503e200 (diff)
downloadopenttd-297fd3dda3abe353ebe2fe77c67b011e24d403bc.tar.xz
Codechange: Replaced SmallVector::Include() with include()
-rw-r--r--src/animated_tile.cpp2
-rw-r--r--src/core/smallvec_type.hpp31
-rw-r--r--src/economy.cpp2
-rw-r--r--src/fios.cpp2
-rw-r--r--src/gfx.cpp2
-rw-r--r--src/hotkeys.cpp2
-rw-r--r--src/network/network_content.cpp2
-rw-r--r--src/network/network_content.h2
-rw-r--r--src/network/network_content_gui.cpp2
-rw-r--r--src/rail_cmd.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/subsidy.cpp2
-rw-r--r--src/vehicle.cpp4
-rw-r--r--src/vehicle_gui.cpp4
14 files changed, 33 insertions, 28 deletions
diff --git a/src/animated_tile.cpp b/src/animated_tile.cpp
index eb10b9b8d..5204547dd 100644
--- a/src/animated_tile.cpp
+++ b/src/animated_tile.cpp
@@ -43,7 +43,7 @@ void DeleteAnimatedTile(TileIndex tile)
void AddAnimatedTile(TileIndex tile)
{
MarkTileDirtyByTile(tile);
- _animated_tiles.Include(tile);
+ include(_animated_tiles, tile);
}
/**
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index 0ab82c4fc..9162c17b9 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -18,6 +18,24 @@
#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.
*
* @note There are no asserts in the class so you have
@@ -67,19 +85,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)
*
* @return the pointer to the first item
diff --git a/src/economy.cpp b/src/economy.cpp
index d306fd0ba..1f17612f7 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -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;
diff --git a/src/fios.cpp b/src/fios.cpp
index a1369e1cd..6acb2d891 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -706,7 +706,7 @@ public:
FioFCloseFile(f);
- this->Include(id);
+ include(*this, id);
return true;
}
};
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 42bb56400..dad675772 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -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);
}
}
}
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index 8bec7e400..39cf4c0a1 100644
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -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) :
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index fe7905de8..617a2bc6b 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -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);
}
}
}
diff --git a/src/network/network_content.h b/src/network/network_content.h
index 7cce7fc0a..08e7755aa 100644
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -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)); }
};
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index b7237cadd..8e3ec9686 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -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) {
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 3a24fb65f..c6548eefb 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -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;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index fcbf514bc..6811290ad 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -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);
}
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index eac81e362..8f823a1ab 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -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;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index f1b727971..267c20491 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -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());
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 9fcebd4e6..82403a2d1 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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) {