mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-05-08 03:27:58 +03:00
Added GetKey() / SetKey() in con_set's Entry, so ScriptVariable can override it and set the key appropriately
This commit is contained in:
parent
2ac2800ecb
commit
b10ce9a426
6 changed files with 105 additions and 62 deletions
|
@ -29,6 +29,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
class Class;
|
||||
class Archiver;
|
||||
|
||||
template<typename key, typename value>
|
||||
class con_map;
|
||||
|
||||
template<typename key, typename value>
|
||||
class con_map_enum;
|
||||
|
||||
|
@ -53,11 +56,15 @@ class con_set
|
|||
public:
|
||||
class Entry
|
||||
{
|
||||
public:
|
||||
k key;
|
||||
v value;
|
||||
friend con_set<k, v>;
|
||||
friend con_set_enum<k, v>;
|
||||
|
||||
Entry *next;
|
||||
private:
|
||||
Entry* next;
|
||||
k key;
|
||||
|
||||
public:
|
||||
v value;
|
||||
|
||||
public:
|
||||
void *operator new(size_t size);
|
||||
|
@ -68,6 +75,8 @@ public:
|
|||
#ifdef ARCHIVE_SUPPORTED
|
||||
void Archive(Archiver& arc);
|
||||
#endif
|
||||
k& GetKey();
|
||||
void SetKey(const k& newKey);
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -137,6 +146,18 @@ con_set<k, v>::Entry::Entry()
|
|||
next = NULL;
|
||||
}
|
||||
|
||||
template<typename k, typename v>
|
||||
void con_set<k, v>::Entry::SetKey(const k& newKey)
|
||||
{
|
||||
key = newKey;
|
||||
}
|
||||
|
||||
template<typename k, typename v>
|
||||
k& con_set<k, v>::Entry::GetKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
template<typename key, typename value>
|
||||
con_set<key, value>::con_set()
|
||||
{
|
||||
|
@ -217,7 +238,7 @@ void con_set<key, value>::resize(int count)
|
|||
old = e->next;
|
||||
|
||||
// insert the old entry to the table hashindex
|
||||
index = HashCode<key>(e->key) % tableLength;
|
||||
index = HashCode<key>(e->GetKey()) % tableLength;
|
||||
|
||||
e->next = table[index];
|
||||
table[index] = e;
|
||||
|
@ -238,7 +259,7 @@ typename con_set<k, v>::Entry *con_set<k, v>::findKeyEntry(const k& key) const
|
|||
entry = table[HashCode<k>(key) % tableLength];
|
||||
|
||||
for (; entry != NULL; entry = entry->next) {
|
||||
if (entry->key == key) {
|
||||
if (entry->GetKey() == key) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +304,7 @@ typename con_set<k, v>::Entry *con_set<k, v>::addNewKeyEntry(const k& key)
|
|||
entry->next = table[index];
|
||||
}
|
||||
|
||||
entry->key = key;
|
||||
entry->SetKey(key);
|
||||
|
||||
table[index] = entry;
|
||||
|
||||
|
@ -299,13 +320,15 @@ bool con_set<key, value>::isEmpty(void)
|
|||
template<typename k, typename v>
|
||||
bool con_set<k, v>::remove(const k& key)
|
||||
{
|
||||
int index = HashCode<k>(key) % tableLength;
|
||||
int hash;
|
||||
Entry *prev = NULL;
|
||||
Entry *entry;
|
||||
|
||||
for (entry = table[index]; entry != NULL; entry = entry->next) {
|
||||
// just to make sure we're using the correct overloaded operator
|
||||
if (!(entry->key == key)) {
|
||||
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)) {
|
||||
prev = entry;
|
||||
continue;
|
||||
}
|
||||
|
@ -317,7 +340,7 @@ bool con_set<k, v>::remove(const k& key)
|
|||
if (prev) {
|
||||
prev->next = entry->next;
|
||||
} else {
|
||||
table[index] = entry->next;
|
||||
table[hash] = entry->next;
|
||||
}
|
||||
|
||||
count--;
|
||||
|
@ -345,7 +368,7 @@ template<typename key, typename value>
|
|||
key *con_set<key, value>::firstKeyValue(void)
|
||||
{
|
||||
if (defaultEntry) {
|
||||
return &defaultEntry->key;
|
||||
return &defaultEntry->GetKey();
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -373,7 +396,7 @@ bool con_set<k, v>::keyExists(const k& key)
|
|||
Entry *entry;
|
||||
|
||||
for (entry = table; entry != NULL; entry = entry->next) {
|
||||
if (entry->key == key) {
|
||||
if (entry->GetKey() == key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -582,7 +605,7 @@ key *con_map_enum<key, value>::CurrentKey(void)
|
|||
Entry *entry = m_Set_Enum.CurrentElement();
|
||||
|
||||
if (entry) {
|
||||
return &entry->key;
|
||||
return &entry->GetKey();
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -606,7 +629,7 @@ key *con_map_enum<key, value>::NextKey(void)
|
|||
Entry *entry = m_Set_Enum.NextElement();
|
||||
|
||||
if (entry) {
|
||||
return &entry->key;
|
||||
return &entry->GetKey();
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -3204,7 +3204,7 @@ void Listener::CancelWaitingAll()
|
|||
ConList stoppedListeners;
|
||||
|
||||
for (e = en.NextElement(); e != NULL; e = en.NextElement()) {
|
||||
CancelWaitingSources(e->key, e->value, stoppedListeners);
|
||||
CancelWaitingSources(e->GetKey(), e->value, stoppedListeners);
|
||||
}
|
||||
|
||||
delete m_WaitForList;
|
||||
|
@ -3504,7 +3504,7 @@ void Listener::UnregisterAll(void)
|
|||
en = *m_NotifyList;
|
||||
|
||||
for (e = en.NextElement(); e != NULL; e = en.NextElement()) {
|
||||
UnregisterTargets(e->key, e->value, stoppedListeners, stoppedNames);
|
||||
UnregisterTargets(e->GetKey(), e->value, stoppedListeners, stoppedNames);
|
||||
}
|
||||
|
||||
delete m_NotifyList;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue