openmohaa/code/qcommon/con_set.h

696 lines
15 KiB
C
Raw Permalink Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// con_set.h: C++ map/set classes. Contains an hash table to improve the speed of finding a key
#pragma once
2016-03-27 11:49:47 +02:00
#include "mem_blockalloc.h"
2023-01-29 20:59:31 +01:00
#if defined(GAME_DLL)
# include "../fgame/g_local.h"
# define SET_Alloc gi.Malloc
# define SET_Free gi.Free
#elif defined(CGAME_DLL)
# include "../cgame/cg_local.h"
# define SET_Alloc cgi.Malloc
# define SET_Free cgi.Free
#elif defined(REF_DLL)
# include "../renderercommon/tr_common.h"
# define SET_Alloc ri.Malloc
# define SET_Free ri.Free
#else
# include "qcommon.h"
# define SET_Alloc Z_Malloc
# define SET_Free Z_Free
#endif
2016-03-27 11:49:47 +02:00
class Class;
2023-01-29 20:59:31 +01:00
class Archiver;
2016-03-27 11:49:47 +02:00
template<typename k, typename v>
class con_set;
template<typename key, typename value>
class con_map;
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
2016-03-27 11:49:47 +02:00
class con_map_enum;
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
2016-03-27 11:49:47 +02:00
class con_set_enum;
template<typename T>
2023-08-19 03:02:30 +02:00
struct con_set_is_pointer {
static const bool con_value = false;
};
2016-03-27 11:49:47 +02:00
template<typename T>
2023-08-19 03:02:30 +02:00
struct con_set_is_pointer<T *> {
static const bool con_value = true;
};
2016-03-27 11:49:47 +02:00
/**
* This class was originally inside con_set (con_set::Entry).
* But because GCC is being extremely annoying and is moaning
* because of specialization after instantiation,
* the class is now laying there.
*/
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
class con_set_Entry
2016-03-27 11:49:47 +02:00
{
friend con_set<k, v>;
friend con_set_enum<k, v>;
private:
con_set_Entry *next;
k key;
public:
v value;
2016-03-27 11:49:47 +02:00
public:
void *operator new(size_t size) { return con_set<k, v>::NewEntry(size); }
2016-03-27 11:49:47 +02:00
void operator delete(void *ptr) { con_set<k, v>::DeleteEntry(ptr); }
2016-03-27 11:49:47 +02:00
con_set_Entry()
: key(k())
, value(v())
, next(NULL)
{}
2016-03-27 11:49:47 +02:00
2023-01-29 20:59:31 +01:00
#ifdef ARCHIVE_SUPPORTED
void Archive(Archiver& arc);
2016-03-27 11:49:47 +02:00
#endif
k& GetKey() { return key; }
void SetKey(const k& newKey) { key = newKey; }
};
template<typename k, typename v>
class con_set
{
friend class con_set_enum<k, v>;
public:
using Entry = con_set_Entry<k, v>;
2016-03-27 11:49:47 +02:00
public:
2023-08-19 03:02:30 +02:00
static MEM_BlockAlloc<Entry> Entry_allocator;
2016-03-27 11:49:47 +02:00
protected:
2023-08-19 03:02:30 +02:00
Entry **table; // hashtable
unsigned int tableLength;
unsigned int threshold;
unsigned int count; // num of entries
short unsigned int tableLengthIndex;
Entry *defaultEntry;
2016-03-27 11:49:47 +02:00
protected:
2023-08-19 03:02:30 +02:00
Entry *findKeyEntry(const k& key) const;
Entry *addKeyEntry(const k& key);
Entry *addNewKeyEntry(const k& key);
2016-03-27 11:49:47 +02:00
public:
static void *NewEntry(size_t size);
static void DeleteEntry(void *entry);
static void *NewTable(size_t count);
static void DeleteTable(void *table);
2016-03-27 11:49:47 +02:00
public:
2023-08-19 03:02:30 +02:00
con_set();
~con_set();
2016-03-27 11:49:47 +02:00
2023-01-29 20:59:31 +01:00
#ifdef ARCHIVE_SUPPORTED
2023-08-19 03:02:30 +02:00
void Archive(Archiver& arc);
2016-03-27 11:49:47 +02:00
#endif
2023-08-19 03:02:30 +02:00
void clear();
void resize(int count = 0);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
v *findKeyValue(const k& key) const;
k *firstKeyValue();
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
v& addKeyValue(const k& key);
v& addNewKeyValue(const k& key);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
bool keyExists(const k& key);
bool isEmpty();
bool remove(const k& key);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
unsigned int size();
2016-03-27 11:49:47 +02:00
};
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
MEM_BlockAlloc<typename con_set<k, v>::Entry> con_set<k, v>::Entry_allocator;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
void *con_set<k, v>::NewEntry(size_t size)
2016-03-27 11:49:47 +02:00
{
return Entry_allocator.Alloc();
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
void con_set<k, v>::DeleteEntry(void *entry)
2016-03-27 11:49:47 +02:00
{
Entry_allocator.Free(entry);
2016-03-27 11:49:47 +02:00
}
template<typename k, typename v>
void *con_set<k, v>::NewTable(size_t count)
{
return SET_Alloc(sizeof(Entry *) * (int)count);
}
template<typename k, typename v>
void con_set<k, v>::DeleteTable(void *table)
{
SET_Free(table);
}
template<typename k>
int HashCode(const k& key);
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
2016-03-27 11:49:47 +02:00
con_set<key, value>::con_set()
{
2023-08-19 03:02:30 +02:00
tableLength = 1;
table = &defaultEntry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
threshold = 1;
count = 0;
tableLengthIndex = 0;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
defaultEntry = NULL;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
2016-03-27 11:49:47 +02:00
con_set<key, value>::~con_set()
{
2023-08-19 03:02:30 +02:00
clear();
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
void con_set<key, value>::clear()
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = NULL;
Entry *next = NULL;
unsigned int i;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
for (i = 0; i < tableLength; i++) {
for (entry = table[i]; entry != NULL; entry = next) {
next = entry->next;
delete entry;
}
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (tableLength > 1) {
DeleteTable(table);
2023-08-19 03:02:30 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
tableLength = 1;
table = &defaultEntry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
threshold = 1;
count = 0;
tableLengthIndex = 0;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
defaultEntry = NULL;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
void con_set<key, value>::resize(int count)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry **oldTable = table;
Entry *e, *old;
unsigned int oldTableLength = tableLength;
unsigned int i;
unsigned int index;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (count > 0) {
tableLength += count;
threshold = tableLength;
} else {
//threshold = ( unsigned int )( ( float )tableLength * 0.75f );
threshold = (unsigned int)((float)tableLength * 0.75);
if (threshold < 1) {
threshold = 1;
}
2016-08-13 18:32:13 +02:00
2023-08-19 03:02:30 +02:00
tableLength += threshold;
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
// allocate a new table
table = new (NewTable(tableLength)) Entry *[tableLength]();
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
// rehash the table
for (i = oldTableLength; i > 0; i--) {
// rehash all entries from the old table
for (e = oldTable[i - 1]; e != NULL; e = old) {
old = e->next;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
// insert the old entry to the table hashindex
index = HashCode<key>(e->GetKey()) % tableLength;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
e->next = table[index];
table[index] = e;
}
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (oldTableLength > 1) {
// delete the previous table
DeleteTable(oldTable);
2023-08-19 03:02:30 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
typename con_set<k, v>::Entry *con_set<k, v>::findKeyEntry(const k& key) const
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
entry = table[HashCode<k>(key) % tableLength];
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
for (; entry != NULL; entry = entry->next) {
if (entry->GetKey() == key) {
2023-08-19 03:02:30 +02:00
return entry;
}
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return NULL;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
typename con_set<k, v>::Entry *con_set<k, v>::addKeyEntry(const k& key)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
entry = findKeyEntry(key);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (entry != NULL) {
return entry;
} else {
return addNewKeyEntry(key);
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
typename con_set<k, v>::Entry *con_set<k, v>::addNewKeyEntry(const k& key)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry;
int hash;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (count >= threshold) {
resize();
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
count++;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
entry = new Entry;
entry->SetKey(key);
hash = HashCode<k>(entry->GetKey()) % tableLength;
2023-08-19 03:02:30 +02:00
if (defaultEntry == NULL) {
defaultEntry = entry;
entry->next = NULL;
} else {
entry->next = table[hash];
2023-08-19 03:02:30 +02:00
}
table[hash] = entry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return entry;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
bool con_set<key, value>::isEmpty(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return count == 0;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
bool con_set<k, v>::remove(const k& key)
2016-03-27 11:49:47 +02:00
{
int hash;
int i;
Entry *prev = NULL;
Entry *entry, *e;
2016-03-27 11:49:47 +02:00
hash = HashCode<k>(key) % tableLength;
for (entry = table[hash]; entry != NULL; entry = entry->next) {
// just to make sure we're using the correct overloaded operator for the key
if (!(entry->GetKey() == key)) {
2023-08-19 03:02:30 +02:00
prev = entry;
continue;
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (defaultEntry == entry) {
defaultEntry = prev ? prev : table[hash];
// find a default entry
for (i = 0; i < tableLength && !defaultEntry; i++) {
for (e = table[i]; e; e = e->next) {
if (e == entry) {
continue;
}
defaultEntry = e;
break;
}
}
2023-08-19 03:02:30 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (prev) {
prev->next = entry->next;
} else {
table[hash] = entry->next;
2023-08-19 03:02:30 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
count--;
delete entry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return true;
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return false;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
v *con_set<k, v>::findKeyValue(const k& key) const
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = findKeyEntry(key);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (entry != NULL) {
return &entry->value;
} else {
return NULL;
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
key *con_set<key, value>::firstKeyValue(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
if (defaultEntry) {
return &defaultEntry->GetKey();
2023-08-19 03:02:30 +02:00
} else {
return NULL;
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
v& con_set<k, v>::addKeyValue(const k& key)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = addKeyEntry(key);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return entry->value;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
v& con_set<k, v>::addNewKeyValue(const k& key)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = addNewKeyEntry(key);
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return entry->value;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename k, typename v>
bool con_set<k, v>::keyExists(const k& key)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
for (entry = table; entry != NULL; entry = entry->next) {
if (entry->GetKey() == key) {
2023-08-19 03:02:30 +02:00
return true;
}
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return false;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
unsigned int con_set<key, value>::size()
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return count;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
class con_set_enum
{
2023-08-19 03:02:30 +02:00
friend class con_map_enum<key, value>;
public:
2023-08-19 03:02:30 +02:00
using Entry = typename con_set<key, value>::Entry;
protected:
2023-08-19 03:02:30 +02:00
con_set<key, value> *m_Set;
unsigned int m_Index;
Entry *m_CurrentEntry;
Entry *m_NextEntry;
public:
2023-08-19 03:02:30 +02:00
con_set_enum();
con_set_enum(con_set<key, value>& set);
2023-08-19 03:02:30 +02:00
bool operator=(con_set<key, value>& set);
2023-08-19 03:02:30 +02:00
Entry *NextElement(void);
Entry *CurrentElement(void);
};
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
con_set_enum<key, value>::con_set_enum()
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
m_Set = NULL;
m_Index = 0;
m_CurrentEntry = NULL;
m_NextEntry = NULL;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
con_set_enum<key, value>::con_set_enum(con_set<key, value>& set)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
*this = set;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
bool con_set_enum<key, value>::operator=(con_set<key, value>& set)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
m_Set = &set;
m_Index = m_Set->tableLength;
m_CurrentEntry = NULL;
m_NextEntry = NULL;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return true;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
typename con_set_enum<key, value>::Entry *con_set_enum<key, value>::CurrentElement(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return m_CurrentEntry;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
typename con_set_enum<key, value>::Entry *con_set_enum<key, value>::NextElement(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
if (!m_NextEntry) {
while (1) {
if (!m_Index) {
break;
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
m_Index--;
m_NextEntry = m_Set->table[m_Index];
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (m_NextEntry) {
break;
}
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (!m_NextEntry) {
m_CurrentEntry = NULL;
return NULL;
}
}
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
m_CurrentEntry = m_NextEntry;
m_NextEntry = m_NextEntry->next;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return m_CurrentEntry;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
class con_map
{
friend class con_map_enum<key, value>;
private:
2023-08-19 03:02:30 +02:00
con_set<key, value> m_con_set;
public:
#ifdef ARCHIVE_SUPPORTED
2023-08-19 03:02:30 +02:00
void Archive(Archiver& arc);
#endif
2023-08-19 03:02:30 +02:00
void clear();
virtual void resize(int count = 0);
2023-08-19 03:02:30 +02:00
value& operator[](const key& index);
2023-08-19 03:02:30 +02:00
value *find(const key& index);
bool remove(const key& index);
2023-08-19 03:02:30 +02:00
unsigned int size();
};
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
void con_map<key, value>::clear()
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
m_con_set.clear();
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
void con_map<key, value>::resize(int count)
2016-08-13 18:32:13 +02:00
{
2023-08-19 03:02:30 +02:00
m_con_set.resize(count);
2016-08-13 18:32:13 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
value& con_map<key, value>::operator[](const key& index)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return m_con_set.addKeyValue(index);
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
value *con_map<key, value>::find(const key& index)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return m_con_set.findKeyValue(index);
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
bool con_map<key, value>::remove(const key& index)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return m_con_set.remove(index);
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
unsigned int con_map<key, value>::size(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
return m_con_set.size();
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
class con_map_enum
{
public:
2023-08-19 03:02:30 +02:00
using Entry = typename con_set_enum<key, value>::Entry;
private:
2023-08-19 03:02:30 +02:00
con_set_enum<key, value> m_Set_Enum;
public:
2023-08-19 03:02:30 +02:00
con_map_enum();
con_map_enum(con_map<key, value>& map);
2023-08-19 03:02:30 +02:00
bool operator=(con_map<key, value>& map);
2023-08-19 03:02:30 +02:00
key *NextKey(void);
value *NextValue(void);
key *CurrentKey(void);
value *CurrentValue(void);
};
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
con_map_enum<key, value>::con_map_enum()
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
m_Set_Enum.m_Set = NULL;
m_Set_Enum.m_Index = 0;
m_Set_Enum.m_CurrentEntry = NULL;
m_Set_Enum.m_NextEntry = NULL;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
con_map_enum<key, value>::con_map_enum(con_map<key, value>& map)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
*this = map;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
bool con_map_enum<key, value>::operator=(con_map<key, value>& map)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
m_Set_Enum = map.m_con_set;
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
return true;
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
key *con_map_enum<key, value>::CurrentKey(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = m_Set_Enum.CurrentElement();
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (entry) {
return &entry->GetKey();
2023-08-19 03:02:30 +02:00
} else {
return NULL;
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
value *con_map_enum<key, value>::CurrentValue(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = m_Set_Enum.CurrentElement();
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (entry) {
return &entry->value;
} else {
return NULL;
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
key *con_map_enum<key, value>::NextKey(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = m_Set_Enum.NextElement();
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (entry) {
return &entry->GetKey();
2023-08-19 03:02:30 +02:00
} else {
return NULL;
}
2016-03-27 11:49:47 +02:00
}
2023-08-19 03:02:30 +02:00
template<typename key, typename value>
value *con_map_enum<key, value>::NextValue(void)
2016-03-27 11:49:47 +02:00
{
2023-08-19 03:02:30 +02:00
Entry *entry = m_Set_Enum.NextElement();
2016-03-27 11:49:47 +02:00
2023-08-19 03:02:30 +02:00
if (entry) {
return &entry->value;
} else {
return NULL;
}
2016-03-27 11:49:47 +02:00
}