Overview
Comment: | Add deserialization. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
dca3061dfcb44b35535beed51921492f |
User & Date: | js on 2011-06-03 15:14:18 |
Other Links: | manifest | tags |
Context
2011-06-04
| ||
13:29 | Fix -[OFURL isEqual:]. check-in: 9d48ed225c user: js tags: trunk | |
2011-06-03
| ||
15:14 | Add deserialization. check-in: dca3061dfc user: js tags: trunk | |
2011-05-29
| ||
21:47 | Inline of_condition_* on Win32 as well to prevent warnings. check-in: a1c5b19c7c user: js tags: trunk | |
Changes
Modified ObjFW.xcodeproj/project.pbxproj from [a5bc71a558] to [65c853b1de].
︙ | |||
227 228 229 230 231 232 233 234 235 236 237 238 239 240 | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | + | 4B90B7A2133AD87D00BD33CB /* OFBindFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B798133AD87D00BD33CB /* OFBindFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B90B7A3133AD87D00BD33CB /* OFBindFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B799133AD87D00BD33CB /* OFBindFailedException.m */; }; 4B90B7A4133AD87D00BD33CB /* OFConnectionFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79A133AD87D00BD33CB /* OFConnectionFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B90B7A5133AD87D00BD33CB /* OFConnectionFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */; }; 4B90B7A6133AD87D00BD33CB /* OFListenFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */; }; 4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B989C2E13771A3700109A30 /* OFSerialization.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BC5E7D6137F0D0E0076F962 /* OFSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5E7D5137F0D0E0076F962 /* OFSerialization.m */; }; 4BD98C03133814220048DD5B /* objfw-defs.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD98C011338140B0048DD5B /* objfw-defs.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BDF37B51338055600F9A81A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDF37B41338055600F9A81A /* config.h */; }; 4BF33AFB133807590059CEF7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; }; 4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66E1235358D0076B512 /* OFArrayTests.m */; }; 4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */; }; 4BF33AFE133807A20059CEF7 /* OFDataArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66F1235358D0076B512 /* OFDataArrayTests.m */; }; 4BF33AFF133807A20059CEF7 /* OFDateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E512DF4259005C7A0C /* OFDateTests.m */; }; |
︙ | |||
520 521 522 523 524 525 526 527 528 529 530 531 532 533 | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | + | 4BAF5F48123460C900F4E111 /* OFStreamObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver.m; path = src/OFStreamObserver.m; sourceTree = "<group>"; }; 4BAF5F49123460C900F4E111 /* OFStreamSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamSocket.h; path = src/OFStreamSocket.h; sourceTree = "<group>"; }; 4BAF5F4A123460C900F4E111 /* OFStreamSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamSocket.m; path = src/OFStreamSocket.m; sourceTree = "<group>"; }; 4BB50DCF12F863C700C9393F /* of_asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = of_asprintf.h; path = src/of_asprintf.h; sourceTree = SOURCE_ROOT; }; 4BB50DD012F863C700C9393F /* of_asprintf.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = of_asprintf.m; path = src/of_asprintf.m; sourceTree = SOURCE_ROOT; }; 4BBA36C411406AB700CBA3AC /* atomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = atomic.h; path = src/atomic.h; sourceTree = "<group>"; }; 4BBA36C511406AB700CBA3AC /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macros.h; path = src/macros.h; sourceTree = "<group>"; }; 4BC5E7D5137F0D0E0076F962 /* OFSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSerialization.m; path = src/OFSerialization.m; sourceTree = "<group>"; }; 4BD86D801237A6C600ED9912 /* OFBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFBlock.h; path = src/OFBlock.h; sourceTree = SOURCE_ROOT; }; 4BD86D811237A6C600ED9912 /* OFBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFBlock.m; path = src/OFBlock.m; sourceTree = SOURCE_ROOT; }; 4BD98C011338140B0048DD5B /* objfw-defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "objfw-defs.h"; path = "src/objfw-defs.h"; sourceTree = SOURCE_ROOT; }; 4BDF37B41338055600F9A81A /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = SOURCE_ROOT; }; 4BE17AD812FD744C002CEB0B /* foundation-compat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "foundation-compat.m"; path = "src/foundation-compat.m"; sourceTree = SOURCE_ROOT; }; 4BE17AD912FD746D002CEB0B /* OFDataArray+Hashing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFDataArray+Hashing.h"; path = "src/OFDataArray+Hashing.h"; sourceTree = SOURCE_ROOT; }; 4BE17ADA12FD746D002CEB0B /* OFDataArray+Hashing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFDataArray+Hashing.m"; path = "src/OFDataArray+Hashing.m"; sourceTree = SOURCE_ROOT; }; |
︙ | |||
787 788 789 790 791 792 793 794 795 796 797 798 799 800 | 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | + | 4B6799771099E7C50041064A /* OFObject.h */, 4B6799781099E7C50041064A /* OFObject.m */, 4B6799791099E7C50041064A /* OFPlugin.h */, 4B67997A1099E7C50041064A /* OFPlugin.m */, 4B981CDE116F71DD00294DB7 /* OFSeekableStream.h */, 4B981CDF116F71DD00294DB7 /* OFSeekableStream.m */, 4B989C2E13771A3700109A30 /* OFSerialization.h */, 4BC5E7D5137F0D0E0076F962 /* OFSerialization.m */, 4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */, 4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */, 4B67997D1099E7C50041064A /* OFStream.h */, 4B67997E1099E7C50041064A /* OFStream.m */, 4BAF5F47123460C900F4E111 /* OFStreamObserver.h */, 4BAF5F48123460C900F4E111 /* OFStreamObserver.m */, 4BAF5F49123460C900F4E111 /* OFStreamSocket.h */, |
︙ | |||
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 | 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 | + | 4B55A100133ABEA900B58A93 /* OFThreadJoinFailedException.m in Sources */, 4B55A102133ABEA900B58A93 /* OFThreadStartFailedException.m in Sources */, 4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */, 4B17FFAA133A34E7003E6DCD /* OFTruncatedDataException.m in Sources */, 4B17FFB6133A375B003E6DCD /* OFUnboundNamespaceException.m in Sources */, 4B17FFB2133A3664003E6DCD /* OFUnsupportedProtocolException.m in Sources */, 4B55A117133AC24600B58A93 /* OFWriteFailedException.m in Sources */, 4BC5E7D6137F0D0E0076F962 /* OFSerialization.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 4BF33AEC133807310059CEF7 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( |
︙ |
Modified src/Makefile from [2f646cb5ed] to [bff15d4ff7].
︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | + | OFMutableArray.m \ OFMutableDictionary.m \ OFMutableString.m \ OFNumber.m \ OFObject.m \ ${OFPLUGIN_M} \ OFSeekableStream.m \ OFSerialization.m \ OFSHA1Hash.m \ OFStream.m \ OFStreamObserver.m \ OFStreamSocket.m \ OFString.m \ OFString+Hashing.m \ OFString+URLEncoding.m \ |
︙ | |||
47 48 49 50 51 52 53 | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | - | OFXMLParser.m \ base64.m \ of_asprintf.m \ unicode.m INCLUDES := ${SRCS:.m=.h} \ OFCollection.h \ |
︙ |
Modified src/OFArray.m from [d444e53917] to [8ef39fadce].
︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | + | #import "OFArray.h" #import "OFDataArray.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "macros.h" @implementation OFArray + array { |
︙ | |||
217 218 219 220 221 222 223 224 225 226 227 228 229 230 | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | for (i = 0; i < length; i++) [objects[i] release]; [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { OFAutoreleasePool *pool, *pool2; OFEnumerator *enumerator; OFXMLElement *child; pool = [[OFAutoreleasePool alloc] init]; if (![[element name] isEqual: @"object"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS] || ![[[element attributeForName: @"class"] stringValue] isEqual: [isa className]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; enumerator = [[element elementsForName: @"object" namespace: OF_SERIALIZATION_NS] objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((child = [enumerator nextObject]) != nil) { id object = [OFSerialization objectByDeserializingXMLElement: child]; [array addItem: &object]; [object retain]; [pool2 releaseObjects]; } [pool release]; } @catch (id e) { [self release]; @throw e; } return self; } - (size_t)count { return [array count]; |
︙ |
Modified src/OFDate.m from [e2944cd61c] to [31c04ee022].
︙ | |||
234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | self = [self init]; seconds += seconds_; microseconds += microseconds_; seconds += microseconds / 1000000; microseconds %= 1000000; return self; } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *secondsElement, *microsecondsElement; if (![[element name] isEqual: @"object"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS] || ![[[element attributeForName: @"class"] stringValue] isEqual: [isa className]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; secondsElement = [element elementForName: @"seconds" namespace: OF_SERIALIZATION_NS]; microsecondsElement = [element elementForName: @"microseconds" namespace: OF_SERIALIZATION_NS]; if (secondsElement == nil || microsecondsElement == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; seconds = (int64_t)[[secondsElement stringValue] decimalValue]; microseconds = (uint32_t)[[microsecondsElement stringValue] decimalValue]; [pool release]; } @catch (id e) { [self release]; @throw e; } return self; } - (BOOL)isEqual: (id)object { OFDate *otherDate; |
︙ |
Modified src/OFDictionary.m from [5f45c17283] to [a5322a8311].
︙ | |||
462 463 464 465 466 467 468 469 470 471 472 473 474 475 | 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | } @catch (id e) { [object release]; @throw e; } data[j]->object = object; } } @catch (id e) { [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement*)element { @try { OFAutoreleasePool *pool, *pool2; OFMutableDictionary *dictionary; OFArray *pairs; OFEnumerator *enumerator; OFXMLElement *pair; pool = [[OFAutoreleasePool alloc] init]; if (![[element name] isEqual: @"object"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS] || ![[[element attributeForName: @"class"] stringValue] isEqual: [isa className]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; dictionary = [OFMutableDictionary dictionary]; pairs = [element elementsForName: @"pair" namespace: OF_SERIALIZATION_NS]; enumerator = [pairs objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((pair = [enumerator nextObject]) != nil) { OFXMLElement *keyElement, *valueElement; id <OFSerialization, OFCopying> key; id <OFSerialization> object; keyElement = [pair elementForName: @"key" namespace: OF_SERIALIZATION_NS]; valueElement = [pair elementForName: @"value" namespace: OF_SERIALIZATION_NS]; if (keyElement == nil || valueElement == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; key = [OFSerialization objectByDeserializingXMLElement: [keyElement elementForName: @"object" namespace: OF_SERIALIZATION_NS]]; object = [OFSerialization objectByDeserializingXMLElement: [valueElement elementForName: @"object" namespace: OF_SERIALIZATION_NS]]; [dictionary setObject: object forKey: key]; [pool2 releaseObjects]; } self = [self initWithDictionary: dictionary]; [pool release]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ |
Modified src/OFList.m from [8b7bb79b80] to [3246422836].
︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | + - + - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + | #import "OFList.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "macros.h" @implementation OFList + list { return [[[self alloc] init] autorelease]; } |
︙ | |||
173 174 175 176 177 178 179 | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | - + - - - - + - - - | [listObject->object release]; [self freeMemory: listObject]; } - (id)firstObject { |
︙ |
Modified src/OFNumber.m from [01b0cb5868] to [d234546f66].
︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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 | 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; |
︙ |
Modified src/OFSerialization.h from [14e103c34d] to [9b361d0e27].
︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" @class OFString; @class OFXMLElement; #define OF_SERIALIZATION_NS @"https://webkeks.org/objfw/serialization" /** * \brief A protocol for serializing objects. */ @protocol OFSerialization <OFObject> /** * \brief Initializes the object with the specified XML element serialization. * * \param element An OFXMLElement with the serialized object * \return An initialized object */ - initWithSerialization: (OFXMLElement*)element; /** * \brief Serializes the object into an XML element. * * \return The object serialized into an XML element */ - (OFXMLElement*)XMLElementBySerializing; @end /** * \brief A class that provides class methods for serializing and deserializing * objects. */ @interface OFSerialization: OFObject /** * \brief Creates a string by serializing the specified object. * * \param object The object to serialize * \return The object serialized as a string */ + (OFString*)stringBySerializingObject: (id <OFSerialization>)object; /** * \brief Deserializes the specified string into an object. * * \param string The string describing the serialized object * \return The deserialized object */ + (id)objectByDeserializingString: (OFString*)string; /** * \brief Deserializes the specified XML element into an object. * * \param string The XML element describing the serialized object * \return The deserialized object */ + (id)objectByDeserializingXMLElement: (OFXMLElement*)element; @end |
Added src/OFSerialization.m version [551d38e4e9].