home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somd / cpp / stack / stack.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  2.9 KB  |  115 lines

  1. //
  2. //   COMPONENT_NAME: somx
  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. //
  13.  
  14. /* %Z% %I% %W% %G% %U% [%H% %T%] */
  15. /*
  16.  *  This file was generated by the SOM Compiler and Emitter Framework.
  17.  *  Generated using: 
  18.  *      SOM Emitter emitxtm: 2.37
  19.  */
  20.  
  21. #ifndef SOM_Module_stack_Source
  22. #define SOM_Module_stack_Source
  23. #endif
  24. #define Stack_Class_Source
  25.  
  26. #include "stack.xih"
  27.  
  28. SOM_Scope boolean  SOMLINK full(Stack *somSelf,  Environment *ev)
  29. {
  30.     StackData *somThis = StackGetData(somSelf);
  31.     StackMethodDebug("Stack","full");
  32.  
  33.     /* Return statement to be customized: */
  34.     return(somThis->stackTop == stackSize);
  35. }
  36.  
  37. SOM_Scope boolean  SOMLINK empty(Stack *somSelf,  Environment *ev)
  38. {
  39.     StackData *somThis = StackGetData(somSelf);
  40.     StackMethodDebug("Stack","empty");
  41.  
  42.     /* Return statement to be customized: */
  43.     return(somThis->stackTop == 0);
  44. }
  45.  
  46. SOM_Scope long  SOMLINK top(Stack *somSelf,  Environment *ev)
  47. {
  48.     StackData *somThis = StackGetData(somSelf);
  49.     StackMethodDebug("Stack","top");
  50.  
  51.     /* Return statement to be customized: */
  52.     if (somThis->stackTop > 0)
  53.     {
  54.  
  55.        return(somThis->stackimpl[somThis->stackTop -1]);
  56.     }
  57.     else
  58.     {
  59.        somSetException(ev, USER_EXCEPTION, ex_STACK_UNDERFLOW, NULL);
  60.        return(-1L);
  61.     }
  62. }
  63.  
  64. SOM_Scope long  SOMLINK pop(Stack *somSelf,  Environment *ev)
  65. {
  66.     StackData *somThis = StackGetData(somSelf);
  67.     StackMethodDebug("Stack","pop");
  68.  
  69.     /* Return statement to be customized: */
  70.     if (somThis->stackTop > 0)
  71.     {
  72.        somThis->stackTop--;
  73.        return(somThis->stackimpl[somThis->stackTop]);
  74.     }
  75.     else
  76.     {
  77.        somSetException(ev, USER_EXCEPTION, ex_STACK_UNDERFLOW, NULL);
  78.        return(-1L);
  79.     }
  80. }
  81.  
  82. SOM_Scope void  SOMLINK push(Stack *somSelf,  Environment *ev, 
  83.                              long el)
  84. {
  85.     StackData *somThis = StackGetData(somSelf);
  86.     StackMethodDebug("Stack","push");
  87.     if (somThis->stackTop < stackSize)
  88.     {
  89.        somThis->stackimpl[somThis->stackTop] = el;
  90.        somThis->stackTop++;
  91.     }
  92.     else
  93.     {
  94.        somSetException(ev, USER_EXCEPTION, ex_STACK_OVERFLOW, NULL);
  95.     }
  96. }
  97.  
  98. SOM_Scope void SOMLINK somDefaultInit(Stack *somSelf, somInitCtrl* ctrl)
  99. {
  100.     StackData *somThis; /* set in BeginInitializer */
  101.     somInitCtrl globalCtrl;
  102.     somBooleanVector myMask;
  103.     StackMethodDebug("Stack","somDefaultInit");
  104.     Stack_BeginInitializer_somDefaultInit;
  105.  
  106.     Stack_Init_SOMObject_somDefaultInit(somSelf, ctrl);
  107.  
  108.     /* stackTop is index into stackValues for next pushed stack element.
  109.      * stackValues[0..(stackSize-1)] holds stack elements.
  110.      */
  111.  
  112.      somThis->stackTop = 0;
  113. }
  114.  
  115.