coastline 0.0.4
Loading...
Searching...
No Matches
registry.h
Go to the documentation of this file.
1#ifndef COASTLINE_EAR_REGISTRY_H
2#define COASTLINE_EAR_REGISTRY_H
3
4#include <bit>
5#include <cstdint>
6#include <type_traits>
7
8#include "ear/mfc.h"
9
10class EarEnvironment;
11class EarWaveSample;
12class EarPlayback;
13class EarChannel;
14class EarPresetTable;
15
21template <typename Value>
24public:
33 BOOL LookupWordPointerMapValue(std::uint16_t key, Value *&value) const {
34 void *entry;
35 if (!Lookup(key, entry)) {
36 return FALSE;
37 }
38 value = static_cast<Value *>(entry);
39 return TRUE;
40 }
41
48 void SetWordPointerMapValue(std::uint16_t key, Value *value) {
49 SetAt(key, value);
50 }
51
55 void GrowWhenFull() {
56 if (GetCount() != static_cast<int>(GetHashTableSize())) {
57 return;
58 }
60 copy.InitHashTable(GetCount(), TRUE);
61 POSITION position = GetStartPosition();
62 do {
63 WORD key;
64 void *entry;
65 GetNextAssoc(position, key, entry);
66 copy.SetWordPointerMapValue(key, static_cast<Value *>(entry));
67 } while (position);
68 RemoveAll();
69 InitHashTable(copy.GetCount() + 10, TRUE);
70 position = copy.GetStartPosition();
71 do {
72 WORD key;
73 void *entry;
74 copy.GetNextAssoc(position, key, entry);
75 SetWordPointerMapValue(key, static_cast<Value *>(entry));
76 } while (position);
77 copy.RemoveAll();
78 }
79};
80
86template <typename Value>
89public:
97 void SetDwordPointerMapValue(DWORD key, Value *value) {
98#if TGR_PLATFORM == TGR_PLATFORM_WIN
99 SetAt(std::bit_cast<void *>(key), value);
100#else
101 // A pointer of the map is wider than the key on a 64-bit processor.
102 SetAt(std::bit_cast<void *>(static_cast<std::uintptr_t>(key)), value);
103#endif
104 }
105
113#if TGR_PLATFORM == TGR_PLATFORM_WIN
114 return RemoveKey(std::bit_cast<void *>(key));
115#else
116 return RemoveKey(std::bit_cast<void *>(static_cast<std::uintptr_t>(key)));
117#endif
118 }
119};
120
123public:
129 explicit EarActiveEventRegistry(int blockSize = 10);
132
137 BOOL IsEmpty() const {
138 return count == 0;
139 }
140
147 BOOL Lookup(DWORD key, WORD &value) const;
154 void SetAt(DWORD key, WORD value);
162
163private:
164 class Association;
165 Association **hashTable;
166 UINT hashTableSize;
167 int count;
168 Association *freeAssociations;
169 CPlex *blocks;
170 int blockSize;
171};
172
178extern EarWordPointerRegistry<EarEnvironment> g_EnvironmentRegistry;
183extern EarWordPointerRegistry<EarWaveSample> g_PresetRegistry;
188extern EarActiveEventRegistry g_ActiveEventRegistry;
189
194extern EarDwordPointerRegistry<EarPlayback> g_PlaybackRegistry;
195
200extern EarWordPointerRegistry<EarChannel> g_ChannelRegistry;
205extern EarWordPointerRegistry<EarPresetTable> g_MatrixRegistry;
207
208#endif /* COASTLINE_EAR_REGISTRY_H */
T bit_cast(T... args)
BOOL RemoveKey(void *key)
Remove an association and release all storage when the map becomes empty.
void SetAt(void *key, void *value)
Insert or replace a pointer without releasing the previous value.
CMapPtrToPtr(int blockSize=10)
Initialise an empty map with 17 buckets allocated on first insertion.
int GetCount() const
CMapWordToPtr(int blockSize=10)
Initialise an empty map with 17 buckets allocated on first insertion.
void GetNextAssoc(POSITION &position, WORD &key, void *&value) const
Retrieve an association in hash-bucket order and advance the cursor.
POSITION GetStartPosition() const
void RemoveAll()
Release all associations and buckets without deleting pointer values.
void SetAt(WORD key, void *value)
Insert or replace a pointer without releasing the previous value.
UINT GetHashTableSize() const
void InitHashTable(UINT hashSize, BOOL allocate=TRUE)
Replace bucket storage in an empty map without changing the association-pool configuration.
BOOL Lookup(WORD key, void *&value) const
Look up a pointer without changing the output on a missing key.
Polymorphic MFC compatibility base with inactive serialisation and diagnostic hooks.
Definition mfc.h:26
Map 32-bit event identifiers to 16-bit channel handles using pooled associations.
Definition registry.h:122
~EarActiveEventRegistry() override
Release hash buckets and association pools without changing external events.
void SetAt(DWORD key, WORD value)
Insert or replace a channel handle.
BOOL IsEmpty() const
Definition registry.h:137
BOOL RemoveKey(DWORD key)
Remove an association without stopping the event.
EarActiveEventRegistry(int blockSize=10)
Initialise an empty registry with 17 hash buckets allocated on first insertion.
BOOL Lookup(DWORD key, WORD &value) const
Look up a channel handle without changing the output on a missing key.
Map 32-bit handles through pointer keys without deleting registered objects.
Definition registry.h:88
void SetDwordPointerMapValue(DWORD key, Value *value)
Insert or replace a borrowed object pointer using the handle bits as the map key.
Definition registry.h:97
BOOL RemovePlaybackRegistryKey(DWORD key)
Remove a mapping without releasing the registered object.
Definition registry.h:112
Default-registration marker, set after a registration attempt even when registration fails.
Definition environment.h:94
Common event playback state with overridable media, device, and stream operations.
Definition earplayback.h:17
A wave file loaded whole into memory, which a preset registers and sample playbacks share.
Definition wavesample.h:15
Map 16-bit handles to borrowed object pointers without deleting registered objects.
Definition registry.h:23
void GrowWhenFull()
Rebuild with ten additional buckets when entry count equals bucket count.
Definition registry.h:55
void SetWordPointerMapValue(std::uint16_t key, Value *value)
Insert or replace a pointer without releasing the previous object.
Definition registry.h:48
BOOL LookupWordPointerMapValue(std::uint16_t key, Value *&value) const
Look up a registered pointer without changing the output on a missing key.
Definition registry.h:33
T is_class_v
struct __POSITION * POSITION
Opaque container position representation; instances must not be dereferenced.
#define TRUE
Definition ultratypes.h:53
#define FALSE
Definition ultratypes.h:54
typedef BOOL
typedef DWORD
typedef UINT
typedef WORD