]> granicus.if.org Git - graphviz/commitdiff
use new graph prototype and attribute symbol walking functions
authorglenlow <devnull@localhost>
Thu, 27 Mar 2008 11:55:33 +0000 (11:55 +0000)
committerglenlow <devnull@localhost>
Thu, 27 Mar 2008 11:55:33 +0000 (11:55 +0000)
macosx/GVGraphDefaultAttributes.h
macosx/GVGraphDefaultAttributes.m

index 3e96cc187b648bba7ae0be4f08bfd074b119d4d4..9d71144adeb724bfbf7bfc69099198d02c3060ef 100644 (file)
 @interface GVGraphDefaultAttributes : NSMutableDictionary
 {
        GVGraph *_graph;
-       Agdict_t *_defaultAttributes;
-       Agsym_t *(*_attributeDeclaration)(Agraph_t *, char *, char *);
+       void *_proto;
 }
 
-@property(readonly) NSString *name;
-
-- (id)initWithGraph:(GVGraph *)graph defaultAttributes:(Agdict_t *)defaultAttributes attributeDeclaration:(Agsym_t *(*)(Agraph_t *, char *, char *))attributeDeclaration;
+- (id)initWithGraph:(GVGraph *)graph prototype:(void *)proto;
 
 /* dictionary primitive methods */
 - (NSUInteger)count;
index ed4bf7980ad110289e540f73b19c71c9bfaa222e..1cc265031b501ca39093cc27804ac32a43409ad5 100644 (file)
 
 @interface GVGraphDefaultAttributeKeyEnumerator : NSEnumerator
 {
-       Agsym_t **_nextSymbol;
-       Agsym_t **_lastSymbol;
+       void *_proto;
+       Agsym_t *_nextSymbol;
 }
 
-- (id)initWithSymbols:(Agsym_t **)symbols count:(NSUInteger)count;
+- (id)initWithPrototype:(void *)proto;
 - (NSArray *)allObjects;
 - (id)nextObject;
 
 
 @implementation GVGraphDefaultAttributeKeyEnumerator
 
-- (id)initWithSymbols:(Agsym_t **)symbols count:(NSUInteger)count
+- (id)initWithPrototype:(void *)proto
 {
        if (self = [super init]) {
-               _nextSymbol = symbols;
-               _lastSymbol = symbols + count;
+               _proto = proto;
+               _nextSymbol = agfstattr(_proto);
        }
        return self;
 }
 - (NSArray *)allObjects
 {
        NSMutableArray* all = [NSMutableArray array];
-       for (; _nextSymbol < _lastSymbol; ++_nextSymbol)
-               if ((*_nextSymbol)->value && *(*_nextSymbol)->value)
-                       [all addObject:[NSString stringWithUTF8String:(*_nextSymbol)->name]];
+       for (; _nextSymbol; _nextSymbol = agnxtattr(_proto, _nextSymbol)) {
+               char *attributeValue = _nextSymbol->value;
+               if (attributeValue && *attributeValue)
+                       [all addObject:[NSString stringWithUTF8String:attributeValue]];
+       }
                        
        return all;
 }
 
 - (id)nextObject
 {
-       char* nextName = NULL;
-       for (; _nextSymbol < _lastSymbol && !nextName; ++_nextSymbol)
-               if ((*_nextSymbol)->value && *(*_nextSymbol)->value)
-                       nextName = (*_nextSymbol)->name;
-               
-       return nextName ? [NSString stringWithUTF8String:nextName] : nil;
+       for (; _nextSymbol; _nextSymbol = agnxtattr(_proto, _nextSymbol)) {
+               char *attributeValue = _nextSymbol->value;
+               if (attributeValue && *attributeValue)
+                       return [NSString stringWithUTF8String:attributeValue];
+       }
+       return nil;
 }
 
 @end
 
 @implementation GVGraphDefaultAttributes
 
-- (id)initWithGraph:(GVGraph *)graph defaultAttributes:(Agdict_t *)defaultAttributes attributeDeclaration:(Agsym_t *(*)(Agraph_t *, char *, char *))attributeDeclaration
+- (id)initWithGraph:(GVGraph *)graph prototype:(void *)proto
 {
        if (self = [super init]) {
                _graph = graph; /* not retained to avoid a retain cycle */
-               _defaultAttributes = defaultAttributes;
-               _attributeDeclaration = attributeDeclaration;
+               _proto = proto;
        }
        return self;
 }
 
-- (NSString*)name
-{
-       return _defaultAttributes->name ? [NSString stringWithUTF8String:_defaultAttributes->name] : nil;
-}
-
 - (NSUInteger)count
 {
        NSUInteger symbolCount = 0;
-       Agsym_t **nextSymbol, **lastSymbol;
-       for (nextSymbol = _defaultAttributes->list, lastSymbol = _defaultAttributes->list + dtsize(_defaultAttributes->dict); nextSymbol < lastSymbol; ++nextSymbol)
-               if ((*nextSymbol)->value && *(*nextSymbol)->value)
+       Agsym_t *nextSymbol;
+       for (nextSymbol = agfstattr(_proto); nextSymbol; nextSymbol = agnxtattr(_proto, nextSymbol))
+               if (nextSymbol->value && *(nextSymbol->value))
                        ++symbolCount;
        return symbolCount;
 }
 
 - (NSEnumerator *)keyEnumerator
 {
-       return [[[GVGraphDefaultAttributeKeyEnumerator alloc] initWithSymbols: _defaultAttributes->list count:dtsize(_defaultAttributes->dict)] autorelease];
+       return [[[GVGraphDefaultAttributeKeyEnumerator alloc] initWithPrototype:_proto] autorelease];
 }
 
 - (id)objectForKey:(id)aKey
 {
        id object = nil;
-       Agsym_t *attributeSymbol = dtmatch(_defaultAttributes->dict, [aKey UTF8String]);
+       Agsym_t *attributeSymbol = agfindattr(_proto, (char*)[aKey UTF8String]);
        if (attributeSymbol) {
                char *attributeValue = attributeSymbol->value;
                if (attributeValue && *attributeValue)
-                       object = [NSString stringWithUTF8String:attributeSymbol->value];
+                       object = [NSString stringWithUTF8String:attributeValue];
        }
        return object;
 }
 
 - (void)setObject:(id)anObject forKey:(id)aKey
 {
-       _attributeDeclaration([_graph graph], (char *)[aKey UTF8String], (char *)[anObject UTF8String]);
+       agattr(_proto, (char *)[aKey UTF8String], (char *)[anObject UTF8String]);
        [_graph noteChanged:YES];
 }
 
 - (void)removeObjectForKey:(id)aKey
 {
-       _attributeDeclaration([_graph graph], (char *)[aKey UTF8String], "");
+       agattr(_proto, (char *)[aKey UTF8String], "");
        [_graph noteChanged:YES];
 }
 @end