-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefinitionsAndIncludes.h
87 lines (75 loc) · 1.98 KB
/
DefinitionsAndIncludes.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef DEFINITIONSANDINCLUDE_H
#define DEFINITIONSANDINCLUDE_H
//memory leak check
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
//windows headers
#include <windows.h>
LRESULT CALLBACK MsgProc(HWND HWND, UINT uMsg, WPARAM wParam, LPARAM lParam);
//directx headers
#define D3D_DEBUG_INFO
#include <d3d9.h>
#include <d3dx9.h>
// c/c++ runtime library
#include <cstdio>
#include <cstdlib>
#include <wchar.h>
#include <ctime>
//file input/output
#include <fstream>
//containers
#include <list>
#include <vector>
//resources
#include "resource.h"
#include "squall.h"
#define SAFE_RELEASE(pointer) { if (pointer != NULL) { delete (pointer); (pointer)=NULL; } }
#define SAFE_ARRAY_RELEASE(pointer) { if (pointer != NULL) { delete [](pointer); (pointer)=NULL; } }
#define SAFE_COM_RELEASE(pointer) { if (pointer != NULL) { pointer->Release(); (pointer)=NULL; } }
template <class T>
class SmartPointer
{
T* pointer;
DWORD *counter;
bool isArray;
public:
SmartPointer(T* data, bool isArray = false) { this->pointer = data; this->counter = new DWORD; *this->counter = 0; this->isArray = isArray;}
T* GetData() { return this->pointer; }
SmartPointer(SmartPointer &right) {
(*right.counter)++;
this->counter = right.counter;
this->pointer = right.pointer;
this->isArray = right.isArray;
}
~SmartPointer() {
if(*this->counter == 0)
{
this->isArray ? delete []this->pointer : delete this->pointer;
delete this->counter;
}
else (*this->counter)--;
}
};
template <class T>
class SmartPointerCOM
{
T* pointer;
DWORD *counter;
public:
SmartPointerCOM(T* data, bool isArray = false) { this->pointer = data; this->counter = new DWORD; *this->counter = 0;}
T* GetData() { return this->pointer; }
SmartPointerCOM(SmartPointerCOM &right) {
(*right.counter)++;
this->counter = right.counter;
this->pointer = right.pointer;
}
~SmartPointerCOM() {
if(*this->counter == 0)
{
this->pointer->Release();
delete this->counter;
}
else (*this->counter)--;
}
};
#endif