Isle
Loading...
Searching...
No Matches
mxatom.cpp
Go to the documentation of this file.
1#include "mxatom.h"
2
3#include "decomp.h"
4#include "mxmisc.h"
5#include "mxomni.h"
6
7#include <assert.h>
8
12
13// FUNCTION: LEGO1 0x100acf90
14// FUNCTION: BETA10 0x1012308b
15MxAtomId::MxAtomId(const char* p_str, LookupMode p_mode)
16{
17 if (!MxOmni::GetInstance()) {
18 return;
19 }
20
21 if (!AtomSet()) {
22 return;
23 }
24
25 MxAtom* atom = GetAtom(p_str, p_mode);
26 *this = atom->GetKey();
27 atom->Inc();
28}
29
30// FUNCTION: LEGO1 0x100acfd0
31// FUNCTION: BETA10 0x10123130
33{
34 Destroy();
35}
36
37// FUNCTION: LEGO1 0x100acfe0
38// FUNCTION: BETA10 0x101231a6
39void MxAtomId::Destroy()
40{
41 if (!m_internal) {
42 return;
43 }
44
45 if (!MxOmni::GetInstance()) {
46 return;
47 }
48
49 if (!AtomSet()) {
50 return;
51 }
52
53#ifdef COMPAT_MODE
54 MxAtomSet::iterator it;
55 {
56 MxAtom idAtom(m_internal);
57 it = AtomSet()->find(&idAtom);
58 }
59#else
60 MxAtomSet::iterator it = AtomSet()->find(&MxAtom(m_internal));
61#endif
62 assert(it != AtomSet()->end());
63
64 MxAtom* atom = (MxAtom*) (*it);
65 atom->Dec();
66}
67
68// FUNCTION: LEGO1 0x100ad1c0
69// FUNCTION: BETA10 0x101232b9
71{
72 if (m_internal) {
73 Destroy();
74 }
75
76 if (p_atomId.m_internal && MxOmni::GetInstance() && AtomSet()) {
77 MxAtom* atom = GetAtom(p_atomId.m_internal, e_exact);
78 atom->Inc();
79 }
80
81 m_internal = p_atomId.m_internal;
82
83 return *this;
84}
85
86// FUNCTION: LEGO1 0x100ad210
87// FUNCTION: BETA10 0x10123378
88MxAtom* MxAtomId::GetAtom(const char* p_str, LookupMode p_mode)
89{
90 MxAtomId unused;
91 MxAtom* atom = new MxAtom(p_str);
92 assert(atom);
93
94 switch (p_mode) {
95 case e_exact:
96 break;
97 case e_upperCase:
98 atom->GetKey().ToUpperCase();
99 break;
100 case e_lowerCase:
101 case e_lowerCase2:
102 atom->GetKey().ToLowerCase();
103 break;
104 }
105
106 MxAtomSet::iterator it = AtomSet()->find(atom);
107 if (it != AtomSet()->end()) {
108 // Atom already in the set. Delete temp value and return it.
109 delete atom;
110 atom = *it;
111 }
112 else {
113 // Atom is not in the set. Add it.
114 AtomSet()->insert(atom);
115 }
116
117 return atom;
118}
119
120// FUNCTION: LEGO1 0x100ad7e0
121// FUNCTION: BETA10 0x100553e0
123{
124 // Reset but do not delete MxAtomId object.
125 Destroy();
126 m_internal = NULL;
127}
128
129// FUNCTION: LEGO1 0x100ad7f0
130// FUNCTION: BETA10 0x101235d5
132{
133 m_value++;
134}
135
136// FUNCTION: LEGO1 0x100ad800
137// FUNCTION: BETA10 0x1012364a
139{
140 if (m_value) {
141 m_value--;
142 }
143}
[AI] Atomized (unique) string identifier, managed by reference counting.
Definition: mxatom.h:124
void Clear()
[AI] Disassociates the atom ID from any atom (decrements reference count, sets internal pointer to NU...
Definition: mxatom.cpp:122
~MxAtomId()
[AI] Destructor for atom ID.
Definition: mxatom.cpp:32
MxAtomId()
[AI] Constructs a null/empty atom ID.
Definition: mxatom.h:182
MxAtomId & operator=(const MxAtomId &p_atomId)
[AI] Copy assignment operator.
Definition: mxatom.cpp:70
[AI] Set of unique atom pointers, managed with custom comparison for atomization and fast lookup.
Definition: mxatom.h:98
[AI] Key-value pair representing a unique string (atom) and its reference count.
Definition: mxatom.h:33
MxString & GetKey()
[AI] Gets the atom key (the string stored in this atom).
Definition: mxatom.h:64
void Dec()
[AI] Decrements the usage count for this atom.
Definition: mxatom.cpp:138
void Inc()
[AI] Increments the usage count for this atom, indicating one more client is using it.
Definition: mxatom.cpp:131
static MxOmni * GetInstance()
[AI] Returns the singleton instance of the MxOmni subsystem coordinator.
Definition: mxomni.cpp:289
void ToLowerCase()
Converts the string contents to lowercase in-place.
Definition: mxstring.cpp:97
void ToUpperCase()
Converts the string contents to uppercase in-place.
Definition: mxstring.cpp:90
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
LookupMode
[AI] Lookup mode used to control case sensitivity and normalization when atomizing strings.
Definition: mxatom.h:105
@ e_upperCase
[AI] Convert the string to upper case before matching/creating.
Definition: mxatom.h:108
@ e_lowerCase2
[AI] Alternative or legacy lower case mode, functionally equivalent to e_lowerCase.
Definition: mxatom.h:109
@ e_exact
[AI] Match the string exactly, no case change.
Definition: mxatom.h:106
@ e_lowerCase
[AI] Convert the string to lower case before matching/creating.
Definition: mxatom.h:107
MxAtomSet * AtomSet()
[AI] Returns the single atom set for global registered atom/value pairs.
Definition: mxmisc.cpp:41