Some final header nits.
[macgdbp.git] / Source / VariableNode.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2011, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "VariableNode.h"
18
19 #include "NSXMLElementAdditions.h"
20
21 @implementation VariableNode {
22 NSMutableArray* _children;
23 }
24
25 @synthesize name = _name;
26 @synthesize fullName = _fullName;
27 @synthesize className = _className;
28 @synthesize type = _type;
29 @synthesize value = _value;
30 @synthesize childCount = _childCount;
31 @synthesize address = _address;
32
33 - (id)initWithXMLNode:(NSXMLElement*)node {
34 if (self = [super init]) {
35 _name = [[[node attributeForName:@"name"] stringValue] copy];
36 _fullName = [[[node attributeForName:@"fullname"] stringValue] copy];
37 _className = [[[node attributeForName:@"classname"] stringValue] copy];
38 _type = [[[node attributeForName:@"type"] stringValue] copy];
39 _value = [[node base64DecodedValue] copy];
40 _children = [[NSMutableArray alloc] init];
41 if ([node children]) {
42 [self setChildrenFromXMLChildren:[node children]];
43 }
44 _childCount = [[[node attributeForName:@"numchildren"] stringValue] integerValue];
45 _address = [[[node attributeForName:@"address"] stringValue] copy];
46 }
47 return self;
48 }
49
50 - (void)dealloc {
51 [_name release];
52 [_fullName release];
53 [_className release];
54 [_type release];
55 [_value release];
56 [_children release];
57 [_address release];
58 [super dealloc];
59 }
60
61 - (void)setChildrenFromXMLChildren:(NSArray*)children {
62 [self willChangeValueForKey:@"children"];
63
64 [_children removeAllObjects];
65
66 for (NSXMLNode* child in children) {
67 // Other child nodes may be the string value.
68 if ([child isKindOfClass:[NSXMLElement class]]) {
69 VariableNode* node = [[VariableNode alloc] initWithXMLNode:(NSXMLElement*)child];
70 // Don't include the CLASSNAME property as that information is retreeived
71 // elsewhere.
72 if (![node.name isEqualToString:@"CLASSNAME"])
73 [_children addObject:node];
74 [node release];
75 }
76 }
77
78 [self didChangeValueForKey:@"children"];
79 }
80
81 - (BOOL)isLeaf {
82 return self.childCount == 0;
83 }
84
85 - (NSString*)displayType {
86 if (self.className != nil) {
87 return [NSString stringWithFormat:@"%@ (%@)", self.className, self.type];
88 }
89 return self.type;
90 }
91
92 - (NSString*)description {
93 return [NSString stringWithFormat:@"<VariableNode %p : %@>", self, self.fullName];
94 }
95
96 @end