mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Use NewEntry/DeleteEntry like con_set
This commit is contained in:
parent
ad1748b8be
commit
178c486b83
1 changed files with 45 additions and 34 deletions
|
@ -26,34 +26,51 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "mem_blockalloc.h"
|
||||
|
||||
template<typename key, typename value>
|
||||
template<typename k, typename v>
|
||||
class con_arrayset;
|
||||
|
||||
template<typename k, typename v>
|
||||
class con_arrayset_enum;
|
||||
|
||||
template<typename k, typename v>
|
||||
class con_arrayset_Entry
|
||||
{
|
||||
friend con_arrayset<k, v>;
|
||||
friend con_arrayset_enum<k, v>;
|
||||
|
||||
public:
|
||||
k key;
|
||||
v value;
|
||||
unsigned int index;
|
||||
|
||||
con_arrayset_Entry *next;
|
||||
|
||||
public:
|
||||
void *operator new(size_t size) { return con_arrayset<k, v>::NewEntry(size); }
|
||||
|
||||
void operator delete(void *ptr) { con_arrayset<k, v>::DeleteEntry(ptr); }
|
||||
|
||||
con_arrayset_Entry()
|
||||
{
|
||||
this->key = k();
|
||||
this->value = v();
|
||||
|
||||
index = 0;
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
#ifdef ARCHIVE_SUPPORTED
|
||||
void Archive(Archiver& arc);
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename k, typename v>
|
||||
class con_arrayset
|
||||
{
|
||||
friend class con_arrayset_enum<k, v>;
|
||||
|
||||
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<k, v>;
|
||||
|
||||
public:
|
||||
static MEM_BlockAlloc<Entry> 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();
|
||||
|
@ -96,25 +117,15 @@ template<typename k, typename v>
|
|||
MEM_BlockAlloc<typename con_arrayset<k, v>::Entry> con_arrayset<k, v>::Entry_allocator;
|
||||
|
||||
template<typename k, typename v>
|
||||
void *con_arrayset<k, v>::Entry::operator new(size_t size)
|
||||
void *con_arrayset<k, v>::NewEntry(size_t size)
|
||||
{
|
||||
return Entry_allocator.Alloc();
|
||||
}
|
||||
|
||||
template<typename k, typename v>
|
||||
void con_arrayset<k, v>::Entry::operator delete(void *ptr)
|
||||
void con_arrayset<k, v>::DeleteEntry(void *entry)
|
||||
{
|
||||
Entry_allocator.Free(ptr);
|
||||
}
|
||||
|
||||
template<typename k, typename v>
|
||||
con_arrayset<k, v>::Entry::Entry()
|
||||
{
|
||||
this->key = k();
|
||||
this->value = v();
|
||||
|
||||
index = 0;
|
||||
next = NULL;
|
||||
Entry_allocator.Free(entry);
|
||||
}
|
||||
|
||||
template<typename key, typename value>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue