1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename        : ALL.H
22 //Description : General-purpose header file
23 
24 #ifndef __ALL_H
25 #define __ALL_H
26 
27 //--------- Include other headers -------//
28 
29 #include <OMISC.h>
30 #include <OSTR.h>
31 #include <OFILE.h>
32 #include <GAMEDEF.h>
33 #include <OERROR.h>
34 
35 
36 //-------- Define macro functions -------//
37 
38 #define MAX(a,b)        (((a) > (b)) ? (a) : (b))
39 #define MIN(a,b)        (((a) < (b)) ? (a) : (b))
40 
41 //---------- define class Mem ----------//
42 
43 struct MemInfo;
44 
45 class Mem
46 {
47 public :
48 	MemInfo* info_array;
49 	short    ptr_num;
50 	short    ptr_used;
51 
52 public :
53 	Mem();
54 	~Mem();
55 
56 	char* add(unsigned, const char*, int);
57 	char* add_clear(unsigned, const char*,int);
58 	char* resize(void*,unsigned, const char*,int);
59 	char* resize_keep_data(void *orgPtr, unsigned orgSize, unsigned newSize, const char* fileName, int fileLine);
60 	void  del(void*,const char*,int);
61 
62 	int get_mem_size(void *memPtr);
63 };
64 
65 extern Mem mem;
66 
67 //------ memory allocation functions --------//
68 
69 #ifndef NO_MEM_CLASS
70 
71 	#define mem_add(memSize)             mem.add(memSize, __FILE__, __LINE__)
72 	#define mem_add_clear(memSize)       mem.add_clear(memSize, __FILE__, __LINE__)
73 	#define mem_resize(orgPtr,newSize)   mem.resize(orgPtr, newSize, __FILE__, __LINE__)
74 	#define mem_del(memPtr)              mem.del(memPtr, __FILE__, __LINE__)
75 
76 #else
77 
78 	#include <stdlib.h>
79 
80 	#define mem_add(memSize)            ((char*)malloc(memSize))
81 	#define mem_add_clear(memSize)      ((char*)calloc(1,memSize))
82 	#define mem_resize(orgPtr, newSize) ((char*)realloc(orgPtr,newSize))
83 	#define mem_del(memPtr)             free(memPtr)
84 
85 #endif
86 
87 //--------------------------------------------//
88 
89 #endif
90