~ubuntu-branches/ubuntu/lucid/graphviz/lucid-updates

« back to all changes in this revision

Viewing changes to macosx/GVGraphDefaultAttributes.m

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-06-19 20:23:23 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080619202323-ls23h96ntj9ny94m
Tags: 2.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Drop libttf-dev (libttf-dev is in universe) (LP: #174749).
  - Replace gs-common with ghostscript.
  - Build-depend on python-dev instead of python2.4-dev or python2.5-dev.
  - Mention the correct python version for the python bindings in the
    package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: */
 
3
 
 
4
/**********************************************************
 
5
*      This software is part of the graphviz package      *
 
6
*                http://www.graphviz.org/                 *
 
7
*                                                         *
 
8
*            Copyright (c) 1994-2008 AT&T Corp.           *
 
9
*                and is licensed under the                *
 
10
*            Common Public License, Version 1.0           *
 
11
*                      by AT&T Corp.                      *
 
12
*                                                         *
 
13
*        Information and Software Systems Research        *
 
14
*              AT&T Research, Florham Park NJ             *
 
15
**********************************************************/
 
16
 
 
17
#import "GVGraphDefaultAttributes.h"
 
18
#import "GVGraph.h"
 
19
 
 
20
@interface GVGraphDefaultAttributeKeyEnumerator : NSEnumerator
 
21
{
 
22
        Agsym_t **_nextSymbol;
 
23
        Agsym_t **_lastSymbol;
 
24
}
 
25
 
 
26
- (id)initWithSymbols:(Agsym_t **)symbols count:(NSUInteger)count;
 
27
- (NSArray *)allObjects;
 
28
- (id)nextObject;
 
29
 
 
30
@end
 
31
 
 
32
@implementation GVGraphDefaultAttributeKeyEnumerator
 
33
 
 
34
- (id)initWithSymbols:(Agsym_t **)symbols count:(NSUInteger)count
 
35
{
 
36
        if (self = [super init]) {
 
37
                _nextSymbol = symbols;
 
38
                _lastSymbol = symbols + count;
 
39
        }
 
40
        return self;
 
41
}
 
42
 
 
43
- (NSArray *)allObjects
 
44
{
 
45
        NSMutableArray* all = [NSMutableArray array];
 
46
        for (; _nextSymbol < _lastSymbol; ++_nextSymbol)
 
47
                if ((*_nextSymbol)->value && *(*_nextSymbol)->value)
 
48
                        [all addObject:[NSString stringWithUTF8String:(*_nextSymbol)->name]];
 
49
                        
 
50
        return all;
 
51
}
 
52
 
 
53
- (id)nextObject
 
54
{
 
55
        char* nextName = NULL;
 
56
        for (; _nextSymbol < _lastSymbol && !nextName; ++_nextSymbol)
 
57
                if ((*_nextSymbol)->value && *(*_nextSymbol)->value)
 
58
                        nextName = (*_nextSymbol)->name;
 
59
                
 
60
        return nextName ? [NSString stringWithUTF8String:nextName] : nil;
 
61
}
 
62
 
 
63
@end
 
64
 
 
65
@implementation GVGraphDefaultAttributes
 
66
 
 
67
- (id)initWithGraph:(GVGraph *)graph defaultAttributes:(Agdict_t *)defaultAttributes attributeDeclaration:(Agsym_t *(*)(Agraph_t *, char *, char *))attributeDeclaration
 
68
{
 
69
        if (self = [super init]) {
 
70
                _graph = graph; /* not retained to avoid a retain cycle */
 
71
                _defaultAttributes = defaultAttributes;
 
72
                _attributeDeclaration = attributeDeclaration;
 
73
        }
 
74
        return self;
 
75
}
 
76
 
 
77
- (NSString*)name
 
78
{
 
79
        return _defaultAttributes->name ? [NSString stringWithUTF8String:_defaultAttributes->name] : nil;
 
80
}
 
81
 
 
82
- (NSUInteger)count
 
83
{
 
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)
 
88
                        ++symbolCount;
 
89
        return symbolCount;
 
90
}
 
91
 
 
92
- (NSEnumerator *)keyEnumerator
 
93
{
 
94
        return [[[GVGraphDefaultAttributeKeyEnumerator alloc] initWithSymbols: _defaultAttributes->list count:dtsize(_defaultAttributes->dict)] autorelease];
 
95
}
 
96
 
 
97
- (id)objectForKey:(id)aKey
 
98
{
 
99
        id object = nil;
 
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];
 
105
        }
 
106
        return object;
 
107
}
 
108
 
 
109
- (void)setObject:(id)anObject forKey:(id)aKey
 
110
{
 
111
        _attributeDeclaration([_graph graph], (char *)[aKey UTF8String], (char *)[anObject UTF8String]);
 
112
        [_graph noteChanged:YES];
 
113
}
 
114
 
 
115
- (void)removeObjectForKey:(id)aKey
 
116
{
 
117
        _attributeDeclaration([_graph graph], (char *)[aKey UTF8String], "");
 
118
        [_graph noteChanged:YES];
 
119
}
 
120
@end