]> src.bluestatic.org Git - macgdbp.git/blob - Source/VariableNode.m
CFBundleVersion is no longer incremented by gitcrement.
[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 - (id)initWithXMLNode:(NSXMLElement*)node {
26 if (self = [super init]) {
27 _name = [[[node attributeForName:@"name"] stringValue] copy];
28 _fullName = [[[node attributeForName:@"fullname"] stringValue] copy];
29 _className = [[[node attributeForName:@"classname"] stringValue] copy];
30 _type = [[[node attributeForName:@"type"] stringValue] copy];
31 _value = [[node base64DecodedValue] copy];
32 _children = [[NSMutableArray alloc] init];
33 if ([node children]) {
34 [self setChildrenFromXMLChildren:[node children]];
35 }
36 _childCount = [[[node attributeForName:@"numchildren"] stringValue] integerValue];
37 _address = [[[node attributeForName:@"address"] stringValue] copy];
38 }
39 return self;
40 }
41
42 - (void)dealloc {
43 [_name release];
44 [_fullName release];
45 [_className release];
46 [_type release];
47 [_value release];
48 [_children release];
49 [_address release];
50 [super dealloc];
51 }
52
53 - (void)setChildrenFromXMLChildren:(NSArray*)children {
54 [self willChangeValueForKey:@"children"];
55
56 [_children removeAllObjects];
57
58 for (NSXMLNode* child in children) {
59 // Other child nodes may be the string value.
60 if ([child isKindOfClass:[NSXMLElement class]]) {
61 VariableNode* node = [[VariableNode alloc] initWithXMLNode:(NSXMLElement*)child];
62 // Don't include the CLASSNAME property as that information is retrieved
63 // elsewhere.
64 if (![node.name isEqualToString:@"CLASSNAME"])
65 [_children addObject:node];
66 [node release];
67 }
68 }
69
70 [self didChangeValueForKey:@"children"];
71 }
72
73 - (BOOL)isLeaf {
74 return self.childCount == 0;
75 }
76
77 - (NSString*)displayType {
78 if (self.className != nil) {
79 return [NSString stringWithFormat:@"%@ (%@)", self.className, self.type];
80 }
81 return self.type;
82 }
83
84 - (NSString*)description {
85 return [NSString stringWithFormat:@"<VariableNode %p : %@>", self, self.fullName];
86 }
87
88 @end