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