Change some Asserts to DbgAssert

This commit is contained in:
s1lentq 2023-12-14 02:54:32 +07:00
parent f97c9d9f46
commit 4928c56f21
5 changed files with 34 additions and 34 deletions

View File

@ -144,28 +144,28 @@ inline const T *CUtlArray<T, MAX_SIZE>::Base() const
template <typename T, size_t MAX_SIZE> template <typename T, size_t MAX_SIZE>
inline T &CUtlArray<T, MAX_SIZE>::operator[](int i) inline T &CUtlArray<T, MAX_SIZE>::operator[](int i)
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
return m_Memory[i]; return m_Memory[i];
} }
template <typename T, size_t MAX_SIZE> template <typename T, size_t MAX_SIZE>
inline const T &CUtlArray<T, MAX_SIZE>::operator[](int i) const inline const T &CUtlArray<T, MAX_SIZE>::operator[](int i) const
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
return m_Memory[i]; return m_Memory[i];
} }
template <typename T, size_t MAX_SIZE> template <typename T, size_t MAX_SIZE>
inline T &CUtlArray<T, MAX_SIZE>::Element(int i) inline T &CUtlArray<T, MAX_SIZE>::Element(int i)
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
return m_Memory[i]; return m_Memory[i];
} }
template <typename T, size_t MAX_SIZE> template <typename T, size_t MAX_SIZE>
inline const T &CUtlArray<T, MAX_SIZE>::Element(int i) const inline const T &CUtlArray<T, MAX_SIZE>::Element(int i) const
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
return m_Memory[i]; return m_Memory[i];
} }
@ -251,7 +251,7 @@ void CUtlArray<T, MAX_SIZE>::SortPredicate(F &&predicate)
template <typename T, size_t MAX_SIZE> template <typename T, size_t MAX_SIZE>
void CUtlArray<T, MAX_SIZE>::CopyArray(const T *pArray, size_t count) void CUtlArray<T, MAX_SIZE>::CopyArray(const T *pArray, size_t count)
{ {
Assert(count < MAX_SIZE); DbgAssert(count < MAX_SIZE);
for (size_t n = 0; n < count; n++) for (size_t n = 0; n < count; n++)
m_Memory[n] = pArray[n]; m_Memory[n] = pArray[n];

View File

@ -248,14 +248,14 @@ inline I CUtlLinkedList<T, I>::Tail() const
template <class T, class I> template <class T, class I>
inline I CUtlLinkedList<T, I>::Previous(I i) const inline I CUtlLinkedList<T, I>::Previous(I i) const
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
return InternalElement(i).m_Previous; return InternalElement(i).m_Previous;
} }
template <class T, class I> template <class T, class I>
inline I CUtlLinkedList<T, I>::Next(I i) const inline I CUtlLinkedList<T, I>::Next(I i) const
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
return InternalElement(i).m_Next; return InternalElement(i).m_Next;
} }
@ -319,7 +319,7 @@ I CUtlLinkedList<T, I>::AllocInternal(bool multilist)
if (m_TotalElements == m_Memory.NumAllocated()) if (m_TotalElements == m_Memory.NumAllocated())
m_Memory.Grow(); m_Memory.Grow();
Assert(m_TotalElements != InvalidIndex()); DbgAssert(m_TotalElements != InvalidIndex());
elem = (I)m_TotalElements; elem = (I)m_TotalElements;
m_TotalElements++; m_TotalElements++;
@ -356,7 +356,7 @@ I CUtlLinkedList<T, I>::Alloc(bool multilist)
template <class T, class I> template <class T, class I>
void CUtlLinkedList<T, I>::Free(I elem) void CUtlLinkedList<T, I>::Free(I elem)
{ {
Assert(IsValidIndex(elem)); DbgAssert(IsValidIndex(elem));
Unlink(elem); Unlink(elem);
ListElem_t &internalElem = InternalElement(elem); ListElem_t &internalElem = InternalElement(elem);
@ -520,7 +520,7 @@ void CUtlLinkedList<T, I>::RemoveAll()
template <class T, class I> template <class T, class I>
void CUtlLinkedList<T, I>::LinkBefore(I before, I elem) void CUtlLinkedList<T, I>::LinkBefore(I before, I elem)
{ {
Assert(IsValidIndex(elem)); DbgAssert(IsValidIndex(elem));
// Unlink it if it's in the list at the moment // Unlink it if it's in the list at the moment
Unlink(elem); Unlink(elem);
@ -540,7 +540,7 @@ void CUtlLinkedList<T, I>::LinkBefore(I before, I elem)
{ {
// Here, we're not linking to the end. Set the prev pointer to point to // Here, we're not linking to the end. Set the prev pointer to point to
// the element we're linking. // the element we're linking.
Assert(IsInList(before)); DbgAssert(IsInList(before));
ListElem_t& beforeElem = InternalElement(before); ListElem_t& beforeElem = InternalElement(before);
newElem.m_Previous = beforeElem.m_Previous; newElem.m_Previous = beforeElem.m_Previous;
beforeElem.m_Previous = elem; beforeElem.m_Previous = elem;
@ -559,7 +559,7 @@ void CUtlLinkedList<T, I>::LinkBefore(I before, I elem)
template <class T, class I> template <class T, class I>
void CUtlLinkedList<T, I>::LinkAfter(I after, I elem) void CUtlLinkedList<T, I>::LinkAfter(I after, I elem)
{ {
Assert(IsValidIndex(elem)); DbgAssert(IsValidIndex(elem));
// Unlink it if it's in the list at the moment // Unlink it if it's in the list at the moment
if (IsInList(elem)) if (IsInList(elem))
@ -579,7 +579,7 @@ void CUtlLinkedList<T, I>::LinkAfter(I after, I elem)
{ {
// Here, we're not linking to the end. Set the next pointer to point to // Here, we're not linking to the end. Set the next pointer to point to
// the element we're linking. // the element we're linking.
Assert(IsInList(after)); DbgAssert(IsInList(after));
ListElem_t& afterElem = InternalElement(after); ListElem_t& afterElem = InternalElement(after);
newElem.m_Next = afterElem.m_Next; newElem.m_Next = afterElem.m_Next;
afterElem.m_Next = elem; afterElem.m_Next = elem;
@ -598,7 +598,7 @@ void CUtlLinkedList<T, I>::LinkAfter(I after, I elem)
template <class T, class I> template <class T, class I>
void CUtlLinkedList<T, I>::Unlink(I elem) void CUtlLinkedList<T, I>::Unlink(I elem)
{ {
Assert(IsValidIndex(elem)); DbgAssert(IsValidIndex(elem));
if (IsInList(elem)) if (IsInList(elem))
{ {
ListElem_t *pBase = m_Memory.Base(); ListElem_t *pBase = m_Memory.Base();

View File

@ -250,7 +250,7 @@ inline void CUtlMap<K, T, I>::PurgeAndDeleteElements()
template <typename K, typename T, typename I> template <typename K, typename T, typename I>
void DeepCopyMap(const CUtlMap<K, T, I> &pmapIn, CUtlMap<K, T, I> *out_pmapOut) void DeepCopyMap(const CUtlMap<K, T, I> &pmapIn, CUtlMap<K, T, I> *out_pmapOut)
{ {
Assert(out_pmapOut); DbgAssert(out_pmapOut);
out_pmapOut->Purge(); out_pmapOut->Purge();
FOR_EACH_MAP_FAST(pmapIn, i) FOR_EACH_MAP_FAST(pmapIn, i)

View File

@ -121,7 +121,7 @@ template <class T, class I>
CUtlMemory<T, I>::CUtlMemory(int nGrowSize, int nInitSize) : m_pMemory(0), CUtlMemory<T, I>::CUtlMemory(int nGrowSize, int nInitSize) : m_pMemory(0),
m_nAllocationCount(nInitSize), m_nGrowSize(nGrowSize) m_nAllocationCount(nInitSize), m_nGrowSize(nGrowSize)
{ {
Assert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER)); DbgAssert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER));
if (m_nAllocationCount) if (m_nAllocationCount)
{ {
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T)); m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
@ -149,7 +149,7 @@ void CUtlMemory<T,I>::Init(int nGrowSize, int nInitSize)
m_nGrowSize = nGrowSize; m_nGrowSize = nGrowSize;
m_nAllocationCount = nInitSize; m_nAllocationCount = nInitSize;
Assert(nGrowSize >= 0); DbgAssert(nGrowSize >= 0);
if (m_nAllocationCount) if (m_nAllocationCount)
{ {
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T)); m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
@ -174,28 +174,28 @@ void CUtlMemory<T, I>::SetExternalBuffer(T *pMemory, int numElements)
template <class T, class I> template <class T, class I>
inline T& CUtlMemory<T, I>::operator[](I i) inline T& CUtlMemory<T, I>::operator[](I i)
{ {
Assert(IsIdxValid(i)); DbgAssert(IsIdxValid(i));
return m_pMemory[i]; return m_pMemory[i];
} }
template <class T, class I> template <class T, class I>
inline T const& CUtlMemory<T, I>::operator[](I i) const inline T const& CUtlMemory<T, I>::operator[](I i) const
{ {
Assert(IsIdxValid(i)); DbgAssert(IsIdxValid(i));
return m_pMemory[i]; return m_pMemory[i];
} }
template <class T, class I> template <class T, class I>
inline T& CUtlMemory<T, I>::Element(I i) inline T& CUtlMemory<T, I>::Element(I i)
{ {
Assert(IsIdxValid(i)); DbgAssert(IsIdxValid(i));
return m_pMemory[i]; return m_pMemory[i];
} }
template <class T, class I> template <class T, class I>
inline T const& CUtlMemory<T, I>::Element(I i) const inline T const& CUtlMemory<T, I>::Element(I i) const
{ {
Assert(IsIdxValid(i)); DbgAssert(IsIdxValid(i));
return m_pMemory[i]; return m_pMemory[i];
} }
@ -209,7 +209,7 @@ bool CUtlMemory<T, I>::IsExternallyAllocated() const
template <class T, class I> template <class T, class I>
void CUtlMemory<T, I>::SetGrowSize(int nSize) void CUtlMemory<T, I>::SetGrowSize(int nSize)
{ {
Assert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER)); DbgAssert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER));
m_nGrowSize = nSize; m_nGrowSize = nSize;
} }
@ -250,12 +250,12 @@ inline bool CUtlMemory<T, I>::IsIdxValid(I i) const
template <class T, class I> template <class T, class I>
void CUtlMemory<T, I>::Grow(int num) void CUtlMemory<T, I>::Grow(int num)
{ {
Assert(num > 0); DbgAssert(num > 0);
if (IsExternallyAllocated()) if (IsExternallyAllocated())
{ {
// Can't grow a buffer whose memory was externally allocated // Can't grow a buffer whose memory was externally allocated
Assert(0); DbgAssert(0);
return; return;
} }
@ -281,7 +281,7 @@ void CUtlMemory<T, I>::Grow(int num)
{ {
// Compute an allocation which is at least as big as a cache line... // Compute an allocation which is at least as big as a cache line...
m_nAllocationCount = (31 + sizeof(T)) / sizeof(T); m_nAllocationCount = (31 + sizeof(T)) / sizeof(T);
Assert(m_nAllocationCount != 0); DbgAssert(m_nAllocationCount != 0);
} }
} }
@ -305,7 +305,7 @@ inline void CUtlMemory<T, I>::EnsureCapacity(int num)
if (IsExternallyAllocated()) if (IsExternallyAllocated())
{ {
// Can't grow a buffer whose memory was externally allocated // Can't grow a buffer whose memory was externally allocated
Assert(0); DbgAssert(0);
return; return;
} }

View File

@ -398,7 +398,7 @@ inline typename CUtlRBTree<T, I, L, M>::Links_t const &CUtlRBTree<T, I, L, M>::L
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
inline typename CUtlRBTree<T, I, L, M>::Links_t &CUtlRBTree<T, I, L, M>::Links(I i) inline typename CUtlRBTree<T, I, L, M>::Links_t &CUtlRBTree<T, I, L, M>::Links(I i)
{ {
Assert(i != InvalidIndex()); DbgAssert(i != InvalidIndex());
return *(Links_t *)&m_Elements[i]; return *(Links_t *)&m_Elements[i];
} }
@ -460,7 +460,7 @@ I CUtlRBTree<T, I, L, M>::NewNode()
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
void CUtlRBTree<T, I, L, M>::FreeNode(I i) void CUtlRBTree<T, I, L, M>::FreeNode(I i)
{ {
Assert(IsValidIndex(i) && (i != InvalidIndex())); DbgAssert(IsValidIndex(i) && (i != InvalidIndex()));
Destruct(&Element(i)); Destruct(&Element(i));
SetLeftChild(i, i); // indicates it's in not in the tree SetLeftChild(i, i); // indicates it's in not in the tree
SetRightChild(i, m_FirstFree); SetRightChild(i, m_FirstFree);
@ -624,7 +624,7 @@ void CUtlRBTree<T, I, L, M>::LinkToParent(I i, I parent, bool isLeft)
InsertRebalance(i); InsertRebalance(i);
Assert(IsValid()); DbgAssert(IsValid());
} }
// Rebalance the tree after a deletion // Rebalance the tree after a deletion
@ -872,7 +872,7 @@ I CUtlRBTree<T, I, L, M>::FirstInorder() const
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
I CUtlRBTree<T, I, L, M>::NextInorder(I i) const I CUtlRBTree<T, I, L, M>::NextInorder(I i) const
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
if (RightChild(i) != InvalidIndex()) if (RightChild(i) != InvalidIndex())
{ {
@ -895,7 +895,7 @@ I CUtlRBTree<T, I, L, M>::NextInorder(I i) const
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
I CUtlRBTree<T, I, L, M>::PrevInorder(I i) const I CUtlRBTree<T, I, L, M>::PrevInorder(I i) const
{ {
Assert(IsValidIndex(i)); DbgAssert(IsValidIndex(i));
if (LeftChild(i) != InvalidIndex()) if (LeftChild(i) != InvalidIndex())
{ {
@ -953,7 +953,7 @@ I CUtlRBTree<T, I, L, M>::NextPreorder(I i) const
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
I CUtlRBTree<T, I, L, M>::PrevPreorder(I i) const I CUtlRBTree<T, I, L, M>::PrevPreorder(I i) const
{ {
Assert(0); // Not implemented yet DbgAssert(0); // Not implemented yet
return InvalidIndex(); return InvalidIndex();
} }
@ -1120,7 +1120,7 @@ void CUtlRBTree<T, I, L, M>::SetLessFunc(typename CUtlRBTree<T, I, L, M>::LessFu
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
void CUtlRBTree<T, I, L, M>::FindInsertionPosition(T const &insert, I &parent, bool &leftchild) void CUtlRBTree<T, I, L, M>::FindInsertionPosition(T const &insert, I &parent, bool &leftchild)
{ {
Assert(m_LessFunc); DbgAssert(m_LessFunc);
// Find where node belongs // Find where node belongs
I current = m_Root; I current = m_Root;
@ -1167,7 +1167,7 @@ void CUtlRBTree<T, I, L, M>::Insert(const T *pArray, int nItems)
template <class T, class I, typename L, class M> template <class T, class I, typename L, class M>
I CUtlRBTree<T, I, L, M>::Find(T const &search) const I CUtlRBTree<T, I, L, M>::Find(T const &search) const
{ {
Assert(m_LessFunc); DbgAssert(m_LessFunc);
I current = m_Root; I current = m_Root;
while (current != InvalidIndex()) while (current != InvalidIndex())