Next: The Rot2d Example
Up: Creating a New Class
Previous: The Data Structure for
Together with the methods described in section 5.4.2 the following methods provide the basic operations for
handling classes and methods in an object-oriented environment. All
these basic methods belong to class Root, therefore they can
be invoked on every class via inheritance.
To create a new class call
- (CLASS * ) GRAPE(superclass, "new-class")(name, size)
- CLASS * superclass
char * name
int size
This will create a subclass of superclass named name. For
every new instance of this class size bytes of memory will be
allocated, therefore size should be the size of the struct of the
new class (sizeof(NAME)). The result of this method is a pointer of
type CLASS * to the new class. This value should be stored in
a class pointer CLASS *Name, see section 5.3.2 for naming conventions.
Classes can be deleted by calling
- GRAPE(My_Class, "delete")()
- CLASS * My_Class
The class My_Class will be removed from the class hierarchy only
if there are neither subclasses nor instances of My_Class left.
All "delete" methods should return NULL, then the return value of
the "delete" call can be used to reset the pointer to the instance or
class that was deleted:
obj = (MY_CLASS *)GRAPE(obj, "delete")();
To check if a class with a specific name exists the method
- (CLASS * ) GRAPE(class, "find-class")(name)
- CLASS * class
char * name
can be used. It will search all subclasses of class class for a
class named name and return the pointer to that class or NULL
if no class with that name exists.
SFB 256 Universität Bonn and IAM Universität Freiburg Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik,
Universität Bonn.