home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / freeclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  3.1 KB  |  121 lines

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