Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 9ceb69b

Browse files
committed
Use std::function for memory allocation/deallocation callbacks
1 parent b60d662 commit 9ceb69b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

System/Entity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace RTE {
231231

232232
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233233

234-
Entity::ClassInfo::ClassInfo(const std::string &name, ClassInfo *pParentInfo, void * (*fpAllocFunc)(), void(*fpDeallocFunc)(void *), Entity * (*fpNewFunc)(), int allocBlockCount) :
234+
Entity::ClassInfo::ClassInfo(const std::string &name, ClassInfo *pParentInfo, MemoryAllocate fpAllocFunc, MemoryDeallocate fpDeallocFunc, Entity * (*fpNewFunc)(), int allocBlockCount) :
235235
m_Name(name),
236236
m_pParentInfo(pParentInfo),
237237
m_fpAllocate(fpAllocFunc),

System/Entity.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace RTE {
88

9+
typedef std::function<void*()> MemoryAllocate; //!< Convenient name definition for the memory allocation callback function.
10+
typedef std::function<void(void*)> MemoryDeallocate; //!< Convenient name definition for the memory deallocation callback function.
911

1012
#pragma region Global Macro Definitions
1113
#define ABSTRACTCLASSINFO(TYPE, PARENT) \
@@ -92,7 +94,7 @@ namespace RTE {
9294
/// <param name="fpDeallocFunc">Function pointer to the raw deallocation function of memory. If the represented Entity subclass isn't concrete, pass in 0.</param>
9395
/// <param name="fpNewFunc">Function pointer to the new instance factory. If the represented Entity subclass isn't concrete, pass in 0.</param>
9496
/// <param name="allocBlockCount">The number of new instances to fill the pre-allocated pool with when it runs out.</param>
95-
ClassInfo(const std::string &name, ClassInfo *pParentInfo = 0, void * (*fpAllocFunc)() = 0, void(*fpDeallocFunc)(void *) = 0, Entity * (*fpNewFunc)() = 0, int allocBlockCount = 10);
97+
ClassInfo(const std::string &name, ClassInfo *pParentInfo = 0, MemoryAllocate fpAllocFunc = 0, MemoryDeallocate fpDeallocFunc = 0, Entity * (*fpNewFunc)() = 0, int allocBlockCount = 10);
9698
#pragma endregion
9799

98100
#pragma region Getters
@@ -182,9 +184,10 @@ namespace RTE {
182184
int m_PoolAllocBlockCount; //!< The number of instances to fill up the pool of this type with each time it runs dry.
183185
int m_InstancesInUse; //!< The number of allocated instances passed out from the pool.
184186

185-
void *(*m_fpAllocate)(); //!< Raw memory allocation for the size of the type this ClassInfo describes.
186-
void(*m_fpDeallocate)(void *); //!< Raw memory deallocation for the size of the type this ClassInfo describes.
187+
MemoryAllocate m_fpAllocate; //!< Raw memory allocation for the size of the type this ClassInfo describes.
188+
MemoryDeallocate m_fpDeallocate; //!< Raw memory deallocation for the size of the type this ClassInfo describes.
187189

190+
// TODO: figure out why this doesn't want to work when defined as std::function.
188191
Entity *(*m_fpNewInstance)(); //!< Returns an actual new instance of the type that this describes.
189192

190193
// Forbidding copying

0 commit comments

Comments
 (0)