diff options
Diffstat (limited to 'backend/util.cpp')
-rw-r--r-- | backend/util.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/backend/util.cpp b/backend/util.cpp index afac06e..557df4c 100644 --- a/backend/util.cpp +++ b/backend/util.cpp @@ -1,22 +1,41 @@ +#include <stdio.h> #include <stdlib.h> #include "util.h" +#include "WeaponObject.h" +#include "ArmorObject.h" + +template <> void safe_free(void * & ptr) { if (ptr == nullptr) return; free(ptr); ptr = nullptr; } + +template <> void safe_free(const char * & ptr) { auto x = static_cast<void *>(const_cast<char *>(ptr)); safe_free(x); } -void safe_free(char * & ptr) { - auto x = static_cast<void *>(ptr); - safe_free(x); + +template <> +void safe_free(WeaponObject * & ptr) { + delete ptr; } -void safe_free(FILE * & ptr) { + +template <> +void safe_free(ArmorObject * & ptr) { + delete ptr; +} + + +template <typename T> +void safe_free(T * & ptr) { auto x = static_cast<void *>(ptr); safe_free(x); } +template void safe_free(char * &); +template void safe_free(FILE * &); + |