#ifndef _CG_CPP_H_ #define _CG_CPP_H_ #if defined(_LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus) #include extern void *cgnew_temp; /* * We've got a slightly modified syntax for new, as the standard one * doesn't work properly. * It should work just the same though.... * Except that you can only call the default constructor using new * others are called by parameter counts * eg. * my_class *test; * test=new(my_class); // Use the default constructor my_class::my_class(void) * test=new1(my_class,"hello"); // use a single parameter constructor my_class::my_class(char*) * test=new2(my_class,"hello",74); // use a two parameter constructor my_class::my_class(char*,int) * */ #define new(x) (x*)cgnew_temp=(x*)malloc(sizeof(x)); \ { \ x *temp=(x*)cgnew_temp; \ temp->__ct(); \ } #define new1(x,a) (x*)cgnew_temp=(x*)malloc(sizeof(x)); \ { \ x *temp=(x*)cgnew_temp; \ temp->__ct((a)); \ } #define new2(x,a,b) (x*)cgnew_temp=(x*)malloc(sizeof(x)); \ { \ x *temp=(x*)cgnew_temp; \ temp->__ct((a),(b)); \ } #define new3(x,a,b,c) (x*)cgnew_temp=(x*)malloc(sizeof(x)); \ { \ x *temp=(x*)cgnew_temp; \ temp->__ct((a),(b),(c)); \ } /* * In a slight change to delete, we set the pointer variable to NULL after * calling the destructor and freeing the memory - it makes bug tracking slightly easier */ #define delete(x) (x)->__dt(0); \ free(x); \ (x)=NULL; #endif #endif