Force a re-serialization of Breakpoints on decode.
[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)setChildrenFromXMLChildren:(NSArray*)children {
43 [self willChangeValueForKey:@"children"];
44
45 [_children removeAllObjects];
46
47 for (NSXMLNode* child in children) {
48 // Other child nodes may be the string value.
49 if ([child isKindOfClass:[NSXMLElement class]]) {
50 VariableNode* node = [[VariableNode alloc] initWithXMLNode:(NSXMLElement*)child];
51 // Don't include the CLASSNAME property as that information is retrieved
52 // elsewhere.
53 if (![node.name isEqualToString:@"CLASSNAME"])
54 [_children addObject:node];
55 }
56 }
57
58 [self didChangeValueForKey:@"children"];
59 }
60
61 - (BOOL)isLeaf {
62 return self.childCount == 0;
63 }
64
65 - (NSString*)displayType {
66 if (self.className != nil) {
67 return [NSString stringWithFormat:@"%@ (%@)", self.className, self.type];
68 }
69 return self.type;
70 }
71
72 - (NSString*)description {
73 return [NSString stringWithFormat:@"<VariableNode %p : %@>", self, self.fullName];
74 }
75
76 @end