Jump to content

SomClassResolve

From EDM2
Revision as of 16:40, 10 October 2017 by Martini (talk | contribs) (Macros)

This function obtains a pointer to the procedure that implements a static method for instances of a particular SOM class.

Syntax

SOMClass        cls;
somMToken       mToken;
somMethodPtr    rc;

rc = somClassResolve(cls, mToken);

Parameters

cls (SOMClass)
A pointer to the class object whose instance method procedure is required.
mToken (somMToken)
The method token for the method to be resolved. The SOM API requires that if the class "XYZ" introduces the static method "foo", then the method token for "foo" is found in the class data structure for "XYZ" (called XYZClassData) in the structure member named "foo" (i.e., at XYZClassData.foo). Method tokens can also be obtained using the somGetMethodToken method. A pointer to the class object whose instance method procedure is required.

Return Code

rc (somMethodPtr)
A pointer to the somMethodProc (procedure) that implements the specified method for the specified class of SOM object.

Remarks

This function is used to obtain a pointer to the procedure that implements the specified method for instances of the specified SOM class. The returned procedure pointer can then be used to invoke the method. The somClassResolve function is used to support "casted" method calls, in which a method is resolved with respect to a specified class rather than the class of which an object is a direct instance. The somClassResolve function can only be used to obtain a method procedure for a static method (a method declared in an IDL specification for a class); dynamic methods do not have method tokens.

The SOM language usage bindings for C and C++ do not support casted method calls, so this function must be used directly to achieve this functionality. Whenever using SOM method procedure pointers, it is necessary to indicate the use of system linkage to the compiler. The way this is done depends on the compiler and the system being used. However, C and C++ usage bindings provide an appropriate typedef for this purpose. The name of the typedef is based on the name of the class that introduces the method, as illustrated in the example below.

Example Code

// SOM IDL for class A and class B
#include <somobj.idl>
module scrExample {
  interface A : SOMObject { void foo(); implementation
{ callstyle=oidl;};};
  interface B : A  {  implementation { foo: override;};};
};

// Example C++ program to implement and test module scrExample
#define SOM_Module_screxample_Source
#include <scrExample.xih>
#include <stdio.h>

SOM_Scope void SOMLINK scrExample_Afoo(scrExample_A *somSelf);
{  printf("1\n");}

SOM_Scope void SOMLINK scrExample_Bfoo(scrExample_B *somSelf);
{ printf("2\n");}

main()
{
  scrExample_B  *objPtr = new scrExample_B;

// This prints 2
objPtr->foo();

// This prints 1
   ((somTD_scrExample_A_foo) /* A necessary method procedure cast */
     somClassResolve(
              ,_scrExample_A, // the A class object
              scrExample_AClassData.foo) // the foo method token
     ) /* end of method procedure expression */
     (objPtr); /* method arguments */

// This prints 2
   ((somTD_scrExample_A_foo) /* A necessary method procedure cast */
     somClassResolve(
              ,_scrExample_B, // the B class object
              scrExample_AClassData.foo) // the foo method token
     ) /* end of method procedure expression */
     (objPtr); /* method arguments */

}

Related

Data Structures

  • somMethodPtr (sombtype.h)
  • SOMClass (somcls.idl)
  • somMToken (somapi.h)

Functions

  • somResolveByName
  • somParentResolve
  • somParentNumResolve
  • somResolve

Methods

  • somDispatch
  • somClassDispatch
  • somFindMethod
  • somFindMethodOk
  • somGetMethodToken

Macros

  • SOM_Resolve
  • SOM_ResolveNoCheck