X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e99c30481090eb4ceaec74c0c1b5fac89b235e7f..e5d7a5b37b76fc5fa21c4c3be5b7d19f56e2453d:/include/wx/dynarray.h diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index 37e106f5f2..7174148866 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -64,7 +64,7 @@ typedef int (CMPFUNC_CONV *CMPFUNC)(const void* pItem1, const void* pItem2); @memo Base class for template array and list classes */ // ---------------------------------------------------------------------------- -class wxBaseArray +class WXDLLEXPORT wxBaseArray { public: /** @name ctors and dtor */ @@ -86,19 +86,22 @@ public: /** @name memory management */ //@{ /// empties the list, but doesn't release memory - void Empty() { m_uiCount = 0; } + void Empty() { m_nCount = 0; } /// empties the list and releases memory void Clear(); /// preallocates memory for given number of items - void Alloc(uint uiSize); + void Alloc(size_t uiSize); + /// minimizes the memory used by the array (frees unused memory) + void Shrink(); //@} /** @name simple accessors */ //@{ /// number of elements in the array - uint Count() const { return m_uiCount; } + size_t Count() const { return m_nCount; } + size_t GetCount() const { return m_nCount; } /// is it empty? - bool IsEmpty() const { return m_uiCount == 0; } + bool IsEmpty() const { return m_nCount == 0; } //@} protected: @@ -109,10 +112,10 @@ protected: /** @name items access */ //@{ /// get item at position uiIndex (range checking is done in debug version) - long& Item(uint uiIndex) const - { wxASSERT( uiIndex < m_uiCount ); return m_pItems[uiIndex]; } + long& Item(size_t uiIndex) const + { wxASSERT( uiIndex < m_nCount ); return m_pItems[uiIndex]; } /// same as Item() - long& operator[](uint uiIndex) const { return Item(uiIndex); } + long& operator[](size_t uiIndex) const { return Item(uiIndex); } //@} /** @name item management */ @@ -131,11 +134,11 @@ protected: /// add item assuming the array is sorted with fnCompare function void Add(long lItem, CMPFUNC fnCompare); /// add new element at given position (it becomes Item[uiIndex]) - void Insert(long lItem, uint uiIndex); + void Insert(long lItem, size_t uiIndex); /// remove first item matching this value void Remove(long lItem); /// remove item by index - void Remove(uint uiIndex); + void Remove(size_t uiIndex); //@} /// sort array elements using given compare function @@ -144,8 +147,8 @@ protected: private: void Grow(); // makes array bigger if needed - uint m_uiSize, // current size of the array - m_uiCount; // current number of elements + size_t m_nSize, // current size of the array + m_nCount; // current number of elements long *m_pItems; // pointer to data }; @@ -162,7 +165,7 @@ private: // ---------------------------------------------------------------------------- #define _WX_DEFINE_ARRAY(T, name) \ typedef int (CMPFUNC_CONV *CMPFUNC##T)(T *pItem1, T *pItem2); \ -class name : public wxBaseArray \ +class WXDLLEXPORTLOCAL name : public wxBaseArray \ { \ public: \ name() \ @@ -172,9 +175,9 @@ public: \ { ((wxBaseArray *)this)->operator=((const wxBaseArray&)src); \ return *this; } \ \ - T& operator[](uint uiIndex) const \ + T& operator[](size_t uiIndex) const \ { return (T&)(wxBaseArray::Item(uiIndex)); } \ - T& Item(uint uiIndex) const \ + T& Item(size_t uiIndex) const \ { return (T&)(wxBaseArray::Item(uiIndex)); } \ T& Last() const \ { return (T&)(wxBaseArray::Item(Count() - 1)); } \ @@ -184,15 +187,15 @@ public: \ \ void Add(T Item) \ { wxBaseArray::Add((long)Item); } \ - void Insert(T Item, uint uiIndex) \ + void Insert(T Item, size_t uiIndex) \ { wxBaseArray::Insert((long)Item, uiIndex) ; } \ \ - void Remove(uint uiIndex) { wxBaseArray::Remove(uiIndex); } \ + void Remove(size_t uiIndex) { wxBaseArray::Remove(uiIndex); } \ void Remove(T Item) \ { int iIndex = Index(Item); \ wxCHECK2_MSG( iIndex != NOT_FOUND, return, \ "removing inexisting element in wxArray::Remove" ); \ - wxBaseArray::Remove((uint)iIndex); } \ + wxBaseArray::Remove((size_t)iIndex); } \ \ void Sort(CMPFUNC##T fCmp) { wxBaseArray::Sort((CMPFUNC)fCmp); } \ } @@ -216,7 +219,7 @@ public: \ // ---------------------------------------------------------------------------- #define _WX_DEFINE_SORTED_ARRAY(T, name) \ typedef int (CMPFUNC_CONV *SCMPFUNC##T)(T pItem1, T pItem2); \ -class name : public wxBaseArray \ +class WXDLLEXPORTLOCAL name : public wxBaseArray \ { \ public: \ name(SCMPFUNC##T fn) \ @@ -227,9 +230,9 @@ public: \ m_fnCompare = src.m_fnCompare; \ return *this; } \ \ - T& operator[](uint uiIndex) const \ + T& operator[](size_t uiIndex) const \ { return (T&)(wxBaseArray::Item(uiIndex)); } \ - T& Item(uint uiIndex) const \ + T& Item(size_t uiIndex) const \ { return (T&)(wxBaseArray::Item(uiIndex)); } \ T& Last() const \ { return (T&)(wxBaseArray::Item(Count() - 1)); } \ @@ -240,12 +243,12 @@ public: \ void Add(T Item) \ { wxBaseArray::Add((long)Item, (CMPFUNC)m_fnCompare); } \ \ - void Remove(uint uiIndex) { wxBaseArray::Remove(uiIndex); } \ + void Remove(size_t uiIndex) { wxBaseArray::Remove(uiIndex); } \ void Remove(T Item) \ { int iIndex = Index(Item); \ wxCHECK2_MSG( iIndex != NOT_FOUND, return, \ "removing inexisting element in wxArray::Remove" ); \ - wxBaseArray::Remove((uint)iIndex); } \ + wxBaseArray::Remove((size_t)iIndex); } \ \ private: \ SCMPFUNC##T m_fnCompare; \ @@ -256,7 +259,7 @@ private: \ // ---------------------------------------------------------------------------- #define _WX_DECLARE_LIST(T, name) \ typedef int (CMPFUNC_CONV *CMPFUNC##T)(T** pItem1, T** pItem2); \ -class name : public wxBaseArray \ +class WXDLLEXPORTLOCAL name : public wxBaseArray \ { \ public: \ name() { } \ @@ -265,9 +268,9 @@ public: \ \ ~name(); \ \ - T& operator[](uint uiIndex) const \ + T& operator[](size_t uiIndex) const \ { return *(T*)wxBaseArray::Item(uiIndex); } \ - T& Item(uint uiIndex) const \ + T& Item(size_t uiIndex) const \ { return *(T*)wxBaseArray::Item(uiIndex); } \ T& Last() const \ { return *(T*)(wxBaseArray::Item(Count() - 1)); } \ @@ -278,16 +281,16 @@ public: \ void Add(const T* pItem) \ { wxBaseArray::Add((long)pItem); } \ \ - void Insert(const T& Item, uint uiIndex); \ - void Insert(const T* pItem, uint uiIndex) \ + void Insert(const T& Item, size_t uiIndex); \ + void Insert(const T* pItem, size_t uiIndex) \ { wxBaseArray::Insert((long)pItem, uiIndex); } \ \ void Empty(); \ \ - T* Detach(uint uiIndex) \ + T* Detach(size_t uiIndex) \ { T* p = (T*)wxBaseArray::Item(uiIndex); \ wxBaseArray::Remove(uiIndex); return p; } \ - void Remove(uint uiIndex); \ + void Remove(size_t uiIndex); \ \ void Sort(CMPFUNC##T fCmp) { wxBaseArray::Sort((CMPFUNC)fCmp); } \ \ @@ -392,6 +395,8 @@ private: \ // # overhead if not used? // ---------------------------------------------------------------------------- +#define WXDLLEXPORTLOCAL WXDLLEXPORT + //@{ /** @name ArrayInt */ WX_DEFINE_ARRAY(int, wxArrayInt); @@ -403,5 +408,8 @@ WX_DEFINE_ARRAY(void *, wxArrayPtrVoid); //@} +#undef WXDLLEXPORTLOCAL +#define WXDLLEXPORTLOCAL + #endif // _DYNARRAY_H