Rewrite variable and property loading.
[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 // Private Properties //////////////////////////////////////////////////////////
22
23 @interface VariableNode ()
24
25 @property (copy) NSString* name;
26 @property (copy) NSString* fullName;
27 @property (copy) NSString* className;
28 @property (copy) NSString* type;
29 @property (copy) NSString* value;
30 @property (retain) NSArray* children;
31 @property (copy) NSString* address;
32
33 @end
34
35 ////////////////////////////////////////////////////////////////////////////////
36
37 @implementation VariableNode
38
39 @synthesize name = name_;
40 @synthesize fullName = fullName_;
41 @synthesize className = className_;
42 @synthesize type = type_;
43 @synthesize value = value_;
44 @synthesize children = children_;
45 @synthesize childCount = childCount_;
46 @synthesize address = address_;
47
48 - (id)initWithXMLNode:(NSXMLElement*)node
49 {
50 if (self = [super init]) {
51 self.name = [[node attributeForName:@"name"] stringValue];
52 self.fullName = [[node attributeForName:@"fullname"] stringValue];
53 self.className = [[node attributeForName:@"classname"] stringValue];
54 self.type = [[node attributeForName:@"type"] stringValue];
55 self.value = [node base64DecodedValue];
56 self.children = [NSMutableArray array];
57 if ([node children]) {
58 [self setChildrenFromXMLChildren:[node children]];
59 }
60 childCount_ = [[[node attributeForName:@"numchildren"] stringValue] integerValue];
61 self.address = [[node attributeForName:@"address"] stringValue];
62 }
63 return self;
64 }
65
66 - (void)dealloc
67 {
68 self.name = nil;
69 self.fullName = nil;
70 self.className = nil;
71 self.type = nil;
72 self.value = nil;
73 self.children = nil;
74 self.address = nil;
75 [super dealloc];
76 }
77
78 - (void)setChildrenFromXMLChildren:(NSArray*)children
79 {
80 [self willChangeValueForKey:@"children"];
81
82 [children_ removeAllObjects];
83
84 for (NSXMLNode* child in children) {
85 // Other child nodes may be the string value.
86 if ([child isKindOfClass:[NSXMLElement class]]) {
87 VariableNode* node = [[VariableNode alloc] initWithXMLNode:(NSXMLElement*)child];
88 // Don't include the CLASSNAME property as that information is retreeived
89 // elsewhere.
90 if (![node.name isEqualToString:@"CLASSNAME"])
91 [children_ addObject:node];
92 [node release];
93 }
94 }
95
96 [self didChangeValueForKey:@"children"];
97 }
98
99 - (BOOL)isLeaf
100 {
101 return (self.childCount == 0);
102 }
103
104 - (NSString*)displayType
105 {
106 if (self.className != nil) {
107 return [NSString stringWithFormat:@"%@ (%@)", self.className, self.type];
108 }
109 return self.type;
110 }
111
112 - (NSString*)description
113 {
114 return [NSString stringWithFormat:@"<VariableNode %p : %@>", self, self.fullName];
115 }
116
117 @end