OLD | NEW |
(Empty) | |
| 1 // -*- mode: ObjC -*- |
| 2 |
| 3 // This file is part of class-dump, a utility for examining the Objective-C seg
ment of Mach-O files. |
| 4 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard. |
| 5 |
| 6 #import "CDTopoSortNode.h" |
| 7 |
| 8 #import "NSObject-CDExtensions.h" |
| 9 |
| 10 @implementation CDTopoSortNode |
| 11 |
| 12 - (id)initWithObject:(id <CDTopologicalSort>)anObject; |
| 13 { |
| 14 if ([super init] == nil) |
| 15 return nil; |
| 16 |
| 17 sortableObject = [anObject retain]; |
| 18 dependancies = [[NSMutableSet alloc] init]; |
| 19 color = CDWhiteNodeColor; |
| 20 |
| 21 [self addDependanciesFromArray:[sortableObject dependancies]]; |
| 22 |
| 23 return self; |
| 24 } |
| 25 |
| 26 - (void)dealloc; |
| 27 { |
| 28 [sortableObject release]; |
| 29 [dependancies release]; |
| 30 |
| 31 [super dealloc]; |
| 32 } |
| 33 |
| 34 - (NSString *)identifier; |
| 35 { |
| 36 return [sortableObject identifier]; |
| 37 } |
| 38 |
| 39 - (id <CDTopologicalSort>)sortableObject; |
| 40 { |
| 41 return sortableObject; |
| 42 } |
| 43 |
| 44 - (NSArray *)dependancies; |
| 45 { |
| 46 return [dependancies allObjects]; |
| 47 } |
| 48 |
| 49 - (void)addDependancy:(NSString *)anIdentifier; |
| 50 { |
| 51 [dependancies addObject:anIdentifier]; |
| 52 } |
| 53 |
| 54 - (void)removeDependancy:(NSString *)anIdentifier; |
| 55 { |
| 56 [dependancies removeObject:anIdentifier]; |
| 57 } |
| 58 |
| 59 - (void)addDependanciesFromArray:(NSArray *)identifiers; |
| 60 { |
| 61 [self performSelector:@selector(addDependancy:) withObjectsFromArray:identif
iers]; |
| 62 //[identifiers makeObject:self performSelector:@selector(addDependancy:)]; |
| 63 } |
| 64 |
| 65 - (CDNodeColor)color; |
| 66 { |
| 67 return color; |
| 68 } |
| 69 |
| 70 - (void)setColor:(CDNodeColor)newColor; |
| 71 { |
| 72 color = newColor; |
| 73 } |
| 74 |
| 75 - (NSString *)description; |
| 76 { |
| 77 return [NSString stringWithFormat:@"%@ (%d) depends on %@", [self identifier
], color, [[dependancies allObjects] componentsJoinedByString:@", "]]; |
| 78 } |
| 79 |
| 80 - (NSComparisonResult)ascendingCompareByIdentifier:(id)otherNode; |
| 81 { |
| 82 return [[self identifier] compare:[otherNode identifier]]; |
| 83 } |
| 84 |
| 85 - (void)topologicallySortNodes:(NSDictionary *)nodesByIdentifier intoArray:(NSMu
tableArray *)sortedArray; |
| 86 { |
| 87 NSArray *dependantIdentifiers; |
| 88 CDTopoSortNode *aNode; |
| 89 |
| 90 dependantIdentifiers = [self dependancies]; |
| 91 for (NSString *anIdentifier in dependantIdentifiers) { |
| 92 aNode = [nodesByIdentifier objectForKey:anIdentifier]; |
| 93 if ([aNode color] == CDWhiteNodeColor) { |
| 94 [aNode setColor:CDGrayNodeColor]; |
| 95 [aNode topologicallySortNodes:nodesByIdentifier intoArray:sortedArra
y]; |
| 96 } else if ([aNode color] == CDGrayNodeColor) { |
| 97 NSLog(@"Warning: Possible circular reference? %@ -> %@", [self ident
ifier], [aNode identifier]); |
| 98 } |
| 99 } |
| 100 |
| 101 [sortedArray addObject:[self sortableObject]]; |
| 102 [self setColor:CDBlackNodeColor]; |
| 103 } |
| 104 |
| 105 @end |
OLD | NEW |