Differences From Artifact [bc121f7ad1]:
- File
src/OFNumber.m
— part of check-in
[cba771824e]
at
2013-06-19 19:14:11
on branch trunk
— Implement the new MessagePack specification.
No support for extensions yet.
This obsoletes BinaryPack. (user: js, size: 36336) [annotate] [blame] [check-ins using]
To Artifact [779309786a]:
- File
src/OFNumber.m
— part of check-in
[3d16a30f41]
at
2013-06-22 12:12:36
on branch trunk
— Rework exceptions.
This mostly removes the argument for the class in which the exception
occurred. As backtraces were recently added for all platforms, the
passed class does not give any extra information on where the exception
occurred anymore.This also removes a few other arguments which were not too helpful. In
the past, the idea was to pass as many arguments as possible so that it
is easier to find the origin of the exception. However, as backtraces
are a much better way to find the origin, those are not useful anymore
and just make the exception more cumbersome to use. The rule is now to
only pass arguments that might help in recovering from the exception or
provide information that is otherwise not easily accessible. (user: js, size: 35770) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
88 89 90 91 92 93 94 | case OF_NUMBER_UINTPTR: \ return (t)_value.uintptr; \ case OF_NUMBER_FLOAT: \ return (t)_value.float_; \ case OF_NUMBER_DOUBLE: \ return (t)_value.double_; \ default: \ | | < | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | case OF_NUMBER_UINTPTR: \ return (t)_value.uintptr; \ case OF_NUMBER_FLOAT: \ return (t)_value.float_; \ case OF_NUMBER_DOUBLE: \ return (t)_value.double_; \ default: \ @throw [OFInvalidFormatException exception]; \ } #define CALCULATE(o, n) \ switch (_type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ _value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ |
︙ | ︙ | |||
178 179 180 181 182 183 184 | case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: \ _value.float_ o [n floatValue]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ _value.double_ o [n doubleValue]]; \ default: \ | | < | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: \ _value.float_ o [n floatValue]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ _value.double_ o [n doubleValue]]; \ default: \ @throw [OFInvalidFormatException exception]; \ } #define CALCULATE2(o, n) \ switch (_type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ _value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ |
︙ | ︙ | |||
263 264 265 266 267 268 269 | return [OFNumber numberWithIntPtr: \ _value.intptr o [n intPtrValue]]; \ case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: \ _value.uintptr o [n uIntPtrValue]]; \ case OF_NUMBER_FLOAT: \ case OF_NUMBER_DOUBLE: \ | | < < | < | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | return [OFNumber numberWithIntPtr: \ _value.intptr o [n intPtrValue]]; \ case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: \ _value.uintptr o [n uIntPtrValue]]; \ case OF_NUMBER_FLOAT: \ case OF_NUMBER_DOUBLE: \ @throw [OFInvalidArgumentException exception]; \ default: \ @throw [OFInvalidFormatException exception]; \ } #define CALCULATE3(o) \ switch (_type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: _value.bool_ o]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: _value.schar o]; \ |
︙ | ︙ | |||
334 335 336 337 338 339 340 | case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: _value.uintptr o]; \ case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: _value.float_ o]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: _value.double_ o]; \ default: \ | | < | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: _value.uintptr o]; \ case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: _value.float_ o]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: _value.double_ o]; \ default: \ @throw [OFInvalidFormatException exception]; \ } @implementation OFNumber + (instancetype)numberWithBool: (bool)bool_ { return [[[self alloc] initWithBool: bool_] autorelease]; } |
︙ | ︙ | |||
781 782 783 784 785 786 787 | @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) | | < < | < < | 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; typeString = [[element attributeForName: @"type"] stringValue]; if ([typeString isEqual: @"boolean"]) { _type = OF_NUMBER_BOOL; if ([[element stringValue] isEqual: @"true"]) _value.bool_ = true; else if ([[element stringValue] isEqual: @"false"]) _value.bool_ = false; else @throw [OFInvalidArgumentException exception]; } else if ([typeString isEqual: @"unsigned"]) { /* * FIXME: This will fail if the value is bigger than * INTMAX_MAX! */ _type = OF_NUMBER_UINTMAX; _value.uintmax = [element decimalValue]; |
︙ | ︙ | |||
829 830 831 832 833 834 835 | } d; d.u = (uint64_t)[element hexadecimalValue]; _type = OF_NUMBER_DOUBLE; _value.double_ = d.d; } else | | < < | 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | } d; d.u = (uint64_t)[element hexadecimalValue]; _type = OF_NUMBER_DOUBLE; _value.double_ = d.d; } else @throw [OFInvalidArgumentException exception]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
1010 1011 1012 1013 1014 1015 1016 | } - (of_comparison_result_t)compare: (id <OFComparing>)object { OFNumber *number; if (![object isKindOfClass: [OFNumber class]]) | | < < | 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | } - (of_comparison_result_t)compare: (id <OFComparing>)object { OFNumber *number; if (![object isKindOfClass: [OFNumber class]]) @throw [OFInvalidArgumentException exception]; number = (OFNumber*)object; if (_type & OF_NUMBER_FLOAT || number->_type & OF_NUMBER_FLOAT) { double double1 = [self doubleValue]; double double2 = [number doubleValue]; |
︙ | ︙ | |||
1253 1254 1255 1256 1257 1258 1259 | case OF_NUMBER_FLOAT: return [OFNumber numberWithFloat: fmodf(_value.float_, [number floatValue])]; case OF_NUMBER_DOUBLE: return [OFNumber numberWithDouble: fmod(_value.double_, [number doubleValue])]; default: | | < | 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 | case OF_NUMBER_FLOAT: return [OFNumber numberWithFloat: fmodf(_value.float_, [number floatValue])]; case OF_NUMBER_DOUBLE: return [OFNumber numberWithDouble: fmod(_value.double_, [number doubleValue])]; default: @throw [OFInvalidFormatException exception]; } } - copy { return [self retain]; } |
︙ | ︙ | |||
1317 1318 1319 1320 1321 1322 1323 | if (![ret containsString: @"."]) [ret appendString: @".0"]; [ret makeImmutable]; return ret; default: | | < | 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 | if (![ret containsString: @"."]) [ret appendString: @".0"]; [ret makeImmutable]; return ret; default: @throw [OFInvalidFormatException exception]; } } - (OFXMLElement*)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; |
︙ | ︙ | |||
1396 1397 1398 1399 1400 1401 1402 | [element addAttributeWithName: @"type" stringValue: @"double"]; [element setStringValue: [OFString stringWithFormat: @"%016" PRIx64, d.u]]; break; default: | | < | 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 | [element addAttributeWithName: @"type" stringValue: @"double"]; [element setStringValue: [OFString stringWithFormat: @"%016" PRIx64, d.u]]; break; default: @throw [OFInvalidFormatException exception]; } [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; |
︙ | ︙ | |||
1511 1512 1513 1514 1515 1516 1517 | data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else | | < | 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 | data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else { uintmax_t value = [self uIntMaxValue]; if (value <= 127) { uint8_t tmp = ((uint8_t)value & 0x7F); data = [OFDataArray dataArrayWithItemSize: 1 |
︙ | ︙ | |||
1563 1564 1565 1566 1567 1568 1569 | data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else | | < | 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 | data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } return data; } @end |