123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #ifndef __ALL_H
- #define __ALL_H
- #ifndef __WINDOWS_
- #include <windows.h>
- #endif
- #ifndef __OMISC_H
- #include <OMISC.h>
- #endif
- #ifndef __OSTR_H
- #include <OSTR.h>
- #endif
- #ifndef __OFILE_H
- #include <OFILE.h>
- #endif
- #ifndef __GAMEDEF_H
- #include <GAMEDEF.h>
- #endif
- #define max(a,b) (((a) > (b)) ? (a) : (b))
- #define min(a,b) (((a) < (b)) ? (a) : (b))
- #ifdef DEBUG
- void __cdecl debug_msg( char* fmt, ... );
- #endif
- struct MemInfo;
- class Mem
- {
- public :
- MemInfo* info_array;
- short ptr_num;
- short ptr_used;
- public :
- Mem();
- ~Mem();
- char* add(unsigned,char*,int);
- char* add_clear(unsigned,char*,int);
- char* resize(void*,unsigned,char*,int);
- char* resize_keep_data(void *orgPtr, unsigned orgSize, unsigned newSize, char* fileName, int fileLine);
- void del(void*,char*,int);
- int get_mem_size(void *memPtr);
- };
- char* mem_resize_keep_data(void*,unsigned,unsigned);
- extern Mem mem;
- typedef void (*ExtraHandler)();
- class Error
- {
- private:
- ExtraHandler extra_handler;
- public:
- Error();
- void internal(char*,char*,int);
- void mem();
- void msg(char*,...);
- void run(char*,...);
- void set_extra_handler(ExtraHandler extraHandler) { extra_handler = extraHandler; }
- };
- extern Error err;
- #ifdef DEBUG
- #define err_when(cond) if(cond) err.internal(NULL,__FILE__, __LINE__)
- #define err_here() err.internal(NULL,__FILE__, __LINE__)
- #define err_if(cond) if(cond)
- #define err_else else
- #define err_now(msg) err.run(msg) // internal error
-
- #else
- #define err_when(cond)
- #define err_here()
- #define err_if(cond)
- #define err_else
- #define err_now(msg)
- #endif
- #ifndef NO_MEM_CLASS
- #define mem_add(memSize) mem.add(memSize, __FILE__, __LINE__)
- #define mem_add_clear(memSize) mem.add_clear(memSize, __FILE__, __LINE__)
- #define mem_resize(orgPtr,newSize) mem.resize(orgPtr, newSize, __FILE__, __LINE__)
- #define mem_del(memPtr) mem.del(memPtr, __FILE__, __LINE__)
- #define mem_resize_keep_data(orgPtr, orgSize, newSize) \
- mem.resize_keep_data(orgPtr, orgSize, newSize, __FILE__, __LINE__)
- #else
- #define mem_add(memSize) ((char*)malloc(memSize))
- #define mem_add_clear(memSize) ((char*)calloc(1,memSize))
- #define mem_resize(orgPtr, newSize) ((char*)realloc(orgPtr,newSize))
- #define mem_del(memPtr) free(memPtr)
-
- #endif
- #endif
|