Rev | Line | |
---|
[10587] | 1 | /* $Id: gen_object.h,v 1.8 2004-04-20 10:11:42 sandervl Exp $ */
|
---|
[2469] | 2 | /*
|
---|
| 3 | * Generic Object Class for OS/2
|
---|
| 4 | *
|
---|
| 5 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
| 6 | *
|
---|
| 7 | */
|
---|
| 8 | #ifndef __GEN_OBJECT_H__
|
---|
| 9 | #define __GEN_OBJECT_H__
|
---|
| 10 |
|
---|
| 11 | #include <heapshared.h>
|
---|
[5935] | 12 | #ifdef OS2_INCLUDED
|
---|
| 13 | #include <win32api.h>
|
---|
| 14 | #endif
|
---|
[10587] | 15 | #include <VMutex.h>
|
---|
[2469] | 16 |
|
---|
| 17 | class GenericObject
|
---|
| 18 | {
|
---|
| 19 | public:
|
---|
[10587] | 20 | GenericObject(GenericObject **head, VMutex *pLock);
|
---|
[2469] | 21 | virtual ~GenericObject();
|
---|
| 22 |
|
---|
| 23 | GenericObject *GetHead() { return *head; };
|
---|
| 24 | GenericObject *GetNext() { return next; };
|
---|
| 25 |
|
---|
[10587] | 26 | void lock() { pLock->enter(); };
|
---|
| 27 | void unlock() { pLock->leave(); };
|
---|
[2469] | 28 |
|
---|
[5935] | 29 | void link();
|
---|
| 30 | void unlink();
|
---|
[2469] | 31 |
|
---|
[5950] | 32 | #ifdef DEBUG
|
---|
| 33 | LONG addRef();
|
---|
| 34 | #else
|
---|
[5935] | 35 | LONG addRef() { return InterlockedIncrement(&refCount); };
|
---|
[5950] | 36 | #endif
|
---|
[5935] | 37 | LONG getRefCount() { return refCount; };
|
---|
| 38 | LONG release();
|
---|
| 39 |
|
---|
| 40 | void markDeleted() { fDeletePending = TRUE; };
|
---|
| 41 |
|
---|
[10587] | 42 | static void lock(VMutex *pLock) { pLock->enter(); };
|
---|
| 43 | static void unlock(VMutex *pLock) { pLock->leave(); };
|
---|
[5935] | 44 |
|
---|
[2469] | 45 | static void DestroyAll(GenericObject *head);
|
---|
| 46 |
|
---|
| 47 | #ifdef __DEBUG_ALLOC__
|
---|
| 48 | void *operator new(size_t size, const char *filename, size_t lineno)
|
---|
| 49 | {
|
---|
| 50 | return _smalloc(size);
|
---|
| 51 | }
|
---|
| 52 | void operator delete(void *location, const char *filename, size_t lineno)
|
---|
| 53 | {
|
---|
| 54 | free(location);
|
---|
| 55 | }
|
---|
| 56 | #else
|
---|
| 57 | void *operator new(size_t size)
|
---|
| 58 | {
|
---|
| 59 | return _smalloc(size);
|
---|
| 60 | }
|
---|
| 61 | void operator delete(void *location)
|
---|
| 62 | {
|
---|
| 63 | free(location);
|
---|
| 64 | }
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | private:
|
---|
| 68 |
|
---|
| 69 | protected:
|
---|
| 70 |
|
---|
[10587] | 71 | VMutex *pLock;
|
---|
[5935] | 72 | LONG refCount;
|
---|
| 73 | ULONG fLinked : 1,
|
---|
| 74 | fDeletePending : 1;
|
---|
| 75 |
|
---|
| 76 | GenericObject **head;
|
---|
[10587] | 77 | GenericObject *next;
|
---|
[2469] | 78 | };
|
---|
| 79 |
|
---|
| 80 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.