Fixed various memory leaks.
[MenuTunes.git] / PlaylistNode.m
1 /*
2  *      MenuTunes
3  *  PlaylistNode
4  *    Helper class for keeping track of sources, playlists and folders
5  *
6  *  Original Author : Kent Sutherland <ksuther@ithinksw.com>
7  *   Responsibility : Kent Sutherland <ksuther@ithinksw.com>
8  *
9  *  Copyright (c) 2005 iThink Software.
10  *  All Rights Reserved
11  *
12  */
13
14 #import "PlaylistNode.h"
15
16
17 @implementation PlaylistNode
18
19 + (PlaylistNode *)playlistNodeWithName:(NSString *)n type:(ITMTNodeType)t index:(int)i
20 {
21         return [[[PlaylistNode alloc] initWithName:n type:t index:i] autorelease];
22 }
23
24 - (id)initWithName:(NSString *)n type:(ITMTNodeType)t index:(int)i
25 {
26         if ( (self = [super init]) ) {
27                 _name = [n retain];
28                 _type = t;
29                 _index = i;
30                 _children = nil;
31                 _parent = nil;
32         }
33         return self;
34 }
35
36 - (void)dealloc
37 {
38         [_name release];
39         [_children release];
40         [_parent release];
41         [super dealloc];
42 }
43
44 - (NSString *)description
45 {
46         return [NSString stringWithFormat:@"{%@, index: %i, type: %i, parent: %@, children: %@}", _name, _index, _type, [_parent name], _children];
47 }
48
49 - (NSString *)name
50 {
51         return _name;
52 }
53
54 - (NSMutableArray *)children
55 {
56         if (!_children) {
57                 _children = [[NSMutableArray alloc] init];
58         }
59         return _children;
60 }
61
62 - (int)index
63 {
64         return _index;
65 }
66
67 - (void)setType:(ITMTNodeType)t
68 {
69         _type = t;
70 }
71
72 - (ITMTNodeType)type
73 {
74         return _type;
75 }
76
77 - (PlaylistNode *)parent
78 {
79         return _parent;
80 }
81
82 - (void)setParent:(PlaylistNode *)p
83 {
84         [_parent release];
85         _parent = [p retain];
86 }
87
88 - (ITMTRemotePlayerSource)sourceType
89 {
90         return _sourceType;
91 }
92
93 - (void)setSourceType:(ITMTRemotePlayerSource)t
94 {
95         _sourceType = t;
96 }
97
98 @end