// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION // // This software is supplied under the terms of a license agreement or // nondisclosure agreement with Emergent Game Technologies and may not // be copied or disclosed except in accordance with the terms of that // agreement. // // Copyright (c) 1996-2007 Emergent Game Technologies. // All Rights Reserved. // // Emergent Game Technologies, Chapel Hill, North Carolina 27517 // http://www.emergent.net //--------------------------------------------------------------------------- // NiTSet inline functions //--------------------------------------------------------------------------- template inline NiTSet::NiTSet(unsigned int uiInitialSize) { if (uiInitialSize > 0) { m_pBase = TAlloc::Allocate(uiInitialSize); NIASSERT(m_pBase != NULL); } else { m_pBase = NULL; } m_uiAlloced = uiInitialSize; m_uiUsed = 0; } //--------------------------------------------------------------------------- template inline NiTSet::~NiTSet() { TAlloc::Deallocate(m_pBase); } //--------------------------------------------------------------------------- template inline unsigned int NiTSet::GetSize() const { return m_uiUsed; } //--------------------------------------------------------------------------- template inline T* NiTSet::GetBase() const { return m_pBase; } //--------------------------------------------------------------------------- template inline const T& NiTSet::GetAt(unsigned int uiIndex) const { NIASSERT(uiIndex < m_uiUsed); return m_pBase[uiIndex]; } //--------------------------------------------------------------------------- template inline T& NiTSet::GetAt(unsigned int uiIndex) { NIASSERT(uiIndex < m_uiUsed); return m_pBase[uiIndex]; } //--------------------------------------------------------------------------- template inline void NiTSet::Add(const T& element) { NIASSERT(m_uiUsed <= m_uiAlloced); if (m_uiUsed == m_uiAlloced) { Realloc(m_uiAlloced > 0 ? (2 * m_uiAlloced) : 1); } NIASSERT(m_uiUsed < m_uiAlloced); m_pBase[m_uiUsed++] = element; } //--------------------------------------------------------------------------- template inline void NiTSet::AddUnique(const T& element) { NIASSERT(m_uiUsed <= m_uiAlloced); if (Find(element) == -1) { Add(element); } } //--------------------------------------------------------------------------- template inline int NiTSet::Find(const T& element) const { // If the element is in the list, the index is returned, else -1. NIASSERT(m_uiUsed <= m_uiAlloced); unsigned int i; for (i = 0; i < m_uiUsed; i++) { if (m_pBase[i] == element) return i; } return -1; } //--------------------------------------------------------------------------- template inline void NiTSet::RemoveAt(unsigned int uiIndex) { NIASSERT(uiIndex < m_uiUsed); m_pBase[uiIndex] = m_pBase[--m_uiUsed]; } //--------------------------------------------------------------------------- template inline void NiTSet::OrderedRemoveAt(unsigned int uiIndex) { NIASSERT(uiIndex < m_uiUsed); for (unsigned int ui = uiIndex; ui < m_uiUsed - 1; ui++) { m_pBase[ui] = m_pBase[ui + 1]; } m_uiUsed--; } //--------------------------------------------------------------------------- template inline void NiTSet::ReplaceAt(unsigned int uiIndex, const T& element) { if (uiIndex >= m_uiUsed) { return; } m_pBase[uiIndex] = element; } //--------------------------------------------------------------------------- template inline void NiTSet::RemoveAll() { m_uiUsed = 0; } //--------------------------------------------------------------------------- template inline void NiTSet::Realloc() { Realloc(m_uiUsed); } //--------------------------------------------------------------------------- template inline void NiTSet::Realloc(unsigned int uiNewSize) { NIASSERT(uiNewSize >= m_uiUsed); if (uiNewSize != m_uiAlloced) { T *pNewBase; unsigned int i; if (uiNewSize > 0) { pNewBase = TAlloc::Allocate(uiNewSize); NIASSERT(pNewBase != NULL); for (i = 0; i < m_uiUsed; i++) { pNewBase[i] = m_pBase[i]; } } else { pNewBase = NULL; } TAlloc::Deallocate(m_pBase); m_pBase = pNewBase; m_uiAlloced = uiNewSize; } } //--------------------------------------------------------------------------- template inline NiTObjectSet::NiTObjectSet(unsigned int uiInitialSize) : NiTSet >(uiInitialSize) { } //--------------------------------------------------------------------------- template inline NiTPrimitiveSet::NiTPrimitiveSet(unsigned int uiInitialSize): NiTSet >(uiInitialSize) { } //---------------------------------------------------------------------------