home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v5.zip / TOOLKT21 / CPLUS / OS2H / SOMOBJ.XH < prev    next >
Text File  |  1993-05-03  |  16KB  |  527 lines

  1.  
  2. /*
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: somobj.xh.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitxh: 1.11
  8.  */
  9.  
  10. /*
  11.  *  SOMObject: System Object Model root class
  12.  *  Copyright (c) International Business Machines Corporation
  13.  *                1991, 1992
  14.  */
  15.  
  16. #ifndef somobj_xh
  17. #define somobj_xh
  18. class SOMObject;
  19.  
  20. /*
  21.  *  This is the SOM root class, all SOM classes must be descended from
  22.  *  <SOMObject>. <SOMObject> has no instance data so there is no
  23.  *  per-instance cost to to being descended from it.
  24.  */
  25.  
  26. #define SOMObject_MajorVersion 1
  27. #define SOMObject_MinorVersion 1
  28.  
  29. /* C++ som defs */
  30. #include <som.xh>
  31. #include <somcls.API>
  32.  
  33. #ifndef SOMObject_API
  34. #define SOMObject_API
  35. /*
  36.  * The Class API
  37.  */
  38.  
  39. /* A procedure to create the SOMObject Class */
  40. SOMEXTERN SOMClass * SOMLINK SOMObjectNewClass(
  41.         integer4 majorVersion,
  42.         integer4 minorVersion);
  43.  
  44. /* A macro to return the SOMObject class object */
  45. #define _SOMObject ((SOMClass*)SOMObjectClassData.classObject)
  46.  
  47. /* The static interface to SOMObject and its instances */
  48. SOMEXTERN struct SOMObjectClassDataStructure {
  49.     SOMClass *classObject;
  50.     somMToken somInit;
  51.     somMToken somUninit;
  52.     somMToken somFree;
  53.     somMToken somMissingMethod;
  54.     somMToken somGetClassName;
  55.     somMToken somGetClass;
  56.     somMToken somIsA;
  57.     somMToken somRespondsTo;
  58.     somMToken somIsInstanceOf;
  59.     somMToken somGetSize;
  60.     somMToken somDumpSelf;
  61.     somMToken somDumpSelfInt;
  62.     somMToken somPrintSelf;
  63.     somMToken somFreeObj;
  64.     somMToken somDispatchV;
  65.     somMToken somDispatchL;
  66.     somMToken somDispatchA;
  67.     somMToken somDispatchD;
  68. } SOMObjectClassData;
  69.  
  70. /*
  71.  * -- Typedefs for Procedures that support SOMObject Methods
  72.  */
  73. extern "C" {
  74. typedef void    (SOMLINK *somTD_SOMObject_somFree)(SOMObject *somSelf);
  75. typedef void    (SOMLINK *somTD_SOMObject_somInit)(SOMObject *somSelf);
  76. typedef void    (SOMLINK *somTD_SOMObject_somUninit)(SOMObject *somSelf);
  77. typedef SOMClass *   (SOMLINK *somTD_SOMObject_somGetClass)(SOMObject *somSelf);
  78. typedef zString    (SOMLINK *somTD_SOMObject_somGetClassName)(SOMObject *somSelf);
  79. typedef integer4    (SOMLINK *somTD_SOMObject_somGetSize)(SOMObject *somSelf);
  80. typedef int    (SOMLINK *somTD_SOMObject_somIsA)(SOMObject *somSelf,SOMClass *aClassObj);
  81. typedef int    (SOMLINK *somTD_SOMObject_somIsInstanceOf)(SOMObject *somSelf,SOMClass *aClassObj);
  82. typedef int    (SOMLINK *somTD_SOMObject_somRespondsTo)(SOMObject *somSelf,IN somId mId);
  83. typedef void    (SOMLINK *somTD_SOMObject_somDispatchV)(SOMObject *somSelf,INOUT somId methodId,INOUT somId descriptor,...);
  84. typedef integer4    (SOMLINK *somTD_SOMObject_somDispatchL)(SOMObject *somSelf,INOUT somId methodId,INOUT somId descriptor,...);
  85. typedef void *   (SOMLINK *somTD_SOMObject_somDispatchA)(SOMObject *somSelf,INOUT somId methodId,INOUT somId descriptor,...);
  86. typedef float8    (SOMLINK *somTD_SOMObject_somDispatchD)(SOMObject *somSelf,INOUT somId methodId,INOUT somId descriptor,...);
  87. typedef SOMObject *   (SOMLINK *somTD_SOMObject_somPrintSelf)(SOMObject *somSelf);
  88. typedef void    (SOMLINK *somTD_SOMObject_somDumpSelf)(SOMObject *somSelf,int level);
  89. typedef void    (SOMLINK *somTD_SOMObject_somDumpSelfInt)(SOMObject *somSelf,int level);
  90. }
  91.  
  92.  
  93. #endif /* SOMObject_API */
  94.  
  95.  
  96. /*
  97.  * -- The C++ Wrapper Class for SOMObject
  98.  */
  99.  
  100. class SOMObject
  101. {
  102. public:
  103.  
  104. void *operator new(size_t size)
  105. {
  106.    (void) size;
  107.    if (!SOMObjectClassData.classObject) 
  108.       SOMObjectNewClass(SOMObject_MajorVersion,SOMObject_MinorVersion);
  109.    return (void *)
  110.       ((somTD_SOMClass_somNew)
  111.       somResolve(SOM_TestCls((SOMAny *)(SOMObjectClassData.classObject),
  112.                              SOMClassClassData.classObject),
  113.                  SOMClassClassData.somNew))
  114.          ((SOMClass*)(SOMObjectClassData.classObject));
  115. }
  116.  
  117. void operator delete(void * obj)
  118. {
  119.    ((SOMObject *)obj)->somFree();
  120. }
  121.  
  122. /*
  123.  *  Initialization / Termination group
  124.  */
  125.  
  126. /* public method: somFree */
  127.  
  128. /*
  129.  *  Releases the storage associated with <self>, assuming that <self>
  130.  *  was created by <somNew> (or another class method that used
  131.  *  <somNew>).  No future references should be made to <self>.  Will
  132.  *  call <somUninit> on <self> before releasing the storage.
  133.  * 
  134.  *  This method must only be called on objects created by <somNew> (see
  135.  *  the definition of <somClass>) and never on objects created by
  136.  *  <somRenew>.
  137.  * 
  138.  *  It should not be necessary to override this method. (Override
  139.  *  <somUninit> instead.)
  140.  */
  141. void    somFree()
  142. {
  143.    SOM_Resolve((SOMAny *)this,SOMObject,somFree)
  144.     (this);
  145. }
  146.  
  147.  
  148. /* public method: somInit */
  149.  
  150. /*
  151.  *  Initializes <self>.  As instances of <SOMObject> do not have any
  152.  *  instance data there is nothing to initialize and you need not call
  153.  *  this method.  It is provided to induce consistency among
  154.  *  subclasses that require initialization.
  155.  * 
  156.  *  <somInit> is called automatically as a side effect of object
  157.  *  creation (ie, by <somNew>).  If this effect is not desired, you
  158.  *  can supply your own version of <somNew> (in a user-written metaclass)
  159.  *  which does not invoke <somInit>.
  160.  * 
  161.  *  When overriding this method you should always call the parent class
  162.  *  version of this method BEFORE doing your own initialization.
  163.  */
  164. void    somInit()
  165. {
  166.    SOM_Resolve((SOMAny *)this,SOMObject,somInit)
  167.     (this);
  168. }
  169.  
  170.  
  171. /* public method: somUninit */
  172.  
  173. /*
  174.  *  Un-initializes self.  As instances of <SOMObject> do not have any
  175.  *  instance data there is nothing to un-initialize and you need not
  176.  *  call this method.  It is provided to induce consistency among
  177.  *  subclasses that require un-initialization.
  178.  * 
  179.  *  Use this method to clean up anything necessary such as dynamically
  180.  *  allocated storage. However this method does not release the actual
  181.  *  storage assigned to the object instance. This method is provided as
  182.  *  a complement to <somFree> which also releases the storage
  183.  *  associated with a dynamically allocated object. Usually you would
  184.  *  just call <somFree> which will always call <somUninit>. However, in
  185.  *  cases where <somRenew> (see the definition of <SOMClass>) was used
  186.  *  to create an object instance, <somFree> cannot be called and you
  187.  *  must call <somUninit> explicitly.
  188.  * 
  189.  *  When overriding this method you should always call the parentclass
  190.  *  version of this method AFTER doing your own un-initialization.
  191.  */
  192. void    somUninit()
  193. {
  194.    SOM_Resolve((SOMAny *)this,SOMObject,somUninit)
  195.     (this);
  196. }
  197.  
  198.  
  199. /* public method: somGetClass */
  200.  
  201. /*
  202.  *  Returns this object's class object.
  203.  */
  204. SOMClass *   somGetClass()
  205. {
  206.    return (SOMClass*) SOM_Resolve((SOMAny *)this,SOMObject,somGetClass)
  207.     (this);
  208. }
  209.  
  210.  
  211. /* public method: somGetClassName */
  212.  
  213. /*
  214.  *  Returns a pointer to this object's class's name, as a NULL
  215.  *  terminated string.
  216.  * 
  217.  *  It should not be necessary to override this method as it just
  218.  *  invokes the class object's method (<somGetName>) to get the name.
  219.  */
  220. zString    somGetClassName()
  221. {
  222.    return (zString) SOM_Resolve((SOMAny *)this,SOMObject,somGetClassName)
  223.     (this);
  224. }
  225.  
  226.  
  227. /* public method: somGetSize */
  228.  
  229. /*
  230.  *  Returns the size of this instance in bytes.
  231.  */
  232. integer4    somGetSize()
  233. {
  234.    return (integer4) SOM_Resolve((SOMAny *)this,SOMObject,somGetSize)
  235.     (this);
  236. }
  237.  
  238.  
  239. /* public method: somIsA */
  240.  
  241. /*
  242.  *  Returns 1 (true) if <self>'s class is a descendent class of
  243.  *  <aClassObj> and 0 (false) otherwise.  Note: a class object is
  244.  *  considered to be descended from itself for the purposes of this
  245.  *  method.
  246.  */
  247. int    somIsA(SOMClass *aClassObj)
  248. {
  249.    return (int) SOM_Resolve((SOMAny *)this,SOMObject,somIsA)
  250.     (this,aClassObj);
  251. }
  252.  
  253.  
  254. /* public method: somIsInstanceOf */
  255.  
  256. /*
  257.  *  Returns 1 (true) if <self> is an instance of the specified
  258.  *  <aClassObj> and 0 (false) otherwise.
  259.  */
  260. int    somIsInstanceOf(SOMClass *aClassObj)
  261. {
  262.    return (int) SOM_Resolve((SOMAny *)this,SOMObject,somIsInstanceOf)
  263.     (this,aClassObj);
  264. }
  265.  
  266.  
  267. /* public method: somRespondsTo */
  268.  
  269. /*
  270.  *  Returns 1 (true) if the indicated method is supported by this
  271.  *  object's class and 0 (false) otherwise.
  272.  */
  273. int    somRespondsTo(IN somId mId)
  274. {
  275.    return (int) SOM_Resolve((SOMAny *)this,SOMObject,somRespondsTo)
  276.     (this,mId);
  277. }
  278.  
  279.  
  280. /*
  281.  *  These methods make it easier for very dynamic domains to bind to
  282.  *  the SOM object protocol boundry.
  283.  * 
  284.  *  These methods determine the appropriate method procedure and then
  285.  *  call it with the arguments specified.  The default implementation
  286.  *  of these methods provided in this class simply lookup the method by
  287.  *  name and call it.  However, other classes may choose to implement
  288.  *  any form of lookup they wish.  For example, one could provide an
  289.  *  implementation of these methods that used the CLOS form of method
  290.  *  resolution. For domains that can do so it will generally be much
  291.  *  faster to invoke their methods directly rather than going through a
  292.  *  dispatch method.  However, all methods are reachable through the
  293.  *  dispatch methods.  SOM provides a small set of external procedures
  294.  *  that wrap these method calls so that the caller need never do method
  295.  *  resolution.
  296.  * 
  297.  *  These methods are declared to take a variable length argument list,
  298.  *  but like all such methods the SOM object protocol boundry requires
  299.  *  that the variable part of the argument list be assembled into the
  300.  *  standard, platform-specific, data structure for variable argument
  301.  *  lists before the method is actually invoked.  This can be very
  302.  *  useful in domains that need to construct the argument list at
  303.  *  runtime. As they can invoke methods without being able to put the
  304.  *  constructed arguments in the normal form for a call.  This is
  305.  *  helpful because such an operation is usually impossible in most
  306.  *  high level languages and platform-specific assembler language
  307.  *  routines would have to be used.
  308.  * 
  309.  *  Note: It was decided to have different methods for different return
  310.  *  value shapes. This avoids the memory mangement problems that would
  311.  *  arise in some domains if an additional parameter was required to
  312.  *  carry the return value.
  313.  * 
  314.  *  Note: SOM does not support return values except for the four
  315.  *  families shown below. Within a family (such as integer) SOM only
  316.  *  supports the largest member.
  317.  */
  318.  
  319. /* public method: somDispatchV */
  320.  
  321. /*
  322.  *  Does not return a value.
  323.  */
  324.  
  325. /* the va_list invocation form */
  326. void    SOMObject_somDispatchV(INOUT somId methodId,
  327.         INOUT somId descriptor,
  328.         va_list ap)
  329. {
  330.    SOM_Resolve((SOMAny *)this,SOMObject,somDispatchV)
  331.     (this,methodId,descriptor,ap);
  332. }
  333.  
  334. /* the varargs invocation form */
  335. void    somDispatchV(INOUT somId methodId,
  336.         INOUT somId descriptor,
  337.         ...)
  338. {
  339.    va_list ap;
  340.    va_start(ap, descriptor);
  341.    SOM_Resolve((SOMAny *)this,SOMObject,somDispatchV)
  342.     (this,methodId,descriptor,ap);
  343.    va_end(ap);
  344. }
  345.  
  346.  
  347. /* public method: somDispatchL */
  348.  
  349. /*
  350.  *  Returns a 4 byte quanity in the normal manner that integer data is
  351.  *  returned. This 4 byte quanity can, of course, be something other
  352.  *  than an integer.
  353.  */
  354.  
  355. /* the va_list invocation form */
  356. integer4    SOMObject_somDispatchL(INOUT somId methodId,
  357.         INOUT somId descriptor,
  358.         va_list ap)
  359. {
  360.    return SOM_Resolve((SOMAny *)this,SOMObject,somDispatchL)
  361.     (this,methodId,descriptor,ap);
  362. }
  363.  
  364. /* the varargs invocation form */
  365. integer4    somDispatchL(INOUT somId methodId,
  366.         INOUT somId descriptor,
  367.         ...)
  368. {
  369.    va_list ap;
  370.    va_start(ap, descriptor);
  371.    integer4 result = 
  372.       (integer4) SOM_Resolve((SOMAny *)this,SOMObject,somDispatchL)
  373.     (this,methodId,descriptor,ap);
  374.    va_end(ap);
  375.    return result;
  376. }
  377.  
  378.  
  379. /* public method: somDispatchA */
  380.  
  381. /*
  382.  *  Returns a data structure address in the normal manner that such data is
  383.  *  returned.
  384.  */
  385.  
  386. /* the va_list invocation form */
  387. void *   SOMObject_somDispatchA(INOUT somId methodId,
  388.         INOUT somId descriptor,
  389.         va_list ap)
  390. {
  391.    return SOM_Resolve((SOMAny *)this,SOMObject,somDispatchA)
  392.     (this,methodId,descriptor,ap);
  393. }
  394.  
  395. /* the varargs invocation form */
  396. void *   somDispatchA(INOUT somId methodId,
  397.         INOUT somId descriptor,
  398.         ...)
  399. {
  400.    va_list ap;
  401.    va_start(ap, descriptor);
  402.    void* result = 
  403.       (void*) SOM_Resolve((SOMAny *)this,SOMObject,somDispatchA)
  404.     (this,methodId,descriptor,ap);
  405.    va_end(ap);
  406.    return result;
  407. }
  408.  
  409.  
  410. /* public method: somDispatchD */
  411.  
  412. /*
  413.  *  Returns a 8 byte quanity in the normal manner that floating point
  414.  *  data is returned.
  415.  */
  416.  
  417. /* the va_list invocation form */
  418. float8    SOMObject_somDispatchD(INOUT somId methodId,
  419.         INOUT somId descriptor,
  420.         va_list ap)
  421. {
  422.    return SOM_Resolve((SOMAny *)this,SOMObject,somDispatchD)
  423.     (this,methodId,descriptor,ap);
  424. }
  425.  
  426. /* the varargs invocation form */
  427. float8    somDispatchD(INOUT somId methodId,
  428.         INOUT somId descriptor,
  429.         ...)
  430. {
  431.    va_list ap;
  432.    va_start(ap, descriptor);
  433.    float8 result = 
  434.       (float8) SOM_Resolve((SOMAny *)this,SOMObject,somDispatchD)
  435.     (this,methodId,descriptor,ap);
  436.    va_end(ap);
  437.    return result;
  438. }
  439.  
  440.  
  441. /*
  442.  *  The methods in this group are provided to support program
  443.  *  development.  They have been defined in such a way that most
  444.  *  development contexts will find them easy to expoit. However, some
  445.  *  contexts may need to customize their I/O facilities. We have
  446.  *  attempted to allow this customization in a very portable manner,
  447.  *  however not all contexts will be able to perform the customization
  448.  *  operations directly because they require passing function
  449.  *  parameters. We chose this approach because it allows great
  450.  *  platform-neutral flexibility and we felt that any provider of
  451.  *  development support would find it reasonable to provide the
  452.  *  customizations necessary for her/his specific development
  453.  *  environment.
  454.  * 
  455.  *  The chosen approach relies on a character output routine.  An
  456.  *  external variable, <SOMOutCharRoutine>, points to this routine.  The
  457.  *  SOM environment provides an implementation of this routine that should
  458.  *  work in most development environments (it writes to the standard output
  459.  *  stream).  A development context can, however, assign a new value to
  460.  *  <SOMOutCharRoutine> and thereby redefine the output process.  SOM
  461.  *  provides no special support for doing this assigment.
  462.  */
  463.  
  464. /* public method: somPrintSelf */
  465.  
  466. /*
  467.  *  Uses <SOMOutCharRoutine> to write a brief string with identifying
  468.  *  information about this object.  The default implementation just gives
  469.  *  the object's class name and its address in memory.
  470.  *  <self> is returned.
  471.  */
  472. SOMObject *   somPrintSelf()
  473. {
  474.    return (SOMObject*) SOM_Resolve((SOMAny *)this,SOMObject,somPrintSelf)
  475.     (this);
  476. }
  477.  
  478.  
  479. /* public method: somDumpSelf */
  480.  
  481. /*
  482.  *  Uses <SOMOutCharRoutine> to write a detailed description of this object
  483.  *  and its current state.
  484.  * 
  485.  *  <level> indicates the nesting level for describing compound objects
  486.  *  it must be greater than or equal to zero.  All lines in the
  487.  *  description will be preceeded by <2*level> spaces.
  488.  * 
  489.  *  This routine only actually writes the data that concerns the object
  490.  *  as a whole, such as class, and uses <somDumpSelfInt> to describe
  491.  *  the object's current state.  This approach allows readable
  492.  *  descriptions of compound objects to be constructed.
  493.  * 
  494.  *  Generally it is not necessary to override this method, if it is
  495.  *  overriden it generally must be completely replaced.
  496.  */
  497. void    somDumpSelf(int level)
  498. {
  499.    SOM_Resolve((SOMAny *)this,SOMObject,somDumpSelf)
  500.     (this,level);
  501. }
  502.  
  503.  
  504. /* public method: somDumpSelfInt */
  505.  
  506. /*
  507.  *  Uses <SOMOutCharRoutine> to write out the current state of this object.
  508.  *  Generally this method will need to be overridden.  When overriding
  509.  *  it, begin by calling the parent class form of this method and then
  510.  *  write out a description of your class's instance data. This will
  511.  *  result in a description of all the object's instance data going
  512.  *  from its root ancestor class to its specific class.
  513.  */
  514. void    somDumpSelfInt(int level)
  515. {
  516.    SOM_Resolve((SOMAny *)this,SOMObject,somDumpSelfInt)
  517.     (this,level);
  518. }
  519.  
  520.  
  521.  
  522. };   /* SOMObject */
  523.  
  524.  
  525.  
  526. #endif       /* somobj_xh */
  527.