Changeset - r23535:9604c18808f0
[Not reviewed]
master
0 14 0
Henry Wilson - 6 years ago 2019-02-20 21:35:41
m3henry@googlemail.com
Codechange: Replaced SmallVector::Include() with include()
14 files changed with 33 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/animated_tile.cpp
Show inline comments
 
@@ -43,7 +43,7 @@ void DeleteAnimatedTile(TileIndex tile)
 
void AddAnimatedTile(TileIndex tile)
 
{
 
	MarkTileDirtyByTile(tile);
 
	_animated_tiles.Include(tile);
 
	include(_animated_tiles, tile);
 
}
 

	
 
/**
src/core/smallvec_type.hpp
Show inline comments
 
@@ -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
src/economy.cpp
Show inline comments
 
@@ -1058,7 +1058,7 @@ static uint DeliverGoodsToIndustry(const
 
		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;
src/fios.cpp
Show inline comments
 
@@ -706,7 +706,7 @@ public:
 

	
 
		FioFCloseFile(f);
 

	
 
		this->Include(id);
 
		include(*this, id);
 
		return true;
 
	}
 
};
src/gfx.cpp
Show inline comments
 
@@ -968,7 +968,7 @@ static void GfxBlitter(const Sprite * co
 
		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);
 
			}
 
		}
 
	}
src/hotkeys.cpp
Show inline comments
 
@@ -248,7 +248,7 @@ Hotkey::Hotkey(const uint16 *default_key
 
 */
 
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) :
src/network/network_content.cpp
Show inline comments
 
@@ -930,7 +930,7 @@ void ClientNetworkContentSocketHandler::
 
		this->ReverseLookupDependency(parents, tree[i]);
 

	
 
		for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
 
			tree.Include(*piter);
 
			include(tree, *piter);
 
		}
 
	}
 
}
src/network/network_content.h
Show inline comments
 
@@ -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)); }
 
};
src/network/network_content_gui.cpp
Show inline comments
 
@@ -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) {
src/rail_cmd.cpp
Show inline comments
 
@@ -1534,7 +1534,7 @@ static Vehicle *UpdateTrainPowerProc(Veh
 
	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;
 
}
src/station_cmd.cpp
Show inline comments
 
@@ -1614,7 +1614,7 @@ CommandCost RemoveFromRailBaseStation(Ti
 

	
 
			DeallocateSpecFromStation(st, specindex);
 

	
 
			affected_stations.Include(st);
 
			include(affected_stations, st);
 

	
 
			if (v != NULL) RestoreTrainReservation(v);
 
		}
src/subsidy.cpp
Show inline comments
 
@@ -577,7 +577,7 @@ bool CheckSubsidised(CargoID cargo_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;
 
		}
src/vehicle.cpp
Show inline comments
 
@@ -2899,10 +2899,10 @@ void GetVehicleSet(VehicleSet &set, Vehi
 
		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());
src/vehicle_gui.cpp
Show inline comments
 
@@ -238,7 +238,7 @@ byte GetBestFittingSubType(Vehicle *v_fr
 
	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) {
0 comments (0 inline, 0 general)