mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +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"
|
#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;
|
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>
|
template<typename k, typename v>
|
||||||
class con_arrayset
|
class con_arrayset
|
||||||
{
|
{
|
||||||
friend class con_arrayset_enum<k, v>;
|
friend class con_arrayset_enum<k, v>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class Entry
|
using Entry = con_arrayset_Entry<k, v>;
|
||||||
{
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static MEM_BlockAlloc<Entry> Entry_allocator;
|
static MEM_BlockAlloc<Entry> Entry_allocator;
|
||||||
|
@ -72,6 +89,10 @@ protected:
|
||||||
Entry *addKeyEntry(const k& key);
|
Entry *addKeyEntry(const k& key);
|
||||||
Entry *addNewKeyEntry(const k& key);
|
Entry *addNewKeyEntry(const k& key);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void *NewEntry(size_t size);
|
||||||
|
static void DeleteEntry(void *entry);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
con_arrayset();
|
con_arrayset();
|
||||||
~con_arrayset();
|
~con_arrayset();
|
||||||
|
@ -87,7 +108,7 @@ public:
|
||||||
unsigned int findKeyIndex(const k& key);
|
unsigned int findKeyIndex(const k& key);
|
||||||
unsigned int addKeyIndex(const k& key);
|
unsigned int addKeyIndex(const k& key);
|
||||||
unsigned int addNewKeyIndex(const k& key);
|
unsigned int addNewKeyIndex(const k& key);
|
||||||
bool remove(const k &key);
|
bool remove(const k& key);
|
||||||
|
|
||||||
v& operator[](unsigned int index);
|
v& operator[](unsigned int index);
|
||||||
};
|
};
|
||||||
|
@ -96,25 +117,15 @@ template<typename k, typename v>
|
||||||
MEM_BlockAlloc<typename con_arrayset<k, v>::Entry> con_arrayset<k, v>::Entry_allocator;
|
MEM_BlockAlloc<typename con_arrayset<k, v>::Entry> con_arrayset<k, v>::Entry_allocator;
|
||||||
|
|
||||||
template<typename k, typename v>
|
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();
|
return Entry_allocator.Alloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename k, typename v>
|
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);
|
Entry_allocator.Free(entry);
|
||||||
}
|
|
||||||
|
|
||||||
template<typename k, typename v>
|
|
||||||
con_arrayset<k, v>::Entry::Entry()
|
|
||||||
{
|
|
||||||
this->key = k();
|
|
||||||
this->value = v();
|
|
||||||
|
|
||||||
index = 0;
|
|
||||||
next = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename key, typename value>
|
template<typename key, typename value>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue