|
Wired Foundation
2.0
A foundation framework for the Wired implementation on Mac OS X
|
00001 /* $Id$ */ 00002 00003 /* 00004 * Copyright (c) 2003-2009 Axel Andersson 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00017 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 00020 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00022 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00023 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00024 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00025 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00026 * POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00029 #import <WiredFoundation/NSDictionary-WIFoundation.h> 00030 #import <WiredFoundation/NSNumber-WIFoundation.h> 00031 00032 @implementation NSDictionary(WIFoundation) 00033 00034 - (int)intForKey:(id)key { 00035 id object; 00036 00037 object = [self objectForKey:key]; 00038 00039 if(object) 00040 return [object intValue]; 00041 00042 return 0; 00043 } 00044 00045 00046 00047 - (unsigned int)unsignedIntForKey:(id)key { 00048 id object; 00049 00050 object = [self objectForKey:key]; 00051 00052 if(object) 00053 return [object unsignedIntValue]; 00054 00055 return 0; 00056 } 00057 00058 00059 00060 - (NSInteger)integerForKey:(id)key { 00061 id object; 00062 00063 object = [self objectForKey:key]; 00064 00065 if(object) 00066 return [object integerValue]; 00067 00068 return 0; 00069 } 00070 00071 00072 00073 - (NSUInteger)unsignedIntegerForKey:(id)key { 00074 id object; 00075 00076 object = [self objectForKey:key]; 00077 00078 if(object) 00079 return [object unsignedIntegerValue]; 00080 00081 return 0; 00082 } 00083 00084 00085 00086 - (BOOL)boolForKey:(id)key { 00087 id object; 00088 00089 object = [self objectForKey:key]; 00090 00091 if(object) 00092 return [object boolValue]; 00093 00094 return NO; 00095 } 00096 00097 00098 00099 - (float)floatForKey:(id)key { 00100 id object; 00101 00102 object = [self objectForKey:key]; 00103 00104 if(object) 00105 return [object floatValue]; 00106 00107 return 0.0f; 00108 } 00109 00110 00111 00112 - (double)doubleForKey:(id)key { 00113 id object; 00114 00115 object = [self objectForKey:key]; 00116 00117 if(object) 00118 return [object doubleValue]; 00119 00120 return 0.0; 00121 } 00122 00123 @end 00124 00125 00126 00127 @implementation NSMutableDictionary(WIFoundation) 00128 00129 - (void)setInt:(int)value forKey:(id)key { 00130 [self setObject:[NSNumber numberWithInt:value] forKey:key]; 00131 } 00132 00133 00134 00135 - (void)setUnsignedInt:(unsigned int)value forKey:(id)key { 00136 [self setObject:[NSNumber numberWithUnsignedInt:value] forKey:key]; 00137 } 00138 00139 00140 00141 - (void)setInteger:(NSInteger)value forKey:(id)key { 00142 [self setObject:[NSNumber numberWithInteger:value] forKey:key]; 00143 } 00144 00145 00146 00147 - (void)setUnsignedInteger:(NSUInteger)value forKey:(id)key { 00148 [self setObject:[NSNumber numberWithUnsignedInteger:value] forKey:key]; 00149 } 00150 00151 00152 00153 - (void)setBool:(BOOL)value forKey:(id)key { 00154 [self setObject:[NSNumber numberWithBool:value] forKey:key]; 00155 } 00156 00157 00158 00159 - (void)setFloat:(float)value forKey:(id)key { 00160 [self setObject:[NSNumber numberWithFloat:value] forKey:key]; 00161 } 00162 00163 00164 00165 - (void)setDouble:(double)value forKey:(id)key { 00166 [self setObject:[NSNumber numberWithDouble:value] forKey:key]; 00167 } 00168 00169 @end