forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBlockStackElem.m
77 lines (62 loc) · 2.18 KB
/
BlockStackElem.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
/* BlockStackElem.m Copyright (c) 2001-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "BlockStackElem.h"
#import "FSBlock.h"
@implementation BlockStackElem
+ (BlockStackElem *)blockStackElemWithBlock:(FSBlock *)theBlock errorStr:(NSString *)theErrorStr firstCharIndex:(NSInteger)first lastCharIndex:(NSInteger)last
{
return [[[self alloc] initWithBlock:theBlock errorStr:theErrorStr firstCharIndex:first lastCharIndex:last] autorelease];
}
- (FSBlock *)block {return block;}
- (void)dealloc
{
[block release];
[errorStr release];
[super dealloc];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeInteger:firstCharIndex forKey:@"firstCharIndex"];
[coder encodeInteger:lastCharIndex forKey:@"lastCharIndex"];
[coder encodeObject:errorStr forKey:@"errorStr"];
[coder encodeObject:block forKey:@"block"];
}
- (NSString *)errorStr {return errorStr;}
- (NSInteger) firstCharIndex {return firstCharIndex;}
- (BlockStackElem *)initWithBlock:(FSBlock *)theBlock errorStr:(NSString *)theErrorStr firstCharIndex:(NSInteger)first lastCharIndex:(NSInteger)last
{
// NSLog([NSString stringWithFormat:@"---- BlockStackElem initWithBlock:%@ errorStr:%@ firstCharIndex:%d lastCharIndex:%d", theBlock, theErrorStr, first, last]);
if ((self = [super init]))
{
block = [theBlock retain];
errorStr = [theErrorStr retain];
firstCharIndex = first;
lastCharIndex = last;
return self;
}
return nil;
}
- (id)initWithCoder:(NSCoder *)coder
{
self = [super init];
if ( [coder allowsKeyedCoding] )
{
firstCharIndex = [coder decodeIntegerForKey:@"firstCharIndex"];
lastCharIndex = [coder decodeIntegerForKey:@"lastCharIndex"];
errorStr = [[coder decodeObjectForKey:@"errorStr"] retain];
block = [[coder decodeObjectForKey:@"block"] retain];
}
else
{
int temp;
[coder decodeValueOfObjCType:@encode(int) at:&temp];
firstCharIndex = temp;
[coder decodeValueOfObjCType:@encode(int) at:&temp];
lastCharIndex = temp;
errorStr = [[coder decodeObject] retain];
block = [[coder decodeObject] retain];
}
return self;
}
- (NSInteger) lastCharIndex {return lastCharIndex;}
@end