forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFSPilot.m
127 lines (105 loc) · 3.59 KB
/
FSPilot.m
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
/* FSPilot.m Copyright (c) 1998-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "FSPilot.h"
@implementation FSPilot
////////////////////////////////// User methods ////////////////////////////////
+ (id) pilotWithName:(id)theName address:(id)theAddress salary:(id)theSalary
{
return [[[self alloc] initWithName:theName address:theAddress salary:theSalary] autorelease];
}
+ (id) pilotWithName:(id)theName address:(id)theAddress salary:(id)theSalary age:(id)theAge
{
return [[[self alloc] initWithName:theName address:theAddress salary:theSalary age:theAge] autorelease];
}
- (id) address {return address;}
- (void) address:(id)theAddress {[theAddress retain]; [address release]; address = theAddress;}
- (void) setAddress:(id)theAddress {[theAddress retain]; [address release]; address = theAddress;}
- (id) age {return age;}
- (void) setAge:(id)theAge {[theAge retain]; [age release]; age = theAge;}
- (id) salary {return salary;}
- (void) salary:(id)theSalary {[theSalary retain]; [salary release]; salary = theSalary;}
- (void) setSalary:(id)theSalary {[theSalary retain]; [salary release]; salary = theSalary;}
- (id) name {return name;}
- (void) name:(id)theName {id old = name; name = [theName retain]; [old release];}
- (void) setName:(id)theName {[theName retain]; [name release]; name = theName;}
- (void) sendMail:(NSString *)mailContent
{
NSLog(@"The folowing mail has been sent to pilot %@: %@", [self name], mailContent);
}
////////////////////////////////// Other methods ////////////////////////////////
+ (void)initialize
{
static BOOL tooLate = NO;
if ( !tooLate )
{
[self setVersion:1];
tooLate = YES;
}
}
- (id)copyWithZone:(NSZone *)zone
{
return [[[self class] allocWithZone:zone] initWithName:name address:address salary:salary age:age];
}
- (void) dealloc
{
[name release];
[address release];
[salary release];
[age release];
[super dealloc];
}
- (NSString *)description
{ return [NSString stringWithFormat:@"FSPilot(name = %@, address = %@, salary = %@, age= %@)", name, address, salary, age];}
- (void)encodeWithCoder:(NSCoder *)coder
{
if ([coder allowsKeyedCoding])
{
[coder encodeObject:name forKey:@"name"];
[coder encodeObject:address forKey:@"address"];
[coder encodeObject:salary forKey:@"salary"];
[coder encodeObject:age forKey:@"age"];
}
else
{
[coder encodeObject:name];
[coder encodeObject:address];
[coder encodeObject:salary];
[coder encodeObject:age];
}
}
- (id)initWithCoder:(NSCoder *)coder
{
self = [super init];
if ([coder allowsKeyedCoding])
{
name = [[coder decodeObjectForKey:@"name"] retain];
address = [[coder decodeObjectForKey:@"address"] retain];
salary = [[coder decodeObjectForKey:@"salary"] retain];
age = [[coder decodeObjectForKey:@"age"] retain];
}
else
{
name = [[coder decodeObject] retain];
address = [[coder decodeObject] retain];
salary = [[coder decodeObject] retain];
age = [[coder decodeObject] retain];
}
return self;
}
- (id) initWithName:(id)theName address:(id)theAddress salary:(id)theSalary
{
return [self initWithName:theName address:theAddress salary:theSalary age:nil];
}
- (id) initWithName:(id)theName address:(id)theAddress salary:(id)theSalary age:(id)theAge
{
if ((self = [super init]))
{
[self setName:theName];
[self setAddress:theAddress];
[self setSalary:theSalary];
[self setAge:theAge];
return self;
}
return nil;
}
@end