diff --git a/code/qcommon/con_arrayset.h b/code/qcommon/con_arrayset.h index 753c1e2c..38dd3362 100644 --- a/code/qcommon/con_arrayset.h +++ b/code/qcommon/con_arrayset.h @@ -26,34 +26,51 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "mem_blockalloc.h" -template +template +class con_arrayset; + +template class con_arrayset_enum; +template +class con_arrayset_Entry +{ + friend con_arrayset; + friend con_arrayset_enum; + +public: + k key; + v value; + unsigned int index; + + con_arrayset_Entry *next; + +public: + void *operator new(size_t size) { return con_arrayset::NewEntry(size); } + + void operator delete(void *ptr) { con_arrayset::DeleteEntry(ptr); } + + con_arrayset_Entry() + { + this->key = k(); + this->value = v(); + + index = 0; + next = NULL; + } + +#ifdef ARCHIVE_SUPPORTED + void Archive(Archiver& arc); +#endif +}; + template class con_arrayset { friend class con_arrayset_enum; public: - class Entry - { - public: - k key; - v value; - unsigned int index; - - Entry *next; - - public: - void *operator new(size_t size); - void operator delete(void *ptr); - - Entry(); - -#ifdef ARCHIVE_SUPPORTED - void Archive(Archiver& arc); -#endif - }; + using Entry = con_arrayset_Entry; public: static MEM_BlockAlloc Entry_allocator; @@ -72,6 +89,10 @@ protected: Entry *addKeyEntry(const k& key); Entry *addNewKeyEntry(const k& key); +public: + static void *NewEntry(size_t size); + static void DeleteEntry(void *entry); + public: con_arrayset(); ~con_arrayset(); @@ -87,7 +108,7 @@ public: unsigned int findKeyIndex(const k& key); unsigned int addKeyIndex(const k& key); unsigned int addNewKeyIndex(const k& key); - bool remove(const k &key); + bool remove(const k& key); v& operator[](unsigned int index); }; @@ -96,25 +117,15 @@ template MEM_BlockAlloc::Entry> con_arrayset::Entry_allocator; template -void *con_arrayset::Entry::operator new(size_t size) +void *con_arrayset::NewEntry(size_t size) { return Entry_allocator.Alloc(); } template -void con_arrayset::Entry::operator delete(void *ptr) +void con_arrayset::DeleteEntry(void *entry) { - Entry_allocator.Free(ptr); -} - -template -con_arrayset::Entry::Entry() -{ - this->key = k(); - this->value = v(); - - index = 0; - next = NULL; + Entry_allocator.Free(entry); } template