home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / objam01.lha / objam / runtime / objects.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  1.2 KB  |  57 lines

  1. /*
  2. ** ObjectiveAmiga: Class related functions
  3. ** See GNU:lib/libobjam/ReadMe for details
  4. */
  5.  
  6.  
  7. #include <proto/exec.h>
  8.  
  9. #include <libraries/objc.h>
  10. #include <clib/objc_protos.h>
  11.  
  12. #include "misc.h" /* For the ANSI function emulations */
  13. #include "zone.h" /* For quick access to the default zone */
  14.  
  15.  
  16. id class_create_instance(OCClass* class)
  17. {
  18.   return class_create_instance_from_zone(class,__DefaultMallocZone);
  19. }
  20.  
  21. id class_create_instance_from_zone(OCClass* class, NXZone* zone)
  22. {
  23.   id newObject = nil;
  24.   if(CLS_ISCLASS(class)) newObject=(id)__objc_xmalloc_from_zone(class->instance_size,zone);
  25.   if(newObject)
  26.   {
  27.     bzero (newObject, class->instance_size);
  28.     newObject->class_pointer = class;
  29.   }
  30.   return newObject;
  31. }
  32.  
  33. id object_copy(id object)
  34. {
  35.   return object_copy_from_zone(object,__DefaultMallocZone);
  36. }
  37.  
  38. id object_copy_from_zone(id object, NXZone* zone)
  39. {
  40.   id copy;
  41.  
  42.   if(object) if(CLS_ISCLASS(object->class_pointer))
  43.   {
  44.     copy = class_create_instance_from_zone(object->class_pointer,zone);
  45.     CopyMem((APTR)object, (APTR)copy, object->class_pointer->instance_size);
  46.     return copy;
  47.   }
  48.   else return nil;
  49. }
  50.  
  51.  
  52. id object_dispose(id object)
  53. {
  54.   if(object) if(CLS_ISCLASS(object->class_pointer)) __objc_xfree((void *)object);
  55.   return nil;
  56. }
  57.