diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-04-10 22:07:06 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-10 23:22:20 +0200 |
commit | 7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch) | |
tree | 99f134b7e66367cf11e10bc5061896eab4a3264f /src/misc | |
parent | 3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff) | |
download | openttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz |
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/binaryheap.hpp | 2 | ||||
-rw-r--r-- | src/misc/blob.hpp | 12 | ||||
-rw-r--r-- | src/misc/countedptr.hpp | 32 | ||||
-rw-r--r-- | src/misc/dbg_helpers.h | 4 | ||||
-rw-r--r-- | src/misc/fixedsizearray.hpp | 2 | ||||
-rw-r--r-- | src/misc/getoptdata.cpp | 14 | ||||
-rw-r--r-- | src/misc/getoptdata.h | 24 | ||||
-rw-r--r-- | src/misc/hashtable.hpp | 38 |
8 files changed, 64 insertions, 64 deletions
diff --git a/src/misc/binaryheap.hpp b/src/misc/binaryheap.hpp index 5bd2b794a..11e419711 100644 --- a/src/misc/binaryheap.hpp +++ b/src/misc/binaryheap.hpp @@ -72,7 +72,7 @@ public: { this->Clear(); free(this->data); - this->data = NULL; + this->data = nullptr; } protected: diff --git a/src/misc/blob.hpp b/src/misc/blob.hpp index b1a5b667d..e725ccd27 100644 --- a/src/misc/blob.hpp +++ b/src/misc/blob.hpp @@ -86,9 +86,9 @@ public: /** move constructor - take ownership of blob data */ inline ByteBlob(BlobHeader * const & src) { - assert(src != NULL); + assert(src != nullptr); header = src; - *const_cast<BlobHeader**>(&src) = NULL; + *const_cast<BlobHeader**>(&src) = nullptr; } /** destructor */ @@ -221,7 +221,7 @@ public: /** append new bytes at the end of existing data bytes - reallocates if necessary */ inline void AppendRaw(const void *p, size_t num_bytes) { - assert(p != NULL); + assert(p != nullptr); if (num_bytes > 0) { memcpy(Append(num_bytes), p, num_bytes); } @@ -317,8 +317,8 @@ public: OnTransfer(const OnTransfer& src) : header(src.header) { - assert(src.header != NULL); - *const_cast<typename base::BlobHeader**>(&src.header) = NULL; + assert(src.header != nullptr); + *const_cast<typename base::BlobHeader**>(&src.header) = nullptr; } OnTransfer(CBlobT& src) : header(src.header) @@ -328,7 +328,7 @@ public: ~OnTransfer() { - assert(header == NULL); + assert(header == nullptr); } }; diff --git a/src/misc/countedptr.hpp b/src/misc/countedptr.hpp index e7b28a626..83d0e036d 100644 --- a/src/misc/countedptr.hpp +++ b/src/misc/countedptr.hpp @@ -34,8 +34,8 @@ protected: Tcls *m_pT; public: - /** default (NULL) construct or construct from a raw pointer */ - inline CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj) + /** default (nullptr) construct or construct from a raw pointer */ + inline CCountedPtr(Tcls *pObj = nullptr) : m_pT(pObj) { AddRef(); } @@ -56,16 +56,16 @@ protected: /** add one ref to the underlaying object */ inline void AddRef() { - if (m_pT != NULL) m_pT->AddRef(); + if (m_pT != nullptr) m_pT->AddRef(); } public: /** release smart pointer (and decrement ref count) if not null */ inline void Release() { - if (m_pT != NULL) { + if (m_pT != nullptr) { Tcls *pT = m_pT; - m_pT = NULL; + m_pT = nullptr; pT->Release(); } } @@ -73,21 +73,21 @@ public: /** dereference of smart pointer - const way */ inline const Tcls *operator->() const { - assert(m_pT != NULL); + assert(m_pT != nullptr); return m_pT; } /** dereference of smart pointer - non const way */ inline Tcls *operator->() { - assert(m_pT != NULL); + assert(m_pT != nullptr); return m_pT; } /** raw pointer casting operator - const way */ inline operator const Tcls*() const { - assert(m_pT == NULL); + assert(m_pT == nullptr); return m_pT; } @@ -100,7 +100,7 @@ public: /** operator & to support output arguments */ inline Tcls** operator&() { - assert(m_pT == NULL); + assert(m_pT == nullptr); return &m_pT; } @@ -121,16 +121,16 @@ public: /** assignment operator helper */ inline void Assign(Tcls *pT); - /** one way how to test for NULL value */ + /** one way how to test for nullptr value */ inline bool IsNull() const { - return m_pT == NULL; + return m_pT == nullptr; } - /** another way how to test for NULL value */ + /** another way how to test for nullptr value */ //inline bool operator == (const CCountedPtr &sp) const {return m_pT == sp.m_pT;} - /** yet another way how to test for NULL value */ + /** yet another way how to test for nullptr value */ //inline bool operator != (const CCountedPtr &sp) const {return m_pT != sp.m_pT;} /** assign pointer w/o incrementing ref count */ @@ -144,7 +144,7 @@ public: inline Tcls *Detach() { Tcls *pT = m_pT; - m_pT = NULL; + m_pT = nullptr; return pT; } }; @@ -154,10 +154,10 @@ inline void CCountedPtr<Tcls_>::Assign(Tcls *pT) { /* if they are the same, we do nothing */ if (pT != m_pT) { - if (pT != NULL) pT->AddRef(); // AddRef new pointer if any + if (pT != nullptr) pT->AddRef(); // AddRef new pointer if any Tcls *pTold = m_pT; // save original ptr m_pT = pT; // update m_pT to new value - if (pTold != NULL) pTold->Release(); // release old ptr if any + if (pTold != nullptr) pTold->Release(); // release old ptr if any } } diff --git a/src/misc/dbg_helpers.h b/src/misc/dbg_helpers.h index acc1437d0..2e2a1a7e9 100644 --- a/src/misc/dbg_helpers.h +++ b/src/misc/dbg_helpers.h @@ -155,8 +155,8 @@ struct DumpTarget { { static size_t type_id = ++LastTypeId(); - if (s == NULL) { - /* No need to dump NULL struct. */ + if (s == nullptr) { + /* No need to dump nullptr struct. */ WriteLine("%s = <null>", name); return; } diff --git a/src/misc/fixedsizearray.hpp b/src/misc/fixedsizearray.hpp index c694ff7a1..ec1d58bf3 100644 --- a/src/misc/fixedsizearray.hpp +++ b/src/misc/fixedsizearray.hpp @@ -94,7 +94,7 @@ public: Clear(); /* free the memory block occupied by items */ free(((byte*)data) - HeaderSize); - data = NULL; + data = nullptr; } /** Clear (destroy) all items */ diff --git a/src/misc/getoptdata.cpp b/src/misc/getoptdata.cpp index 7859594dd..d80898f08 100644 --- a/src/misc/getoptdata.cpp +++ b/src/misc/getoptdata.cpp @@ -26,7 +26,7 @@ int GetOptData::GetOpt() const OptionData *odata; char *s = this->cont; - if (s == NULL) { + if (s == nullptr) { if (this->numleft == 0) return -1; // No arguments left -> finished. s = this->argv[0]; @@ -37,8 +37,8 @@ int GetOptData::GetOpt() /* Is it a long option? */ for (odata = this->options; odata->flags != ODF_END; odata++) { - if (odata->longname != NULL && !strcmp(odata->longname, s)) { // Long options always use the entire argument. - this->cont = NULL; + if (odata->longname != nullptr && !strcmp(odata->longname, s)) { // Long options always use the entire argument. + this->cont = nullptr; goto set_optval; } } @@ -49,19 +49,19 @@ int GetOptData::GetOpt() /* Is it a short option? */ for (odata = this->options; odata->flags != ODF_END; odata++) { if (odata->shortname != '\0' && *s == odata->shortname) { - this->cont = (s[1] != '\0') ? s + 1 : NULL; + this->cont = (s[1] != '\0') ? s + 1 : nullptr; set_optval: // Handle option value of *odata . - this->opt = NULL; + this->opt = nullptr; switch (odata->flags) { case ODF_NO_VALUE: return odata->id; case ODF_HAS_VALUE: case ODF_OPTIONAL_VALUE: - if (this->cont != NULL) { // Remainder of the argument is the option value. + if (this->cont != nullptr) { // Remainder of the argument is the option value. this->opt = this->cont; - this->cont = NULL; + this->cont = nullptr; return odata->id; } /* No more arguments, either return an error or a value-less option. */ diff --git a/src/misc/getoptdata.h b/src/misc/getoptdata.h index 4ce916aa1..4777c85b5 100644 --- a/src/misc/getoptdata.h +++ b/src/misc/getoptdata.h @@ -25,12 +25,12 @@ struct OptionData { byte id; ///< Unique identification of this option data, often the same as #shortname. char shortname; ///< Short option letter if available, else use \c '\0'. uint16 flags; ///< Option data flags. @see OptionDataFlags - const char *longname; ///< Long option name including '-'/'--' prefix, use \c NULL if not available. + const char *longname; ///< Long option name including '-'/'--' prefix, use \c nullptr if not available. }; /** Data storage for parsing command line options. */ struct GetOptData { - char *opt; ///< Option value, if available (else \c NULL). + char *opt; ///< Option value, if available (else \c nullptr). int numleft; ///< Number of arguments left in #argv. char **argv; ///< Remaining command line arguments. const OptionData *options; ///< Command line option descriptions. @@ -43,11 +43,11 @@ struct GetOptData { * @param options Command line option descriptions. */ GetOptData(int argc, char **argv, const OptionData *options) : - opt(NULL), + opt(nullptr), numleft(argc), argv(argv), options(options), - cont(NULL) + cont(nullptr) { } @@ -58,7 +58,7 @@ struct GetOptData { * General macro for creating an option. * @param id Identification of the option. * @param shortname Short option name. Use \c '\0' if not used. - * @param longname Long option name including leading '-' or '--'. Use \c NULL if not used. + * @param longname Long option name including leading '-' or '--'. Use \c nullptr if not used. * @param flags Flags of the option. */ #define GETOPT_GENERAL(id, shortname, longname, flags) { id, shortname, flags, longname } @@ -66,21 +66,21 @@ struct GetOptData { /** * Short option without value. * @param shortname Short option name. Use \c '\0' if not used. - * @param longname Long option name including leading '-' or '--'. Use \c NULL if not used. + * @param longname Long option name including leading '-' or '--'. Use \c nullptr if not used. */ #define GETOPT_NOVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_NO_VALUE) /** * Short option with value. * @param shortname Short option name. Use \c '\0' if not used. - * @param longname Long option name including leading '-' or '--'. Use \c NULL if not used. + * @param longname Long option name including leading '-' or '--'. Use \c nullptr if not used. */ #define GETOPT_VALUE(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_HAS_VALUE) /** * Short option with optional value. * @param shortname Short option name. Use \c '\0' if not used. - * @param longname Long option name including leading '-' or '--'. Use \c NULL if not used. + * @param longname Long option name including leading '-' or '--'. Use \c nullptr if not used. * @note Options with optional values are hopelessly ambiguous, eg "-opt -value", avoid them. */ #define GETOPT_OPTVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_OPTIONAL_VALUE) @@ -90,23 +90,23 @@ struct GetOptData { * Short option without value. * @param shortname Short option name. Use \c '\0' if not used. */ -#define GETOPT_SHORT_NOVAL(shortname) GETOPT_NOVAL(shortname, NULL) +#define GETOPT_SHORT_NOVAL(shortname) GETOPT_NOVAL(shortname, nullptr) /** * Short option with value. * @param shortname Short option name. Use \c '\0' if not used. */ -#define GETOPT_SHORT_VALUE(shortname) GETOPT_VALUE(shortname, NULL) +#define GETOPT_SHORT_VALUE(shortname) GETOPT_VALUE(shortname, nullptr) /** * Short option with optional value. * @param shortname Short option name. Use \c '\0' if not used. * @note Options with optional values are hopelessly ambiguous, eg "-opt -value", avoid them. */ -#define GETOPT_SHORT_OPTVAL(shortname) GETOPT_OPTVAL(shortname, NULL) +#define GETOPT_SHORT_OPTVAL(shortname) GETOPT_OPTVAL(shortname, nullptr) /** Option terminator. */ -#define GETOPT_END() { '\0', '\0', ODF_END, NULL} +#define GETOPT_END() { '\0', '\0', ODF_END, nullptr} #endif /* GETOPTDATA_H */ diff --git a/src/misc/hashtable.hpp b/src/misc/hashtable.hpp index 1078f1861..49f321bff 100644 --- a/src/misc/hashtable.hpp +++ b/src/misc/hashtable.hpp @@ -21,42 +21,42 @@ struct CHashTableSlotT Titem_ *m_pFirst; - inline CHashTableSlotT() : m_pFirst(NULL) {} + inline CHashTableSlotT() : m_pFirst(nullptr) {} /** hash table slot helper - clears the slot by simple forgetting its items */ inline void Clear() { - m_pFirst = NULL; + m_pFirst = nullptr; } /** hash table slot helper - linear search for item with given key through the given blob - const version */ inline const Titem_ *Find(const Key &key) const { - for (const Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { + for (const Titem_ *pItem = m_pFirst; pItem != nullptr; pItem = pItem->GetHashNext()) { if (pItem->GetKey() == key) { /* we have found the item, return it */ return pItem; } } - return NULL; + return nullptr; } /** hash table slot helper - linear search for item with given key through the given blob - non-const version */ inline Titem_ *Find(const Key &key) { - for (Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { + for (Titem_ *pItem = m_pFirst; pItem != nullptr; pItem = pItem->GetHashNext()) { if (pItem->GetKey() == key) { /* we have found the item, return it */ return pItem; } } - return NULL; + return nullptr; } /** hash table slot helper - add new item to the slot */ inline void Attach(Titem_ &new_item) { - assert(new_item.GetHashNext() == NULL); + assert(new_item.GetHashNext() == nullptr); new_item.SetHashNext(m_pFirst); m_pFirst = &new_item; } @@ -66,12 +66,12 @@ struct CHashTableSlotT { if (m_pFirst == &item_to_remove) { m_pFirst = item_to_remove.GetHashNext(); - item_to_remove.SetHashNext(NULL); + item_to_remove.SetHashNext(nullptr); return true; } Titem_ *pItem = m_pFirst; for (;;) { - if (pItem == NULL) { + if (pItem == nullptr) { return false; } Titem_ *pNextItem = pItem->GetHashNext(); @@ -79,7 +79,7 @@ struct CHashTableSlotT pItem = pNextItem; } pItem->SetHashNext(item_to_remove.GetHashNext()); - item_to_remove.SetHashNext(NULL); + item_to_remove.SetHashNext(nullptr); return true; } @@ -87,27 +87,27 @@ struct CHashTableSlotT inline Titem_ *Detach(const Key &key) { /* do we have any items? */ - if (m_pFirst == NULL) { - return NULL; + if (m_pFirst == nullptr) { + return nullptr; } /* is it our first item? */ if (m_pFirst->GetKey() == key) { Titem_ &ret_item = *m_pFirst; m_pFirst = m_pFirst->GetHashNext(); - ret_item.SetHashNext(NULL); + ret_item.SetHashNext(nullptr); return &ret_item; } /* find it in the following items */ Titem_ *pPrev = m_pFirst; - for (Titem_ *pItem = m_pFirst->GetHashNext(); pItem != NULL; pPrev = pItem, pItem = pItem->GetHashNext()) { + for (Titem_ *pItem = m_pFirst->GetHashNext(); pItem != nullptr; pPrev = pItem, pItem = pItem->GetHashNext()) { if (pItem->GetKey() == key) { /* we have found the item, unlink and return it */ pPrev->SetHashNext(pItem->GetHashNext()); - pItem->SetHashNext(NULL); + pItem->SetHashNext(nullptr); return pItem; } } - return NULL; + return nullptr; } }; @@ -211,7 +211,7 @@ public: int hash = CalcHash(key); Slot &slot = m_slots[hash]; Titem_ *item = slot.Detach(key); - if (item != NULL) { + if (item != nullptr) { m_num_items--; } return item; @@ -221,7 +221,7 @@ public: Titem_& Pop(const Tkey &key) { Titem_ *item = TryPop(key); - assert(item != NULL); + assert(item != nullptr); return *item; } @@ -250,7 +250,7 @@ public: { int hash = CalcHash(new_item); Slot &slot = m_slots[hash]; - assert(slot.Find(new_item.GetKey()) == NULL); + assert(slot.Find(new_item.GetKey()) == nullptr); slot.Attach(new_item); m_num_items++; } |