Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Huggle::Collectable Class Reference

Base for all items that are supposed to be collected by garbage collector. More...

#include <collectable.hpp>

+ Inheritance diagram for Huggle::Collectable:

Public Member Functions

unsigned long CollectableID ()
 CollectableID. More...
 
QString DebugHgc ()
 DebugHgc. More...
 
bool IsLocked ()
 
bool IsManaged ()
 IsManaged Managed class is deleted by GC and must not be deleted by hand. More...
 
void Lock ()
 Lock this object so that other threads can't change consumers or modify its properties.
 
void RegisterConsumer (const int consumer)
 Registers a consumer. More...
 
void RegisterConsumer (const QString consumer)
 Registers a consumer. More...
 
virtual bool SafeDelete ()
 Use this if you are not sure if you can delete this object in this moment.
 
void Unlock ()
 Unlock this object for deletion by other threads.
 
void UnregisterConsumer (const int consumer)
 This function will remove a string which prevent the object from being removed. More...
 
void UnregisterConsumer (const QString consumer)
 This function will remove a string which prevent the object from being removed. More...
 

Private Member Functions

void SetManaged ()
 

Static Private Member Functions

static QString ConsumerIdToString (const int id)
 

Private Attributes

unsigned long CID
 
QStringList Consumers
 
QList< int > iConsumers
 
bool Locked
 
bool Managed
 Internal variable that contains a cache whether object is managed.
 
QMutex * QL
 

Static Private Attributes

static unsigned long LastCID = 0
 
static QMutex WideLock
 

Detailed Description

Base for all items that are supposed to be collected by garbage collector.

In order for any item to be maintained by garbage collector it must be inherited from this class. Every object by default when created is unmanaged, which means, that garbage collector doesn't care about it. In order to change it to managed object, you have to register at least one consumer. Once you do that, the class must not be explicitly deleted using delete, if you do that unrecoverable exception will be thrown. The class which is managed (you can verify that by calling Collectable::IsManaged) can be only deleted by garbage collector when no consumers are using it. Basically every object that has 0 consumers, will be deleted.

Definition at line 34 of file collectable.hpp.

Member Function Documentation

unsigned long Collectable::CollectableID ( )

CollectableID.

Returns

Definition at line 93 of file collectable.cpp.

Referenced by DebugHgc().

QString Collectable::DebugHgc ( )

DebugHgc.

Returns
debug info

Definition at line 137 of file collectable.cpp.

References CollectableID().

bool Collectable::IsLocked ( )

Whether the object is locked (other threads can't register nor unregister consumers neither it is possible to delete this object by any other thread)

Definition at line 162 of file collectable.cpp.

bool Collectable::IsManaged ( )

IsManaged Managed class is deleted by GC and must not be deleted by hand.

Returns
whether the class is managed

Definition at line 179 of file collectable.cpp.

References Managed.

Referenced by Huggle::GC::DeleteOld().

void Collectable::RegisterConsumer ( const QString  consumer)

Registers a consumer.

This function will store a string which prevent the object from being removed by QueryGC, by calling this function you change the query type to managed

Parameters
consumerString that lock the object

Definition at line 76 of file collectable.cpp.

References Lock(), and Unlock().

void Collectable::UnregisterConsumer ( const QString  consumer)

This function will remove a string which prevent the object from being removed.

Parameters
consumerUnique string that unlock the object

Definition at line 85 of file collectable.cpp.

References Lock(), and Unlock().


The documentation for this class was generated from the following files: