Skip to content

Commit 004b4dd

Browse files
authored
Merge pull request #5623 from dhthwy/usenullptr
use nullptr in Core
2 parents 16cbc6d + fb2a140 commit 004b4dd

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

library/Core.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ using std::string;
103103

104104
// FIXME: A lot of code in one file, all doing different things... there's something fishy about it.
105105

106-
static bool parseKeySpec(std::string keyspec, int *psym, int *pmod, std::string *pfocus = NULL);
106+
static bool parseKeySpec(std::string keyspec, int *psym, int *pmod, std::string *pfocus = nullptr);
107107
size_t loadScriptFiles(Core* core, color_ostream& out, const std::vector<std::string>& prefix, const std::filesystem::path& folder);
108108

109109
namespace DFHack {
@@ -210,7 +210,7 @@ thread_local int CommandDepthCounter::depth = 0;
210210

211211
void Core::cheap_tokenise(std::string const& input, std::vector<std::string>& output)
212212
{
213-
std::string *cur = NULL;
213+
std::string *cur = nullptr;
214214
size_t i = 0;
215215

216216
// Check the first non-space character
@@ -241,7 +241,7 @@ void Core::cheap_tokenise(std::string const& input, std::vector<std::string>& ou
241241
{
242242
unsigned char c = input[i];
243243
if (isspace(c)) {
244-
cur = NULL;
244+
cur = nullptr;
245245
} else {
246246
if (!cur) {
247247
output.push_back("");
@@ -280,7 +280,7 @@ static void fHKthread(IODATA * iodata)
280280
{
281281
Core * core = iodata->core;
282282
PluginManager * plug_mgr = iodata->plug_mgr;
283-
if(plug_mgr == 0 || core == 0)
283+
if(!plug_mgr || !core)
284284
{
285285
std::cerr << "Hotkey thread has croaked." << std::endl;
286286
return;
@@ -1409,7 +1409,7 @@ static void fIOthread(IODATA * iod)
14091409
main_history.load(HISTORY_FILE.c_str());
14101410

14111411
Console & con = core->getConsole();
1412-
if (plug_mgr == 0)
1412+
if (plug_mgr == nullptr)
14131413
{
14141414
con.printerr("Something horrible happened in Core's constructor...\n");
14151415
return;
@@ -1481,18 +1481,18 @@ Core::Core() :
14811481
toolCount{0}
14821482
{
14831483
// init the console. This must be always the first step!
1484-
plug_mgr = 0;
1484+
plug_mgr = nullptr;
14851485
errorstate = false;
14861486
vinfo = 0;
14871487
memset(&(s_mods), 0, sizeof(s_mods));
14881488

14891489
// set up hotkey capture
14901490
suppress_duplicate_keyboard_events = true;
14911491
hotkey_set = NO;
1492-
last_world_data_ptr = NULL;
1493-
last_local_map_ptr = NULL;
1492+
last_world_data_ptr = nullptr;
1493+
last_local_map_ptr = nullptr;
14941494
last_pause_state = false;
1495-
top_viewscreen = NULL;
1495+
top_viewscreen = nullptr;
14961496

14971497
color_ostream::log_errors_to_stderr = true;
14981498
};
@@ -1516,7 +1516,7 @@ void Core::fatal (std::string output, const char * title)
15161516
std::cout << "DFHack fatal error: " << out.str() << std::endl;
15171517
if (!title)
15181518
title = "DFHack error!";
1519-
DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, title, out.str().c_str(), NULL);
1519+
DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, title, out.str().c_str(), nullptr);
15201520

15211521
bool is_headless = bool(getenv("DFHACK_HEADLESS"));
15221522
if (is_headless)
@@ -1989,7 +1989,7 @@ void Core::doUpdate(color_ostream &out)
19891989
Lua::Core::Reset(out, "DF code execution");
19901990

19911991
// find the current viewscreen
1992-
df::viewscreen *screen = NULL;
1992+
df::viewscreen *screen = nullptr;
19931993
if (df::global::gview)
19941994
{
19951995
screen = &df::global::gview->view;
@@ -2215,7 +2215,7 @@ namespace DFHack {
22152215
}
22162216

22172217
void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event event) {
2218-
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(0,
2218+
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(nullptr,
22192219
(int)SC_WORLD_LOADED, "onLoad", "onLoadWorld", "onWorldLoaded", "",
22202220
(int)SC_WORLD_UNLOADED, "onUnload", "onUnloadWorld", "onWorldUnloaded", "",
22212221
(int)SC_MAP_LOADED, "onMapLoad", "onLoadMap", "",
@@ -2315,7 +2315,7 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
23152315
else
23162316
{
23172317
char timebuf[30];
2318-
time_t rawtime = time(NULL);
2318+
time_t rawtime = time(nullptr);
23192319
struct tm * timeinfo = localtime(&rawtime);
23202320
strftime(timebuf, sizeof(timebuf), "[%Y-%m-%dT%H:%M:%S%z] ", timeinfo);
23212321
evtlog << timebuf;
@@ -2401,7 +2401,7 @@ int Core::Shutdown ( void )
24012401
if(plug_mgr)
24022402
{
24032403
delete plug_mgr;
2404-
plug_mgr = 0;
2404+
plug_mgr = nullptr;
24052405
}
24062406
// invalidate all modules
24072407
allModules.clear();
@@ -2983,7 +2983,7 @@ bool Process::patchMemory(void *target, const void* src, size_t count)
29832983
#define MODULE_GETTER(TYPE) \
29842984
TYPE * Core::get##TYPE() \
29852985
{ \
2986-
if(errorstate) return NULL;\
2986+
if(errorstate) return nullptr;\
29872987
if(!s_mods.p##TYPE)\
29882988
{\
29892989
std::unique_ptr<Module> mod = create##TYPE();\

library/include/Core.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ namespace DFHack
200200

201201
std::filesystem::path getHackPath();
202202

203-
bool isWorldLoaded() { return (last_world_data_ptr != NULL); }
204-
bool isMapLoaded() { return (last_local_map_ptr != NULL && last_world_data_ptr != NULL); }
203+
bool isWorldLoaded() { return (last_world_data_ptr != nullptr); }
204+
bool isMapLoaded() { return (last_local_map_ptr != nullptr && last_world_data_ptr != nullptr); }
205205

206206
static df::viewscreen *getTopViewscreen();
207207

@@ -252,7 +252,7 @@ namespace DFHack
252252
void operator=(Core const&); // Don't implement
253253

254254
// report error to user while failing
255-
void fatal (std::string output, const char * title = NULL);
255+
void fatal (std::string output, const char * title = nullptr);
256256

257257
// 1 = fatal failure
258258
bool errorstate;

0 commit comments

Comments
 (0)