[29484] users/rhwood/MacPorts.Framework

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 25 02:57:36 PDT 2007


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

Log Message:
-----------
Add method to pass int as state flags.
Add method to create an MPPort object from a Tcl_List.
Subclassing NSMutableDictionary is just plain weird.

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

Modified: users/rhwood/MacPorts.Framework/MPPort.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPPort.h	2007-09-25 09:55:50 UTC (rev 29483)
+++ users/rhwood/MacPorts.Framework/MPPort.h	2007-09-25 09:57:35 UTC (rev 29484)
@@ -8,12 +8,33 @@
 
 #import <Cocoa/Cocoa.h>
 #import "MPConstants.h"
+#import "MPInterpreter.h"
 
 @interface MPPort : NSMutableDictionary {
 
+	NSMutableDictionary *embeddedDictionary;
+
 }
 
+- (id)init;
+- (id)initWithCapacity:(unsigned)numItems;
+- (id)initWithTclListAsString:(NSString *)string;
+
 - (NSString *)name;
 - (NSString *)version;
 
+- (void) setPortWithTclListAsString:(NSString *)string;
+- (void) addDependencyAsPortName:(NSString *)dependency;
+- (void)setState:(int)state;
+
+- (unsigned)count;
+- (NSEnumerator *)keyEnumerator;
+- (id)objectForKey:(id)aKey;
+- (void)removeObjectForKey:(id)aKey;
+- (void)setObject:(id)anObject forKey:(id)aKey;
+- (void)setDictionary:(NSDictionary *)otherDictionary;
+
++ (Class)classForKeyedUnarchiver;
+- (Class)classForKeyedArchiver;
+
 @end

Modified: users/rhwood/MacPorts.Framework/MPPort.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPPort.m	2007-09-25 09:55:50 UTC (rev 29483)
+++ users/rhwood/MacPorts.Framework/MPPort.m	2007-09-25 09:57:35 UTC (rev 29484)
@@ -11,19 +11,103 @@
 
 @implementation MPPort
 
-- (id) init {
+- (id)init {
 	self = [super init];
 	if (self != nil) {
-		[self setObject:MPPortStateUnknown forKey:@"state"];
+		embeddedDictionary = [[NSMutableDictionary alloc] initWithCapacity:15];
+		[self setState:MPPortStateUnknown];
 	}
 	return self;
 }
 
+- (id)initWithCapacity:(unsigned)numItems {
+	self = [super init];
+	if (self != nil) {
+		embeddedDictionary = [[NSMutableDictionary alloc] initWithCapacity:numItems];
+		[self setState:MPPortStateUnknown];
+	}
+	return self;
+}
+
+- (id) initWithTclListAsString:(NSString *)string {
+	self = [super init];
+	if (self != nil) {
+		embeddedDictionary = [[NSMutableDictionary alloc] initWithCapacity:15];
+		[self setState:MPPortStateUnknown];
+		[self setPortWithTclListAsString:string];
+	}
+	return self;
+}
+
 - (void) dealloc {
 	[super dealloc];
 }
 
+- (void) setPortWithTclListAsString:(NSString *)string {
+	MPInterpreter *interpreter;
+	interpreter = [MPInterpreter sharedInterpreter];
+	
+	[self setDictionary:[interpreter dictionaryFromTclListAsString:string]];
 
+	// for each of the following properties:
+	// create strings for tokenizable properties to facilitate rapid searching
+	// tokenize the properties
+	// create sets of the depends_* tokenized properties that contain only the dependency name, not the dependency type
+	// make the descriptions readable
+	if ([self objectForKey:@"maintainers"] != nil) {
+		[self setObject:[self objectForKey:@"maintainers"] forKey:@"maintainersAsString"];		
+		[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"maintainers"]] forKey:@"maintainers"];
+	}
+	if ([self objectForKey:@"categories"] != nil) {
+		[self setObject:[self objectForKey:@"categories"] forKey:@"categoriesAsString"];
+		[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"categories"]] forKey:@"categories"];
+	}
+	if ([self objectForKey:@"depends_build"] != nil) {
+		[self setObject:[self objectForKey:@"depends_build"] forKey:@"depends_buildAsString"];
+		[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"depends_build"]] forKey:@"depends_build"];
+		[self addDependencyAsPortName:@"depends_build"];
+	}
+	if ([self objectForKey:@"depends_lib"] != nil) {
+		[self setObject:[self objectForKey:@"depends_lib"] forKey:@"depends_libAsString"];
+		[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"depends_lib"]] forKey:@"depends_lib"];
+		[self addDependencyAsPortName:@"depends_lid"];
+	}
+	if ([self objectForKey:@"depends_run"] != nil) {
+		[self setObject:[self objectForKey:@"depends_run"] forKey:@"depends_runAsString"];
+		[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"depends_run"]] forKey:@"depends_run"];
+		[self addDependencyAsPortName:@"depends_run"];
+	}
+
+	@try {
+		if ([[self valueForKey:@"long_description"] characterAtIndex:0] == '{') {
+			[self setValue:[self valueForKey:@"description"] forKey:@"long_description"];
+		}
+	} 
+	@catch (NSException *e) {
+		[self setValue:[NSString stringWithFormat:
+			NSLocalizedStringWithDefaultValue(@"setPortWithTclListAsStringDescreiptionError",
+											  @"Localizable",
+											  [NSBundle mainBundle],
+											  @"Port has an invalid desciption or long_description key.",
+											  @"Error statement for exception raised when testing long_description.")]
+				forKey:@"long_description"];
+	}
+	// generate a composite version string: version_revision
+	[self setValue:[[[self valueForKey:@"version"] stringByAppendingString:@"_"] stringByAppendingString:[self valueForKey:@"revision"]] forKey:@"compositeVersion"];
+	// set the status flag to unknown
+	[self setState:MPPortStateUnknown];
+}	
+
+- (void)addDependencyAsPortName:(NSString *)dependency {
+	NSMutableArray *array;
+	int i;
+	array = [[NSMutableArray alloc] initWithArray:[self objectForKey:dependency]];
+	for (i = 0; i < [array count]; i++) {
+		[array replaceObjectAtIndex:i withObject:[[[array objectAtIndex:i] componentsSeparatedByString:@":"] lastObject]];
+	}
+	[self setObject:[[NSArray alloc] initWithArray:array] forKey:[dependency stringByAppendingString:@"AsPortName"]];	
+}
+
 - (NSString *)name {
 	return [self objectForKey:@"name"];
 }
@@ -32,4 +116,45 @@
 	return [self objectForKey:@"version"];
 }
 
+#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];
+}
+
+- (void)setDictionary:(NSDictionary *)otherDictionary {
+	[embeddedDictionary setDictionary:otherDictionary];
+	[self setState:MPPortStateUnknown];
+}
+
+- (void)setState:(int)state {
+	[self setObject:[NSNumber numberWithInt:state] forKey:@"state"];
+}
+
+- (Class)classForKeyedArchiver {
+	return [MPPort class];
+}
+
++ (Class)classForKeyedUnarchiver {
+	return [MPPort class];
+}
+
 @end

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


More information about the macports-changes mailing list