Class class describes a PCE class. All classes (including class class itself) are an instance of this class. The classes are organised in a single-inheritance hierarchy. Class object is the root of the PCE class hierarchy. A class can be regarded meta-data describing (among others) the following properties of its instances:
send
virtual machine operation.
get
virtual machine operation.
->load_defaults.
The user may create and modify classes to extend the PCE system. Classes are created just like any other PCE object:
?- new(X, class(person, object)).
Creates a class named person below class object. Initially class person only differs from class object by its name.
<->inspect’for this instance
is @on.
->inspect.
Each code object is
activated in turn and the returned status of the execution is ignored.
Argument binding:
@arg1 Instance who's slot changed @arg2 Name of the changed slot.
Changes are not notified before the initialisation of the instance is complete or after the destruction has started.
This trap is used by the inspector tool. See also class->created_message
and
class->freed_message.
<-clone
returns @nil.
See also object<-clone
and variable<-clone_style.
@arg1 Name of the class @arg2 Reference to the new instance @arg3 Action that caused the creation of the object
Possible values for @arg3 are:
new Normal creation (new/2 or class <-instance)loaded Loaded by source_sink <-objectclone Cloned using object <-clone
May be used to keep track of the set of instances of this class in
combination wit class->freed_message.
See also class->changed_message
and class->record_instances.
<-delegate
consists of instance variable
objects that should be used for delegation. The PCE message passing
system will try to forward an incoming message to the values of these
instance variables after it failed to locate an implementation at the
object or class level. The elements of this chain are tried in the order
they appear in the chain.
class ->delegateAdds a variable at the end class ->prepend_delegateAdds a variable at the start
See also class<-send_method
and class<-get_method.
<->inspect:
@on’,
its reference will be passed to the code
objects in this chain. Argument binding:
@arg1: Object to be freed.
This message is sent as the first action of object->free.
See also
class->changed_message
and class->created_message.
<->catch_all’.
<-get_method
and class<-send_method, object<-send_method
and‘object
class<-get_method’,
for resolving methods.
<->slot.
The -get_table and -send_table both map selectors onto implementations.
The implementation is either a method or a variable. All these tables
only contain the currently resolved methods: they are initially empty.
Used and maintained by:
-local_table class <-instance_variable-get_table class <-get_method-send_table class <-send_method
Handles at the class level are normally declared using the handle/4 construct expanded by the Prolog defined class compiler.
inside a graphical
object.
parts of the instance.<-slot.
The behaviour<-context
argument may be used to find the class on which a variable is defined.
The following code returns a chain of instance variables not
inherited:
new(Vs, chain),
send(Class?instance_variables, for_all,
if(@arg1?context == Class,
message(Vs, append, @arg1)))
<-instances
contains all instances of this class that have been created since the
table was attached to the class. Note that instances of sub-classes are not
in this table. The table is maintained by the new() and free()
virtual machine operations as well as by object<-clone
and
source_sink<-object.
This table is attached using class->record_instances.
If the first argument is @on
or @default an class<-instances
table is attached. If this argument is @off
a possible associated table is detached. If the second (recursive)
argument is @on
(default), class->record_instances
will be invoked with the same arguments on all sub-classes. Thus
?- send(class(object), record_instances).
Will record the instances of all classes.
See also class->created_message
and class->freed_message.
-get_tablePCE built-in classes have relatively short and simple names. It is adviced to prefix application classes with a common prefix to avoid conflicts with other packages or future PCE classes. For example, all classes consituting PceDraw are called draw_<something>.
subtoo is @on
it adds the number of instances created in all
class<-sub_classes
recursively.
To find the actual number of existing instances, subtract
class<-no_freed.
<-name, class<-super_class, class<-sub_classes,
class<-summary and -make_class_function
are defined. All other slots have undefined values.
When information or instances of a non-realised class are requested,
XPCE will invoke class->realise
on the class to build the class.
Inherits description from: class->realise
->save_in_file.
If this methods encounters a slot holding an instance of this class it
will save the instance according to the value of class<-save_style:
normal Save the instance to the file external Save the (named) reference to the file nil Write @nil to the file
See also variable<-save_style
and source_sink<-object.
<->selected: @on’.
See also graphical.selection_style. This
class_variable
object is redefined for each subclass of graphical.-get_table<-sub_classes
and class<-super_class
define the class hierarchy. The class hierarchy is visualised using the‘Class
Hierarchy’tool from the online manual tools. The class<-super_class
of class object is @nil.
The method class<-super_class_name
is used to create the appropriate term description (see object<-_arg).
<-_arg
to return the nth (1-based) argument of the term-description.
If element <n> of this vector has value <selector>, the
class must define <-<selector> and the nth (1-based) result of object<-_arg
is the result of <-<selector> on the object.
For example, class point
defined class<-term_functor: point and class<-term_vector
vector(x,y). Therefore the term has the form:
point(`point<-x`, `point<-y`)
->is_a
and object->instance_of.
After a modification on the class hierarchy (normally a class created),
PCE numbers the class-hierarchy top-down and left-to-right.
The slot -tree_index is assigned the current number when this class
is first reached, while the slot -neighbour_index is assigned the
current number after numbering the subtree below this class. Now,
a class A is_a B iff
(A<-tree_index) >= (B<-tree_index) AND (A<-tree_index) < (B<-neighbour_index)
answers to methods, this table is called the answer
table internally.
If an object is made an attribute of another object, it will be
removed from the answer table and reclaimed by the garbage collector it
its reference count drops to zero. Object remaining in the answer table
are reclaimed if the context in which they where created is
ended. The main event-loop starts/ends such a context and likewise do
all method executions.
Now consider the code below, which produces an alphabetically ordered list of class-names:
?- new(Chain, chain),
send(@classes, for_all,
message(Chain, append, @arg1)),
send(Chain, sort).
With the above schema, Chain will be an answer object
after creation. It will be made a slot of the message
object, thus loosing its answer status. After the chain->for_all,
PCE will garbage collect the message. The reference count of the chain
drops to zero and thus the chain is reclaimed too.
This situation is common and therefore class code
sets the class<-un_answer
flags to @off.
This tells variable->send
not to remove the chain from the answer table.
-changed_messages
|int,
style={recursive,reference,reference_chain,value,alien,nil}<-clone_style
of named variable. Equivalent to
get(Class, instance_variable, Name, Var), send(Var, clone_style, Style)
See also object<-clone.
-created_messages
|int-delegate-freed_messages
->get_method, class->send_method
and class->instance_variable
are used to expand or redefine the behaviour of a class. They are
normally used right after the class has been created. The following
restrictions apply:
send access there
should not be a send_method and if a variable has get
access there should not be a get_method with the same name. If both
exist, the method is used instead of the variable.
Note that both the Prolog and Lisp language interfaces provide an interface for defining methods. See their resp. manual.
The methods object->slot, object->send_super,‘object
object<-get_super’and
friends are designed to support the definition of method
implementations. See also class code.
-handles
->instance_of.
|int-delegate.e. fills the class
definition). Called by the kernel if details are requested for a class
that has been registered using pce->define_class.
See also class<-realised.-instances|int,
style={normal,nil}<-save_style
for named variable.
-name
or type object of type<-kind
into a class object.
If a class does not exist and the argument is a name, the
pce->exception
with context argument the name of the required class is generated. This
mechanism is used by the autoloader (pce_autoload/2).
<-get_method
and object<-send_method
operate at the object level and take care of object-level defined
behaviour as well as delegation.
See also object->has_get_method
and object<-get_method.
<-alloc_value
of the corresponding variable
object.
variable -initial_value), execute these funcions and assign
the slot values.
->initialise
to the new object with the arguments given to this method.
->initialise
fails, the exception
initialise_failed is raised using pce->exception.
The context parameter is the (incomplete) object reference.
->initialise
succeeds, class<-instance
returns the new object.
NOTE: pce<-instance
is an alternative for creating objects. This gate has two advantages:
type conversion allows you to specify the class-name
rather than the class, and -if the class does not yet exist-, an
exception is raised allowing the class autoloading to create it. See
also class create and new/2
|int -> variable<-instance_variables,
class<-send_method
or class<-get_method.super is specified, class<-lookup
verifies the super and generates an error message on a mismatch. This
method ensures that
?- get(class(point), instance, 4, 5, P).
Actually returns an instance of the existing class point instead of returning an instance of a new class named point.
subtoo is
@on the freed
instances of class<-sub_classes
are added. See also class<-no_created.-sub_classes