Tabs to spaces.
[macgdbp.git] / Source / NSXMLElementAdditions.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2010, 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 <Cocoa/Cocoa.h>
18 #include "base64.h"
19 #import "AppDelegate.h"
20
21 @implementation NSXMLElement (GDBpAdditions)
22
23 /**
24 * Return's the property's full name
25 */
26 - (NSString*)fullname
27 {
28 return [[self attributeForName:@"fullname"] stringValue];
29 }
30
31 /**
32 * Return's the property's name from the attributes list
33 */
34 - (NSString*)variable
35 {
36 return [[self attributeForName:@"name"] stringValue];
37 }
38
39 /**
40 * Returns whether or not this node has any children
41 */
42 - (BOOL)isLeaf
43 {
44 return ([[[self attributeForName:@"children"] stringValue] intValue] == 0);
45 }
46
47 /**
48 * Override children so we can fetch more depth as needed
49 */
50 - (NSArray*)subnodes
51 {
52 NSArray* children = [self children];
53 if (![self isLeaf] && [children count] < 1)
54 {
55 return [[[(AppDelegate*)[NSApp delegate] debugger] connection] getProperty:[self fullname]];
56 }
57 return children;
58 }
59
60 /**
61 * Returns the value of the property
62 */
63 - (NSString*)value
64 {
65 // not a leaf, so don't display any value
66 if (![self isLeaf])
67 {
68 return @"...";
69 }
70
71 // base64 encoded data
72 if ([[[self attributeForName:@"encoding"] stringValue] isEqualToString:@"base64"])
73 {
74 const char* str = [[self stringValue] UTF8String];
75 int strlen = [[self stringValue] length];
76
77 char* data;
78 size_t datalen;
79
80 if (!base64_decode_alloc(str, strlen, &data, &datalen))
81 NSLog(@"error in converting %@ from base64", self);
82
83 NSString* ret = nil;
84 if (data)
85 {
86 ret = [NSString stringWithUTF8String:data];
87 free(data);
88 }
89
90 return ret;
91 }
92
93 // just a normal string
94 return [self stringValue];
95 }
96
97 /**
98 * Returns the type of variable this is
99 */
100 - (NSString*)type
101 {
102 NSXMLNode* className = [self attributeForName:@"classname"];
103 NSString* type = [[self attributeForName:@"type"] stringValue];
104 if (className != nil)
105 {
106 return [NSString stringWithFormat:@"%@ (%@)", [className stringValue], type];
107 }
108 return type;
109 }
110
111 @end