summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorleo2002-04-12 21:30:55 +0000
committerleo2002-04-12 21:30:55 +0000
commitd3b46f0412d25ffd7ab1407b7bc892aa5eea4147 (patch)
tree955588b5610945fbe3f2fad745d7b5bad869a617 /common
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')
-rwxr-xr-xcommon/array.cpp28
-rwxr-xr-xcommon/array.h4
2 files changed, 32 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;
+}
diff --git a/common/array.h b/common/array.h
index c8ce59c..1c5d5a3 100755
--- a/common/array.h
+++ b/common/array.h
@@ -8,6 +8,8 @@ class PtrArray
PtrArray (int nSize = 0);
~PtrArray ();
+ typedef int (*LC_PTRARRAY_COMPARE_FUNC) (T* a, T* b, void* data);
+
void SetSize (int nSize);
int GetSize () const
{ return m_nLength; }
@@ -15,6 +17,8 @@ class PtrArray
T* RemoveIndex (int nIndex);
T* RemovePointer (T* pObj);
void Add (T* pObj);
+ void AddSorted (T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData);
+ void InsertAt (int nIndex, T* pObj);
T* operator [](int nIndex) const
{ return m_pData[nIndex]; }