3 * Copyright (c) 2011, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import "VariableNode.h"
19 #include "NSXMLElementAdditions.h"
21 @implementation VariableNode
{
22 NSMutableArray
* _children
;
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
]];
36 _childCount
= [[[node attributeForName
:@
"numchildren"] stringValue
] integerValue
];
37 _address
= [[[node attributeForName
:@
"address"] stringValue
] copy
];
53 - (void)setChildrenFromXMLChildren
:(NSArray
*)children
{
54 [self willChangeValueForKey
:@
"children"];
56 [_children removeAllObjects
];
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
64 if (![node.name isEqualToString
:@
"CLASSNAME"])
65 [_children addObject
:node
];
70 [self didChangeValueForKey
:@
"children"];
74 return self.childCount
== 0;
77 - (NSString
*)displayType
{
78 if (self.className
!= nil) {
79 return [NSString stringWithFormat
:@
"%@ (%@)", self.className
, self.type
];
84 - (NSString
*)description
{
85 return [NSString stringWithFormat
:@
"<VariableNode %p : %@>", self, self.fullName
];