Safe Haskell | None |
---|---|
Language | Haskell2010 |
Graphics.QML.Objects.Weak
Description
Facilities for working with weak references, finalisers, and factory pools.
- data WeakObjRef tt
- toWeakObjRef :: ObjRef tt -> IO (WeakObjRef tt)
- fromWeakObjRef :: WeakObjRef tt -> IO (ObjRef tt)
- data ObjFinaliser tt
- newObjFinaliser :: (ObjRef tt -> IO ()) -> IO (ObjFinaliser tt)
- addObjFinaliser :: ObjFinaliser tt -> ObjRef tt -> IO ()
- data FactoryPool tt
- newFactoryPool :: Ord tt => (tt -> IO (ObjRef tt)) -> IO (FactoryPool tt)
- getPoolObject :: Ord tt => FactoryPool tt -> tt -> IO (ObjRef tt)
Weak Object References
data WeakObjRef tt Source #
Represents a weak reference to a QML object which wraps the type tt
.
Unlike ordinary strong references, a weak reference does not prevent the QML garbage collector from collecting the underlying object. Weak references can be used to monitor the life cycles of QML objects.
toWeakObjRef :: ObjRef tt -> IO (WeakObjRef tt) Source #
Converts a strong ObjRef
into a WeakObjRef
.
fromWeakObjRef :: WeakObjRef tt -> IO (ObjRef tt) Source #
Converts a WeakObjRef
into a strong ObjRef
.
If the underlying QML object has already been collected then the resulting
ObjRef
can be used to reincarnate it.
Object Finalisers
data ObjFinaliser tt Source #
Represents an object finaliser function for QML objects which wrap the
type tt
.
newObjFinaliser :: (ObjRef tt -> IO ()) -> IO (ObjFinaliser tt) Source #
Create a new object finaliser from a finaliser function.
Note that at the time the finaliser is called the runtime will have already
comitted to collecting the underlying QML object. The ObjRef
passed into
the finaliser can be used to reincarnate the object, but this QML object
will have a distinct identity to the original.
addObjFinaliser :: ObjFinaliser tt -> ObjRef tt -> IO () Source #
Adds an object finaliser to an QML object.
The finaliser will be called no more than once for each time it was added to an object. The timing of finaliser execution is subject to the combined behaviour of the Haskell and QML garbage collectors. All outstanding finalisers will be run when the QML engine is terminated provided that the program does not prematurely exit.
Factory Pools
data FactoryPool tt Source #
Represents an object factory which maintains a one-to-one mapping between
values of type tt
and QML object instances.
ObjRef
s manufactured by the pool are cached using the wrapped type tt
as
the lookup key in an ordered map. The pool uses weak references to
automatically purge objects which no longer have any strong references
leading to them from either Haskell or QML code.
newFactoryPool :: Ord tt => (tt -> IO (ObjRef tt)) -> IO (FactoryPool tt) Source #
Creates a new FactoryPool
using the supplied factory function.
getPoolObject :: Ord tt => FactoryPool tt -> tt -> IO (ObjRef tt) Source #
Return the pool's canonical QML object for a value of tt
, either by
creating it or looking it up in the pool's cache of objects.