]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/fl/garbagec.h
generate makefile.unx files using bakefile
[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 #include "wx/list.h"
16 #include "wx/fl/fldefs.h"
17
18 struct GCItem
19 {
20 void* mpObj;
21 wxList mRefs; // references to other nodes
22 };
23
24 inline void* gc_node_to_obj( wxObjectList::compatibility_iterator pGCNode )
25 {
26 return ( (GCItem*) (pGCNode->GetData()) )->mpObj;
27 }
28
29 /*
30 This class implements an extremely slow but simple garbage collection algorithm.
31 */
32
33 class WXDLLIMPEXP_FL GarbageCollector
34 {
35 protected:
36 wxList mAllNodes;
37 wxList mRegularLst;
38 wxList mCycledLst;
39
40 // Internal method for finding a node.
41 wxNode* FindItemNode( void* pForObj );
42
43 // Internal method for resolving references.
44 void ResolveReferences();
45
46 // Internal method for findind and freeing a node.
47 wxNode* FindReferenceFreeItemNode();
48
49 // Remove references to this node.
50 void RemoveReferencesToNode( wxNode* pItemNode );
51
52 // Destroys a list of items.
53 void DestroyItemList( wxList& lst );
54
55 public:
56
57 // Default constructor.
58 GarbageCollector() {}
59
60 // Destructor.
61 virtual ~GarbageCollector();
62
63 // Prepare data for garbage collection.
64
65 virtual void AddObject( void* pObj, int refCnt = 1 );
66
67 // Prepare data for garbage collection.
68
69 virtual void AddDependency( void* pObj, void* pDependsOnObj );
70
71 // Executes garbage collection algorithm.
72
73 virtual void ArrangeCollection();
74
75 // Accesses the results of the algorithm.
76
77 wxList& GetRegularObjects();
78
79 // Get cycled objects.
80
81 wxList& GetCycledObjects();
82
83 // Removes all data from the garbage collector.
84
85 void Reset();
86 };
87
88 #endif /* __GARBAGEC_G__ */
89