PageRenderTime 67ms CodeModel.GetById 36ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/CDTopoSortNode.m

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