home *** CD-ROM | disk | FTP | other *** search
- //
- // MiscListExtensions.m -- extensions to List for deep copies
- // Originally written by Drew Davidson (c) 1994 by Drew Davidson.
- // Modified and extended by Don Yacktman for inclusion into the MiscKit.
- // Version 1.0. All rights reserved.
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- // check for respondsTo: added by Don for safety's sake. We really need
- // to have the Object class have a deepCopy category...
-
- #import <misckit/misckit.h>
-
- @implementation List(DeepCopy)
-
- - deepCopy
- { int i;
-
- self = [self copy]; // none of the contained objects are copied
- for (i = 0; i < numElements; i++) {
- id theObject = [self objectAt:i];
- if ([theObject respondsTo:@selector(deepCopy)])
- [self replaceObject:theObject with:[theObject deepCopy]];
- else
- [self replaceObject:theObject with:[theObject copy]];
- }
- return(self);
- }
-
- - deepCopyFromZone:(NXZone *)zone
- { int i;
-
- self = [self copyFromZone:zone]; // none of the contained objects are copied
- for (i = 0; i < numElements; i++) {
- id theObject = [self objectAt:i];
- if ([theObject respondsTo:@selector(deepCopyFromZone:)])
- [self replaceObject:theObject with:[theObject deepCopyFromZone:zone]];
- else
- [self replaceObject:theObject with:[theObject copyFromZone:zone]];
- }
- return(self);
- }
-
- @end
-