return nil;
}
-#ifdef WITH_CGRAPH
_graph = agread(file,0);
-#else
- _graph = agread(file);
-#endif
if (!_graph) {
if (outError)
*outError = [NSError errorWithDomain:GVGraphvizErrorDomain code:GVFileParseError userInfo:nil];
parentDir = (char *)[[URL path] fileSystemRepresentation];
ptr = strrchr(parentDir,'/');
*ptr = 0;
-#ifdef WITH_CGRAPH
agattr(_graph,AGRAPH,"imagepath",parentDir);
-#else
- agraphattr(_graph,"imagepath",parentDir);
-#endif
}
fclose(file);
}
_freeLastLayout = NO;
_arguments = [[GVGraphArguments alloc] initWithGraph:self];
-#ifdef WITH_CGRAPH
_graphAttributes = [[GVGraphDefaultAttributes alloc] initWithGraph:self prototype:AGRAPH];
_defaultNodeAttributes = [[GVGraphDefaultAttributes alloc] initWithGraph:self prototype:AGNODE];
_defaultEdgeAttributes = [[GVGraphDefaultAttributes alloc] initWithGraph:self prototype:AGEDGE];
-#else
- _graphAttributes = [[GVGraphDefaultAttributes alloc] initWithGraph:self prototype:_graph];
- _defaultNodeAttributes = [[GVGraphDefaultAttributes alloc] initWithGraph:self prototype:agprotonode(_graph)];
- _defaultEdgeAttributes = [[GVGraphDefaultAttributes alloc] initWithGraph:self prototype:agprotoedge(_graph)];
-#endif
}
return self;
@interface GVGraphDefaultAttributeKeyEnumerator : NSEnumerator
{
-#ifdef WITH_CGRAPH
graph_t *_graph;
int _kind;
-#else
- void *_proto;
-#endif
Agsym_t *_nextSymbol;
}
-#ifdef WITH_CGRAPH
- (id)initWithGraphLoc:(graph_t *)graph prototype:(int)kind;
-#else
-- (id)initWithPrototypeLoc:(void *)proto;
-#endif
- (NSArray *)allObjects;
- (id)nextObject;
@implementation GVGraphDefaultAttributeKeyEnumerator
-#ifdef WITH_CGRAPH
- (id)initWithGraphLoc:(graph_t *)graph prototype:(int)kind;
{
if (self = [super init]) {
}
return nil;
}
-#else
-- (id)initWithPrototypeLoc:(void *)proto
-{
- if (self = [super init]) {
- _proto = proto;
- _nextSymbol = agfstattr(_proto);
- }
- return self;
-}
-
-- (NSArray *)allObjects
-{
- NSMutableArray* all = [NSMutableArray array];
- for (; _nextSymbol; _nextSymbol = agnxtattr(_proto, _nextSymbol)) {
- char *attributeValue = _nextSymbol->value;
- if (attributeValue && *attributeValue)
- [all addObject:[NSString stringWithUTF8String:attributeValue]];
- }
-
- return all;
-}
-
-- (id)nextObject
-{
- for (; _nextSymbol; _nextSymbol = agnxtattr(_proto, _nextSymbol)) {
- char *attributeValue = _nextSymbol->value;
- if (attributeValue && *attributeValue)
- return [NSString stringWithUTF8String:attributeValue];
- }
- return nil;
-}
-#endif
@end
@implementation GVGraphDefaultAttributes
-#ifdef WITH_CGRAPH
- (id)initWithGraph:(GVGraph *)graph prototype:(int)kind
{
if (self = [super init]) {
agattr(_graph->_graph, _kind, (char *)[aKey UTF8String], "");
[_graph noteChanged:YES];
}
-#else
-- (id)initWithGraph:(GVGraph *)graph prototype:(void *)proto
-{
- if (self = [super init]) {
- _graph = graph; /* not retained to avoid a retain cycle */
- _proto = proto;
- }
- return self;
-}
-
-- (NSUInteger)count
-{
- NSUInteger symbolCount = 0;
- 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] initWithPrototypeLoc:_proto] autorelease];
-}
-
-- (id)objectForKey:(id)aKey
-{
- id object = nil;
- Agsym_t *attributeSymbol = agfindattr(_proto, (char*)[aKey UTF8String]);
- if (attributeSymbol) {
- char *attributeValue = attributeSymbol->value;
- if (attributeValue && *attributeValue)
- object = [NSString stringWithUTF8String:attributeValue];
- }
- return object;
-}
-
-- (void)setObject:(id)anObject forKey:(id)aKey
-{
- agattr(_proto, (char *)[aKey UTF8String], (char *)[anObject UTF8String]);
- [_graph noteChanged:YES];
-}
-
-- (void)removeObjectForKey:(id)aKey
-{
- agattr(_proto, (char *)[aKey UTF8String], "");
- [_graph noteChanged:YES];
-}
-#endif
@end