Jump to content

somIsA

From EDM2

This method tests whether an object is an instance of a given class or of one of its descendant classes. Not generally overridden.

For backward compatibility, this method does not take an Environment parameter.

Original Class
SOMObject

Syntax

boolean somIsA (SOMObject receiver, SOMClass aClass)

Parameters

receiver (SOMObject)
A pointer to the object to be tested.
aClass (SOMClass)
A pointer to the class that the object should be tested against.

Return Code

rc (boolean)
Returns 1 (true) if the receiving object is an instance of the specified class or (unlike somIsInstanceOf) of any of its descendant classes, and 0 (false) otherwise.

Remarks

Use the somIsA method to determine if an object can be treated like an instance of aClass. SOM guarantees that if somIsA returns true, then the receiver will respond to all (static or dynamic) methods supported by aClass.

Example Code

#include <dog.h>
/* ----------------------------------
   Note:  Dog is derived from Animal.
   ---------------------------------- */
main()
{
  Animal myAnimal;
  Dog myDog;
  SOMClass animalClass;
  SOMClass dogClass;

  myAnimal = AnimalNew();
  myDog = DogNew();
  animalClass = _somGetClass (myAnimal);
  dogClass = _somGetClass (myDog);
  if (_somIsA (myDog, animalClass))
     somPrintf ("myDog IS an Animal\n");
  else
     somPrintf ("myDog IS NOT an Animal\n");
  if (_somIsA (myAnimal, dogClass))
     somPrintf ("myAnimal IS a Dog\n");
  else
     somPrintf ("myAnimal IS NOT a Dog\n");
  _somFree (myAnimal);
  _somFree (myDog);
}
/*
Output from this program:
myDog IS an Animal
myAnimal IS NOT a Dog
*/

Related

Methods