2001-10-19 19:41:13 +00:00
|
|
|
#import "Resource.h"
|
|
|
|
|
|
|
|
@implementation Resource
|
|
|
|
|
|
|
|
NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
[self initWithType:@"" andID:[NSNumber numberWithShort:128]];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[name release];
|
|
|
|
[type release];
|
|
|
|
[resID release];
|
|
|
|
[size release];
|
|
|
|
[attributes release];
|
|
|
|
[data release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)name
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setName:(NSString *)newName
|
|
|
|
{
|
|
|
|
[name autorelease];
|
|
|
|
name = [newName copy];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because name changed to %@", ResourceChangedNotification, name );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)type
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setType:(NSString *)newType
|
|
|
|
{
|
|
|
|
[type autorelease];
|
|
|
|
type = [newType copy];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because type changed to %@", ResourceChangedNotification, type );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *)resID
|
|
|
|
{
|
|
|
|
return resID;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setResID:(NSNumber *)newResID
|
|
|
|
{
|
|
|
|
[resID autorelease];
|
|
|
|
resID = [newResID copy];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because res ID changed to %@", ResourceChangedNotification, [resID stringValue] );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *)size
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSize:(NSNumber *)newSize
|
|
|
|
{
|
|
|
|
[size autorelease];
|
|
|
|
size = [newSize copy];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because size changed to %@", ResourceChangedNotification, [size stringValue] );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *)attributes
|
|
|
|
{
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAttributes:(NSNumber *)newAttributes
|
|
|
|
{
|
|
|
|
[attributes autorelease];
|
|
|
|
attributes = [newAttributes copy];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because attributes changed to %@", ResourceChangedNotification, [attributes stringValue] );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)dirty
|
|
|
|
{
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDirty:(BOOL)newValue
|
|
|
|
{
|
|
|
|
dirty = newValue;
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because resource became %@", ResourceChangedNotification, dirty? @"dirty":@"clean" );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSData *)data
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setData:(NSData *)newData
|
|
|
|
{
|
|
|
|
[data autorelease];
|
|
|
|
data = [newData retain];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ResourceChangedNotification object:self];
|
2002-02-02 11:31:28 +00:00
|
|
|
// NSLog( @"%@ posted because data changed", ResourceChangedNotification );
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithType:(NSString *)typeValue andID:(NSNumber *)resIDValue
|
|
|
|
{
|
|
|
|
[self initWithType:typeValue andID:resIDValue withName:@"" andAttributes:[NSNumber numberWithUnsignedShort:0]];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithType:(NSString *)typeValue andID:(NSNumber *)resIDValue withName:(NSString *)nameValue andAttributes:(NSNumber *)attributesValue
|
|
|
|
{
|
|
|
|
[self initWithType:typeValue andID:resIDValue withName:nameValue andAttributes:attributesValue data:[NSData data] ofLength:[NSNumber numberWithUnsignedLong:0]];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithType:(NSString *)typeValue andID:(NSNumber *)resIDValue withName:(NSString *)nameValue andAttributes:(NSNumber *)attributesValue data:(NSData *)dataValue ofLength:(NSNumber *)sizeValue
|
|
|
|
{
|
2002-02-02 11:31:28 +00:00
|
|
|
self = [super init];
|
2001-10-19 19:41:13 +00:00
|
|
|
[self setName:nameValue];
|
|
|
|
[self setType:typeValue];
|
|
|
|
[self setResID:resIDValue];
|
|
|
|
[self setSize:sizeValue];
|
|
|
|
[self setAttributes:attributesValue];
|
|
|
|
[self setData:dataValue];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)resourceOfType:(NSString *)typeValue andID:(NSNumber *)resIDValue
|
|
|
|
{
|
2002-02-02 11:31:28 +00:00
|
|
|
Resource *resource = [[Resource allocWithZone:[self zone]] initWithType:typeValue andID:resIDValue];
|
|
|
|
return [resource autorelease];
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)resourceOfType:(NSString *)typeValue andID:(NSNumber *)resIDValue withName:(NSString *)nameValue andAttributes:(NSNumber *)attributesValue
|
|
|
|
{
|
2002-02-02 11:31:28 +00:00
|
|
|
Resource *resource = [[Resource allocWithZone:[self zone]] initWithType:typeValue andID:resIDValue withName:nameValue andAttributes:attributesValue];
|
|
|
|
return [resource autorelease];
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)resourceOfType:(NSString *)typeValue andID:(NSNumber *)resIDValue withName:(NSString *)nameValue andAttributes:(NSNumber *)attributesValue data:(NSData *)dataValue ofLength:(NSNumber *)sizeValue
|
|
|
|
{
|
2002-02-02 11:31:28 +00:00
|
|
|
Resource *resource = [[Resource allocWithZone:[self zone]] initWithType:typeValue andID:resIDValue withName:nameValue andAttributes:attributesValue data:dataValue ofLength:sizeValue];
|
|
|
|
return [resource autorelease];
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|