Jump to content

SomSubstituteClass: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:somSubstituteClass}}
{{DISPLAYTITLE:somSubstituteClass}}
This method causes the [[somFindClass]], [[somFindClsInFile]], and [[somClassFromId]]methods to substitute one class for another.  
This method causes the [[somFindClass]], [[somFindClsInFile]], and [[somClassFromId]]methods to substitute one class for another.
 
;Note: For backward compatibility, this method does not take an Environment parameter.
;Original Class: [[SOMClassMgr]]


'''Note:''' For backward compatibility, this method does not take an Environment parameter.
==Syntax==
==Syntax==
<PRE>
<PRE>
Line 14: Line 16:


==Parameters==
==Parameters==
; receiver (SOMClassMgr) : Usually SOMClassMgrObject or a pointer to an instance of a user-defined subclass of  
;receiver (SOMClassMgr): Usually SOMClassMgrObject or a pointer to an instance of a user-defined subclass of SOMClassMgr.
SOMClassMgr.  
;origClassName (string): A NULL terminated string containing the old class name.
 
;newClassName (string): A NULL terminated string containing the new class name.
; origClassName (string) : A NULL terminated string containing the old class name.  
 
; newClassName (string) : A NULL terminated string containing the new class name.  


==Return Code==
==Return Code==
; rc (long) : The somSubstituteClass method returns a value of zero to indicate success; a non-zero value indicates an error was detected.  
;rc (long): The somSubstituteClass method returns a value of zero to indicate success; a non-zero value indicates an error was detected.


==Remarks==
==Remarks==
Line 58: Line 57:
}
}
</PRE>
</PRE>


==Related==
==Related==
===Methods===
;Methods
* [[somClassFromId]]  
* [[somClassFromId]]
* [[somFindClass]]  
* [[somFindClass]]
* [[somFindClsInFile]]  
* [[somFindClsInFile]]
* [[somMergeInto]]
* [[somMergeInto]]


[[Category:SOM Kernel]]
[[Category:SOM method]]

Latest revision as of 05:06, 6 May 2020

This method causes the somFindClass, somFindClsInFile, and somClassFromIdmethods to substitute one class for another.

Note
For backward compatibility, this method does not take an Environment parameter.
Original Class
SOMClassMgr

Syntax

SOMClassMgr    receiver;
string         origClassName;
string         newClassName;
long           rc;

rc = somSubstituteClass(receiver, origClassName, newClassName);

Parameters

receiver (SOMClassMgr)
Usually SOMClassMgrObject or a pointer to an instance of a user-defined subclass of SOMClassMgr.
origClassName (string)
A NULL terminated string containing the old class name.
newClassName (string)
A NULL terminated string containing the new class name.

Return Code

rc (long)
The somSubstituteClass method returns a value of zero to indicate success; a non-zero value indicates an error was detected.

Remarks

The somSubstituteClass method causes the somFindClass, somFindClsInFile, and somClassFromId methods to return the class named newClassName whenever they would normally return the class named origClassName. This effectively results in class newClassName replacing or substituting for class origClassName. For example, the <origClassName>New macro will subsequently create instances of newClassName.

Some restrictions are enforced to ensure that this works well. Both class origClassName and class newClassName must have been already registered before issuing this method, and newClass must be an immediate child of origClass. In addition (although not enforced), no instances should exist of either class at the time this method is invoked.

A convenience macro (SOM_SubstituteClass ) is provided for C or C++ users. In one operation, it creates both the old and the new class and then substitutes the new one in place of the old. The use of both the somSubstituteClass method and the SOM_SubstituteClass macro is illustrated in the example below.

Original Class

Example Code

#include <student.h>
#include <mystud.h>

/* Macro form */
SOM_SubstituteClass
 (Student, MyStudent);
/* Direct use of the method, equivalent to
 * the macro form above.
 */
{
SOMClass origClass, replacementClass;

origClass = StudentNewClass (Student_MajorVersion,
                                        Student_MinorVersion);
replacementClass = MyStudentNewClass (MyStudent_MajorVersion,
                                      MyStudent_MinorVersion);
SOMClassMgr_somSubstituteClass
 (
    SOMClass_somGetName (origClass),
    SOMClass_somGetName (replacementClass));
}

Related

Methods