SOM Kernel Reference 1-147
More information and examples on object initialization (especially regarding the
somDefaultInit method) are given in the topic “Initializing and Uninitializing Objects” in
Chapter 5, “Implementing Classes in SOM,” of the SOM Toolkit User’s Guide.
Parameters
receiver A pointer to the object to be initialized.
C Example
Following is the implementation for a class Animal that introduces an attribute sound of type
string and overrides somInit and somUninit, along with a main program that creates and
then frees an instance of class Animal:
#define Animal_Class_Source
#include <animal.ih>
#include <string.h>
SOM_Scope void SOMLINK somInit (Animal somSelf)
{
AnimalData *somThis = AnimalGetData (somSelf);
Environment *ev = somGetGlobalEnvironment();
Animal_parents_somInit (somSelf);
if (!__get_sound(somSelf, ev)) {
__set_sound(somSelf, ev, SOMMalloc(100));
strcpy (__get_sound(somSelf, ev), ”Unknown Noise”);
somPrintf (”New Animal Initialized\n”);
}
}
SOM_Scope void SOMLINK somUninit (Animal somSelf)
{
AnimalData *somThis = AnimalGetData (somSelf);
Environment *ev = somGetGlobalEnvironment();
if (__get_sound(somSelf, ev)) {
SOMFree(__get_sound(somSelf, ev);
__set_sound(somSelf, ev, (char*)0);
somPrintf (”Animal Uninitialized\n”);
Animal_parents_somUninit (somSelf);
}
}
/* main program */
#include <animal.h>
void main()
{
Animal myAnimal;
myAnimal = AnimalNew ();
_somFree (myAnimal);
}
/*
Program output:
New Animal Initialized
Animal Uninitialized
*/
Original Class
SOMObject
Related Information
Methods: somDefaultInit, somNew, somRenew, somDestruct, somUninit
Comentários a estes Manuais