Merge: Codechange: Use null pointer literal instead of the NULL macro

This commit is contained in:
Jonathan G Rennison
2019-04-11 18:14:13 +01:00
585 changed files with 6604 additions and 6604 deletions

View File

@@ -324,15 +324,15 @@ void LinkGraphOverlay::RefreshDrawCache()
{
for (StationSupplyList::iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) {
const Station *st = Station::GetIfValid(i->id);
if (st == NULL) continue;
if (st == nullptr) continue;
i->pt = this->GetStationMiddle(st);
}
for (LinkList::iterator i(this->cached_links.begin()); i != this->cached_links.end(); ++i) {
const Station *sta = Station::GetIfValid(i->from_id);
if (sta == NULL) continue;
if (sta == nullptr) continue;
const Station *stb = Station::GetIfValid(i->to_id);
if (stb == NULL) continue;
if (stb == nullptr) continue;
i->from_pt = this->GetStationMiddle(sta);
i->to_pt = this->GetStationMiddle(stb);
@@ -408,7 +408,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
if (!this->IsPointVisible(pt, dpi, 3 * this->scale)) continue;
const Station *st = Station::GetIfValid(i->id);
if (st == NULL) continue;
if (st == nullptr) continue;
uint r = this->scale * 2 + this->scale * 2 * min(200, i->quantity) / 200;
@@ -450,7 +450,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 */
@@ -504,7 +504,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);
@@ -668,7 +668,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);

View File

@@ -106,7 +106,7 @@ void LinkGraphJob::FinaliseJob()
/* 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;
}
@@ -126,7 +126,7 @@ void LinkGraphJob::FinaliseJob()
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. */
@@ -291,7 +291,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;
@@ -321,6 +321,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)
{}

View File

@@ -63,7 +63,7 @@ private:
protected:
const LinkGraph link_graph; ///< Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
std::shared_ptr<LinkGraphJobGroup> group; ///< JOb group thread the job is running in or NULL if it's running in the main thread.
std::shared_ptr<LinkGraphJobGroup> group; ///< JOb group thread the job is running in or nullptr if it's running in the main thread.
const LinkGraphSettings settings; ///< Copy of _settings_game.linkgraph at spawn time.
DateTicks join_date_ticks; ///< Date when the job is to be joined.
DateTicks start_date_ticks; ///< Date when the job was started.
@@ -426,9 +426,9 @@ public:
*/
inline void Detach()
{
if (this->parent != NULL) {
if (this->parent != nullptr) {
this->parent->num_children--;
this->parent = NULL;
this->parent = nullptr;
}
}

View File

@@ -85,7 +85,7 @@ class LinkGraphJobGroup : public std::enable_shared_from_this<LinkGraphJobGroup>
friend LinkGraphJob;
private:
std::thread thread; ///< Thread the job group is running in or NULL if it's running in the main thread.
std::thread thread; ///< Thread the job group is running in or nullptr if it's running in the main thread.
const std::vector<LinkGraphJob *> jobs; ///< The set of jobs in this job set
private:

View File

@@ -121,7 +121,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)
{}
/**
@@ -273,7 +273,7 @@ struct AnnoSetAllocatorStore {
size_t next_position;
void *last_freed;
AnnoSetAllocatorStore() : current_block(NULL), next_position(0), last_freed(NULL) {}
AnnoSetAllocatorStore() : current_block(nullptr), next_position(0), last_freed(nullptr) {}
~AnnoSetAllocatorStore()
{
@@ -316,12 +316,12 @@ struct AnnoSetAllocator {
Ttype* allocate(size_t n)
{
if (store.current_block == NULL) NewBlock();
if (store.current_block == nullptr) NewBlock();
assert(n == 1);
if (store.last_freed != NULL) {
if (store.last_freed != nullptr) {
Ttype* out = static_cast<Ttype*>(store.last_freed);
store.last_freed = NULL;
store.last_freed = nullptr;
return out;
}
@@ -377,7 +377,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
#endif
Tedge_iterator iter(this->job);
uint size = this->job.Size();
paths.resize(size, NULL);
paths.resize(size, nullptr);
this->job.path_allocator.SetParameters(sizeof(AnnosWrapper<Tannotation>), (8192 - 32) / sizeof(AnnosWrapper<Tannotation>));
@@ -424,16 +424,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;
this->job.path_allocator.Free(path);
}
path = parent;
@@ -522,7 +522,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();
@@ -573,7 +573,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;
}
@@ -597,11 +597,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;
@@ -628,7 +628,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*. */

View File

@@ -29,14 +29,14 @@
/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading, CargoTypes cargo_mask)
{
/* If there are no orders we can't predict anything.*/
if (v->orders.list == NULL) return;
if (v->orders.list == nullptr) return;
CargoTypes have_cargo_mask = v->GetLastLoadingStationValidCargoMask();
/* Scan orders for cargo-specific load/unload, and run LinkRefresher separately for each set of cargoes where they differ. */
while (cargo_mask != 0) {
CargoTypes iter_cargo_mask = cargo_mask;
for (const Order *o = v->orders.list->GetFirstOrder(); o != NULL; o = o->next) {
for (const Order *o = v->orders.list->GetFirstOrder(); o != nullptr; o = o->next) {
if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_IMPLICIT)) {
if (o->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD) {
CargoMaskValueFilter<uint>(iter_cargo_mask, [&](CargoID cargo) -> uint {
@@ -53,7 +53,7 @@
/* Make sure the first order is a useful order. */
const Order *first = v->orders.list->GetNextDecisionNode(v->GetOrder(v->cur_implicit_order_index), 0, iter_cargo_mask);
if (first != NULL) {
if (first != nullptr) {
HopSet seen_hops;
LinkRefresher refresher(v, &seen_hops, allow_merge, is_full_loading, iter_cargo_mask);
@@ -99,7 +99,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);
@@ -118,7 +118,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;
@@ -188,10 +188,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
@@ -203,7 +203,7 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops, this_cargo_mask);
assert(this_cargo_mask == this->cargo_mask);
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
@@ -232,7 +232,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. */
@@ -256,7 +256,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) {
@@ -290,7 +290,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);
@@ -318,7 +318,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;