]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/fl/garbagec.h
implement wxColourDialog::Move() (patch 548048)
[wxWidgets.git] / contrib / include / wx / fl / garbagec.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: garbagec.h
3 // Purpose: GarbageCollector class.
4 // Author: Aleksandras Gluchovas (@Lithuania)
5 // Modified by:
6 // Created: ??/10/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __GARBAGEC_G__
13 #define __GARBAGEC_G__
14
15 #ifdef __GNUG__
16 #pragma interface "garbagec.h"
17 #endif
18
19 #include "wx/list.h"
20
21 struct GCItem
22 {
23 void* mpObj;
24 wxList mRefs; // references to other nodes
25 };
26
27 inline void* gc_node_to_obj( wxNode* pGCNode )
28 {
29 return ( (GCItem*) (pGCNode->Data()) )->mpObj;
30 }
31
32 /*
33 This class implements an extremely slow but simple garbage collection algorithm.
34 */
35
36 class GarbageCollector
37 {
38 protected:
39 wxList mAllNodes;
40 wxList mRegularLst;
41 wxList mCycledLst;
42
43 // Internal method for finding a node.
44 wxNode* FindItemNode( void* pForObj );
45
46 // Internal method for resolving references.
47 void ResolveReferences();
48
49 // Internal method for findind and freeing a node.
50 wxNode* FindReferenceFreeItemNode();
51
52 // Remove references to this node.
53 void RemoveReferencesToNode( wxNode* pItemNode );
54
55 // Destroys a list of items.
56 void DestroyItemList( wxList& lst );
57
58 public:
59
60 // Default constructor.
61 GarbageCollector() {}
62
63 // Destructor.
64 virtual ~GarbageCollector();
65
66 // Prepare data for garbage collection.
67
68 virtual void AddObject( void* pObj, int refCnt = 1 );
69
70 // Prepare data for garbage collection.
71
72 virtual void AddDependency( void* pObj, void* pDependsOnObj );
73
74 // Executes garbage collection algorithm.
75
76 virtual void ArrangeCollection();
77
78 // Accesses the results of the algorithm.
79
80 wxList& GetRegularObjects();
81
82 // Get cycled objects.
83
84 wxList& GetCycledObjects();
85
86 // Removes all data from the garbage collector.
87
88 void Reset();
89 };
90
91 #endif /* __GARBAGEC_G__ */
92