-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGeniusItem.m
More file actions
139 lines (117 loc) · 4.58 KB
/
GeniusItem.m
File metadata and controls
139 lines (117 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
Genius
Copyright (C) 2003-2006 John R Chang
Copyright (C) 2007-2008 Chris Miner
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
http://www.gnu.org/licenses/gpl.txt
*/
#import "GeniusItem.h"
@implementation GeniusItem
//! Initializes new instance with all properties set to nil.
- (id) init
{
self = [super init];
return self;
}
//! Releases instance vars and deallocates instance.
- (void) dealloc
{
[_stringValue release];
[_imageURL release];
[_webResourceURL release];
[_speakableStringValue release];
[_soundURL release];
[super dealloc];
}
//! registers an observer for the relevent fields of this object
- (void) addObserver: (id) observer
{
[self addObserver:observer forKeyPath:@"stringValue" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[self addObserver:observer forKeyPath:@"imageURL" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[self addObserver:observer forKeyPath:@"webResourceURL" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[self addObserver:observer forKeyPath:@"speakableStringValue" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[self addObserver:observer forKeyPath:@"soundURL" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
}
//! un-registers an observer for the relevent fields of this object
- (void) removeObserver: (id) observer
{
[self removeObserver:observer forKeyPath:@"stringValue"];
[self removeObserver:observer forKeyPath:@"imageURL"];
[self removeObserver:observer forKeyPath:@"webResourceURL"];
[self removeObserver:observer forKeyPath:@"speakableStringValue"];
[self removeObserver:observer forKeyPath:@"soundURL"];
}
//! Creates and returns a copy of this instance in the new zone.
/*! @todo Replace calls to @c copy with @c copyWithZone: for the instance variables. */
- (id)copyWithZone:(NSZone *)zone
{
GeniusItem * newItem = [[[self class] allocWithZone:zone] init];
newItem->_stringValue = [_stringValue copy];
newItem->_imageURL = [_imageURL copy];
newItem->_webResourceURL = [_webResourceURL copy];
newItem->_speakableStringValue = [_speakableStringValue copy];
newItem->_soundURL = [_soundURL copy];
return newItem;
}
//! Unpacks instance with help of the provided coder.
/*! @exception NSInternalInconsistencyException when <tt>[coder allowsKeyedCoding]</tt> returns @p NO. */
- (id)initWithCoder:(NSCoder *)coder
{
NSAssert([coder allowsKeyedCoding], @"allowsKeyedCoding");
self = [super init];
_stringValue = [[coder decodeObjectForKey:@"stringValue"] retain];
_imageURL = [[coder decodeObjectForKey:@"imageURL"] retain];
_webResourceURL = [[coder decodeObjectForKey:@"webResourceURL"] retain];
_speakableStringValue = [[coder decodeObjectForKey:@"speakableStringValue"] retain];
_soundURL = [[coder decodeObjectForKey:@"soundURL"] retain];
return self;
}
//! Packs up instance with help of the provided coder.
/*! @exception NSInternalInconsistencyException when <tt>[coder allowsKeyedCoding]</tt> returns @p NO. */
- (void)encodeWithCoder:(NSCoder *)coder
{
NSAssert([coder allowsKeyedCoding], @"allowsKeyedCoding");
if (_stringValue) [coder encodeObject:_stringValue forKey:@"stringValue"];
if (_imageURL) [coder encodeObject:_imageURL forKey:@"imageURL"];
if (_webResourceURL) [coder encodeObject:_webResourceURL forKey:@"webResourceURL"];
if (_speakableStringValue) [coder encodeObject:_speakableStringValue forKey:@"speakableStringValue"];
if (_soundURL) [coder encodeObject:_soundURL forKey:@"soundURL"];
}
//! Same as calling @c stringValue
- (NSString *) description
{
return [self stringValue];
}
//! _stringValue getter
- (NSString *) stringValue
{
return _stringValue;
}
//! _imageURL getter
- (NSURL *) imageURL
{
return _imageURL;
}
//! _webResourceURL getter
- (NSURL *) webResourceURL
{
return _webResourceURL;
}
//! _speakableStringValue getter
- (NSString *) speakableStringValue
{
return _speakableStringValue;
}
//! _soundURL getter
- (NSURL *) soundURL
{
return _soundURL;
}
@end