Changeset - r26744:108afc18327b
[Not reviewed]
master
0 5 0
Rubidium - 23 months ago 2023-01-13 16:54:53
rubidium@openttd.org
Codechange: use smart pointers when cloning iterators
5 files changed with 12 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/bitmap_type.h
Show inline comments
 
@@ -123,13 +123,13 @@ public:
 
		while (this->tile != INVALID_TILE && !this->bitmap->HasTile(TileIndex(this->tile))) {
 
			(*this).OrthogonalTileIterator::operator++();
 
		}
 
		return *this;
 
	}
 

	
 
	virtual TileIterator *Clone() const
 
	virtual std::unique_ptr<TileIterator> Clone() const
 
	{
 
		return new BitmapTileIterator(*this);
 
		return std::make_unique<BitmapTileIterator>(*this);
 
	}
 
};
 

	
 
#endif /* BITMAP_TYPE_HPP */
src/newgrf_airport.h
Show inline comments
 
@@ -55,15 +55,15 @@ public:
 
	/** Get the StationGfx for the current tile. */
 
	StationGfx GetStationGfx() const
 
	{
 
		return this->att->gfx;
 
	}
 

	
 
	virtual AirportTileTableIterator *Clone() const
 
	virtual std::unique_ptr<TileIterator> Clone() const
 
	{
 
		return new AirportTileTableIterator(*this);
 
		return std::make_unique<AirportTileTableIterator>(*this);
 
	}
 
};
 

	
 
/** List of default airport classes. */
 
enum AirportClassID {
 
	APC_BEGIN     = 0,  ///< Lowest valid airport class id
src/road_cmd.cpp
Show inline comments
 
@@ -2397,13 +2397,13 @@ CommandCost CmdConvertRoad(DoCommandFlag
 
	RoadTramType rtt = GetRoadTramType(to_type);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost error = CommandCost((rtt == RTT_TRAM) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert.
 
	bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633)
 

	
 
	TileIterator *iter = new OrthogonalTileIterator(area_start, area_end);
 
	std::unique_ptr<TileIterator> iter = std::make_unique<OrthogonalTileIterator>(area_start, area_end);
 
	for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
 
		/* Is road present on tile? */
 
		if (!MayHaveRoad(tile)) continue;
 

	
 
		/* Converting to the same subtype? */
 
		RoadType from_type = GetRoadType(tile, rtt);
 
@@ -2553,13 +2553,12 @@ CommandCost CmdConvertRoad(DoCommandFlag
 
		/* Roadtype changed, update roadvehicles as when entering different track */
 
		for (RoadVehicle *v : affected_rvs) {
 
			v->CargoChanged();
 
		}
 
	}
 

	
 
	delete iter;
 
	return found_convertible_road ? cost : error;
 
}
 

	
 

	
 
/** Tile callback functions for road tiles */
 
extern const TileTypeProcs _tile_type_road_procs = {
src/station_base.h
Show inline comments
 
@@ -552,15 +552,15 @@ public:
 
		while (this->tile != INVALID_TILE && !st->TileBelongsToAirport(this->tile)) {
 
			(*this).OrthogonalTileIterator::operator++();
 
		}
 
		return *this;
 
	}
 

	
 
	virtual TileIterator *Clone() const
 
	virtual std::unique_ptr<TileIterator> Clone() const
 
	{
 
		return new AirportTileIterator(*this);
 
		return std::make_unique<AirportTileIterator>(*this);
 
	}
 
};
 

	
 
void RebuildStationKdtree();
 

	
 
/**
src/tilearea_type.h
Show inline comments
 
@@ -143,13 +143,13 @@ public:
 
	 */
 
	virtual TileIterator& operator ++() = 0;
 

	
 
	/**
 
	 * Allocate a new iterator that is a copy of this one.
 
	 */
 
	virtual TileIterator *Clone() const = 0;
 
	virtual std::unique_ptr<TileIterator> Clone() const = 0;
 

	
 
	/**
 
	 * Equality comparison.
 
	 */
 
	bool operator ==(const TileIterator &rhs) const
 
	{
 
@@ -222,15 +222,15 @@ public:
 
		} else {
 
			this->tile = INVALID_TILE;
 
		}
 
		return *this;
 
	}
 

	
 
	virtual TileIterator *Clone() const
 
	virtual std::unique_ptr<TileIterator> Clone() const
 
	{
 
		return new OrthogonalTileIterator(*this);
 
		return std::make_unique<OrthogonalTileIterator>(*this);
 
	}
 
};
 

	
 
/** Iterator to iterate over a diagonal area of the map. */
 
class DiagonalTileIterator : public TileIterator {
 
private:
 
@@ -261,13 +261,13 @@ public:
 
	{
 
		*this = DiagonalTileIterator(DiagonalTileArea(corner1, corner2));
 
	}
 

	
 
	TileIterator& operator ++();
 

	
 
	virtual TileIterator *Clone() const
 
	virtual std::unique_ptr<TileIterator> Clone() const
 
	{
 
		return new DiagonalTileIterator(*this);
 
		return std::make_unique<DiagonalTileIterator>(*this);
 
	}
 
};
 

	
 
#endif /* TILEAREA_TYPE_H */
0 comments (0 inline, 0 general)