home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / BST_SystemDocs.lha / BeastV1 / Examples / BST_System / BST_Example1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-03  |  2.9 KB  |  127 lines

  1.  
  2. /****h* Beast/BST_Example1.c [1.0] **************
  3. *
  4. *    NAME
  5. *      BST_Example1 --
  6. *
  7. *    COPYRIGHT
  8. *      Maverick Software Development
  9. *
  10. *    FUNCTION
  11. *
  12. *    AUTHOR
  13. *      Jacco van Weert
  14. *
  15. *    CREATION DATE
  16. *      17-Mar-96
  17. *
  18. *    MODIFICATION HISTORY
  19. *
  20. *    NOTES
  21. *
  22. ****************************************************
  23. */
  24. #include <BEAST:Include/proto/Beast.h>
  25. #include <proto/exec.h>
  26. #include <stdio.h>
  27.  
  28. struct Library *BeastBase;
  29.  
  30. struct TagItem EmptyList[] =
  31. {
  32.   {TAG_DONE, 0}
  33. };
  34.  
  35.  
  36. /************************************************************
  37.  ***** my class instance definition, only used for sizeof()!!
  38.  *****/
  39. struct my_class_Instance
  40. {
  41.     LONG    X;
  42.     LONG    Y;
  43. };
  44.  
  45.  
  46. /***************************************************************************
  47.  **** OBM_INIT method : use the rfcall() macro to define the method function
  48.  ****/
  49. __geta4 rfcall (my_init, BST_MethodFlags MethodFlags, struct BST_Object *Object, struct TagItem *TagList)
  50. {
  51.     /****************************************************
  52.      **** Get pointer to the Instance
  53.      **** Use it always in this way, caching the Instance
  54.      **** pointer is _not_ good practice.
  55.      ****/
  56.     struct my_class_Instance *Instance = Macro_GetInstance;
  57.  
  58.  
  59.     /***************************
  60.      **** Set the default values
  61.      ****/
  62.     Instance->X = 1;
  63.     Instance->Y = 1;
  64.     
  65.     printf("=== Init method %lx %lx %lx\n", MethodFlags, Object, TagList );
  66.     printf("=== X = %ld, Y = %ld \n", Instance->X, Instance->Y );
  67.  
  68.     /*********************************************
  69.      **** IMPORTANT: return always the MethodFlags
  70.      **** The method may alter the MethodFlags.
  71.      ****/
  72.     return( MethodFlags );
  73. }
  74.  
  75.  
  76. /*********************************/
  77. /**** M A I N - P R O G R A M ****/
  78. /*********************************/
  79. main()
  80. {
  81.   struct BST_Class  *my_class;
  82.   struct BST_Object *my_object;
  83.  
  84.   printf("*** Beast OO Example1 START ***\n");
  85.   if (BeastBase = (struct Library *)OpenLibrary("beast.library",0))
  86.     {
  87.       /********************
  88.        **** Create my_class
  89.        ****/
  90.       my_class = BST_MakeClass( "my_firstclass", sizeof( struct my_class_Instance ));
  91.       CLSS_AddMethod( my_class, &my_init, OBM_INIT );
  92.       BST_AddClass(   my_class );
  93.  
  94.       printf("*** my_firstclass created = %lx ***\n", my_class );
  95.  
  96.       /*************************
  97.        **** Now create an object
  98.        ****/
  99.       my_object = OBJ_NewObject( NULL, "my_firstclass", NULL );
  100.       if (my_object != NULL)
  101.     {
  102.       printf("*** my_first Object created = %lx ***\n", my_object );
  103.  
  104.       /********************************
  105.        **** Trigger the OBM_INIT method
  106.        ****/
  107.       OBJ_DoMethod( my_object, OBM_INIT, EmptyList, 0 );
  108.  
  109.     }
  110.  
  111.       /**************************
  112.        **** Get rid of our object
  113.        ****/
  114.       OBJ_DisposeObject( my_object );
  115.  
  116.  
  117.       /********************
  118.        **** Remove my_class
  119.        ****/
  120.       BST_RemoveClass( my_class );
  121.       BST_FreeClass(   my_class );
  122.  
  123.       CloseLibrary( BeastBase );
  124.     }
  125.   printf("*** Beast OO Example1 END ***\n");
  126. }
  127.