home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / MiscKit1.2.6 / Source / MiscListExtensions.m < prev    next >
Encoding:
Text File  |  1994-02-03  |  1.5 KB  |  50 lines

  1. //
  2. //    MiscListExtensions.m -- extensions to List for deep copies
  3. //        Originally written by Drew Davidson (c) 1994 by Drew Davidson.
  4. //        Modified and extended by Don Yacktman for inclusion into the MiscKit.
  5. //                Version 1.0.  All rights reserved.
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. // check for respondsTo: added by Don for safety's sake.  We really need
  15. // to have the Object class have a deepCopy category...
  16.  
  17. #import <misckit/misckit.h>
  18.  
  19. @implementation List(DeepCopy)
  20.  
  21. - deepCopy
  22. {    int        i;
  23.  
  24.     self = [self copy]; // none of the contained objects are copied
  25.     for (i = 0; i < numElements; i++) {
  26.         id theObject = [self objectAt:i];
  27.         if ([theObject respondsTo:@selector(deepCopy)])
  28.             [self replaceObject:theObject with:[theObject deepCopy]];
  29.         else
  30.             [self replaceObject:theObject with:[theObject copy]];
  31.     }
  32.     return(self);
  33. }
  34.  
  35. - deepCopyFromZone:(NXZone *)zone
  36. {    int        i;
  37.  
  38.     self = [self copyFromZone:zone]; // none of the contained objects are copied
  39.     for (i = 0; i < numElements; i++) {
  40.         id theObject = [self objectAt:i];
  41.         if ([theObject respondsTo:@selector(deepCopyFromZone:)])
  42.             [self replaceObject:theObject with:[theObject deepCopyFromZone:zone]];
  43.         else
  44.             [self replaceObject:theObject with:[theObject copyFromZone:zone]];
  45.     }
  46.     return(self);
  47. }
  48.  
  49. @end
  50.