00001 /* $Id: gen_object.h,v 1.7 2001/06/10 09:19:57 sandervl Exp $ */ 00002 /* 00003 * Generic Object Class for OS/2 00004 * 00005 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) 00006 * 00007 */ 00008 #ifndef __GEN_OBJECT_H__ 00009 #define __GEN_OBJECT_H__ 00010 00011 #include <heapshared.h> 00012 #ifdef OS2_INCLUDED 00013 #include <win32api.h> 00014 #endif 00015 00016 class GenericObject 00017 { 00018 public: 00019 GenericObject(GenericObject **head, CRITICAL_SECTION *pLock); 00020 virtual ~GenericObject(); 00021 00022 GenericObject *GetHead() { return *head; }; 00023 GenericObject *GetNext() { return next; }; 00024 00025 void lock() { EnterCriticalSection(pLock); }; 00026 void unlock() { LeaveCriticalSection(pLock); }; 00027 00028 void link(); 00029 void unlink(); 00030 00031 #ifdef DEBUG 00032 LONG addRef(); 00033 #else 00034 LONG addRef() { return InterlockedIncrement(&refCount); }; 00035 #endif 00036 LONG getRefCount() { return refCount; }; 00037 LONG release(); 00038 00039 void markDeleted() { fDeletePending = TRUE; }; 00040 00041 static void lock(CRITICAL_SECTION *pLock) { EnterCriticalSection(pLock); }; 00042 static void unlock(CRITICAL_SECTION *pLock) { LeaveCriticalSection(pLock); }; 00043 00044 static void DestroyAll(GenericObject *head); 00045 00046 #ifdef __DEBUG_ALLOC__ 00047 void *operator new(size_t size, const char *filename, size_t lineno) 00048 { 00049 return _smalloc(size); 00050 } 00051 void operator delete(void *location, const char *filename, size_t lineno) 00052 { 00053 free(location); 00054 } 00055 #else 00056 void *operator new(size_t size) 00057 { 00058 return _smalloc(size); 00059 } 00060 void operator delete(void *location) 00061 { 00062 free(location); 00063 } 00064 #endif 00065 00066 private: 00067 00068 protected: 00069 00070 CRITICAL_SECTION *pLock; 00071 LONG refCount; 00072 ULONG fLinked : 1, 00073 fDeletePending : 1; 00074 00075 GenericObject **head; 00076 GenericObject *next; 00077 }; 00078 00079 #endif