Line | |
---|
1 | /* $Id: gen_object.h,v 1.7 2001-06-10 09:19:57 sandervl Exp $ */
|
---|
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>
|
---|
12 | #ifdef OS2_INCLUDED
|
---|
13 | #include <win32api.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | class GenericObject
|
---|
17 | {
|
---|
18 | public:
|
---|
19 | GenericObject(GenericObject **head, CRITICAL_SECTION *pLock);
|
---|
20 | virtual ~GenericObject();
|
---|
21 |
|
---|
22 | GenericObject *GetHead() { return *head; };
|
---|
23 | GenericObject *GetNext() { return next; };
|
---|
24 |
|
---|
25 | void lock() { EnterCriticalSection(pLock); };
|
---|
26 | void unlock() { LeaveCriticalSection(pLock); };
|
---|
27 |
|
---|
28 | void link();
|
---|
29 | void unlink();
|
---|
30 |
|
---|
31 | #ifdef DEBUG
|
---|
32 | LONG addRef();
|
---|
33 | #else
|
---|
34 | LONG addRef() { return InterlockedIncrement(&refCount); };
|
---|
35 | #endif
|
---|
36 | LONG getRefCount() { return refCount; };
|
---|
37 | LONG release();
|
---|
38 |
|
---|
39 | void markDeleted() { fDeletePending = TRUE; };
|
---|
40 |
|
---|
41 | static void lock(CRITICAL_SECTION *pLock) { EnterCriticalSection(pLock); };
|
---|
42 | static void unlock(CRITICAL_SECTION *pLock) { LeaveCriticalSection(pLock); };
|
---|
43 |
|
---|
44 | static void DestroyAll(GenericObject *head);
|
---|
45 |
|
---|
46 | #ifdef __DEBUG_ALLOC__
|
---|
47 | void *operator new(size_t size, const char *filename, size_t lineno)
|
---|
48 | {
|
---|
49 | return _smalloc(size);
|
---|
50 | }
|
---|
51 | void operator delete(void *location, const char *filename, size_t lineno)
|
---|
52 | {
|
---|
53 | free(location);
|
---|
54 | }
|
---|
55 | #else
|
---|
56 | void *operator new(size_t size)
|
---|
57 | {
|
---|
58 | return _smalloc(size);
|
---|
59 | }
|
---|
60 | void operator delete(void *location)
|
---|
61 | {
|
---|
62 | free(location);
|
---|
63 | }
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | private:
|
---|
67 |
|
---|
68 | protected:
|
---|
69 |
|
---|
70 | CRITICAL_SECTION *pLock;
|
---|
71 | LONG refCount;
|
---|
72 | ULONG fLinked : 1,
|
---|
73 | fDeletePending : 1;
|
---|
74 |
|
---|
75 | GenericObject **head;
|
---|
76 | GenericObject *next;
|
---|
77 | };
|
---|
78 |
|
---|
79 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.