home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / intuition / freeclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.9 KB  |  115 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: freeclass.c,v 1.2 1996/10/24 15:51:19 aros Exp $
  4.     $Log: freeclass.c,v $
  5.     Revision 1.2  1996/10/24 15:51:19  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.1  1996/08/28 17:55:34  digulla
  9.     Proportional gadgets
  10.     BOOPSI
  11.  
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <clib/exec_protos.h>
  17. #include "intuition_intern.h"
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <intuition/classes.h>
  23.     #include <clib/intuition_protos.h>
  24.  
  25.     AROS_LH1(BOOL, FreeClass,
  26.  
  27. /*  SYNOPSIS */
  28.     AROS_LHA(struct IClass *, classPtr, A0),
  29.  
  30. /*  LOCATION */
  31.     struct IntuitionBase *, IntuitionBase, 119, Intuition)
  32.  
  33. /*  FUNCTION
  34.     Only for class implementatores.
  35.  
  36.     Tries to free a class which has been created with MakeClass() in the
  37.     first place. This will not succeed in all cases: Classes which
  38.     still have living objects or which are still beeing used by subclasses
  39.     can't simply be freed. In this case this call will fail.
  40.  
  41.     Public classes will always be removed with RemoveClass() no matter
  42.     if FreeClass() would succeed or not. This gurantees that after the
  43.     call to FreeClass() no new objects can be created.
  44.  
  45.     If you have a pointer to allocated memory in cl_UserData, you must
  46.     make a copy of that pointer, call FreeClass() and if the call
  47.     succeeded, you may free the memory. If you don't follow these rules,
  48.     you might end up with a class which is partially freed.
  49.  
  50.     INPUTS
  51.     classPtr - The pointer you got from MakeClass().
  52.  
  53.     RESULT
  54.     FALSE if the class couldn't be freed at this time. This can happen
  55.     either if there are still objects from this class or if the class
  56.     is used a SuperClass of at least another class.
  57.  
  58.     TRUE if the class could be freed. You must not use classPtr after
  59.     that.
  60.  
  61.     NOTES
  62.     *Always* calls RemoveClass().
  63.  
  64.     EXAMPLE
  65.     // Free a public class with dynamic memory in cl_UserD
  66.  
  67.     int freeMyClass (Class * cl)
  68.     {
  69.         struct MyPerClassData * mpcd;
  70.  
  71.         mpcd = (struct MyPerClassData *)cl->cl_UserData;
  72.  
  73.         if (FreeClass (cl)
  74.         {
  75.         FreeMem (mpcd, sizeof (struct MyPerClassData));
  76.         return (TRUE);
  77.         }
  78.  
  79.         return (FALSE);
  80.     }
  81.  
  82.     BUGS
  83.  
  84.     SEE ALSO
  85.  
  86.     INTERNALS
  87.     MakeClass(), "Basic Object-Oriented Programming System for Intuition"
  88.     and "boopsi Class Reference" Dokument.
  89.  
  90.     HISTORY
  91.     29-10-95    digulla automatically created from
  92.                 intuition_lib.fd and clib/intuition_protos.h
  93.  
  94. *****************************************************************************/
  95. {
  96.     AROS_LIBFUNC_INIT
  97.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  98.  
  99.     /* Make sure no one creates another object from this class. For private
  100.     classes, this call does nothing. */
  101.     RemoveClass (classPtr);
  102.  
  103.     if (!classPtr->cl_SubclassCount && !classPtr->cl_ObjectCount)
  104.     {
  105.     classPtr->cl_Super->cl_SubclassCount --;
  106.  
  107.     FreeMem (classPtr, sizeof (Class));
  108.  
  109.     return (TRUE);
  110.     }
  111.  
  112.     return (FALSE);
  113.     AROS_LIBFUNC_EXIT
  114. } /* FreeClass */
  115.