-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiskUUIDEntry.m
90 lines (69 loc) · 2.45 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
//
// DiskUUIDEntry.m
// Notation
//
// Created by Zachary Schneirov on 1/17/11.
/*Copyright (c) 2010, Zachary Schneirov. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided with
the distribution.
- Neither the name of Notational Velocity nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission. */
#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