Differences From Artifact [01b0cb5868]:
- File
src/OFNumber.m
— part of check-in
[494dca4ae4]
at
2011-05-14 12:26:39
on branch trunk
— Use XML for serialization.
This way, we don't need a new parser and don't use a new format. (user: js, size: 26127) [annotate] [blame] [check-ins using]
To Artifact [d234546f66]:
- File src/OFNumber.m — part of check-in [dca3061dfc] at 2011-06-03 15:14:18 on branch trunk — Add deserialization. (user: js, size: 27799) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "macros.h" #define RETURN_AS(t) \ switch (type) { \ | > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "macros.h" #define RETURN_AS(t) \ switch (type) { \ |
︙ | ︙ | |||
699 700 701 702 703 704 705 706 707 708 709 710 711 712 | - initWithDouble: (double)double_ { self = [super init]; value.double_ = double_; type = OF_NUMBER_DOUBLE; return self; } - (of_number_type_t)type { return type; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | - initWithDouble: (double)double_ { self = [super init]; value.double_ = double_; type = OF_NUMBER_DOUBLE; return self; } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *typeString; if (![[element name] isEqual: @"object"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS] || ![[[element attributeForName: @"class"] stringValue] isEqual: [isa className]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; typeString = [[element attributeForName: @"type"] stringValue]; if ([typeString isEqual: @"boolean"]) { type = OF_NUMBER_BOOL; if ([[element stringValue] isEqual: @"YES"]) value.bool_ = YES; else if ([[element stringValue] isEqual: @"NO"]) value.bool_ = NO; else @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; } else if ([typeString isEqual: @"unsigned"]) { /* * FIXME: This will fail if the value is bigger than * INTMAX_MAX! */ type = OF_NUMBER_UINTMAX; value.uintmax = [[element stringValue] decimalValue]; } else if ([typeString isEqual: @"signed"]) { type = OF_NUMBER_INTMAX; value.intmax = [[element stringValue] decimalValue]; } else if ([typeString isEqual: @"float"]) { type = OF_NUMBER_FLOAT; value.float_ = [[element stringValue] floatValue]; } else if ([typeString isEqual: @"double"]) { type = OF_NUMBER_DOUBLE; value.double_ = [[element stringValue] doubleValue]; } else @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; [pool release]; } @catch (id e) { [self release]; @throw e; } return self; } - (of_number_type_t)type { return type; |
︙ | ︙ |