forked from apaffenholz/PolyViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyNode.m
182 lines (139 loc) · 5.03 KB
/
PropertyNode.m
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/***********************************************************************
* Created by Andreas Paffenholz on 01/08/14.
* Copyright 2012-2014 by Andreas Paffenholz.
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl.txt.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* PropertyNode.m
* PolyViewer
**************************************************************************/
#import "PropertyNode.h"
#import "PropertyNodeValue.h"
@implementation PropertyNode
@synthesize polyObj = _polyObj;
@synthesize propertyName = _propertyName;
@synthesize name = _name;
@synthesize index = _index;
@synthesize hasValue, isObject, isLeaf, isMultiple;
@dynamic children;
@dynamic value;
- (id)init {
NSLog(@"[PropertyNode init] called");
self = [super init];
if (self) {
_polyObj = nil;
_propertyName = @"undefined name";
_name = nil;
_index = 0;
isObject = nil;
isMultiple = nil;
isLeaf = nil;
_children = nil;
_value = nil;
}
return self;
}
- (id)initWithName:(NSString *)propertyName andObj:(id) polyObj asObject:(BOOL) isObj asMultiple:(BOOL) isMult asLeaf:(BOOL) isL {
NSLog(@"[PropertyNode initWithName...] called for name: %@ and with polyObj %@", propertyName, polyObj);
self = [super init];
if (self) {
_polyObj = polyObj;
_propertyName = propertyName;
[_propertyName retain];
_name = nil;
_index = 0;
isObject = isObj;
isMultiple = isMult;
isLeaf = isL;
_children = nil;
_value = nil;
}
NSLog(@"[PropertyNode initWithName...] returning with %@", self);
return self;
}
- (id)initWithName:(NSString *)propertyName andObj:(id) polyObj withIndex:(int)index withName:(NSString *)name asObject:(BOOL) isObj asMultiple:(BOOL) isMult asLeaf:(BOOL) isL {
NSLog(@"[PropertyNode initWithName... (multiple)] called for name: %@ and with polyObj %@", propertyName, polyObj);
self = [super init];
if (self) {
_polyObj = polyObj;
_propertyName = propertyName;
[_propertyName retain];
_name = name;
[_name retain];
_index = index;
isObject = isObj;
isMultiple = isMult;
isLeaf = isL;
_children = nil;
_value = nil;
}
NSLog(@"[PropertyNode initWithName...(multiple)] returning with %@", self);
return self;
}
- (id)initWithObject:(PolymakeObjectWrapper *)polyObj {
NSLog(@"[PropertyNode initWithObject] entering");
self = [super init];
if (self) {
_polyObj = [polyObj retain];
_propertyName = [polyObj getObjectName];
[_propertyName retain];
isObject = TRUE;
isMultiple = FALSE; //FIXME
isLeaf = FALSE;
_children = nil;
_value = nil;
}
NSLog(@"[PropertyNode initWithObject] returning with %@",self);
return self;
}
// get the children of a tag
// as with the value this is only done if really needed
// i.e. if the user opens the triangle in the display
- (NSArray *)children {
NSLog(@"[PropertyNode children] called");
if ( _children == nil ) {
NSLog(@"[PropertyNode children] children not yet defined");
NSMutableArray *newChildren = [NSMutableArray array];
if ( isObject ) { // okay, here we really have to do something
NSLog(@"[PropertyNode children] called for object");
newChildren = [[_polyObj getPropertyListAtRootLevel] copy];
}
_children = [newChildren retain];
}
NSLog(@"[PropertyNode children] returning");
return _children;
}
- (void)resetChildren {
[_children release];
_children = nil;
}
// compute the values of a property
// remember that this is not done during initialization
// but only if the user requests that property for display
- (PropertyNodeValue *)value {
NSLog(@"[PropertyNode value] entering");
if ( _value == nil ) {
NSLog(@"[PropertyNode value] value not yet set");
_value = [[PropertyNodeValue alloc] init];
if ( isLeaf ) {
NSLog(@"[PropertyNode value] at a leaf");
[_value setData:[_polyObj getProperty:_propertyName]];
if ( [[_value data] length] == 0 )
[_value setIsEmpty:YES];
NSLog(@"[PropertyNode value] value set: %@", _value);
[_value retain];
} else {
NSLog(@"[PropertyNode value] not at a leaf");
[_value setData:[[NSString alloc] initWithString:@"<no value>"]];
}
}
NSLog(@"[PropertyNode value] leaving");
return _value;
}
@end