1
/* $Id: GVGraphDefaultAttributes.m,v 1.1 2008/02/11 12:34:07 glenlow Exp $ $Revision: 1.1 $ */
2
/* vim:set shiftwidth=4 ts=8: */
4
/**********************************************************
5
* This software is part of the graphviz package *
6
* http://www.graphviz.org/ *
8
* Copyright (c) 1994-2008 AT&T Corp. *
9
* and is licensed under the *
10
* Common Public License, Version 1.0 *
13
* Information and Software Systems Research *
14
* AT&T Research, Florham Park NJ *
15
**********************************************************/
17
#import "GVGraphDefaultAttributes.h"
20
@interface GVGraphDefaultAttributeKeyEnumerator : NSEnumerator
22
Agsym_t **_nextSymbol;
23
Agsym_t **_lastSymbol;
26
- (id)initWithSymbols:(Agsym_t **)symbols count:(NSUInteger)count;
27
- (NSArray *)allObjects;
32
@implementation GVGraphDefaultAttributeKeyEnumerator
34
- (id)initWithSymbols:(Agsym_t **)symbols count:(NSUInteger)count
36
if (self = [super init]) {
37
_nextSymbol = symbols;
38
_lastSymbol = symbols + count;
43
- (NSArray *)allObjects
45
NSMutableArray* all = [NSMutableArray array];
46
for (; _nextSymbol < _lastSymbol; ++_nextSymbol)
47
if ((*_nextSymbol)->value && *(*_nextSymbol)->value)
48
[all addObject:[NSString stringWithUTF8String:(*_nextSymbol)->name]];
55
char* nextName = NULL;
56
for (; _nextSymbol < _lastSymbol && !nextName; ++_nextSymbol)
57
if ((*_nextSymbol)->value && *(*_nextSymbol)->value)
58
nextName = (*_nextSymbol)->name;
60
return nextName ? [NSString stringWithUTF8String:nextName] : nil;
65
@implementation GVGraphDefaultAttributes
67
- (id)initWithGraph:(GVGraph *)graph defaultAttributes:(Agdict_t *)defaultAttributes attributeDeclaration:(Agsym_t *(*)(Agraph_t *, char *, char *))attributeDeclaration
69
if (self = [super init]) {
70
_graph = graph; /* not retained to avoid a retain cycle */
71
_defaultAttributes = defaultAttributes;
72
_attributeDeclaration = attributeDeclaration;
79
return _defaultAttributes->name ? [NSString stringWithUTF8String:_defaultAttributes->name] : nil;
84
NSUInteger symbolCount = 0;
85
Agsym_t **nextSymbol, **lastSymbol;
86
for (nextSymbol = _defaultAttributes->list, lastSymbol = _defaultAttributes->list + dtsize(_defaultAttributes->dict); nextSymbol < lastSymbol; ++nextSymbol)
87
if ((*nextSymbol)->value && *(*nextSymbol)->value)
92
- (NSEnumerator *)keyEnumerator
94
return [[[GVGraphDefaultAttributeKeyEnumerator alloc] initWithSymbols: _defaultAttributes->list count:dtsize(_defaultAttributes->dict)] autorelease];
97
- (id)objectForKey:(id)aKey
100
Agsym_t *attributeSymbol = dtmatch(_defaultAttributes->dict, [aKey UTF8String]);
101
if (attributeSymbol) {
102
char *attributeValue = attributeSymbol->value;
103
if (attributeValue && *attributeValue)
104
object = [NSString stringWithUTF8String:attributeSymbol->value];
109
- (void)setObject:(id)anObject forKey:(id)aKey
111
_attributeDeclaration([_graph graph], (char *)[aKey UTF8String], (char *)[anObject UTF8String]);
112
[_graph noteChanged:YES];
115
- (void)removeObjectForKey:(id)aKey
117
_attributeDeclaration([_graph graph], (char *)[aKey UTF8String], "");
118
[_graph noteChanged:YES];