Skip to content

Commit b2f8694

Browse files
authored
[ML] Use nullptr instead of 0 in core lib (#35)
1 parent ab45504 commit b2f8694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+256
-255
lines changed

include/core/CContainerPrinter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class CORE_EXPORT CContainerPrinter : private CNonInstantiatable {
246246
//! Print a non associative element pointer for debug.
247247
template<typename T>
248248
static std::string printElement(T* value) {
249-
if (value == 0) {
249+
if (value == nullptr) {
250250
return "\"null\"";
251251
}
252252
std::ostringstream result;
@@ -257,7 +257,7 @@ class CORE_EXPORT CContainerPrinter : private CNonInstantiatable {
257257
//! Print a std::auto_ptr.
258258
template<typename T>
259259
static std::string printElement(const std::auto_ptr<T>& value) {
260-
if (value.get() == 0) {
260+
if (value.get() == nullptr) {
261261
return "\"null\"";
262262
}
263263
std::ostringstream result;

include/core/CFunctional.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CORE_EXPORT CFunctional : CNonInstantiatable {
2323
struct CORE_EXPORT SIsNull {
2424
template<typename T>
2525
bool operator()(const T* ptr) const {
26-
return ptr == 0;
26+
return ptr == nullptr;
2727
}
2828

2929
template<typename T>
@@ -33,7 +33,7 @@ class CORE_EXPORT CFunctional : CNonInstantiatable {
3333

3434
template<typename T>
3535
bool operator()(boost::shared_ptr<T>& ptr) const {
36-
return ptr == 0;
36+
return ptr == nullptr;
3737
}
3838
};
3939

include/core/CMemory.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class CORE_EXPORT CMemory : private CNonInstantiatable {
261261
public:
262262
//! Default template.
263263
template<typename T>
264-
static std::size_t dynamicSize(const T& t, typename boost::disable_if<typename boost::is_pointer<T>>::type* = 0) {
264+
static std::size_t dynamicSize(const T& t, typename boost::disable_if<typename boost::is_pointer<T>>::type* = nullptr) {
265265
std::size_t mem = 0;
266266
if (!memory_detail::SDynamicSizeAlwaysZero<T>::value()) {
267267
mem += memory_detail::SMemoryDynamicSize<T>::dispatch(t);
@@ -271,8 +271,8 @@ class CORE_EXPORT CMemory : private CNonInstantiatable {
271271

272272
//! Overload for pointer.
273273
template<typename T>
274-
static std::size_t dynamicSize(const T& t, typename boost::enable_if<typename boost::is_pointer<T>>::type* = 0) {
275-
if (t == 0) {
274+
static std::size_t dynamicSize(const T& t, typename boost::enable_if<typename boost::is_pointer<T>>::type* = nullptr) {
275+
if (t == nullptr) {
276276
return 0;
277277
}
278278
return staticSize(*t) + dynamicSize(*t);
@@ -630,7 +630,7 @@ class CORE_EXPORT CMemoryDebug : private CNonInstantiatable {
630630
static void dynamicSize(const char* name,
631631
const T& t,
632632
CMemoryUsage::TMemoryUsagePtr mem,
633-
typename boost::disable_if<typename boost::is_pointer<T>>::type* = 0) {
633+
typename boost::disable_if<typename boost::is_pointer<T>>::type* = nullptr) {
634634
memory_detail::SDebugMemoryDynamicSize<T>::dispatch(name, t, mem);
635635
}
636636

@@ -639,8 +639,8 @@ class CORE_EXPORT CMemoryDebug : private CNonInstantiatable {
639639
static void dynamicSize(const char* name,
640640
const T& t,
641641
CMemoryUsage::TMemoryUsagePtr mem,
642-
typename boost::enable_if<typename boost::is_pointer<T>>::type* = 0) {
643-
if (t != 0) {
642+
typename boost::enable_if<typename boost::is_pointer<T>>::type* = nullptr) {
643+
if (t != nullptr) {
644644
mem->addItem("ptr", CMemory::staticSize(*t));
645645
memory_detail::SDebugMemoryDynamicSize<T>::dispatch(name, *t, mem);
646646
}

include/core/CPolymorphicStackObjectCPtr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CPolymorphicStackObjectCPtr {
6565
return *this;
6666
}
6767

68-
operator bool() const { return boost::relaxed_get<CNullPolymorphicStackObjectCPtr>(&m_Storage) == 0; }
68+
operator bool() const { return boost::relaxed_get<CNullPolymorphicStackObjectCPtr>(&m_Storage) == nullptr; }
6969

7070
TConstBase* operator->() const {
7171
#define MAYBE_RETURN(TYPE) \
@@ -80,7 +80,7 @@ class CPolymorphicStackObjectCPtr {
8080
MAYBE_RETURN(TConstD3);
8181
MAYBE_RETURN(TConstD4);
8282
#undef MAYBE_RETURN
83-
return 0;
83+
return nullptr;
8484
}
8585

8686
TConstBase& operator*() const { return *(this->operator->()); }

include/core/CStringSimilarityTester.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class CORE_EXPORT CStringSimilarityTester : private CNonCopyable {
357357
TScopedIntPArray matrixArary;
358358
int** matrix;
359359
matrix = this->setupBerghelRoachMatrix(maxDist, dataArray, matrixArary);
360-
if (matrix == 0) {
360+
if (matrix == nullptr) {
361361
return 0;
362362
}
363363

include/core/CThread.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class CORE_EXPORT CThread : private CNonCopyable {
8888
//! static so that we can take its address like a free function
8989
static TThreadRet STDCALL threadFunc(void* obj);
9090

91+
//! The ID used for unallocated threads
92+
static TThreadId UNALLOCATED_THREAD_ID;
93+
9194
private:
9295
//! ID of the most recently started thread
9396
TThreadId m_ThreadId;

lib/core/CCondition.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ml {
1616
namespace core {
1717

1818
CCondition::CCondition(CMutex& mutex) : m_Mutex(mutex) {
19-
int ret(::pthread_cond_init(&m_Condition, 0));
19+
int ret(::pthread_cond_init(&m_Condition, nullptr));
2020
if (ret != 0) {
2121
LOG_WARN(::strerror(ret));
2222
}
@@ -77,7 +77,7 @@ void CCondition::broadcast() {
7777

7878
bool CCondition::convert(uint32_t t, timespec& tm) {
7979
timeval now;
80-
if (::gettimeofday(&now, 0) < 0) {
80+
if (::gettimeofday(&now, nullptr) < 0) {
8181
LOG_WARN(::strerror(errno));
8282
return false;
8383
}

lib/core/CDetachedProcessSpawner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ bool CDetachedProcessSpawner::spawn(const std::string& processPath, const TStrVe
247247
for (size_t index = 0; index < args.size(); ++index) {
248248
argv.push_back(const_cast<char*>(args[index].c_str()));
249249
}
250-
argv.push_back(static_cast<char*>(0));
250+
argv.push_back(static_cast<char*>(nullptr));
251251

252252
posix_spawn_file_actions_t fileActions;
253253
if (setupFileActions(&fileActions) == false) {

lib/core/CHexUtils.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CHexUtils::CHexUtils(const uint8_t* pkt, size_t pktLen, bool printHeader, bool p
2222
}
2323

2424
CHexUtils::CHexUtils(const TDataVec& data, bool printHeader, bool printAscii)
25-
: m_Pkt((data.size() > 0) ? &data[0] : 0), m_PktLen(data.size()), m_PrintHeader(printHeader), m_PrintAscii(printAscii) {
25+
: m_Pkt((data.size() > 0) ? data.data() : nullptr), m_PktLen(data.size()), m_PrintHeader(printHeader), m_PrintAscii(printAscii) {
2626
}
2727

2828
void CHexUtils::dump(const uint8_t* pkt, size_t pktLen) {
@@ -36,7 +36,7 @@ std::ostream& operator<<(std::ostream& strm, const CHexUtils& hex) {
3636
strm << "DataSize: " << hex.m_PktLen << " {" << core_t::LINE_ENDING;
3737
}
3838

39-
if (hex.m_Pkt != 0) {
39+
if (hex.m_Pkt != nullptr) {
4040
strm << std::hex;
4141

4242
std::string text;

lib/core/CJsonStateRestoreTraverser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ bool CJsonStateRestoreTraverser::advance() {
278278

279279
void CJsonStateRestoreTraverser::logError() {
280280
const char* error(rapidjson::GetParseError_En(m_Reader.GetParseErrorCode()));
281-
LOG_ERROR("Error parsing JSON at offset " << m_Reader.GetErrorOffset() << ": " << ((error != 0) ? error : "No message"));
281+
LOG_ERROR("Error parsing JSON at offset " << m_Reader.GetErrorOffset() << ": " << ((error != nullptr) ? error : "No message"));
282282
this->setBadState();
283283
}
284284

lib/core/CLogger.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ CLogger::CLogger() : m_Logger(0), m_Reconfigured(false), m_ProgramName(CProgName
5555

5656
CLogger::~CLogger() {
5757
log4cxx::LogManager::shutdown();
58-
m_Logger = 0;
58+
m_Logger = nullptr;
5959

60-
if (m_PipeFile != 0) {
60+
if (m_PipeFile != nullptr) {
6161
// Revert the stderr file descriptor.
6262
if (m_OrigStderrFd != -1) {
6363
COsFileFuncs::dup2(m_OrigStderrFd, ::fileno(stderr));
@@ -67,7 +67,7 @@ CLogger::~CLogger() {
6767
}
6868

6969
void CLogger::reset() {
70-
if (m_PipeFile != 0) {
70+
if (m_PipeFile != nullptr) {
7171
// Revert the stderr file descriptor.
7272
if (m_OrigStderrFd != -1) {
7373
COsFileFuncs::dup2(m_OrigStderrFd, ::fileno(stderr));
@@ -121,7 +121,7 @@ void CLogger::reset() {
121121

122122
m_Logger = log4cxx::Logger::getRootLogger();
123123
} catch (log4cxx::helpers::Exception& e) {
124-
if (m_Logger != 0) {
124+
if (m_Logger != nullptr) {
125125
// (Can't use the Ml LOG_ERROR macro here, as the object
126126
// it references is only part constructed.)
127127
LOG4CXX_ERROR(m_Logger, "Could not initialise logger: " << e.what());
@@ -144,10 +144,10 @@ bool CLogger::hasBeenReconfigured() const {
144144
void CLogger::logEnvironment() const {
145145
std::string env("Environment variables:");
146146
// environ is a global variable from the C runtime library
147-
if (environ == 0) {
147+
if (environ == nullptr) {
148148
env += " (None found)";
149149
} else {
150-
for (char** envPtr = environ; *envPtr != 0; ++envPtr) {
150+
for (char** envPtr = environ; *envPtr != nullptr; ++envPtr) {
151151
env += core_t::LINE_ENDING;
152152
env += *envPtr;
153153
}
@@ -188,15 +188,15 @@ bool CLogger::setLoggingLevel(ELevel level) {
188188
}
189189

190190
// Defend against corrupt argument
191-
if (levelToSet == 0) {
191+
if (levelToSet == nullptr) {
192192
return false;
193193
}
194194

195195
// Get a smart pointer to the current logger - this may be different to the
196196
// active logger when we call its setLevel() method, but because it's a
197197
// smart pointer, at least it will still exist
198198
log4cxx::LoggerPtr loggerToChange(m_Logger);
199-
if (loggerToChange == 0) {
199+
if (loggerToChange == nullptr) {
200200
return false;
201201
}
202202

@@ -213,7 +213,7 @@ bool CLogger::setLoggingLevel(ELevel level) {
213213
// Unfortunately, thresholds are a concept lower down the inheritance
214214
// hierarchy than the Appender base class, so we have to downcast.
215215
log4cxx::WriterAppender* writerToChange(dynamic_cast<log4cxx::WriterAppender*>(appenderToChange));
216-
if (writerToChange != 0) {
216+
if (writerToChange != nullptr) {
217217
writerToChange->setThreshold(levelToSet);
218218
}
219219
}
@@ -239,7 +239,7 @@ bool CLogger::reconfigureLogToNamedPipe(const std::string& pipeName) {
239239
}
240240

241241
m_PipeFile = CNamedPipeFactory::openPipeFileWrite(pipeName);
242-
if (m_PipeFile == 0) {
242+
if (m_PipeFile == nullptr) {
243243
LOG_ERROR("Cannot log to named pipe " << pipeName << " as it could not be opened for writing");
244244
return false;
245245
}
@@ -315,13 +315,13 @@ bool CLogger::reconfigureFromProps(log4cxx::helpers::Properties& props) {
315315
// TCP server can be identified as having come from this process.
316316
m_Logger = log4cxx::Logger::getLogger(m_ProgramName);
317317

318-
if (m_Logger == 0) {
318+
if (m_Logger == nullptr) {
319319
// We can't use the log macros if the pointer to the logger is NULL
320320
std::cerr << "Failed to reinitialise logger for " << m_ProgramName << std::endl;
321321
return false;
322322
}
323323
} catch (log4cxx::helpers::Exception& e) {
324-
if (m_Logger != 0) {
324+
if (m_Logger != nullptr) {
325325
LOG_ERROR("Failed to reinitialise logger: " << e.what());
326326
} else {
327327
// We can't use the log macros if the pointer to the logger is NULL

lib/core/CNamedPipeFactory.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace {
2525
//! fclose() doesn't check for NULL pointers, so wrap it for use as a shared_ptr
2626
//! deleter
2727
void safeFClose(FILE* file) {
28-
if (file != 0) {
28+
if (file != nullptr) {
2929
::fclose(file);
3030
}
3131
}
@@ -41,7 +41,7 @@ bool ignoreSigPipe() {
4141
sa.sa_flags = 0;
4242
// Error reporting is deferred, as the logger won't be logging to the right
4343
// place when this function runs
44-
return ::sigaction(SIGPIPE, &sa, 0) == 0;
44+
return ::sigaction(SIGPIPE, &sa, nullptr) == 0;
4545
}
4646

4747
const bool SIGPIPE_IGNORED(ignoreSigPipe());
@@ -162,7 +162,7 @@ std::string CNamedPipeFactory::defaultPath() {
162162
// Make sure path ends with a slash so it's ready to have a file name
163163
// appended. (_PATH_VARTMP already has this on all platforms I've seen,
164164
// but a user-defined $TMPDIR might not.)
165-
std::string path((tmpDir == 0) ? _PATH_VARTMP : tmpDir);
165+
std::string path((tmpDir == nullptr) ? _PATH_VARTMP : tmpDir);
166166
if (path[path.length() - 1] != '/') {
167167
path += '/';
168168
}

lib/core/CProcess.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const char* CProcess::STARTED_MSG("Process Started.");
1818
const char* CProcess::STOPPING_MSG("Process Shutting Down.");
1919
const char* CProcess::STOPPED_MSG("Process Exiting.");
2020

21-
CProcess::CProcess() : m_IsService(false), m_Initialised(false), m_Running(false), m_MlMainFunc(0) {
21+
CProcess::CProcess() : m_IsService(false), m_Initialised(false), m_Running(false), m_MlMainFunc(nullptr) {
2222
}
2323

2424
CProcess& CProcess::instance() {
@@ -39,7 +39,7 @@ CProcess::TPid CProcess::parentId() const {
3939
}
4040

4141
bool CProcess::startDispatcher(TMlMainFunc mlMain, int argc, char* argv[]) {
42-
if (mlMain == 0) {
42+
if (mlMain == nullptr) {
4343
LOG_ABORT("NULL mlMain() function passed");
4444
}
4545

lib/core/CProgName_MacOSX.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace core {
1616

1717
std::string CProgName::progName() {
1818
const char* progName(::getprogname());
19-
if (progName == 0) {
19+
if (progName == nullptr) {
2020
return std::string();
2121
}
2222

0 commit comments

Comments
 (0)