mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use smart pointers when cloning iterators
parent
f667a831a5
commit
b35c791d05
|
@ -126,9 +126,9 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TileIterator *Clone() const
|
virtual std::unique_ptr<TileIterator> Clone() const
|
||||||
{
|
{
|
||||||
return new BitmapTileIterator(*this);
|
return std::make_unique<BitmapTileIterator>(*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,9 @@ public:
|
||||||
return this->att->gfx;
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2400,7 +2400,7 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||||
CommandCost error = CommandCost((rtt == RTT_TRAM) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert.
|
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)
|
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)) {
|
for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
|
||||||
/* Is road present on tile? */
|
/* Is road present on tile? */
|
||||||
if (!MayHaveRoad(tile)) continue;
|
if (!MayHaveRoad(tile)) continue;
|
||||||
|
@ -2556,7 +2556,6 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete iter;
|
|
||||||
return found_convertible_road ? cost : error;
|
return found_convertible_road ? cost : error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -555,9 +555,9 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TileIterator *Clone() const
|
virtual std::unique_ptr<TileIterator> Clone() const
|
||||||
{
|
{
|
||||||
return new AirportTileIterator(*this);
|
return std::make_unique<AirportTileIterator>(*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Allocate a new iterator that is a copy of this one.
|
* 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.
|
* Equality comparison.
|
||||||
|
@ -225,9 +225,9 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TileIterator *Clone() const
|
virtual std::unique_ptr<TileIterator> Clone() const
|
||||||
{
|
{
|
||||||
return new OrthogonalTileIterator(*this);
|
return std::make_unique<OrthogonalTileIterator>(*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -264,9 +264,9 @@ public:
|
||||||
|
|
||||||
TileIterator& operator ++();
|
TileIterator& operator ++();
|
||||||
|
|
||||||
virtual TileIterator *Clone() const
|
virtual std::unique_ptr<TileIterator> Clone() const
|
||||||
{
|
{
|
||||||
return new DiagonalTileIterator(*this);
|
return std::make_unique<DiagonalTileIterator>(*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue