SOMClass

From EDM2
Jump to: navigation, search

SOMClass is the root class for all SOM metaclasses. That is, all SOM metaclasses must be subclasses of SOMClass or some other class derived from it. It defines the essential behavior common to all SOM classes. In particular, it provides a suite of methods for initializing class objects, generic methods for manufacturing instances of those classes, and methods that dynamically obtain or update information about a class and its methods at run time.

Just as all SOM classes are expected to have SOMObject (or a class derived from SOMObject) as their base class, all SOM classes are expected to have SOMClass or a class derived from SOMClass as their metaclass. Metaclasses define "class" methods (sometimes called "factory" methods or "constructors") that manufacture objects from any class object that is defined as an instance of the metaclass.

To define your own class methods, define your own metaclass by subclassing SOMClass or one of its subclasses. Three methods that SOMClass inherits and overrides from SOMObject are typically overridden by any metaclass that introduces instance data somInit, somUninit, and somDumpSelfInt. The new methods introduced in SOMClass that are frequently overridden are somNew, somRenew, and somClassReady. (See the descriptions of these methods for further information.)

Other reasons for creating a new metaclass include tracking object instances, automatic garbage collection, interfacing to a persistent object store, or providing/managing information that is global to a set of object instances.

  • File stem: somcls
  • Base: SOMObject
  • Metaclass : SOMClass (SOMClass is the only class with itself as metaclass.)
  • Ancestor Classes: SOMObject

Types

   typedef sequence <SOMClass> SOMClassSequence;

   struct somOffsetInfo  {
      SOMClass          cls;
      long              offset
      };
   typedef sequence <somOffsetInfo> SOMOffsets;

Attributes

readonly attribute somOffsets somInstanceDataOffsets

_get_somInstanceDataOffsets returns a sequence of structures, each of which indicates an ancestor of the receiver class (or the receiver class itself) and the offset to the beginning of the instance data introduced by the indicated class in an instance of the receiver class. The somOffsets information can be used in conjunction with information derived from calls to a SOM Interface Repository to completely determine the layout of SOM objects at runtime.

Example Code

#include <somcls.xh>
main()
{
   int i;
   SOMClassMgr *scm = somEnvironmentNew();
   somOffsets so = _SOMClass->_get_somInstanceDataOffsets();
   for (i=0; i
      printf("In an instance of SOMClass, %s data starts at %d\n",
                so._buffer[i]->cls->somGetName(),
                so._buffer[i]->offset);
}

Introduced Methods

The following list shows all the SOMClass introduced methods.

Group: Instance Creation (Factory)

Group: Initialization/Termination

Group: Access

Group: Testing

Group: Dynamic

Overridden Methods

The following list shows all the methods overridden by the SOMClass class. These methods are overridden in order to modify the behavior defined by an ancestor class.

Deprecated Methods

Use of the methods listed below is discouraged. There are three reasons for this:

First, these methods are used in constructing classes, and this capability is provided by the function somBuildClass. Class construction in SOM is currently a fairly complex activity, and it is likely to become even more so as the SOMobjects kernel evolves. To avoid breaking source code that constructs classes, you are advised to always use somBuildClass to build SOM classes. Note that the SOM language bindings always use somBuildClass.

Second, these methods are used for customizing aspects of SOM classes, such as method resolution and object creation. Doing this requires that metaclasses override various methods introduced by SOMClass. However, if this is done without the Cooperation Framework that implements the SOM Metaclass Framework, SOMobjects cannot guarantee that applications will function correctly. Unfortunately, the Cooperation Framework (while available to SOM users as an experimental feature) is not officially supported by the SOMobjects Toolkit. So, this is another reason why the following methods are deprecated.

Finally, some of these methods are now obsolete, so it seems appropriate that their use be discouraged.

  • somAddStaticMethod
  • somGetApplyStub
  • somGetClassData
  • somGetClassMtab
  • somGetInstanceOffset
  • somGetMethodOffset
  • somGetParent
  • somGetPCIsMtab
  • somGetPCIsMtabs
  • somGetRdStub
  • somInitClass
  • somInitMIClass
  • somOverrideMtab
  • somOverrideSMethod
  • somSetClassData
  • somSetMethodDescriptor
  • _get_somDirectInitClasses attribute
  • _set_somDirectInitClasses attribute