Saving a pointer as the class object is created: The <className>NewClass macro and the somFindClass method, used to create class objects, both return a pointer to the newly created class object. Hence, one way to obtain a pointer to a class object is to save the value returned by <className>NewClass or somFindClass when the class object is created.

Getting a pointer after the class object is created: After a class object has been created, client programs can also get a pointer to the class object from the class name. When the class name is known at compile time and the client program is using the C or C++ language bindings, the macro

_<className>

can be used to refer to the class object for <className>. Also, when the class name is known at compile time and the client program is using the C or C++ language bindings, the expression

<className>ClassData.classObject

refers to the class object for <className>. For example, _Hello refers to the class object for class "Hello" in C or C++ programs, and HelloClassData.classObject refers to the class object for class "Hello." in C or C++ programs.

Getting a pointer to the class object from an instance: If any instances of the class are known to exist, a pointer to the class object can also be obtained by invoking the somGetClass method on such an instance. (See "Getting the class of an object," above.)

Getting a pointer in other situations: If the class name is not known until run time, or if the client program is not using the C or C++ language bindings, and no instances of the class are known to exist, then the somClassFromId method can be used to obtain a pointer to a class object after the class object has been created. The somClassFromId method should be invoked on the class manager, which is pointed to by the global variable SOMClassMgrObject. The only argument to the method is a somId for the class name, which can be obtained using the somIdFromString function. The method somClassFromId returns a pointer to the class object of the specified class. For example, the following C code stores in "myClass" a pointer to the class object for class "Hello" (or NULL, if the class cannot be located):

   SOMClassMgr cm = somEnvironmentNew();
   somId classId = somIdFromString("Hello");
   SOMClass myClass =_somClassFromId(SOMClassMgrObject,classId
                          Hello_MajorVersion, Hello_MinorVersion);
   SOMFree(classId);


[Back] [Next]