somParentNumResolve

From EDM2
Jump to: navigation, search

This function obtains a pointer to a procedure that implements a method, given a list of method table.

Syntax

somMethodTabs    parentMtab;
int              parentNum;
somMToken        mToken;
somMethodPtr     rc;

rc = _somParentNumResolve(parentMtab, parentNum, mToken);

Parameters

parentMtab (somMethodTabs)
A list of method tables for the parents of the class being implemented. The SOM API specifies that the list of parent method tables for a given class be stored in the auxiliary class data structure of the class, in the parentMtab component. Thus, for the class "XYZ", the parent method table list is found in location XYZCClassData.parentMtab. Parent method table lists are available from class objects via the method call somGetPClsMtabs.
parentNum (int)
The position of the parent for which the method is to be resolved. The order of a class's parents is determined by the order in which they are specified in the interface statement for the class. (The first parent is number 1.)
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.

Return Code

rc (somMethodPtr)
A pointer to a somMethodProc (procedure) that implements the specified method, selected from the specified method table.

Remarks

This function is used to make parent method calls by the C and C++ language implementation bindings. The somParentNumResolve function returns a pointer to a procedure for performing the specified method. This pointer is selected from the specified method table, which is intended to be the method table corresponding to a parent class.

For C and C++ programmers, the implementation bindings for SOM classes provide convenient macros for making parent method calls (the "parent_" macros).

Example Code

// SOM IDL for class A and class B
#include <somobj.h>
module spnrExample {
  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_spnrexample_Source
#include <spnrExample.xih>
#include <stdio.h>

SOM_Scope void SOMLINK spnrExample_Afoo(spnrExample_A *somSelf);
{  printf("1\n"); }

SOM_Scope void SOMLINK spnrExample_Bfoo(spnrExample_B *somSelf);
{ printf("2\n"); }

main()
{
  spnrExample_B  *objPtr = new spnrExample_B;

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

// This prints 1
   ((somTD_spnrExample_A_foo)
/* This method procedure expression cast is necessary */
           somParentNumResolve(
                    ,objPtr->somGetClass()->somGetPClsMtabs(),
                    "1"
                    spnrExample_AClassData.foo) // the foo method token
           ) /* end of method procedure expression */
           (objPtr); /* method arguments */
}

Related

Data Structures
  • somMethodPtr (sombtype.h)
  • somMethodTabs (somapi.h)
  • somMToken (somapi.h)
Functions
Methods
Macros