1
0
forked from 0ad/0ad

replace NULL by nullptr

remove nullptr check before delete. They are redundant.
remove nullptr check after new. They will never be null.
two whitespaces changes forgotten in
https://code.wildfiregames.com/D4800.

Patch by: @phosit
Differential Revision: https://code.wildfiregames.com/D4853
This was SVN commit r27351.
This commit is contained in:
Stan 2023-01-05 12:09:02 +00:00
parent ce9fb7a0b2
commit c729444787

View File

@ -28,7 +28,7 @@
CFsmEvent::CFsmEvent(unsigned int type) CFsmEvent::CFsmEvent(unsigned int type)
{ {
m_Type = type; m_Type = type;
m_Param = NULL; m_Param = nullptr;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -37,7 +37,7 @@ CFsmEvent::CFsmEvent(unsigned int type)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CFsmEvent::~CFsmEvent() CFsmEvent::~CFsmEvent()
{ {
m_Param = NULL; m_Param = nullptr;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -123,7 +123,7 @@ void CFsmTransition::SetNextState(unsigned int nextState)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool CFsmTransition::ApplyConditions() const bool CFsmTransition::ApplyConditions() const
{ {
bool eval = true; bool eval = true;
CallbackList::const_iterator it = m_Conditions.begin(); CallbackList::const_iterator it = m_Conditions.begin();
for (; it != m_Conditions.end(); ++it) for (; it != m_Conditions.end(); ++it)
@ -201,24 +201,12 @@ void CFsm::Shutdown()
// Release transitions // Release transitions
TransitionList::iterator itTransition = m_Transitions.begin(); TransitionList::iterator itTransition = m_Transitions.begin();
for (; itTransition < m_Transitions.end(); ++itTransition) for (; itTransition < m_Transitions.end(); ++itTransition)
{ delete *itTransition;
CFsmTransition* pCurrTransition = *itTransition;
if (!pCurrTransition)
continue;
delete pCurrTransition;
}
// Release events // Release events
EventMap::iterator itEvent = m_Events.begin(); EventMap::iterator itEvent = m_Events.begin();
for (; itEvent != m_Events.end(); ++itEvent) for (; itEvent != m_Events.end(); ++itEvent)
{ delete itEvent->second;
CFsmEvent* pCurrEvent = itEvent->second;
if (!pCurrEvent)
continue;
delete pCurrEvent;
}
m_States.clear(); m_States.clear();
m_Events.clear(); m_Events.clear();
@ -247,7 +235,7 @@ void CFsm::AddState(unsigned int state)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CFsmEvent* CFsm::AddEvent(unsigned int eventType) CFsmEvent* CFsm::AddEvent(unsigned int eventType)
{ {
CFsmEvent* pEvent = NULL; CFsmEvent* pEvent = nullptr;
// Lookup event by type // Lookup event by type
EventMap::iterator it = m_Events.find(eventType); EventMap::iterator it = m_Events.find(eventType);
@ -258,8 +246,6 @@ CFsmEvent* CFsm::AddEvent(unsigned int eventType)
else else
{ {
pEvent = new CFsmEvent(eventType); pEvent = new CFsmEvent(eventType);
if (!pEvent)
return NULL;
// Store new event into internal map // Store new event into internal map
m_Events[eventType] = pEvent; m_Events[eventType] = pEvent;
@ -283,15 +269,10 @@ CFsmTransition* CFsm::AddTransition(unsigned int state, unsigned int eventType,
// Make sure we store the event // Make sure we store the event
CFsmEvent* pEvent = AddEvent(eventType); CFsmEvent* pEvent = AddEvent(eventType);
if (!pEvent) if (!pEvent)
return NULL; return nullptr;
// Create new transition // Create new transition
CFsmTransition* pNewTransition = new CFsmTransition(state); CFsmTransition* pNewTransition = new CFsmTransition(state);
if (!pNewTransition)
{
delete pEvent;
return NULL;
}
// Setup new transition // Setup new transition
pNewTransition->SetEvent(pEvent); pNewTransition->SetEvent(pEvent);
@ -312,7 +293,7 @@ CFsmTransition* CFsm::AddTransition(unsigned int state, unsigned int eventType,
{ {
CFsmTransition* pTransition = AddTransition(state, eventType, nextState); CFsmTransition* pTransition = AddTransition(state, eventType, nextState);
if (!pTransition) if (!pTransition)
return NULL; return nullptr;
// If action specified, register it // If action specified, register it
if (pAction) if (pAction)
@ -329,18 +310,18 @@ CFsmTransition* CFsm::GetTransition(unsigned int state, unsigned int eventType)
{ {
// Valid state? // Valid state?
if (!IsValidState(state)) if (!IsValidState(state))
return NULL; return nullptr;
// Valid event? // Valid event?
if (!IsValidEvent(eventType)) if (!IsValidEvent(eventType))
return NULL; return nullptr;
// Loop through the list of transitions // Loop through the list of transitions
TransitionList::const_iterator it = m_Transitions.begin(); TransitionList::const_iterator it = m_Transitions.begin();
for (; it != m_Transitions.end(); ++it) for (; it != m_Transitions.end(); ++it)
{ {
CFsmTransition* pCurrTransition = *it; CFsmTransition* pCurrTransition = *it;
if ( !pCurrTransition ) if (!pCurrTransition)
continue; continue;
CFsmEvent* pCurrEvent = pCurrTransition->GetEvent(); CFsmEvent* pCurrEvent = pCurrTransition->GetEvent();
@ -353,7 +334,7 @@ CFsmTransition* CFsm::GetTransition(unsigned int state, unsigned int eventType)
} }
// No transition found // No transition found
return NULL; return nullptr;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------