Next: gauche.mop.propagate
- Propagating slot access, Previous: gauche.logger
- User-level logging, Up: Library modules - Gauche extensions [Contents][Index]
gauche.mop.instance-pool
- Instance poolsSometimes, you want to track all instances created from a class. This module provies tools to do that.
An instance pool class is a class that keeps the list of instances of itself and its subclasses.
A class that inherits <instance-pool-mixin>
directly becomes a ’root’
class of the pool. Instances of the subclass of the root class will
be added to the pool.
An application can have multiple root classes. If a class inherits from two or more pooled classes, its instances will be added to all the pools.
The actual implementation of how to manage pools can be customizable
by subclassing <instance-pool-meta>
and overloading methods.
Note that instance pools are global—it keeps all the instances ever created, unless explicitly cleared.
{gauche.mop.instance-pool} A metaclass that adds a class the capability of tracking its instances. By default, instance of itself and its subclasses are tracked.
{gauche.mop.instance-pool}
A mixin class that makes the class that directly inherits this mixin
an instance of <instnace-pool-meta>
. You can use this mixin
class, instead of using metaclass explicitly, to make a class
a root of the pool.
{gauche.mop.instance-pool}
Returns a list of instances in the pool of class,
which should be an instance
of <instance-pool-meta>
.
The list is fresly constructuted every time it is called.
The order of instances are not specified.
{gauche.mop.instance-pool}
Returns an instance of class which satisfies the predicate pred.
If no instance satisfies it, #f
is returned.
{gauche.mop.instance-pool} Remove all instances that satisfies the predicate pred from the pool of class.
{gauche.mop.instance-pool} Calls kons over every instance in the pool of class, with the current accumulated value. The initial value is knil, and each return value of kons is used as the next value. The last return value of kons is returned from the function.
It is functionally equivalent with the following, except that it may
be more efficient (without creating intermediate list). Also, the
order of instances are not guaranteed to be the same as
instance-pool->list
returns.
(fold kons knil (instance-pool->list class))
{gauche.mop.instance-pool}
Apply proc on each instances in the pool of class;
instance-pool-map
gathers the results into a list and returns it,
while instance-pool-for-each
discards the result of proc.
The order in which instances are visited is not specified.
Next: gauche.mop.propagate
- Propagating slot access, Previous: gauche.logger
- User-level logging, Up: Library modules - Gauche extensions [Contents][Index]