Isle
Loading...
Searching...
No Matches
mxatom.h
Go to the documentation of this file.
1#ifndef MXATOM_H
2#define MXATOM_H
3
4#include "mxstl/stlcompat.h"
5#include "mxstring.h"
6#include "mxtypes.h"
7
8// [AI] MxAtom, MxAtomId and supporting structures are used for efficient string-to-identifier mapping (atomization),
9// tracking the existence and use-counts of strings for reuse across the application.
10
11// Counts the number of existing MxAtomId objects based
12// on the matching char* string. A <map> seems fit for purpose here:
13// We have an MxString as a key and MxU16 as the value.
14// And yet a <set> is the best match. The malloc in MxOmni::Create
15// for the _Nil node asks for more bytes than a regular node if a <map>
16// is used, but all nodes are 20 bytes wide with a <set>.
17// Also: the increment/decrement methods suggest a custom type was used
18// for the combined key_value_pair, which doesn't seem possible with <map>.
19
20// SIZE 0x14
33class MxAtom {
34public:
35 // always inlined
36 // FUNCTION: BETA10 0x10123720
41 MxAtom(const char* p_str)
42 {
43 m_key = p_str;
44 m_value = 0;
45 }
46
51 void Inc();
52
57 void Dec();
58
59 // FUNCTION: BETA10 0x101236d0
64 MxString& GetKey() { return m_key; }
65
66 // SYNTHETIC: BETA10 0x10124a50
67 // MxAtom::`scalar deleting destructor'
68
69private:
70 MxString m_key;
71 MxU16 m_value;
72};
73
80 // FUNCTION: LEGO1 0x100ad120
81 // FUNCTION: BETA10 0x10123980
88 int operator()(MxAtom* const& p_val0, MxAtom* const& p_val1) const
89 {
90 return strcmp(p_val0->GetKey().GetData(), p_val1->GetKey().GetData()) > 0;
91 }
92};
93
98class MxAtomSet : public set<MxAtom*, MxAtomCompare> {};
99
110};
111
112// SIZE 0x04
124class MxAtomId {
125public:
131 MxAtomId(const char*, LookupMode);
132
136 ~MxAtomId();
137
144 MxAtomId& operator=(const MxAtomId& p_atomId);
145
146 // FUNCTION: BETA10 0x100178d0
152 MxBool operator==(const MxAtomId& p_atomId) const { return this->m_internal == p_atomId.m_internal; }
153
154#ifdef COMPAT_MODE
155 // Required for modern compilers.
156 // MSVC 4.20 uses a synthetic function from INCLUDE/UTILITY that inverts operator==
162 MxBool operator!=(const MxAtomId& p_atomId) const { return this->m_internal != p_atomId.m_internal; }
163#endif
164
165 // TODO:
166 // BETA10 0x1007dc20 operator==
167 // BETA10 0x10096970 operator!=
168
169 // FUNCTION: BETA10 0x10146dd0
175 MxBool operator==(const char* p_internal) const { return p_internal && !strcmp(m_internal, p_internal); }
176
177 // FUNCTION: BETA10 0x10025d40
182 MxAtomId() { this->m_internal = 0; }
183
187 void Clear();
188
189 // FUNCTION: BETA10 0x100735e0
194 const char* GetInternal() const { return m_internal; }
195
196private:
197 // FUNCTION: BETA10 0x101236f0
203 MxAtomId& operator=(const MxString& p_key)
204 {
205 m_internal = p_key.GetData();
206 return *this;
207 }
208
215 MxAtom* GetAtom(const char*, LookupMode);
216
220 void Destroy();
221
222 const char* m_internal;
223};
224
225#endif // MXATOM_H
[AI] Atomized (unique) string identifier, managed by reference counting.
Definition: mxatom.h:124
MxBool operator==(const char *p_internal) const
[AI] Tests equality against a raw string, using a direct string comparison.
Definition: mxatom.h:175
const char * GetInternal() const
[AI] Returns a pointer to the internal string, or nullptr if not set.
Definition: mxatom.h:194
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
MxBool operator==(const MxAtomId &p_atomId) const
[AI] Tests for equality with another atom ID based on the internal string pointer.
Definition: mxatom.h:152
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
MxAtom(const char *p_str)
[AI] Constructs an MxAtom with the given string as the key.
Definition: mxatom.h:41
Mindscape custom string class for managing dynamic C-strings within the game engine.
Definition: mxstring.h:14
char * GetData() const
Returns a pointer to the internal character buffer.
Definition: mxstring.h:110
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
#define set
[AI] Macro alias for Set<K, Pr>, replacing std::set<K>.
Definition: mxstl.h:413
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
[AI] STL compatibility layer header to provide consistent STL (Standard Template Library) types and a...
[AI] Functor for comparing two MxAtom pointers based on their keys (strings).
Definition: mxatom.h:79
int operator()(MxAtom *const &p_val0, MxAtom *const &p_val1) const
[AI] Compares two atom pointers lexicographically by their string keys.
Definition: mxatom.h:88