summaryrefslogtreecommitdiff
path: root/common/array.cpp
diff options
context:
space:
mode:
authorleo2002-04-12 21:30:55 +0000
committerleo2002-04-12 21:30:55 +0000
commitd3b46f0412d25ffd7ab1407b7bc892aa5eea4147 (patch)
tree955588b5610945fbe3f2fad745d7b5bad869a617 /common/array.cpp
parent1f277ccc64ecc55e6ed284a0f21bbdf932c72b65 (diff)
Added InsertAt and AddSorted functions.
git-svn-id: http://svn.leocad.org/trunk@289 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common/array.cpp')
-rwxr-xr-xcommon/array.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/common/array.cpp b/common/array.cpp
index f8df023..97eb367 100755
--- a/common/array.cpp
+++ b/common/array.cpp
@@ -81,6 +81,34 @@ void PtrArray<T>::Add (T* pObj)
m_pData[m_nLength++] = pObj;
}
+template <class T>
+void PtrArray<T>::AddSorted (T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData)
+{
+ int i;
+
+ for (i = 0; i < GetSize (); i++)
+ if (pFunc (pObj, m_pData[i], pData) < 0)
+ {
+ InsertAt (i, pObj);
+ return;
+ }
+
+ Add (pObj);
+}
+
+template <class T>
+void PtrArray<T>::InsertAt (int nIndex, T* pObj)
+{
+ if (nIndex >= m_nLength)
+ Expand (nIndex - m_nLength + 1);
+ else
+ Expand (1);
+
+ for (int i = m_nLength - 1; i > nIndex; i--)
+ m_pData[i] = m_pData[i-1];
+
+ m_pData[nIndex] = pObj;
+}