-
Notifications
You must be signed in to change notification settings - Fork 405
/
DiskUUIDEntry.m
95 lines (71 loc) · 2.47 KB
/
DiskUUIDEntry.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
//
// DiskUUIDEntry.m
// Notation
//
// Created by Zachary Schneirov on 1/17/11.
/*Copyright (c) 2010, Zachary Schneirov. All rights reserved.
This file is part of Notational Velocity.
Notational Velocity 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 3 of the License, or
(at your option) any later version.
Notational Velocity 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.
You should have received a copy of the GNU General Public License
along with Notational Velocity. If not, see <http://www.gnu.org/licenses/>. */
#import "DiskUUIDEntry.h"
@implementation DiskUUIDEntry
- (id)initWithUUIDRef:(CFUUIDRef)aUUIDRef {
if ([super init]) {
NSAssert(aUUIDRef != nil, @"need a real UUID");
uuidRef = CFRetain(aUUIDRef);
lastAccessed = [[NSDate date] retain];
}
return self;
}
- (void)dealloc {
[lastAccessed release];
CFRelease(uuidRef);
[super dealloc];
}
- (void)encodeWithCoder:(NSCoder *)coder {
NSAssert([coder allowsKeyedCoding], @"keyed-encoding only!");
[coder encodeObject:lastAccessed forKey:VAR_STR(lastAccessed)];
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuidRef);
[coder encodeBytes:(const uint8_t *)&bytes length:sizeof(CFUUIDBytes) forKey:VAR_STR(uuidRef)];
}
- (id)initWithCoder:(NSCoder*)decoder {
NSAssert([decoder allowsKeyedCoding], @"keyed-decoding only!");
if ([super init]) {
lastAccessed = [[decoder decodeObjectForKey:VAR_STR(lastAccessed)] retain];
NSUInteger decodedByteCount = 0;
const uint8_t *bytes = [decoder decodeBytesForKey:VAR_STR(uuidRef) returnedLength:&decodedByteCount];
if (bytes && decodedByteCount) {
uuidRef = CFUUIDCreateFromUUIDBytes(NULL, *(CFUUIDBytes*)bytes);
}
if (!uuidRef) return nil;
}
return self;
}
- (void)see {
[lastAccessed release];
lastAccessed = [[NSDate date] retain];
}
- (CFUUIDRef)uuidRef {
return uuidRef;
}
- (NSDate*)lastAccessed {
return lastAccessed;
}
- (NSString*)description {
return [NSString stringWithFormat:@"DiskUUIDEntry(%@, %@)", lastAccessed, [(id)CFUUIDCreateString(NULL, uuidRef) autorelease]];
}
- (NSUInteger)hash {
return CFHash(uuidRef);
}
- (BOOL)isEqual:(id)otherEntry {
return CFEqual(uuidRef, [otherEntry uuidRef]);
}
@end