aboutsummaryrefslogtreecommitdiff
path: root/backend/util.cpp
blob: 557df4c84422fdd8f3f645c7d0e9fe3f1d697b20 (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
#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);
}

template <>
void safe_free(WeaponObject * & ptr) {
	delete 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 * &);