For Gauche 0.9.14Search (procedure/syntax/module):

Next: , Previous: , Up: ライブラリモジュール - Gauche拡張モジュール   [Contents][Index]

9.18 gauche.mop.instance-pool - インスタンスプール

Module: gauche.mop.instance-pool

Sometimes, 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.

Class: <instance-pool-meta>

{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.

Class: <instance-pool-mixin>

{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.

Generic Function: instance-pool->list class

{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.

Generic Function: instance-pool-find class pred

{gauche.mop.instance-pool} Returns an instance of class which satisfies the predicate pred. If no instance satisfies it, #f is returned.

Generic Function: instance-pool-remove! class pred

{gauche.mop.instance-pool} Remove all instances that satisfies the predicate pred from the pool of class.

Generic Function: instance-pool-fold class kons knil

{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))
Generic Function: instance-pool-map class proc
Generic Function: instance-pool-for-each class proc

{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: , Previous: , Up: ライブラリモジュール - Gauche拡張モジュール   [Contents][Index]


For Gauche 0.9.14Search (procedure/syntax/module):