blob: edf9539986559da2f237a122726b94d46ce07c64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#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) {
// wow c++ casts so readable
auto a = const_cast<char **>(ptr);
auto b = static_cast<void *>(a);
auto c = reinterpret_cast<void**>(b);
safe_free(c);
}
template <>
void safe_free(WeaponObject ** ptr) {
delete *ptr;
*ptr = nullptr;
}
template <>
void safe_free(ArmorObject ** ptr) {
delete *ptr;
*ptr = nullptr;
}
template <typename T>
void safe_free(T ** ptr) {
auto a = static_cast<void *>(ptr);
auto b = reinterpret_cast<void **>(ptr);
safe_free(b);
}
template void safe_free(char **);
template void safe_free(FILE **);
|