-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGVGraphDefaultAttributes.m
More file actions
114 lines (96 loc) · 2.89 KB
/
GVGraphDefaultAttributes.m
File metadata and controls
114 lines (96 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*************************************************************************
* Copyright (c) 2011 AT&T Intellectual Property
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Details at http://www.graphviz.org/
*************************************************************************/
#import "GVGraphDefaultAttributes.h"
#import "GVZGraph.h"
@interface GVGraphDefaultAttributeKeyEnumerator : NSEnumerator
{
graph_t *_graph;
int _kind;
Agsym_t *_nextSymbol;
}
@property(readonly, copy) NSArray *allObjects;
@property(readonly) id nextObject;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithGraphLoc:(graph_t *)graph prototype:(int)kind NS_DESIGNATED_INITIALIZER;
@end
@implementation GVGraphDefaultAttributeKeyEnumerator
- (instancetype)initWithGraphLoc:(graph_t *)graph prototype:(int)kind;
{
if (self = [super init]) {
_graph = graph;
_kind = kind;
_nextSymbol = agnxtattr(_graph, _kind, NULL);
}
return self;
}
- (NSArray *)allObjects
{
NSMutableArray *all = [NSMutableArray array];
for (; _nextSymbol; _nextSymbol = agnxtattr(_graph, _kind, _nextSymbol)) {
char *attributeValue = _nextSymbol->defval;
if (attributeValue && *attributeValue)
[all addObject:@(attributeValue)];
}
return all;
}
- (id)nextObject
{
for (; _nextSymbol; _nextSymbol = agnxtattr(_graph, _kind, _nextSymbol)) {
char *attributeValue = _nextSymbol->defval;
if (attributeValue && *attributeValue)
return @(attributeValue);
}
return nil;
}
@end
@implementation GVGraphDefaultAttributes
- (instancetype)initWithGraph:(GVZGraph *)graph prototype:(int)kind
{
if (self = [super init]) {
_graph = graph;
_kind = kind;
}
return self;
}
- (NSUInteger)count
{
NSUInteger symbolCount = 0;
Agsym_t *nextSymbol = NULL;
for (nextSymbol = agnxtattr(_graph.graph, _kind, nextSymbol); nextSymbol; nextSymbol = agnxtattr(_graph.graph, _kind, nextSymbol))
if (nextSymbol->defval && *(nextSymbol->defval))
++symbolCount;
return symbolCount;
}
- (NSEnumerator *)keyEnumerator
{
return [[GVGraphDefaultAttributeKeyEnumerator alloc] initWithGraphLoc:_graph.graph prototype:_kind];
}
- (NSString *)objectForKey:(NSString *)key
{
NSString *object;
Agsym_t *attributeSymbol = agattr(_graph.graph, _kind, (char *)key.UTF8String, 0);
if (attributeSymbol) {
char *attributeValue = attributeSymbol->defval;
if (attributeValue && *attributeValue)
object = @(attributeValue);
}
return object;
}
- (void)setObject:(NSString *)object forKey:(NSString *)key
{
agattr(_graph.graph, _kind, (char *)key.UTF8String, (char *)object.UTF8String);
[_graph noteChanged:YES];
}
- (void)removeObjectForKey:(NSString *)key
{
agattr(_graph.graph, _kind, (char *)key.UTF8String, "");
[_graph noteChanged:YES];
}
@end