2001-07-24 11:27:12 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-01-21 17:34:42 -05:00
|
|
|
// Name: garbagec.h
|
|
|
|
// Purpose: GarbageCollector class.
|
2001-07-24 11:27:12 -04:00
|
|
|
// Author: Aleksandras Gluchovas (@Lithuania)
|
|
|
|
// Modified by:
|
|
|
|
// Created: ??/10/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Aleksandras Gluchovas
|
2002-01-21 17:34:42 -05:00
|
|
|
// Licence: wxWindows licence
|
2001-07-24 11:27:12 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __GARBAGEC_G__
|
|
|
|
#define __GARBAGEC_G__
|
|
|
|
|
2002-09-07 08:28:46 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
2001-07-24 11:27:12 -04:00
|
|
|
#pragma interface "garbagec.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/list.h"
|
|
|
|
|
|
|
|
struct GCItem
|
|
|
|
{
|
2002-01-21 17:34:42 -05:00
|
|
|
void* mpObj;
|
|
|
|
wxList mRefs; // references to other nodes
|
2001-07-24 11:27:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void* gc_node_to_obj( wxNode* pGCNode )
|
|
|
|
{
|
2002-01-21 17:34:42 -05:00
|
|
|
return ( (GCItem*) (pGCNode->Data()) )->mpObj;
|
2001-07-24 11:27:12 -04:00
|
|
|
}
|
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
/*
|
|
|
|
This class implements an extremely slow but simple garbage collection algorithm.
|
|
|
|
*/
|
2001-07-24 11:27:12 -04:00
|
|
|
|
|
|
|
class GarbageCollector
|
|
|
|
{
|
|
|
|
protected:
|
2002-01-21 17:34:42 -05:00
|
|
|
wxList mAllNodes;
|
|
|
|
wxList mRegularLst;
|
|
|
|
wxList mCycledLst;
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// Internal method for finding a node.
|
|
|
|
wxNode* FindItemNode( void* pForObj );
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// 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 );
|
2001-07-24 11:27:12 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// Default constructor.
|
|
|
|
GarbageCollector() {}
|
|
|
|
|
|
|
|
// Destructor.
|
|
|
|
virtual ~GarbageCollector();
|
|
|
|
|
|
|
|
// Prepare data for garbage collection.
|
|
|
|
|
|
|
|
virtual void AddObject( void* pObj, int refCnt = 1 );
|
|
|
|
|
|
|
|
// Prepare data for garbage collection.
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
virtual void AddDependency( void* pObj, void* pDependsOnObj );
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// Executes garbage collection algorithm.
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
virtual void ArrangeCollection();
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// Accesses the results of the algorithm.
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
wxList& GetRegularObjects();
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// Get cycled objects.
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
wxList& GetCycledObjects();
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
// Removes all data from the garbage collector.
|
2001-07-24 11:27:12 -04:00
|
|
|
|
2002-01-21 17:34:42 -05:00
|
|
|
void Reset();
|
2001-07-24 11:27:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __GARBAGEC_G__ */
|
|
|
|
|