home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / somcdev.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  9.6 KB  |  324 lines

  1. /*
  2.  *   COMPONENT_NAME: somk
  3.  *
  4.  *   ORIGINS: 27
  5.  *
  6.  *
  7.  *   10H9767, 10H9769  (C) COPYRIGHT International Business Machines Corp. 1992,1994
  8.  *   All Rights Reserved
  9.  *   Licensed Materials - Property of IBM
  10.  *   US Government Users Restricted Rights - Use, duplication or
  11.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  12.     Last change:  KAS  23 Sep 94    3:00 pm
  13.  */
  14. /* %Z% %I% %W% %G% %U% [%H% %T%] */
  15.  
  16. /*
  17.  */
  18.  
  19. /*
  20.  *    SOMCDEV.H
  21.  *    System Object Model development support for ANSI C
  22.  *    Multiple Inheritance Version
  23.  */
  24.  
  25. #ifndef somcdev_h
  26. #define somcdev_h
  27.  
  28. #include <somtypes.h>
  29. #if !defined(__SOMDLL__)
  30.   #include <stdlib.h>  /* needed for atexit, used below */
  31. #endif /* __SOMDLL__ */
  32.  
  33.  
  34. /*
  35.  *  Method and Data Resolution macros
  36.  */
  37.  
  38. /*
  39.  *  Method Resolution. Methods are invoked on an object o of some
  40.  *  object class oc, where oc has immediate ancestor classes
  41.  *  called parent classes. Macro arguments include method names
  42.  *  (e.g., mn), object class and parent class names (e.g., ocn, pcn)
  43.  *  and parent class positions (e.g., pcp), expressed in terms of the
  44.  *  left-to-right ordering (beginning with 1, for the first parent)
  45.  *  used when declaring oc's parents. The choice of resolution
  46.  *  macro determines the method table from which methods are selected.
  47.  *
  48.  *  Macros are available to select a method from ...
  49.  */
  50.  
  51. /*
  52.  * Default definition of somresolve_ to call the procedure, somResolve.
  53.  * This may be be changed by emitters on systems for which method
  54.  * tokens are thunks.
  55.  */
  56. #define somresolve_(obj,mToken) (somResolve(obj,mToken))
  57.  
  58. /* from oc's mtbl, with verification of o */
  59. #define SOM_Resolve(o, ocn, mn) \
  60.     (( somTD_ ## ocn ## _ ## mn ) \
  61.      somresolve_(SOM_TestCls(o, ocn ## ClassData.classObject), \
  62.         ocn ## ClassData.mn ))
  63.  
  64. /* from oc's mtbl, without verification of o */
  65. #define SOM_ResolveNoCheck(o, ocn, mn) \
  66.     (( somTD_ ## ocn ## _ ## mn ) \
  67.      somresolve_(o, \
  68.         ocn ## ClassData.mn ))
  69.  
  70. /* from the pcp'th element of oc's CClassData.parentMtab list */
  71. #define SOM_ParentNumResolveCC(pcn, pcp, ocn, mn) \
  72.     (( somTD_ ## pcn ## _ ## mn ) \
  73.      somParentNumResolve( ocn ## CClassData.parentMtab, pcp, \
  74.              pcn ## ClassData.mn ))
  75.  
  76. /* from the pcp'th element of an argument mtab list */
  77. #define SOM_ParentNumResolve(pcn, pcp, mtabs, mn) \
  78.     (( somTD_ ## pcn ## _ ## mn ) \
  79.      somParentNumResolve(mtabs, pcp, \
  80.              pcn ## ClassData.mn ))
  81.  
  82. /* from an argument class's method table */
  83. #define SOM_ClassResolve(cn, class, mn) \
  84.     (( somTD_ ## cn ## _ ## mn ) \
  85.      somClassResolve(class, \
  86.              cn ## ClassData.mn ))
  87.  
  88.  
  89. /* support reintroduction of methods */
  90. /* tdc == typedef class name; cdc == classdata class name */
  91. #define SOM_ResolveD(o, tdc, cdc, mn) \
  92.     (( somTD_ ## tdc ## _ ## mn ) \
  93.       somresolve_(SOM_TestCls(o, cdc ## ClassData.classObject),\
  94.              cdc ## ClassData.mn))
  95.  
  96.  
  97. /* from the first mtbl in an argument mtbl list ...
  98.  
  99.   This macro is here primarily to document the behavior
  100.   of previously-compiled single inheritance code that used
  101.   the macro of this name. The behavior is that of using
  102.   SOM_ParentNumResolve with a pcp of 1.
  103. */
  104. #define SOM_ParentResolveE(pcn, mtbls, mn) \
  105.     (( somTD_ ## pcn ## _ ## mn ) \
  106.      somParentResolve(mtbls, \
  107.               pcn ## ClassData.mn ))
  108.  
  109.  
  110.  
  111. /*
  112.  * Data resolution macro
  113.  */
  114.  
  115. #define SOM_DataResolve(obj, dataId) \
  116.   (somDataResolve(obj, dataId))
  117.  
  118.  
  119. /*  -------------------------------------------------------------------
  120.  *  The following macros are for purposes of backward compatibility
  121.  *  with prior versions of SOM.  There is no advantage to using them
  122.  *  over a direct call to the corresponding routine.
  123.  */
  124.  
  125. #define SOM_CompareValidIds(id1,id2) (somCompareIds(id1,id2))
  126.  
  127. #define SOM_CompareIds(id1,id2) (somCompareIds(id1,id2))
  128.  
  129. #define SOM_StringFromId(id) (somStringFromId(id))
  130.  
  131. #define SOM_IdFromString(str) (somIdFromString(str))
  132.  
  133. #define SOM_CheckId(id) (somCheckId(id))
  134.  
  135. /*
  136.  * Convenience macro for somSubstituteClass method.
  137.  */
  138. #ifdef __cplusplus     
  139. #define SOM_SubstituteClass(old,new) \
  140.     {old##NewClass(old##_MajorVersion, old##_MinorVersion);\
  141.      new##NewClass(new##_MajorVersion, new##_MinorVersion);\
  142.      SOMClassMgrObject->somSubstituteClass(_##old->somGetName(),\
  143.                            _##new->somGetName());}
  144.  
  145.  
  146. #else
  147. #define SOM_SubstituteClass(old,new) \
  148.     {old##NewClass(old##_MajorVersion, old##_MinorVersion);\
  149.      new##NewClass(new##_MajorVersion, new##_MinorVersion);\
  150.      _somSubstituteClass(SOMClassMgrObject,\
  151.              _somGetName(_##old),\
  152.              _somGetName(_##new));}
  153. #endif
  154.  
  155.  
  156. #if !defined(__SOMDLL__)
  157.  
  158.   /*
  159.    * Main programs should register for SOM cleanup at exit
  160.    */
  161.  
  162.    #define SOM_MainProgram()\
  163.     (atexit(somEnvironmentEnd), somMainProgram())
  164.  
  165.   /*
  166.    * somEnvironmentEnd may not have the right
  167.    * linkage to be called by atexit. Allow a user to
  168.    * create a routine that can be called by atexit
  169.    * and which will call somEnvironmentEnd.
  170.    */
  171.  
  172.    #define SOM_MainProgramWithUserExit( userExitFcn ) \
  173.     (atexit( userExitFcn ), somMainProgram())
  174.  
  175. #endif /* __SOMDLL__ */
  176.  
  177. /*
  178.  * Platform provided automatic class library initialization rtns
  179.  * should use this macro to inform the SOM Class Manager that
  180.  * they have been loaded. 
  181.  */
  182. #define SOM_ClassLibrary(name)\
  183.     (somRegisterClassLibrary(name,\
  184.     (somMethodProc *) &SOMInitModule))
  185.  
  186.  
  187. /*
  188.  *   Development support macros and globals
  189.  */
  190.  
  191. #ifdef SOM_STRICT_IDL
  192. #define SOMSTAR
  193. #else
  194. #define SOMSTAR *
  195. #endif
  196.  
  197. /*
  198.  * Macro to get class object
  199.  */
  200. #define SOM_GetClass(obj) (**(SOMClass SOMSTAR **)obj)
  201.  
  202. /*
  203.  * This macro is used throughout the generated source
  204.  * to prevent compiler warnings for unreferenced variables
  205.  */
  206. #ifndef SOM_IgnoreWarning
  207.     #ifdef __xlC__
  208.     #define SOM_IgnoreWarning(v)    
  209.     #else
  210.     #define SOM_IgnoreWarning(v)    (void) v
  211.     #endif
  212. #endif /* SOM_IgnoreWarning */
  213.  
  214. /* Check the validity of method resolution using the specified target  */
  215. /* object.  Note: this macro makes programs bigger and slower.  After  */
  216. /* you are confident that your program is running correctly you should */
  217. /* turn off this macro by defining SOM_NoTest, or adding -DSOM_NoTest  */
  218. /* to your makefile.                                                   */
  219.  
  220. #if !defined(SOM_NoTest) && defined(SOM_TestOn)
  221.   #define SOM_TestCls(obj, class) (somTestCls(((SOMObject SOMSTAR)\
  222.     ((void *)obj)), ((SOMClass SOMSTAR)((void *)class)), __FILE__, __LINE__))
  223.   #define SOM_Measure
  224. #else
  225.   #define SOM_TestCls(obj, class) ((SOMObject SOMSTAR)((void *)obj))
  226. #endif
  227.  
  228. #if !defined(_WIN32)
  229. /* Control the printing of method and procedure entry messages, */
  230. /* 0-none, 1-user, 2-core&user */
  231. SOMEXTERN int SOMDLINK SOM_TraceLevel;
  232.  
  233. /* Control the printing of warning messages, 0-none, 1-all */
  234. SOMEXTERN int SOMDLINK SOM_WarnLevel;
  235.  
  236. /* Control the printing of successful assertions, 0-none, 1-user, */
  237. /* 2-core&user */
  238. SOMEXTERN int SOMDLINK SOM_AssertLevel;
  239. #else
  240. /* Control the printing of method and procedure entry messages, */
  241. /* 0-none, 1-user, 2-core&user */
  242. SOMEXTERN WIN32_DLLIMPORT int SOMDLINK SOM_TraceLevel;
  243.  
  244. /* Control the printing of warning messages, 0-none, 1-all */
  245. SOMEXTERN WIN32_DLLIMPORT int SOMDLINK SOM_WarnLevel;
  246.  
  247. /* Control the printing of successful assertions, 0-none, 1-user, */
  248. /* 2-core&user */
  249. SOMEXTERN WIN32_DLLIMPORT int SOMDLINK SOM_AssertLevel;
  250. #endif
  251.  
  252. /*
  253.  *  Scans argv looking for flags -somt, -somtc, -soma -somac -somw setting
  254.  *  SOM_TraceLevel, SOM_AssertLevel and SOM_WarnLevel as appropriate.
  255.  *  argv is not modified
  256.  */
  257. SOMEXTERN void SOMLINK somCheckArgs(int argc, zString argv[]);
  258.  
  259. #define SOM_Error(c) ((*SOMError) (c,__FILE__, __LINE__))
  260.  
  261. #define SOM_NoTrace(c,m)
  262.  
  263. #ifdef _RETAIL
  264.   #define SOM_Trace(c,m)
  265.   #define SOM_TraceCore(c,m)
  266. #else
  267.   #define SOM_Trace(c,m) if (SOM_TraceLevel > 0) \
  268.       somPrintf("\"%s\": %d:\tIn %s:%s \n", \
  269.       __FILE__, __LINE__, c, m)
  270.  
  271.   #define SOM_TraceCore(c,m) if (SOM_TraceLevel > 1) \
  272.       somPrintf("\"%s\": %d:\tIn %s:%s \n", \
  273.       __FILE__, __LINE__, c, m)
  274. #endif
  275.  
  276. #define SOM_Assert(condition,ecode) \
  277.   (somAssert(condition, ecode, __FILE__, __LINE__, # condition))
  278.  
  279. #define SOM_AssertCore(condition,ecode) \
  280.   (somAssertCore(condition, ecode, __FILE__, __LINE__, # condition))
  281.  
  282. #define SOM_Expect(condition) \
  283.       somTest(condition, SOM_Warn, __FILE__, __LINE__, # condition)
  284.  
  285. #define SOM_WarnMsg(msg) \
  286.   if (SOM_WarnLevel > 0) \
  287.       somPrintf("\"%s\": %d:\tWarning: %s\n", __FILE__, __LINE__, msg)
  288.  
  289. #define SOM_Test(boolexp) \
  290.     somTest(boolexp, SOM_Fatal, __FILE__, __LINE__, # boolexp)
  291.  
  292. #define SOM_TestC(boolexp) \
  293.     somTest(boolexp, SOM_Warn, __FILE__, __LINE__, # boolexp)
  294.  
  295. /*
  296.  *   Default method debug macro, can be overridden
  297.  */
  298. #ifndef SOMMethodDebug
  299. #define SOMMethodDebug(c,m) SOM_Trace(c,m)
  300. #endif
  301.  
  302. /*
  303.  *  Error severity codes, these are added to the base error number to
  304.  *  produce the full error code
  305.  */
  306.  
  307. #define SOM_Ok        0x0
  308. #define SOM_Warn      0x1
  309. #define SOM_Ignore    0x2 /* don't do anything */
  310. #define SOM_Fatal     0x9 /* terminate the program */
  311. #define SOM_Template  0x5 /* use to identify msg templates */
  312.  
  313. #define SOM_EB 20000
  314. #define SOM_FatalCode(code) (SOM_EB + (code)*10 + SOM_Fatal)
  315. #define SOM_WarnCode(code) (SOM_EB + (code)*10 + SOM_Warn)
  316. #define SOM_IgnoreCode(code) (SOM_EB + (code)*10 + SOM_Ignore)
  317. #define SOM_OkCode(code) (SOM_EB + (code)*10 + SOM_Ok)
  318. #define SOM_TemplateCode(code) (SOM_EB + (code)*10 + SOM_Template)
  319. #define SOM_MsgCode(ecode) (((ecode)-SOM_EB)/10)
  320.  
  321. #define SOMERROR_MustOverride SOM_FatalCode(18)
  322.  
  323. #endif /* somcdev_h */
  324.