Skip to content

Commit fb2a140

Browse files
committed
use nullptr in Core
1 parent 30374d0 commit fb2a140

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;
@@ -1424,7 +1424,7 @@ static void fIOthread(IODATA * iod)
14241424
main_history.load(HISTORY_FILE.c_str());
14251425

14261426
Console & con = core->getConsole();
1427-
if (plug_mgr == 0)
1427+
if (plug_mgr == nullptr)
14281428
{
14291429
con.printerr("Something horrible happened in Core's constructor...\n");
14301430
return;
@@ -1496,18 +1496,18 @@ Core::Core() :
14961496
toolCount{0}
14971497
{
14981498
// init the console. This must be always the first step!
1499-
plug_mgr = 0;
1499+
plug_mgr = nullptr;
15001500
errorstate = false;
15011501
vinfo = 0;
15021502
memset(&(s_mods), 0, sizeof(s_mods));
15031503

15041504
// set up hotkey capture
15051505
suppress_duplicate_keyboard_events = true;
15061506
hotkey_set = NO;
1507-
last_world_data_ptr = NULL;
1508-
last_local_map_ptr = NULL;
1507+
last_world_data_ptr = nullptr;
1508+
last_local_map_ptr = nullptr;
15091509
last_pause_state = false;
1510-
top_viewscreen = NULL;
1510+
top_viewscreen = nullptr;
15111511

15121512
color_ostream::log_errors_to_stderr = true;
15131513
};
@@ -1531,7 +1531,7 @@ void Core::fatal (std::string output, const char * title)
15311531
std::cout << "DFHack fatal error: " << out.str() << std::endl;
15321532
if (!title)
15331533
title = "DFHack error!";
1534-
DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, title, out.str().c_str(), NULL);
1534+
DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, title, out.str().c_str(), nullptr);
15351535

15361536
bool is_headless = bool(getenv("DFHACK_HEADLESS"));
15371537
if (is_headless)
@@ -2004,7 +2004,7 @@ void Core::doUpdate(color_ostream &out)
20042004
Lua::Core::Reset(out, "DF code execution");
20052005

20062006
// find the current viewscreen
2007-
df::viewscreen *screen = NULL;
2007+
df::viewscreen *screen = nullptr;
20082008
if (df::global::gview)
20092009
{
20102010
screen = &df::global::gview->view;
@@ -2230,7 +2230,7 @@ namespace DFHack {
22302230
}
22312231

22322232
void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event event) {
2233-
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(0,
2233+
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(nullptr,
22342234
(int)SC_WORLD_LOADED, "onLoad", "onLoadWorld", "onWorldLoaded", "",
22352235
(int)SC_WORLD_UNLOADED, "onUnload", "onUnloadWorld", "onWorldUnloaded", "",
22362236
(int)SC_MAP_LOADED, "onMapLoad", "onLoadMap", "",
@@ -2330,7 +2330,7 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
23302330
else
23312331
{
23322332
char timebuf[30];
2333-
time_t rawtime = time(NULL);
2333+
time_t rawtime = time(nullptr);
23342334
struct tm * timeinfo = localtime(&rawtime);
23352335
strftime(timebuf, sizeof(timebuf), "[%Y-%m-%dT%H:%M:%S%z] ", timeinfo);
23362336
evtlog << timebuf;
@@ -2416,7 +2416,7 @@ int Core::Shutdown ( void )
24162416
if(plug_mgr)
24172417
{
24182418
delete plug_mgr;
2419-
plug_mgr = 0;
2419+
plug_mgr = nullptr;
24202420
}
24212421
// invalidate all modules
24222422
allModules.clear();
@@ -2998,7 +2998,7 @@ bool Process::patchMemory(void *target, const void* src, size_t count)
29982998
#define MODULE_GETTER(TYPE) \
29992999
TYPE * Core::get##TYPE() \
30003000
{ \
3001-
if(errorstate) return NULL;\
3001+
if(errorstate) return nullptr;\
30023002
if(!s_mods.p##TYPE)\
30033003
{\
30043004
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)