Skip to content

Commit

Permalink
Update NULL to nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
xcyle-gh committed Oct 8, 2016
1 parent 459709d commit a5612c6
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 97 deletions.
36 changes: 18 additions & 18 deletions CommonUtilitiesLib/OSHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ OSHeap::OSHeap(UInt32 inStartSize)

void OSHeap::Insert(OSHeapElem* inElem)
{
Assert(inElem != NULL);
Assert(inElem != nullptr);

if ((fHeap == NULL) || (fFreeIndex == fArraySize))
if ((fHeap == nullptr) || (fFreeIndex == fArraySize))
{
fArraySize *= 2;
OSHeapElem** tempArray = NEW OSHeapElem*[fArraySize];
if ((fHeap != NULL) && (fFreeIndex > 1))
if ((fHeap != nullptr) && (fFreeIndex > 1))
memcpy(tempArray, fHeap, sizeof(OSHeapElem*) * fFreeIndex);

delete[] fHeap;
fHeap = tempArray;
}

Assert(fHeap != NULL);
Assert(inElem->fCurrentHeap == NULL);
Assert(fHeap != nullptr);
Assert(inElem->fCurrentHeap == nullptr);
Assert(fArraySize > fFreeIndex);

#if _OSHEAP_TESTING_
Expand Down Expand Up @@ -103,8 +103,8 @@ void OSHeap::Insert(OSHeapElem* inElem)

OSHeapElem* OSHeap::extract(UInt32 inIndex)
{
if ((fHeap == NULL) || (fFreeIndex <= inIndex))
return NULL;
if ((fHeap == nullptr) || (fFreeIndex <= inIndex))
return nullptr;

#if _OSHEAP_TESTING_
sanityCheck(1);
Expand All @@ -113,7 +113,7 @@ OSHeapElem* OSHeap::extract(UInt32 inIndex)
//store a reference to the element we want to extract
OSHeapElem* victim = fHeap[inIndex];
Assert(victim->fCurrentHeap == this);
victim->fCurrentHeap = NULL;
victim->fCurrentHeap = nullptr;

//but now we need to preserve this heuristic. We do this by taking
//the last leaf, putting it at the empty position, then heapifying that chain
Expand Down Expand Up @@ -158,8 +158,8 @@ OSHeapElem* OSHeap::extract(UInt32 inIndex)

OSHeapElem* OSHeap::Remove(OSHeapElem* elem)
{
if ((fHeap == NULL) || (fFreeIndex == 1))
return NULL;
if ((fHeap == nullptr) || (fFreeIndex == 1))
return nullptr;

#if _OSHEAP_TESTING_
sanityCheck(1);
Expand All @@ -173,7 +173,7 @@ OSHeapElem* OSHeap::Remove(OSHeapElem* elem)

//either we've found it, or this is a bogus element
if (theIndex == fFreeIndex)
return NULL;
return nullptr;

return extract(theIndex);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ bool OSHeap::Test()
OSHeapElem elem9;

OSHeapElem* max = victim.ExtractMin();
if (max != NULL)
if (max != nullptr)
return false;

elem1.SetValue(100);
Expand All @@ -224,7 +224,7 @@ bool OSHeap::Test()
if (max != &elem1)
return false;
max = victim.ExtractMin();
if (max != NULL)
if (max != nullptr)
return false;

elem1.SetValue(100);
Expand All @@ -240,7 +240,7 @@ bool OSHeap::Test()
if (max != &elem1)
return false;
max = victim.ExtractMin();
if (max != NULL)
if (max != nullptr)
return false;

victim.Insert(&elem2);
Expand Down Expand Up @@ -369,7 +369,7 @@ bool OSHeap::Test()
if (max != &elem1)
return false;
max = victim.ExtractMin();
if (max != NULL)
if (max != nullptr)
return false;

victim.Insert(&elem1);
Expand All @@ -395,10 +395,10 @@ bool OSHeap::Test()
if (max != &elem2)
return false;
max = victim.Remove(&elem2);
if (max != NULL)
if (max != nullptr)
return false;
max = victim.Remove(&elem8);
if (max != NULL)
if (max != nullptr)
return false;
max = victim.Remove(&elem5);
if (max != &elem5)
Expand All @@ -413,7 +413,7 @@ bool OSHeap::Test()
if (max != &elem4)
return false;
max = victim.Remove(&elem1);
if (max != NULL)
if (max != nullptr)
return false;

return true;
Expand Down
10 changes: 5 additions & 5 deletions CommonUtilitiesLib/OSHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class OSHeap
};

OSHeap(UInt32 inStartSize = kDefaultStartSize);
~OSHeap() { if (fHeap != NULL) delete fHeap; }
~OSHeap() { if (fHeap != nullptr) delete fHeap; }

//ACCESSORS
UInt32 CurrentHeapSize() { return fFreeIndex - 1; }
OSHeapElem* PeekMin() { if (CurrentHeapSize() > 0) return fHeap[1]; return NULL; }
OSHeapElem* PeekMin() { if (CurrentHeapSize() > 0) return fHeap[1]; return nullptr; }

//MODIFIERS

Expand Down Expand Up @@ -86,8 +86,8 @@ class OSHeap
class OSHeapElem
{
public:
OSHeapElem(void* enclosingObject = NULL)
: fValue(0), fEnclosingObject(enclosingObject), fCurrentHeap(NULL) {}
OSHeapElem(void* enclosingObject = nullptr)
: fValue(0), fEnclosingObject(enclosingObject), fCurrentHeap(nullptr) {}
~OSHeapElem() {}

//This data structure emphasizes performance over extensibility
Expand All @@ -99,7 +99,7 @@ class OSHeapElem
SInt64 GetValue() { return fValue; }
void* GetEnclosingObject() { return fEnclosingObject; }
void SetEnclosingObject(void* obj) { fEnclosingObject = obj; }
bool IsMemberOfAnyHeap() { return fCurrentHeap != NULL; }
bool IsMemberOfAnyHeap() { return fCurrentHeap != nullptr; }

private:

Expand Down
22 changes: 11 additions & 11 deletions CommonUtilitiesLib/OSMutexRW.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class OSMutexRW
inline void removeActiveReader() { adjustState(-1); };


inline bool waitingWriters() { return (bool)(fWriteWaiters > 0); }
inline bool waitingReaders() { return (bool)(fReadWaiters > 0); }
inline bool active() { return (bool)(fState != 0); }
inline bool activeReaders() { return (bool)(fState > 0); }
inline bool activeWriter() { return (bool)(fState < 0); } // only one
inline bool waitingWriters() { return fWriteWaiters > 0; }
inline bool waitingReaders() { return fReadWaiters > 0; }
inline bool active() { return fState != 0; }
inline bool activeReaders() { return fState > 0; }
inline bool activeWriter() { return fState < 0; } // only one

#if DEBUGMUTEXRW
static int fCount, fMaxCount;
Expand All @@ -105,10 +105,10 @@ class OSMutexReadWriteLocker
{
public:
OSMutexReadWriteLocker(OSMutexRW *inMutexPtr) : fRWMutexPtr(inMutexPtr) {};
~OSMutexReadWriteLocker() { if (fRWMutexPtr != NULL) fRWMutexPtr->Unlock(); }
~OSMutexReadWriteLocker() { if (fRWMutexPtr != nullptr) fRWMutexPtr->Unlock(); }


void UnLock() { if (fRWMutexPtr != NULL) fRWMutexPtr->Unlock(); }
void UnLock() { if (fRWMutexPtr != nullptr) fRWMutexPtr->Unlock(); }
void SetMutex(OSMutexRW *mutexPtr) { fRWMutexPtr = mutexPtr; }
OSMutexRW* fRWMutexPtr;
};
Expand All @@ -117,16 +117,16 @@ class OSMutexReadLocker : public OSMutexReadWriteLocker
{
public:

OSMutexReadLocker(OSMutexRW *inMutexPtr) : OSMutexReadWriteLocker(inMutexPtr) { if (OSMutexReadWriteLocker::fRWMutexPtr != NULL) OSMutexReadWriteLocker::fRWMutexPtr->LockRead(); }
void Lock() { if (OSMutexReadWriteLocker::fRWMutexPtr != NULL) OSMutexReadWriteLocker::fRWMutexPtr->LockRead(); }
OSMutexReadLocker(OSMutexRW *inMutexPtr) : OSMutexReadWriteLocker(inMutexPtr) { if (OSMutexReadWriteLocker::fRWMutexPtr != nullptr) OSMutexReadWriteLocker::fRWMutexPtr->LockRead(); }
void Lock() { if (OSMutexReadWriteLocker::fRWMutexPtr != nullptr) OSMutexReadWriteLocker::fRWMutexPtr->LockRead(); }
};

class OSMutexWriteLocker : public OSMutexReadWriteLocker
{
public:

OSMutexWriteLocker(OSMutexRW *inMutexPtr) : OSMutexReadWriteLocker(inMutexPtr) { if (OSMutexReadWriteLocker::fRWMutexPtr != NULL) OSMutexReadWriteLocker::fRWMutexPtr->LockWrite(); }
void Lock() { if (OSMutexReadWriteLocker::fRWMutexPtr != NULL) OSMutexReadWriteLocker::fRWMutexPtr->LockWrite(); }
OSMutexWriteLocker(OSMutexRW *inMutexPtr) : OSMutexReadWriteLocker(inMutexPtr) { if (OSMutexReadWriteLocker::fRWMutexPtr != nullptr) OSMutexReadWriteLocker::fRWMutexPtr->LockWrite(); }
void Lock() { if (OSMutexReadWriteLocker::fRWMutexPtr != nullptr) OSMutexReadWriteLocker::fRWMutexPtr->LockWrite(); }

};

Expand Down
26 changes: 13 additions & 13 deletions CommonUtilitiesLib/OSQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ void OSQueue::EnQueue(OSQueueElem* elem)
{
OSMutexLocker theLocker(&fMutex);

Assert(elem != NULL);
Assert(elem != nullptr);
if (elem->fQueue == this)
return;
Assert(elem->fQueue == NULL);
Assert(elem->fQueue == nullptr);
elem->fNext = fSentinel.fNext;
elem->fPrev = &fSentinel;
elem->fQueue = this;
Expand All @@ -64,26 +64,26 @@ OSQueueElem* OSQueue::DeQueue()
Assert(fSentinel.fPrev != &fSentinel);
elem->fPrev->fNext = &fSentinel;
fSentinel.fPrev = elem->fPrev;
elem->fQueue = NULL;
elem->fQueue = nullptr;
fLength--;
return elem;
}

return NULL;
return nullptr;
}

void OSQueue::Remove(OSQueueElem* elem)
{
OSMutexLocker theLocker(&fMutex);

Assert(elem != NULL);
Assert(elem != nullptr);
Assert(elem != &fSentinel);

if (elem->fQueue == this)
{
elem->fNext->fPrev = elem->fPrev;
elem->fPrev->fNext = elem->fNext;
elem->fQueue = NULL;
elem->fQueue = nullptr;
fLength--;
}
}
Expand All @@ -99,9 +99,9 @@ bool OSQueue::Test()
x = (void*)3;
OSQueueElem theElem3(x);

if (theVictim.GetHead() != NULL)
if (theVictim.GetHead() != nullptr)
return false;
if (theVictim.GetTail() != NULL)
if (theVictim.GetTail() != nullptr)
return false;

theVictim.EnQueue(&theElem1);
Expand All @@ -114,9 +114,9 @@ bool OSQueue::Test()
if (theElem != &theElem1)
return false;

if (theVictim.GetHead() != NULL)
if (theVictim.GetHead() != nullptr)
return false;
if (theVictim.GetTail() != NULL)
if (theVictim.GetTail() != nullptr)
return false;

theVictim.EnQueue(&theElem1);
Expand Down Expand Up @@ -193,7 +193,7 @@ bool OSQueue::Test()
theIterVictim.Next();
if (!theIterVictim.IsDone())
return false;
if (theIterVictim.GetCurrent() != NULL)
if (theIterVictim.GetCurrent() != nullptr)
return false;

theVictim.Remove(&theElem1);
Expand Down Expand Up @@ -226,7 +226,7 @@ bool OSQueue::Test()
void OSQueueIter::Next()
{
if (fCurrentElemP == fQueueP->GetTail())
fCurrentElemP = NULL;
fCurrentElemP = nullptr;
else
fCurrentElemP = fCurrentElemP->Prev();
}
Expand All @@ -239,7 +239,7 @@ OSQueueElem* OSQueue_Blocking::DeQueueBlocking(OSThread* inCurThread, SInt32 inT
if (fQueue.GetLength() == 0)
{
fCond.Wait(&fMutex, inTimeoutInMilSecs);
return NULL;
return nullptr;
}
#else
if (fQueue.GetLength() == 0)
Expand Down
16 changes: 8 additions & 8 deletions CommonUtilitiesLib/OSQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class OSQueue;

class OSQueueElem {
public:
OSQueueElem(void* enclosingObject = NULL) : fNext(NULL), fPrev(NULL), fQueue(NULL),
OSQueueElem(void* enclosingObject = nullptr) : fNext(nullptr), fPrev(nullptr), fQueue(nullptr),
fEnclosingObject(enclosingObject) {}
virtual ~OSQueueElem() { Assert(fQueue == NULL); }
virtual ~OSQueueElem() { Assert(fQueue == nullptr); }

bool IsMember(const OSQueue& queue) { return (&queue == fQueue); }
bool IsMemberOfAnyQueue() { return fQueue != NULL; }
bool IsMemberOfAnyQueue() { return fQueue != nullptr; }
void* GetEnclosingObject() { return fEnclosingObject; }
void SetEnclosingObject(void* obj) { fEnclosingObject = obj; }

Expand All @@ -77,8 +77,8 @@ class OSQueue {
void EnQueue(OSQueueElem* object);
OSQueueElem* DeQueue();

OSQueueElem* GetHead() { if (fLength > 0) return fSentinel.fPrev; return NULL; }
OSQueueElem* GetTail() { if (fLength > 0) return fSentinel.fNext; return NULL; }
OSQueueElem* GetHead() { if (fLength > 0) return fSentinel.fPrev; return nullptr; }
OSQueueElem* GetTail() { if (fLength > 0) return fSentinel.fNext; return nullptr; }
UInt32 GetLength() { return fLength; }

void Remove(OSQueueElem* object);
Expand Down Expand Up @@ -107,7 +107,7 @@ class OSQueueIter

}
else
fCurrentElemP = NULL;
fCurrentElemP = nullptr;
}
~OSQueueIter() {}

Expand All @@ -116,7 +116,7 @@ class OSQueueIter
OSQueueElem* GetCurrent() { return fCurrentElemP; }
void Next();

bool IsDone() { return fCurrentElemP == NULL; }
bool IsDone() { return fCurrentElemP == nullptr; }

private:

Expand Down Expand Up @@ -147,7 +147,7 @@ class OSQueue_Blocking

void OSQueueElem::Remove()
{
if (fQueue != NULL)
if (fQueue != nullptr)
fQueue->Remove(this);
}
#endif //_OSQUEUE_H_
Loading

0 comments on commit a5612c6

Please sign in to comment.