#ifndef _OBTRACE_HPP #define _OBTRACE_HPP struct CNODE_STRUCT { char loc[100]; struct CNODE_STRUCT* next; struct CNODE_STRUCT* prev; }; typedef struct CNODE_STRUCT CNODE; #define count (*((int*)init)) #define list (*((CNODE**)(init+sizeof(int)))) template class OBTRACE { public: // method OBTRACE ------------------------------------------ OBTRACE() { if (init == 0) { init = (char*)malloc(sizeof(int)+sizeof(CNODE*)); if (init == 0) { printf("memory allocation error\n"); exit(1); } count = 0; list = 0; } count = count + 1; id=Insert(REPORT()); }//end OBTRACE // method ~OBTRACE ------------------------------------------ ~OBTRACE() { Delete(id); count = count - 1; }//end ~OBTRACE // method GetCount ------------------------------------------ static int GetCount() { if (init == 0) return 0; else return count; }//end GetCount // method reportCount ------------------------------------------ static void ReportCount(FILE* fp,char* type) { fprintf(fp,"[%s] number of objects of class %s = %d\n", REPORT(),type,count); fflush(fp); }//end ReportCount // method ReportAll ------------------------------------------ static void ReportAll(FILE *fp,char* type) { CNODE* cnode; for(cnode = list; cnode != NULL; cnode=cnode->next) fprintf(fp,"undeallocated object of class %s created in %s\n", type,cnode->loc); fflush(fp); } protected: CNODE* id; static char* init; // method Insert ------------------------------------------ static CNODE* Insert(char* local) { CNODE* cnode; cnode=(CNODE*)malloc(sizeof(CNODE)); if (cnode==NULL) { printf("memory allocation error\n"); exit(1); } strcpy(cnode->loc,local); cnode->next=list; cnode->prev=NULL; if (list != NULL) list->prev=cnode; list = cnode; return cnode; }//end Insert // method Delete ------------------------------------------ static void Delete(CNODE* d) { if (d->prev == NULL && d->next == NULL) list = NULL; else if (d->prev == NULL) { d->next->prev = NULL; list = d->next; }else if (d->next == NULL) d->prev->next = NULL; else{ d->prev->next = d->next; d->next->prev = d->prev; } free(d); }//end Delete };//end class OBTRACE #endif // _OBTRACE_HPP