home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somd / cpp / animal / danimal.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  4.3 KB  |  161 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.  
  22.  
  23. #ifndef SOM_Module_danimal_Source
  24. #define SOM_Module_danimal_Source
  25. #endif
  26. #define dAnimal_Class_Source
  27.  
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <windows.h>
  31. #include "dloc.xh"
  32. #include "danimal.xih"
  33. #include "nlsutil.h"   /* 18953 */
  34. #include "animal.h"   /* 18953 */
  35.  
  36. /*
  37.  * Name of animal.
  38.  */
  39.  
  40. SOM_Scope void  SOMLINK _set_name(dAnimal *somSelf,  Environment *ev, 
  41.                                   string name)
  42. {
  43.     dAnimalData *somThis = dAnimalGetData(somSelf);
  44.     dAnimalMethodDebug("dAnimal","_set_name");
  45.     if (somThis->name) SOMFree(somThis->name);
  46.     somThis->name = (string) SOMMalloc(strlen(name) + 1);
  47.     strcpy(somThis->name, name);
  48.  
  49. }
  50.  
  51. /*
  52.  * Type of animal.
  53.  */
  54.  
  55. SOM_Scope void  SOMLINK _set_type(dAnimal *somSelf,  Environment *ev, 
  56.                                   string type)
  57. {
  58.     dAnimalData *somThis = dAnimalGetData(somSelf);
  59.     dAnimalMethodDebug("dAnimal","_set_type");
  60.     if (somThis->type) SOMFree(somThis->type);
  61.     somThis->type = (string) SOMMalloc(strlen(type) + 1);
  62.     strcpy(somThis->type, type);
  63.  
  64. }
  65.  
  66. /*
  67.  * Food animal likes to eat.
  68.  */
  69.  
  70. SOM_Scope void  SOMLINK _set_food(dAnimal *somSelf,  Environment *ev, 
  71.                                   string food)
  72. {
  73.     dAnimalData *somThis = dAnimalGetData(somSelf);
  74.     dAnimalMethodDebug("dAnimal","_set_food");
  75.     if (somThis->food) SOMFree(somThis->food);
  76.     somThis->food = (string) SOMMalloc(strlen(food) + 1);
  77.     strcpy(somThis->food, food);
  78.  
  79. }
  80.  
  81. /*
  82.  * Work area for display method.
  83.  */
  84.  
  85. SOM_Scope void  SOMLINK _set_buff(dAnimal *somSelf,  Environment *ev, 
  86.                                   string buff)
  87. {
  88.     dAnimalData *somThis = dAnimalGetData(somSelf);
  89.     dAnimalMethodDebug("dAnimal","_set_buff");
  90.     if (somThis->buff) SOMFree(somThis->buff);
  91.     somThis->buff = (string) SOMMalloc(strlen(buff) + 1);
  92.     strcpy(somThis->buff, buff);
  93.  
  94. }
  95.  
  96. /*
  97.  * Returns description of animal.
  98.  */
  99.  
  100. SOM_Scope string  SOMLINK display(dAnimal *somSelf,  Environment *ev)
  101. {
  102.     string bp;
  103.  
  104.     dAnimalData *somThis = dAnimalGetData(somSelf);
  105.     dAnimalMethodDebug("dAnimal","display");
  106.  
  107.     /* Return statement to be customized: */
  108.  
  109.     bp = somThis->buff;
  110.     wsprintf(bp, NlsMsgGet(IamId), somThis->type);
  111.  
  112.     bp += strlen(bp);
  113.     wsprintf(bp, NlsMsgGet(MynameId), somThis->name);
  114.  
  115.     bp += strlen(bp);
  116.     wsprintf(bp, NlsMsgGet(ILikeToEatId), somThis->food);
  117.  
  118.     bp += strlen(bp);
  119.     wsprintf(bp, NlsMsgGet(ILiveInId),
  120.             somThis->loc->_get_city(ev),
  121.         somThis->loc->_get_state(ev));
  122.  
  123.     return somThis->buff;
  124.  
  125. }
  126. SOM_Scope void SOMLINK somDefaultInit(dAnimal *somSelf, somInitCtrl* ctrl)
  127. {
  128.     dAnimalData *somThis; /* set in BeginInitializer */
  129.     Environment *ev;
  130.     somInitCtrl globalCtrl;
  131.     somBooleanVector myMask;
  132.     dAnimalMethodDebug("dAnimal","somDefaultInit");
  133.     dAnimal_BeginInitializer_somDefaultInit;
  134.     dAnimal_Init_SOMObject_somDefaultInit(somSelf,ctrl);
  135.  
  136.     ev = somGetGlobalEnvironment();
  137.  
  138.     somSelf->_set_name(ev, "unknown name");
  139.     somSelf->_set_type(ev, "unknown type");
  140.     somSelf->_set_food(ev, "unknown food");
  141.     somThis->loc = new dLocation;
  142.     somThis->buff = (string) SOMMalloc(2048);
  143. }
  144. SOM_Scope void SOMLINK somDestruct(dAnimal *somSelf, octet doFree, somDestructCtrl* ctrl)
  145. {
  146.     dAnimalData *somThis; /* set in BeginDestructor */
  147.     somDestructCtrl globalCtrl;
  148.     somBooleanVector myMask;
  149.     dAnimalMethodDebug("dAnimal","somDestruct");
  150.     dAnimal_BeginDestructor;
  151.  
  152.  
  153.     if (somThis->name) SOMFree(somThis->name);
  154.     if (somThis->type) SOMFree(somThis->type);
  155.     if (somThis->food) SOMFree(somThis->food);
  156.     if (somThis->buff) SOMFree(somThis->buff);
  157.     somThis->loc->somFree();
  158.     dAnimal_EndDestructor;
  159. }
  160.  
  161.