blob: 775616c0a58e31f362fdff4cc101a8c4b1125760 [file] [log] [blame]
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2006 Steve Nygard
#import "CDSymbolReferences.h"
#import <Foundation/Foundation.h>
@implementation CDSymbolReferences
- (id)init;
{
if ([super init] == nil)
return nil;
classes = [[NSMutableSet alloc] init];
protocols = [[NSMutableSet alloc] init];
return self;
}
- (void)dealloc;
{
[classes release];
[protocols release];
[super dealloc];
}
- (NSArray *)classes;
{
return [[classes allObjects] sortedArrayUsingSelector:@selector(compare:)];
}
- (void)addClassName:(NSString *)aClassName;
{
[classes addObject:aClassName];
}
- (void)removeClassName:(NSString *)aClassName;
{
if (aClassName != nil)
[classes removeObject:aClassName];
}
- (NSArray *)protocols;
{
return [[protocols allObjects] sortedArrayUsingSelector:@selector(compare:)];
}
- (void)addProtocolName:(NSString *)aProtocolName;
{
[protocols addObject:aProtocolName];
}
- (void)addProtocolNamesFromArray:(NSArray *)protocolNames;
{
[protocols addObjectsFromArray:protocolNames];
}
- (NSString *)description;
{
return [NSString stringWithFormat:@"<%@:%p> classes: %@, protocols: %@", NSStringFromClass([self class]), self, [self classes], [self protocols]];
}
- (void)_appendToString:(NSMutableString *)resultString;
{
NSArray *names;
int count, index;
names = [self protocols];
count = [names count];
for (index = 0; index < count; index++) {
[resultString appendFormat:@"#import \"%@Protocol.h\"\n", [names objectAtIndex:index]];
}
if (count > 0)
[resultString appendString:@"\n"];
names = [self classes];
if ([names count] > 0) {
[resultString appendFormat:@"@class %@;\n\n", [names componentsJoinedByString:@", "]];
}
}
- (NSString *)referenceString;
{
NSMutableString *referenceString;
referenceString = [[[NSMutableString alloc] init] autorelease];
[self _appendToString:referenceString];
if ([referenceString length] == 0)
return nil;
return referenceString;
}
@end