home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somk / c / animals / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  2.3 KB  |  77 lines

  1. #ifndef lint
  2. static char *sccsid = "%Z% %I% %W% %G% %U% [%H% %T%] (c)IBM Corp. 1993";
  3. #endif
  4.  
  5. #include "animals.h"
  6. #include "nlsutil.h"
  7. #include "msgid.h"
  8. #include <stdio.h>
  9. #define BIG_DOG_MAX 4
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.     Environment *ev = somGetGlobalEnvironment ();
  14.     string bigDogNames[6] = {
  15.         "Lassie", "Guffy", "Waldo", "Pluto", "Elvis", "Spike"
  16.         };
  17.     sequence(Animals_Animal) allCreatures;
  18.     int i;
  19.  
  20.    /* Use translated messages, instead of English */
  21.    bigDogNames[0] = NlsMsgAlloc(LassieId);
  22.    bigDogNames[1] = NlsMsgAlloc(GuffyId);
  23.    bigDogNames[2] = NlsMsgAlloc(WaldoId);
  24.    bigDogNames[3] = NlsMsgAlloc(PlutoId);
  25.    bigDogNames[4] = NlsMsgAlloc(ElvisId);
  26.    bigDogNames[5] = NlsMsgAlloc(SpikeId);
  27.  
  28.     /*
  29.      * Create classes. 
  30.      */
  31.     Animals_AnimalNewClass (Animals_Animal_MajorVersion, 
  32.         Animals_Animal_MinorVersion);
  33.     Animals_DogNewClass (Animals_Dog_MajorVersion, Animals_Dog_MinorVersion);
  34.     Animals_LittleDogNewClass (Animals_LittleDog_MajorVersion, 
  35.         Animals_LittleDog_MinorVersion);
  36.     Animals_BigDogNewClass (Animals_BigDog_MajorVersion,
  37.         Animals_BigDog_MinorVersion);
  38.  
  39.     SOM_TraceLevel = (argc > 1 ? 1 : 0);
  40.  
  41.     /*
  42.      * Create objects using constructors 
  43.      */
  44.     _newAnimal (_Animals_Animal, ev, NlsMsgAlloc(ScaryId), NlsMsgAlloc(RoarId));
  45.     _newDog (_Animals_Dog, ev, NlsMsgAlloc(RoverId), NlsMsgAlloc(GrrId),
  46.         NlsMsgAlloc(RetrieverId), NlsMsgAlloc(YellowId));
  47.     _newDog (_Animals_LittleDog, ev, NlsMsgAlloc(PierreId), 
  48.         NlsMsgAlloc(YapId), NlsMsgAlloc(FrenchPoodleId),
  49.             NlsMsgAlloc(BlackId));
  50.     for (i=0; i<(sizeof(bigDogNames)/sizeof(string)); i++)
  51.         _newDog (_Animals_BigDog, ev, bigDogNames[i], (string) NULL, 
  52.             NlsMsgAlloc(GermanShepherdId), NlsMsgAlloc(BrownId));
  53.  
  54.     /*
  55.      * Display objects. 
  56.      */
  57.     somPrintf (NlsMsgAlloc(SeparatorId));
  58.     allCreatures = __get_instances (_Animals_Animal, ev);
  59.    
  60.     for (i=0; i<allCreatures._length; i++) {
  61.         _display (allCreatures._buffer[i], ev);
  62.     }
  63.  
  64.  
  65.     somPrintf (NlsMsgAlloc(PopulationId), allCreatures._length);
  66.  
  67.     /*
  68.      * Free objects. 
  69.      */
  70.     for (i=0; i<allCreatures._length; i++)
  71.         _somFree (allCreatures._buffer[i]);
  72.  
  73.     somPrintf ("\n");
  74.  
  75.     return(0);
  76. }
  77.