~ubuntu-dev/wxwidgets2.6/upstream-debian

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/////////////////////////////////////////////////////////////////////////////
// Name:        garbagec.h
// Purpose:     GarbageCollector class.
// Author:      Aleksandras Gluchovas (@Lithuania)
// Modified by:
// Created:     ??/10/98
// RCS-ID:      $Id: garbagec.h,v 1.7 2004/07/22 18:51:10 ABX Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef __GARBAGEC_G__
#define __GARBAGEC_G__

#if defined(__GNUG__) && !defined(__APPLE__)
    #pragma interface "garbagec.h"
#endif

#include "wx/list.h"
#include "wx/fl/fldefs.h"

struct GCItem
{
    void*      mpObj;
    wxList    mRefs;   // references to other nodes
};

inline void* gc_node_to_obj( wxObjectList::compatibility_iterator pGCNode )
{
    return ( (GCItem*) (pGCNode->GetData()) )->mpObj;
}

/*
This class implements an extremely slow but simple garbage collection algorithm.
*/

class WXDLLIMPEXP_FL GarbageCollector
{
protected:
    wxList mAllNodes;
    wxList mRegularLst;
    wxList mCycledLst;

        // Internal method for finding a node.
    wxNode* FindItemNode( void* pForObj );

        // Internal method for resolving references.
    void    ResolveReferences();

        // Internal method for findind and freeing a node.
    wxNode* FindReferenceFreeItemNode();

        // Remove references to this node.
    void    RemoveReferencesToNode( wxNode* pItemNode );

        // Destroys a list of items.
    void    DestroyItemList( wxList& lst );

public:

        // Default constructor.
    GarbageCollector() {}

        // Destructor.
    virtual ~GarbageCollector();

        // Prepare data for garbage collection.

    virtual void AddObject( void* pObj, int refCnt = 1 );

        // Prepare data for garbage collection.

    virtual void AddDependency( void* pObj, void* pDependsOnObj );

        // Executes garbage collection algorithm.

    virtual void ArrangeCollection();

        // Accesses the results of the algorithm.

    wxList& GetRegularObjects();

        // Get cycled objects.

    wxList& GetCycledObjects();

        // Removes all data from the garbage collector.

    void Reset();
};

#endif /* __GARBAGEC_G__ */