ObjFW
|
00001 /* 00002 * Copyright (c) 2008, 2009, 2010, 2011 00003 * Jonathan Schleifer <js@webkeks.org> 00004 * 00005 * All rights reserved. 00006 * 00007 * This file is part of ObjFW. It may be distributed under the terms of the 00008 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in 00009 * the packaging of this file. 00010 * 00011 * Alternatively, it may be distributed under the terms of the GNU General 00012 * Public License, either version 2 or 3, which can be found in the file 00013 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this 00014 * file. 00015 */ 00016 00017 #include <sys/types.h> 00018 00019 #import "OFObject.h" 00020 00024 typedef enum of_number_type_t { 00025 OF_NUMBER_BOOL, 00026 OF_NUMBER_CHAR, 00027 OF_NUMBER_SHORT, 00028 OF_NUMBER_INT, 00029 OF_NUMBER_LONG, 00030 OF_NUMBER_UCHAR, 00031 OF_NUMBER_USHORT, 00032 OF_NUMBER_UINT, 00033 OF_NUMBER_ULONG, 00034 OF_NUMBER_INT8, 00035 OF_NUMBER_INT16, 00036 OF_NUMBER_INT32, 00037 OF_NUMBER_INT64, 00038 OF_NUMBER_UINT8, 00039 OF_NUMBER_UINT16, 00040 OF_NUMBER_UINT32, 00041 OF_NUMBER_UINT64, 00042 OF_NUMBER_SIZE, 00043 OF_NUMBER_SSIZE, 00044 OF_NUMBER_INTMAX, 00045 OF_NUMBER_UINTMAX, 00046 OF_NUMBER_PTRDIFF, 00047 OF_NUMBER_INTPTR, 00048 OF_NUMBER_UINTPTR, 00049 OF_NUMBER_FLOAT, 00050 OF_NUMBER_DOUBLE, 00051 } of_number_type_t; 00052 00056 @interface OFNumber: OFObject <OFCopying> 00057 { 00058 union of_number_value { 00059 BOOL bool_; 00060 char char_; 00061 short short_; 00062 int int_; 00063 long long_; 00064 unsigned char uchar; 00065 unsigned short ushort; 00066 unsigned int uint; 00067 unsigned long ulong; 00068 int8_t int8; 00069 int16_t int16; 00070 int32_t int32; 00071 int64_t int64; 00072 uint8_t uint8; 00073 uint16_t uint16; 00074 uint32_t uint32; 00075 uint64_t uint64; 00076 size_t size; 00077 ssize_t ssize; 00078 intmax_t intmax; 00079 uintmax_t uintmax; 00080 ptrdiff_t ptrdiff; 00081 intptr_t intptr; 00082 uintptr_t uintptr; 00083 float float_; 00084 double double_; 00085 } value; 00086 of_number_type_t type; 00087 } 00088 00093 + numberWithBool: (BOOL)bool_; 00094 00099 + numberWithChar: (char)char_; 00100 00105 + numberWithShort: (short)short_; 00106 00111 + numberWithInt: (int)int_; 00112 00117 + numberWithLong: (long)long_; 00118 00123 + numberWithUnsignedChar: (unsigned char)uchar; 00124 00129 + numberWithUnsignedShort: (unsigned short)ushort; 00130 00135 + numberWithUnsignedInt: (unsigned int)uint; 00136 00141 + numberWithUnsignedLong: (unsigned long)ulong; 00142 00147 + numberWithInt8: (int8_t)int8; 00148 00153 + numberWithInt16: (int16_t)int16; 00154 00159 + numberWithInt32: (int32_t)int32; 00160 00165 + numberWithInt64: (int64_t)int64; 00166 00171 + numberWithUInt8: (uint8_t)uint8; 00172 00177 + numberWithUInt16: (uint16_t)uint16; 00178 00183 + numberWithUInt32: (uint32_t)uint32; 00184 00189 + numberWithUInt64: (uint64_t)uint64; 00190 00195 + numberWithSize: (size_t)size; 00196 00201 + numberWithSSize: (ssize_t)ssize; 00202 00207 + numberWithIntMax: (intmax_t)intmax; 00208 00213 + numberWithUIntMax: (uintmax_t)uintmax; 00214 00219 + numberWithPtrDiff: (ptrdiff_t)ptrdiff; 00220 00225 + numberWithIntPtr: (intptr_t)intptr; 00226 00231 + numberWithUIntPtr: (uintptr_t)uintptr; 00232 00237 + numberWithFloat: (float)float_; 00238 00243 + numberWithDouble: (double)double_; 00244 00251 - initWithBool: (BOOL)bool_; 00252 00259 - initWithChar: (char)char_; 00260 00267 - initWithShort: (short)short_; 00268 00275 - initWithInt: (int)int_; 00276 00283 - initWithLong: (long)long_; 00284 00291 - initWithUnsignedChar: (unsigned char)uchar; 00292 00299 - initWithUnsignedShort: (unsigned short)ushort; 00300 00307 - initWithUnsignedInt: (unsigned int)uint; 00308 00315 - initWithUnsignedLong: (unsigned long)ulong; 00316 00323 - initWithInt8: (int8_t)int8; 00324 00331 - initWithInt16: (int16_t)int16; 00332 00339 - initWithInt32: (int32_t)int32; 00340 00347 - initWithInt64: (int64_t)int64; 00348 00355 - initWithUInt8: (uint8_t)uint8; 00356 00363 - initWithUInt16: (uint16_t)uint16; 00364 00371 - initWithUInt32: (uint32_t)uint32; 00372 00379 - initWithUInt64: (uint64_t)uint64; 00380 00387 - initWithSize: (size_t)size; 00388 00395 - initWithSSize: (ssize_t)ssize; 00396 00403 - initWithIntMax: (intmax_t)intmax; 00404 00411 - initWithUIntMax: (uintmax_t)uintmax; 00412 00419 - initWithPtrDiff: (ptrdiff_t)ptrdiff; 00420 00427 - initWithIntPtr: (intptr_t)intptr; 00428 00435 - initWithUIntPtr: (uintptr_t)uintptr; 00436 00443 - initWithFloat: (float)float_; 00444 00451 - initWithDouble: (double)double_; 00452 00456 - (of_number_type_t)type; 00457 00461 - (BOOL)boolValue; 00462 00466 - (char)charValue; 00467 00471 - (short)shortValue; 00472 00476 - (int)intValue; 00477 00481 - (long)longValue; 00482 00486 - (unsigned char)unsignedCharValue; 00487 00491 - (unsigned short)unsignedShortValue; 00492 00496 - (unsigned int)unsignedIntValue; 00497 00501 - (unsigned long)unsignedLongValue; 00502 00506 - (int8_t)int8Value; 00507 00511 - (int16_t)int16Value; 00512 00516 - (int32_t)int32Value; 00517 00521 - (int64_t)int64Value; 00522 00526 - (uint8_t)uInt8Value; 00527 00531 - (uint16_t)uInt16Value; 00532 00536 - (uint32_t)uInt32Value; 00537 00541 - (uint64_t)uInt64Value; 00542 00546 - (size_t)sizeValue; 00547 00551 - (ssize_t)sSizeValue; 00552 00556 - (intmax_t)intMaxValue; 00557 00561 - (uintmax_t)uIntMaxValue; 00562 00566 - (ptrdiff_t)ptrDiffValue; 00567 00571 - (intptr_t)intPtrValue; 00572 00576 - (uintptr_t)uIntPtrValue; 00577 00581 - (float)floatValue; 00582 00586 - (double)doubleValue; 00587 00592 - (OFNumber*)numberByAddingNumber: (OFNumber*)num; 00593 00598 - (OFNumber*)numberBySubtractingNumber: (OFNumber*)num; 00599 00604 - (OFNumber*)numberByMultiplyingWithNumber: (OFNumber*)num; 00605 00610 - (OFNumber*)numberByDividingWithNumber: (OFNumber*)num; 00611 00620 - (OFNumber*)numberByANDingWithNumber: (OFNumber*)num; 00621 00630 - (OFNumber*)numberByORingWithNumber: (OFNumber*)num; 00631 00640 - (OFNumber*)numberByXORingWithNumber: (OFNumber*)num; 00641 00652 - (OFNumber*)numberByShiftingLeftWithNumber: (OFNumber*)num; 00653 00664 - (OFNumber*)numberByShiftingRightWithNumber: (OFNumber*)num; 00665 00669 - (OFNumber*)numberByIncreasing; 00670 00674 - (OFNumber*)numberByDecreasing; 00675 00680 - (OFNumber*)remainderOfDivisionWithNumber: (OFNumber*)num; 00681 @end