[29483] users/rhwood/MacPorts.Framework

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 25 02:55:50 PDT 2007


Revision: 29483
          http://trac.macosforge.org/projects/macports/changeset/29483
Author:   rhwood at macports.org
Date:     2007-09-25 02:55:50 -0700 (Tue, 25 Sep 2007)

Log Message:
-----------
Add ability to pass an MPMacPorts instance and use that in MPIndex instead of generating a new instance.
Subclassing NSMutableDictionary is just plain weird.

Modified Paths:
--------------
    users/rhwood/MacPorts.Framework/MPIndex.h
    users/rhwood/MacPorts.Framework/MPIndex.m

Modified: users/rhwood/MacPorts.Framework/MPIndex.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPIndex.h	2007-09-25 09:53:33 UTC (rev 29482)
+++ users/rhwood/MacPorts.Framework/MPIndex.h	2007-09-25 09:55:50 UTC (rev 29483)
@@ -7,16 +7,40 @@
 //
 
 #import <Cocoa/Cocoa.h>
+#import "MPMacPorts.h"
 #import "MPPort.h"
 
 
 @interface MPIndex : NSMutableDictionary {
 
+	MPMacPorts *macPorts;
+	NSMutableDictionary *embeddedDictionary;
+
 }
 
+- (id)init;
+- (id)initWithCapacity:(unsigned)numItems;
+- (id)initWithMacPorts:(MPMacPorts *)macPortsInstance;
+- (id)initWithCapacity:(unsigned)numItems WithMacPorts:(MPMacPorts *)macPortsInstance;
+
+- (void)finishInitWithCapacity:(unsigned)numItems WithMacPorts:(MPMacPorts *)macPortsInstance;
+
+
+- (void)setIndex;
+- (void)addEntriesFromPortIndex:(NSString *)portIndex;
+
 - (MPPort *)port:(NSString *)name;
 - (NSEnumerator *)portEnumerator;
 - (void)removePort:(NSString *)name;
 - (void)setPort:(MPPort *)port;
 
+- (unsigned)count;
+- (NSEnumerator *)keyEnumerator;
+- (id)objectForKey:(id)aKey;
+- (void)removeObjectForKey:(id)aKey;
+- (void)setObject:(id)anObject forKey:(id)aKey;
+
++ (Class)classForKeyedUnarchiver;
+- (Class)classForKeyedArchiver;
+
 @end

Modified: users/rhwood/MacPorts.Framework/MPIndex.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPIndex.m	2007-09-25 09:53:33 UTC (rev 29482)
+++ users/rhwood/MacPorts.Framework/MPIndex.m	2007-09-25 09:55:50 UTC (rev 29483)
@@ -11,18 +11,75 @@
 
 @implementation MPIndex
 
-- (id) init {
+- (id)init {
 	self = [super init];
 	if (self != nil) {
+		[self finishInitWithCapacity:0 WithMacPorts:[[MPMacPorts alloc] init]];
 	}
 	return self;
 }
 
-- (void) dealloc {
+- (id)initWithCapacity:(unsigned)numItems {
+	self = [super init];
+	if (self != nil) {
+		[self finishInitWithCapacity:(unsigned)numItems WithMacPorts:[[MPMacPorts alloc] init]];
+	}
+	return self;
+}
+
+- (id)initWithMacPorts:(MPMacPorts *)macPortsInstance {
+	self = [super init];
+	if (self != nil) {
+		[self finishInitWithCapacity:0 WithMacPorts:(MPMacPorts *)macPortsInstance];
+	}
+	return self;
+}
+
+- (id)initWithCapacity:(unsigned)numItems WithMacPorts:(MPMacPorts *)macPortsInstance {
+	self = [super init];
+	if (self != nil) {
+		[self finishInitWithCapacity:(unsigned)numItems WithMacPorts:(MPMacPorts *)macPortsInstance];
+	}
+	return self;
+}
+
+- (void)finishInitWithCapacity:(unsigned)numItems WithMacPorts:(MPMacPorts *)macPortsInstance {
+	embeddedDictionary = [[NSMutableDictionary alloc] initWithCapacity:numItems];
+	macPorts = macPortsInstance;
+	[self setIndex];
+}
+
+- (void)dealloc {
+	[embeddedDictionary release];
 	[super dealloc];
 }
 
+- (void)setIndex {
+	NSEnumerator* portIndexEnumerator;
+	NSString* portIndex;
+	[self removeAllObjects];
+	portIndexEnumerator = [[macPorts sources] objectEnumerator];
+	while (portIndex = [portIndexEnumerator nextObject]) {
+		[self addEntriesFromPortIndex:portIndex];
+	}
+}
 
+- (void)addEntriesFromPortIndex:(NSString *)portIndex {
+	NSString* file;
+	NSArray* lines;
+	NSEnumerator* linesEnumerator;
+	id line;
+	file = [[NSString alloc] initWithContentsOfFile:[macPorts pathToPortIndex:portIndex]];
+	lines = [file componentsSeparatedByString:@"\n"];
+	linesEnumerator = [lines objectEnumerator];
+	while (line = [linesEnumerator nextObject]) {
+		// if there are only two token (a portname and a number) we don't want to deal with it
+		if ([[line componentsSeparatedByString:@" "] count] > 2) {
+			[self setPort:[[MPPort alloc] initWithTclListAsString:line]];
+		}
+	}
+}
+
 - (MPPort *)port:(NSString *)name {
 	return [self objectForKey:name];
 }
@@ -39,4 +96,36 @@
 	[self setObject:port forKey:[port name]];
 }
 
+#pragma NSMutableDictionary Protocal
+
+- (unsigned)count {
+	return [embeddedDictionary count];
+}
+
+- (NSEnumerator *)keyEnumerator {
+	return [embeddedDictionary keyEnumerator];
+}
+
+- (id)objectForKey:(id)aKey {
+	return [embeddedDictionary objectForKey:aKey];
+}
+
+- (void)removeObjectForKey:(id)aKey {
+	[embeddedDictionary removeObjectForKey:aKey];
+}
+
+- (void)setObject:(id)anObject forKey:(id)aKey {
+	[self willChangeValueForKey:aKey];
+	[embeddedDictionary setObject:anObject forKey:aKey];
+	[self didChangeValueForKey:aKey];
+}
+
+- (Class)classForKeyedArchiver {
+	return [MPIndex class];
+}
+
++ (Class)classForKeyedUnarchiver {
+	return [MPIndex class];
+}
+
 @end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070925/dea9749f/attachment.html


More information about the macports-changes mailing list