PageRenderTime 78ms CodeModel.GetById 37ms app.highlight 37ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/Foundation/GTMFourCharCode.m

http://macfuse.googlecode.com/
Objective C | 97 lines | 62 code | 17 blank | 18 comment | 8 complexity | 32df27527e42bd03216a9c940cff0b1c MD5 | raw file
 1//
 2//  GTMFourCharCode.m
 3//  Wrapper for FourCharCodes
 4//
 5//  Copyright 2008 Google Inc.
 6//
 7//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 8//  use this file except in compliance with the License.  You may obtain a copy
 9//  of the License at
10// 
11//  http://www.apache.org/licenses/LICENSE-2.0
12// 
13//  Unless required by applicable law or agreed to in writing, software
14//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
16//  License for the specific language governing permissions and limitations under
17//  the License.
18//
19
20#import "GTMDefines.h"
21#import "GTMFourCharCode.h"
22#import <CoreServices/CoreServices.h>
23
24@implementation GTMFourCharCode
25
26+ (id)stringWithFourCharCode:(FourCharCode)code {
27  return GTMCFAutorelease(UTCreateStringForOSType(code));
28}
29
30+ (id)fourCharCodeWithString:(NSString*)string {
31  return [[[self alloc] initWithString:string] autorelease];
32}
33
34+ (id)fourCharCodeWithFourCharCode:(FourCharCode)code {
35  return [[[self alloc] initWithFourCharCode:code] autorelease];
36}
37
38- (id)initWithString:(NSString*)string {
39  NSUInteger length = [string length];
40  if (length == 0 || length > 4) {
41    [self release];
42    return nil;
43  } else {
44    return [self initWithFourCharCode:UTGetOSTypeFromString((CFStringRef)string)];
45  }
46}
47
48- (id)initWithFourCharCode:(FourCharCode)code {
49  if ((self = [super init])) {
50    code_ = code;
51  }
52  return self;
53}
54
55- (id)initWithCoder:(NSCoder *)aDecoder {
56  if ((self = [super init])) {
57    code_ = [aDecoder decodeInt32ForKey:@"FourCharCode"];
58  }
59  return self;
60}
61
62- (void)encodeWithCoder:(NSCoder *)aCoder {
63  [aCoder encodeInt32:code_ forKey:@"FourCharCode"];
64}
65
66- (id)copyWithZone:(NSZone *)zone {
67  return [[[self class] alloc] initWithFourCharCode:code_];
68}
69
70- (BOOL)isEqual:(id)object {
71  return [object isKindOfClass:[self class]] && [object fourCharCode] == code_;
72}
73
74- (NSUInteger)hash {
75  return (NSUInteger)code_;
76}
77
78- (NSString *)description {
79  return [NSString stringWithFormat:@"%@ - %@ (0x%lX)", 
80          [self class],
81          [self stringValue],
82          (unsigned long)code_];
83}
84
85- (FourCharCode)fourCharCode {
86  return code_;
87}
88
89- (NSString*)stringValue {
90  return GTMCFAutorelease(UTCreateStringForOSType(code_));
91}
92
93- (NSNumber*)numberValue {
94  return [NSNumber numberWithUnsignedInt:code_];
95}
96
97@end