This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCORevisionID.m
87 lines (72 loc) · 2.16 KB
/
CORevisionID.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
#import "CORevisionID.h"
#import <EtoileFoundation/ETUUID.h>
@implementation CORevisionID
- (id) initWithPersistentRootBackingStoreUUID: (ETUUID *)aUUID
revisionIndex: (int64_t)anIndex
{
self = [super init];
if (self != nil)
{
backingStoreUUID_ = [aUUID retain];
revisionIndex_ = anIndex;
}
return self;
}
+ (CORevisionID *) revisionWithBackinStoreUUID: (ETUUID *)aUUID
revisionIndex: (int64_t)anIndex
{
return [[[self alloc] initWithPersistentRootBackingStoreUUID: aUUID revisionIndex: anIndex] autorelease];
}
- (void) dealloc
{
[backingStoreUUID_ release];
[super dealloc];
}
- (BOOL) isEqual:(id)object
{
if ([object isKindOfClass: [CORevisionID class]])
{
return ((CORevisionID *)object)->revisionIndex_ == revisionIndex_
&& [((CORevisionID *)object)->backingStoreUUID_ isEqual: backingStoreUUID_];
}
return NO;
}
- (NSUInteger) hash
{
return revisionIndex_ ^ [backingStoreUUID_ hash];
}
- (ETUUID *) backingStoreUUID
{
return backingStoreUUID_;
}
- (int64_t) revisionIndex
{
return revisionIndex_;
}
- (CORevisionID *) revisionIDWithRevisionIndex: (int64_t)anIndex
{
return [[[CORevisionID alloc] initWithPersistentRootBackingStoreUUID: backingStoreUUID_
revisionIndex: anIndex] autorelease];
}
- (id) plist
{
return [NSString stringWithFormat: @"%@:%@", backingStoreUUID_,
[NSNumber numberWithLongLong: (long long)revisionIndex_]];
}
+ (CORevisionID *) revisionIDWithPlist: (id)plist
{
NSArray *comps = [(NSString *)plist componentsSeparatedByString:@":"];
CORevisionID *result = [[[CORevisionID alloc] init] autorelease];
result->backingStoreUUID_ = [[ETUUID UUIDWithString: [comps objectAtIndex: 0]] retain];
result->revisionIndex_ = [(NSString *)[comps objectAtIndex: 1] longLongValue];
return result;
}
- (id) copyWithZone:(NSZone *)zone
{
return [self retain];
}
- (NSString *)description
{
return [NSString stringWithFormat: @"<State Token %@.%lld>", backingStoreUUID_, (long long int)revisionIndex_];
}
@end