isle-portable/LEGO1/mxatomid.cpp

98 lines
2 KiB
C++
Raw Normal View History

#include "mxatomid.h"
2023-10-24 19:38:27 -04:00
#include "mxomni.h"
// OFFSET: LEGO1 0x100acf90
2023-10-24 19:38:27 -04:00
MxAtomId::MxAtomId(const char* p_str, LookupMode p_mode)
{
2023-10-24 19:38:27 -04:00
if (!MxOmni::GetInstance())
return;
2023-10-24 19:38:27 -04:00
if (!AtomIdCounterSet())
return;
2023-10-24 19:38:27 -04:00
MxAtomIdCounter* counter = GetCounter(p_str, p_mode);
m_internal = counter->GetKey()->GetData();
counter->Inc();
}
// OFFSET: LEGO1 0x100acfd0
MxAtomId::~MxAtomId()
{
2023-10-24 19:38:27 -04:00
Destroy();
}
// OFFSET: LEGO1 0x100acfe0
void MxAtomId::Destroy()
{
2023-10-24 19:38:27 -04:00
if (!m_internal)
return;
if (!MxOmni::GetInstance())
return;
if (!AtomIdCounterSet())
return;
// The dtor is called on the counter object immediately,
// so this syntax should be correct.
MxAtomIdCounterSet::iterator it = AtomIdCounterSet()->find(&MxAtomIdCounter(m_internal));
MxAtomIdCounter* counter = (MxAtomIdCounter*) (*it);
counter->Dec();
}
// OFFSET: LEGO1 0x100ad1c0
2023-10-24 19:38:27 -04:00
MxAtomId& MxAtomId::operator=(const MxAtomId& p_atomId)
{
2023-10-24 19:38:27 -04:00
if (m_internal)
Destroy();
2023-10-24 19:38:27 -04:00
if (p_atomId.m_internal && MxOmni::GetInstance() && AtomIdCounterSet()) {
MxAtomIdCounter* counter = GetCounter(p_atomId.m_internal, LookupMode_Exact);
counter->Inc();
}
2023-10-24 19:38:27 -04:00
m_internal = p_atomId.m_internal;
2023-10-24 19:38:27 -04:00
return *this;
}
// OFFSET: LEGO1 0x100ad210
2023-10-24 19:38:27 -04:00
MxAtomIdCounter* MxAtomId::GetCounter(const char* p_str, LookupMode p_mode)
{
2023-10-24 19:38:27 -04:00
MxAtomId _unused;
MxAtomIdCounter* counter = new MxAtomIdCounter(p_str);
switch (p_mode) {
case LookupMode_LowerCase:
case LookupMode_LowerCase2:
counter->GetKey()->ToLowerCase();
break;
case LookupMode_UpperCase:
counter->GetKey()->ToUpperCase();
break;
}
MxAtomIdCounterSet::iterator it = AtomIdCounterSet()->find(counter);
if (it != AtomIdCounterSet()->end()) {
// Counter already in the set. Delete temp value and return it.
delete counter;
counter = *it;
}
else {
// Counter is not in the set. Add it.
AtomIdCounterSet()->insert(counter);
}
return counter;
}
// OFFSET: LEGO1 0x100ad7e0
void MxAtomId::Clear()
{
2023-10-24 19:38:27 -04:00
// Reset but do not delete MxAtomId object.
Destroy();
m_internal = NULL;
}