Simulation Modeling Tool Kit
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
smtk::resource::GarbageCollector Class Reference

A class that owns ephemeral objects and remove them when abandoned. More...

#include <GarbageCollector.h>

Inheritance diagram for smtk::resource::GarbageCollector:
Collaboration diagram for smtk::resource::GarbageCollector:

Public Types

using WeakManagerPtr = smtk::operation::WeakManagerPtr
using Key = smtk::operation::Observers::Key
using ObserverMap = std::map< WeakManagerPtr, Key, std::owner_less< WeakManagerPtr > >

Public Member Functions

 smtkTypeMacroBase (smtk::resource::GarbageCollector)
 smtkCreateMacro (smtk::resource::GarbageCollector)
 GarbageCollector (const GarbageCollector &)=delete
GarbageCollectoroperator= (const GarbageCollector &)=delete
bool add (const smtk::operation::OperationPtr &deleter)
 Queue an operation to clean up an ephemeral resource.

Protected Types

enum  Status { Invalid = 0, NotReady = 1, Ready = 2 }

Protected Member Functions

int collectGarbage (const smtk::operation::Operation &, smtk::operation::EventType, smtk::operation::Operation::Result)

Static Protected Member Functions

static Status checkOperation (const smtk::operation::Operation *op)
 Returns true if the operation is ready to be evaluated, false otherwise.

Protected Attributes

std::set< smtk::operation::OperationPtrm_garbage
 The set of operations used to collect garbage (and whose associations indicate which objects are garbage).
ObserverMap m_observers
 The "ids" of observers calling collectGarbage after each operation.

Detailed Description

A class that owns ephemeral objects and remove them when abandoned.

This class will queue an operation (which you provide) to delete the ephemeral objects associated with the operation when their shared-pointer use-count drops to 1 (indicating they are owned solely by the resource managing them).

Note that your deletion operation must (a) accept associations, (b) prevent its associations from holding references (i.e., "HoldReference"="false"), and (c) require at least 1 associated persistent object.

This class works by adding an observer to the registered operation manager and iterating over its set of delete-operations' associations when any operation completes successfully.

Note that an operation, A, passed to the garbage collector is not guaranteed to run; some other operation, B, may delete the associated objects first. In that case, when B completes successfully, the garbage collector will run, see that A has no valid associated objects (since they are weak references to the deleted object), and remove operation A from its list of collectors. It is also possible A will never be invoked because the program exits while holding references.

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