home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / som30tk.zip / som30os2.zip / include / somcdev.h < prev    next >
C/C++ Source or Header  |  1996-12-24  |  10KB  |  346 lines

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