summaryrefslogtreecommitdiff
path: root/src/linkgraph
diff options
context:
space:
mode:
authorHenry Wilson <m3henry@googlemail.com>2019-04-10 22:07:06 +0100
committerMichael Lutz <michi@icosahedron.de>2019-04-10 23:22:20 +0200
commit7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch)
tree99f134b7e66367cf11e10bc5061896eab4a3264f /src/linkgraph
parent3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff)
downloadopenttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/linkgraph')
-rw-r--r--src/linkgraph/linkgraph_gui.cpp8
-rw-r--r--src/linkgraph/linkgraphjob.cpp8
-rw-r--r--src/linkgraph/linkgraphjob.h4
-rw-r--r--src/linkgraph/mcf.cpp22
-rw-r--r--src/linkgraph/refresh.cpp22
5 files changed, 32 insertions, 32 deletions
diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp
index 6844092c2..ebba160bf 100644
--- a/src/linkgraph/linkgraph_gui.cpp
+++ b/src/linkgraph/linkgraph_gui.cpp
@@ -301,7 +301,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
{
for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) {
const Station *st = Station::GetIfValid(i->first);
- if (st == NULL) continue;
+ if (st == nullptr) continue;
Point pt = this->GetStationMiddle(st);
if (!this->IsPointVisible(pt, dpi, 3 * this->scale)) continue;
@@ -345,7 +345,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
*/
Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
{
- if (this->window->viewport != NULL) {
+ if (this->window->viewport != nullptr) {
return GetViewportStationMiddle(this->window->viewport, st);
} else {
/* assume this is a smallmap */
@@ -399,7 +399,7 @@ NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index)
{
static const uint ENTRIES_PER_ROW = CeilDiv(NUM_CARGO, 5);
NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
- NWidgetHorizontal *row = NULL;
+ NWidgetHorizontal *row = nullptr;
for (uint i = 0; i < NUM_CARGO; ++i) {
if (i % ENTRIES_PER_ROW == 0) {
if (row) panel->Add(row);
@@ -563,7 +563,7 @@ bool LinkGraphLegendWindow::OnTooltip(Point pt, int widget, TooltipCloseConditio
{
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) {
- GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, 0, NULL, close_cond);
+ GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, 0, nullptr, close_cond);
} else {
uint64 params[2];
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp
index 5b8683820..cf180a3ae 100644
--- a/src/linkgraph/linkgraphjob.cpp
+++ b/src/linkgraph/linkgraphjob.cpp
@@ -102,7 +102,7 @@ LinkGraphJob::~LinkGraphJob()
/* The station can have been deleted. Remove all flows originating from it then. */
Station *st = Station::GetIfValid(from.Station());
- if (st == NULL) {
+ if (st == nullptr) {
this->EraseFlows(node_id);
continue;
}
@@ -122,7 +122,7 @@ LinkGraphJob::~LinkGraphJob()
if (from[it->first].Flow() == 0) continue;
StationID to = (*this)[it->first].Station();
Station *st2 = Station::GetIfValid(to);
- if (st2 == NULL || st2->goods[this->Cargo()].link_graph != this->link_graph.index ||
+ if (st2 == nullptr || st2->goods[this->Cargo()].link_graph != this->link_graph.index ||
st2->goods[this->Cargo()].node != it->first ||
(*lg)[node_id][it->first].LastUpdate() == INVALID_DATE) {
/* Edge has been removed. Delete flows. */
@@ -240,7 +240,7 @@ void Path::Fork(Path *base, uint cap, int free_cap, uint dist)
*/
uint Path::AddFlow(uint new_flow, LinkGraphJob &job, uint max_saturation)
{
- if (this->parent != NULL) {
+ if (this->parent != nullptr) {
LinkGraphJob::Edge edge = job[this->parent->node][this->node];
if (max_saturation != UINT_MAX) {
uint usable_cap = edge.Capacity() * max_saturation / 100;
@@ -270,6 +270,6 @@ Path::Path(NodeID n, bool source) :
capacity(source ? UINT_MAX : 0),
free_capacity(source ? INT_MAX : INT_MIN),
flow(0), node(n), origin(source ? n : INVALID_NODE),
- num_children(0), parent(NULL)
+ num_children(0), parent(nullptr)
{}
diff --git a/src/linkgraph/linkgraphjob.h b/src/linkgraph/linkgraphjob.h
index e52d2412d..a20a2025c 100644
--- a/src/linkgraph/linkgraphjob.h
+++ b/src/linkgraph/linkgraphjob.h
@@ -403,9 +403,9 @@ public:
*/
inline void Detach()
{
- if (this->parent != NULL) {
+ if (this->parent != nullptr) {
this->parent->num_children--;
- this->parent = NULL;
+ this->parent = nullptr;
}
}
diff --git a/src/linkgraph/mcf.cpp b/src/linkgraph/mcf.cpp
index 544584ef6..c64674237 100644
--- a/src/linkgraph/mcf.cpp
+++ b/src/linkgraph/mcf.cpp
@@ -104,7 +104,7 @@ public:
* @param job Job to iterate on.
*/
GraphEdgeIterator(LinkGraphJob &job) : job(job),
- i(NULL, NULL, INVALID_NODE), end(NULL, NULL, INVALID_NODE)
+ i(nullptr, nullptr, INVALID_NODE), end(nullptr, nullptr, INVALID_NODE)
{}
/**
@@ -262,7 +262,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
Tedge_iterator iter(this->job);
uint size = this->job.Size();
AnnoSet annos;
- paths.resize(size, NULL);
+ paths.resize(size, nullptr);
for (NodeID node = 0; node < size; ++node) {
Tannotation *anno = new Tannotation(node, node == source_node);
anno->UpdateAnnotation();
@@ -305,16 +305,16 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
void MultiCommodityFlow::CleanupPaths(NodeID source_id, PathVector &paths)
{
Path *source = paths[source_id];
- paths[source_id] = NULL;
+ paths[source_id] = nullptr;
for (PathVector::iterator i = paths.begin(); i != paths.end(); ++i) {
Path *path = *i;
- if (path == NULL) continue;
+ if (path == nullptr) continue;
if (path->GetParent() == source) path->Detach();
- while (path != source && path != NULL && path->GetFlow() == 0) {
+ while (path != source && path != nullptr && path->GetFlow() == 0) {
Path *parent = path->GetParent();
path->Detach();
if (path->GetNumChildren() == 0) {
- paths[path->GetNode()] = NULL;
+ paths[path->GetNode()] = nullptr;
delete path;
}
path = parent;
@@ -404,7 +404,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next
/* this node has already been searched */
if (at_next_pos == Path::invalid_path) return false;
- if (at_next_pos == NULL) {
+ if (at_next_pos == nullptr) {
/* Summarize paths; add up the paths with the same source and next hop
* in one path each. */
PathList &paths = this->job[next_id].Paths();
@@ -450,7 +450,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next
* could be found in this branch, thus it has to be searched again next
* time we spot it.
*/
- path[next_id] = found ? NULL : Path::invalid_path;
+ path[next_id] = found ? nullptr : Path::invalid_path;
return found;
}
@@ -474,11 +474,11 @@ bool MCF1stPass::EliminateCycles()
{
bool cycles_found = false;
uint size = this->job.Size();
- PathVector path(size, NULL);
+ PathVector path(size, nullptr);
for (NodeID node = 0; node < size; ++node) {
/* Starting at each node in the graph find all cycles involving this
* node. */
- std::fill(path.begin(), path.end(), (Path *)NULL);
+ std::fill(path.begin(), path.end(), (Path *)nullptr);
cycles_found |= this->EliminateCycles(path, node, node);
}
return cycles_found;
@@ -505,7 +505,7 @@ MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
Edge edge = job[source][dest];
if (edge.UnsatisfiedDemand() > 0) {
Path *path = paths[dest];
- assert(path != NULL);
+ assert(path != nullptr);
/* Generally only allow paths that don't exceed the
* available capacity. But if no demand has been assigned
* yet, make an exception and allow any valid path *once*. */
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp
index 501f06352..b749d2718 100644
--- a/src/linkgraph/refresh.cpp
+++ b/src/linkgraph/refresh.cpp
@@ -28,11 +28,11 @@
/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading)
{
/* If there are no orders we can't predict anything.*/
- if (v->orders.list == NULL) return;
+ if (v->orders.list == nullptr) return;
/* Make sure the first order is a useful order. */
const Order *first = v->orders.list->GetNextDecisionNode(v->GetOrder(v->cur_implicit_order_index), 0);
- if (first == NULL) return;
+ if (first == nullptr) return;
HopSet seen_hops;
LinkRefresher refresher(v, &seen_hops, allow_merge, is_full_loading);
@@ -75,7 +75,7 @@ LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_mer
memset(this->capacities, 0, sizeof(this->capacities));
/* Assemble list of capacities and set last loading stations to 0. */
- for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
+ for (Vehicle *v = this->vehicle; v != nullptr; v = v->Next()) {
this->refit_capacities.push_back(RefitDesc(v->cargo_type, v->cargo_cap, v->refit_cap));
if (v->refit_cap > 0) {
assert(v->cargo_type < NUM_CARGO);
@@ -94,7 +94,7 @@ bool LinkRefresher::HandleRefit(CargoID refit_cargo)
this->cargo = refit_cargo;
RefitList::iterator refit_it = this->refit_capacities.begin();
bool any_refit = false;
- for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
+ for (Vehicle *v = this->vehicle; v != nullptr; v = v->Next()) {
const Engine *e = Engine::Get(v->engine_type);
if (!HasBit(e->info.refit_mask, this->cargo)) {
++refit_it;
@@ -164,10 +164,10 @@ void LinkRefresher::ResetRefit()
*/
const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next, uint8 flags, uint num_hops)
{
- /* next is good if it's either NULL (then the caller will stop the
+ /* next is good if it's either nullptr (then the caller will stop the
* evaluation) or if it's not conditional and the caller allows it to be
* chosen (by setting USE_NEXT). */
- while (next != NULL && (!HasBit(flags, USE_NEXT) || next->IsType(OT_CONDITIONAL))) {
+ while (next != nullptr && (!HasBit(flags, USE_NEXT) || next->IsType(OT_CONDITIONAL))) {
/* After the first step any further non-conditional order is good,
* regardless of previous USE_NEXT settings. The case of cur and next or
@@ -177,7 +177,7 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next
if (next->IsType(OT_CONDITIONAL)) {
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops);
- if (skip_to != NULL && num_hops < this->vehicle->orders.list->GetNumOrders()) {
+ if (skip_to != nullptr && num_hops < this->vehicle->orders.list->GetNumOrders()) {
/* Make copies of capacity tracking lists. There is potential
* for optimization here: If the vehicle never refits we don't
* need to copy anything. Also, if we've seen the branched link
@@ -204,7 +204,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
{
StationID next_station = next->GetDestination();
Station *st = Station::GetIfValid(cur->GetDestination());
- if (st != NULL && next_station != INVALID_STATION && next_station != st->index) {
+ if (st != nullptr && next_station != INVALID_STATION && next_station != st->index) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
/* Refresh the link and give it a minimum capacity. */
@@ -226,7 +226,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
* loading. Don't do that if the vehicle has been waiting for longer than the entire
* order list is supposed to take, though. If that is the case the total duration is
* probably far off and we'd greatly overestimate the capacity by increasing.*/
- if (this->is_full_loading && this->vehicle->orders.list != NULL &&
+ if (this->is_full_loading && this->vehicle->orders.list != nullptr &&
st->index == vehicle->last_station_visited &&
this->vehicle->orders.list->GetTotalDuration() >
(Ticks)this->vehicle->current_order_time) {
@@ -260,7 +260,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
*/
void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops)
{
- while (next != NULL) {
+ while (next != nullptr) {
if ((next->IsType(OT_GOTO_DEPOT) || next->IsType(OT_GOTO_STATION)) && next->IsRefit()) {
SetBit(flags, WAS_REFIT);
@@ -288,7 +288,7 @@ void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8 flag
}
next = this->PredictNextOrder(cur, next, flags, num_hops);
- if (next == NULL) break;
+ if (next == nullptr) break;
Hop hop(cur->index, next->index, this->cargo);
if (this->seen_hops->find(hop) != this->seen_hops->end()) {
break;