//--------------------------------------------------------------------------- // Microsoft Visual Studio // // Microsoft Confidential // Copyright (C) 1994 - 2000 Microsoft Corporation. // All Rights Reserved. // // Util.h -- utility classes //--------------------------------------------------------------------------- #pragma once ///////////////////////////////////////////////////////////////////////////// // CPtrArrayImpl -- implementation class for CPtrArray class CPtrArrayImpl { private: enum { ALLOC_INCR = 8 }; void** m_ppData; int m_iCount; int m_iAlloc; // CPtrArrayImpl cannot be copied! CPtrArrayImpl(const CPtrArrayImpl&) {} CPtrArrayImpl& operator=(const CPtrArrayImpl&) { return *this; } protected: void * _GetAt (int i); void _SetAt (int i, void* pData); BOOL _Add (void* pData); BOOL _Remove (void* pData); BOOL _InsertAt (int i, void* pObj); BOOL _ReallocData (int iAlloc); void _Sort ( int (__cdecl *compare )(const void *p1, const void *p2)); int _BSearch (const void *key, int (__cdecl *compare )(const void *p1, const void *p2)); void _Attach (int cel, void** prgObj); void _Detach (void) { m_ppData = NULL; m_iCount = m_iAlloc = 0; } public: CPtrArrayImpl(int iAlloc = 0); ~CPtrArrayImpl(); BOOL RemoveAt (int i); void RemoveAll (void) { m_iCount = 0; } void SetTop (int i) { m_iCount = i; } int Count (void) { return m_iCount; } }; inline CPtrArrayImpl::CPtrArrayImpl(int iAlloc) : m_ppData(NULL), m_iCount(0), m_iAlloc(0) { _ReallocData(iAlloc); } ///////////////////////////////////////////////////////////////////////////// // CPtrArray -- simple array of pointers template class CPtrArray : public CPtrArrayImpl { public: CPtrArray (int iAlloc = 0) : CPtrArrayImpl(iAlloc) {} ~CPtrArray() { RemoveAll(); } T * GetAt (int i) { return (T*)_GetAt(i); } void SetAt (int i, T * pObj) { _SetAt(i, pObj); } BOOL Add (T * pObj) { return _Add(pObj); } BOOL Remove (T * pObj) { return _Remove(pObj); } BOOL InsertAt (int i, T * pObj) { return _InsertAt(i, pObj); } void Sort ( int (__cdecl *compare)(T** p1, T** p2)) { _Sort((int (__cdecl *)(const void *, void const *))compare); } int BSearch (const T *pkey, int (__cdecl *compare)(T** p1, T** p2)) { return _BSearch((const void *)pkey, (int (__cdecl *)(const void *, void const *))compare); } void Attach (int cel, T** prgObj) { _Attach(cel, prgObj); } void Detach (void) { _Detach(); } }; #define CArray CPtrArray // for compatibility