Merge branch 'master' into register-feature
[macgdbp.git] / Source / NSXMLElementAdditions.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2002 - 2007, 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
19 @implementation NSXMLElement (NSXMLElementAdditions)
20
21 /**
22 * Return's the property's name from the attributes list
23 */
24 - (NSString *)variable
25 {
26 return [[self attributeForName: @"name"] stringValue];
27 }
28
29 /**
30 * Returns whether or not this node has any children
31 */
32 - (BOOL)isLeaf
33 {
34 BOOL leaf = ([[[self attributeForName: @"children"] stringValue] intValue] == 0);
35
36 // hmm... we're not a leaf but have no children. this must be beyond our depth, so go make us
37 // deeper
38 if (!leaf && [[self children] count] < 1)
39 {
40 // count upwards to see how deep we should go
41 int depth = 0;
42 NSXMLElement *elm = self;
43 while (elm != nil)
44 {
45 depth++;
46 elm = (NSXMLElement *)[elm parent];
47 }
48 NSLog(@"let's go to depth %d for %@", depth, self);
49 }
50
51 return leaf;
52 }
53
54 /**
55 * Returns the value of the property
56 */
57 - (NSString *)value
58 {
59 // not a leaf, so don't display any value
60 if (![self isLeaf])
61 {
62 return @"...";
63 }
64
65 // base64 encoded data
66 if ([[[self attributeForName: @"encoding"] stringValue] isEqualToString: @"base64"])
67 {
68 NSLog(@"base64 encoded %@", [self variable]);
69 }
70
71 // just a normal string
72 return [self stringValue];
73 }
74
75 /**
76 * Returns the type of variable this is
77 */
78 - (NSString *)type
79 {
80 return [[self attributeForName: @"type"] stringValue];
81 }
82
83 @end