coastline 0.0.4
Loading...
Searching...
No Matches
mfc.h
Go to the documentation of this file.
1#ifndef COASTLINE_EAR_MFC_H
2#define COASTLINE_EAR_MFC_H
3
4#include <cstddef>
5
6#if TGR_PLATFORM == TGR_PLATFORM_WIN
7#include <windows.h>
8#else
9#include "common/types.h"
10#endif
11
12class CArchive;
13class CDumpContext;
14class CRuntimeClass;
15class CPlex;
16
24
26class CObject {
27public:
29 virtual CRuntimeClass *GetRuntimeClass() const;
31 virtual ~CObject();
36 virtual void Serialize(CArchive &archive);
38 virtual void AssertValid() const;
43 virtual void Dump(CDumpContext &context) const;
44};
45
47typedef struct __POSITION {
54
60class CMapWordToPtr : public CObject {
61public:
66 explicit CMapWordToPtr(int blockSize = 10);
68 ~CMapWordToPtr() override;
70 int GetCount() const;
74 BOOL IsEmpty() const;
81 BOOL Lookup(WORD key, void *&value) const;
87 void SetAt(WORD key, void *value);
95 void RemoveAll();
104 void GetNextAssoc(POSITION &position, WORD &key, void *&value) const;
110 void InitHashTable(UINT hashSize, BOOL allocate = TRUE);
111
112private:
113 class Association;
114 Association **hashTable;
115 UINT hashTableSize;
116 int count;
117 Association *freeAssociations;
118 CPlex *blocks;
119 int blockSize;
120};
121
126class CWordList : public CObject {
127public:
132 explicit CWordList(int blockSize = 10);
134 ~CWordList() override;
136 BOOL IsEmpty() const;
138 int GetCount() const;
148 WORD &GetNext(POSITION &position);
179 void RemoveAt(POSITION position);
181 void RemoveAll();
182
183private:
184 struct Node;
185 Node *head;
186 Node *tail;
187 int count;
188 Node *freeNodes;
189 CPlex *blocks;
190 int blockSize;
191};
192
193#if TGR_PLATFORM == TGR_PLATFORM_WIN
194class CFileException;
195
197class CFile : public CObject {
198public:
202 modeWrite = 0x0001,
204 modeCreate = 0x1000,
206 typeBinary = 0x8000,
207 };
208
212 ~CFile() override;
221 virtual BOOL Open(LPCSTR fileName, UINT openFlags, CFileException *error = nullptr);
227 virtual void Write(const void *buffer, UINT count);
229 virtual void Close();
230
231private:
232 UINT file;
233 BOOL closeOnDelete;
234#if defined(ENABLE_PATCHES) || !defined(_MSC_VER) || _MSC_VER > 1200
235 // The unused field preserves the MFC class layout.
236 [[maybe_unused]] char *fileName;
237#else
238 char *fileName;
239#endif
240};
241#endif
242
248class CMapPtrToPtr : public CObject {
249public:
254 explicit CMapPtrToPtr(int blockSize = 10);
256 ~CMapPtrToPtr() override;
258 int GetCount() const;
266 void SetAt(void *key, void *value);
272 BOOL RemoveKey(void *key);
278 void InitHashTable(UINT hashSize, BOOL allocate = TRUE);
279
280private:
281 class Association;
282 Association **hashTable;
283 UINT hashTableSize;
284 int count;
285 Association *freeAssociations;
286 CPlex *blocks;
287 int blockSize;
288};
289
290#endif /* COASTLINE_EAR_MFC_H */
virtual void Write(const void *buffer, UINT count)
Attempt a synchronous write without reporting failure or a partial write.
~CFile() override
Close a file successfully opened through this wrapper.
CFile()
Initialise a wrapper without an open file.
virtual void Close()
Close the current file if open and reset the wrapper, discarding closure errors.
OpenFlags
Bit flags accepted by Open(); combinations select access and creation behaviour.
Definition mfc.h:200
@ modeWrite
Request write access rather than the default read access.
Definition mfc.h:202
@ typeBinary
Binary-mode compatibility flag; Windows byte operations require no conversion.
Definition mfc.h:206
@ modeCreate
Create a new file or truncate an existing file.
Definition mfc.h:204
virtual BOOL Open(LPCSTR fileName, UINT openFlags, CFileException *error=nullptr)
Open a Windows file with shared read and write access.
UINT GetHashTableSize() const
~CMapPtrToPtr() override
Release buckets and association pools without deleting key or value objects.
void InitHashTable(UINT hashSize, BOOL allocate=TRUE)
Replace bucket storage in an empty map without changing the association-pool configuration.
BOOL RemoveKey(void *key)
Remove an association and release all storage when the map becomes empty.
int GetCount() const
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
BOOL RemoveKey(WORD key)
Remove an association and release all storage when the map becomes empty.
~CMapWordToPtr() override
Release buckets and association pools without deleting pointer values.
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 IsEmpty() const
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
virtual CRuntimeClass * GetRuntimeClass() const
virtual void AssertValid() const
Do not validate object state.
virtual void Serialize(CArchive &archive)
Do not serialise archive data.
virtual ~CObject()
The base destructor does not perform additional cleanup.
virtual void Dump(CDumpContext &context) const
Do not emit diagnostic output.
CWordList(int blockSize=10)
Initialise an empty list with node allocation deferred until insertion.
POSITION AddTail(WORD value)
Insert a value at the tail.
POSITION InsertAfter(POSITION position, WORD value)
Insert a value after a position, or at the tail for a null position.
BOOL IsEmpty() const
POSITION InsertBefore(POSITION position, WORD value)
Insert a value before a position, or at the head for a null position.
void RemoveAt(POSITION position)
Remove a node and release all pool blocks when the list becomes empty.
~CWordList() override
Release all nodes and pool blocks.
POSITION AddHead(WORD value)
Insert a value at the head.
void RemoveAll()
Remove every node and release all pool blocks.
int GetCount() const
WORD & GetNext(POSITION &position)
Retrieve a node value and advance towards the tail.
WORD & GetHead()
POSITION GetHeadPosition() const
struct __POSITION * POSITION
Opaque container position representation; instances must not be dereferenced.
void * MfcAllocateWithNewHandler(std::size_t size)
Allocate uninitialised storage with the current new handler retried after allocation failure.
The integer and floating-point types of the console, for headers shared with Windows.
#define TRUE
Definition ultratypes.h:53
typedef BOOL
typedef LPCSTR
typedef UINT
typedef WORD