Overview
Comment: | Add serialization and deserialization for OFSet and OFCountedSet. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8d5ca84bc56e5123e0943a252c8b256f |
User & Date: | js on 2011-09-01 18:08:23 |
Other Links: | manifest | tags |
Context
2011-09-06
| ||
11:18 | Fix handling of nested namespaces in OFXMLElement. check-in: 0082e20b04 user: js tags: trunk | |
2011-09-01
| ||
18:08 | Add serialization and deserialization for OFSet and OFCountedSet. check-in: 8d5ca84bc5 user: js tags: trunk | |
14:25 | Throw an OFInvalidArgumentException if serialization can't be parsed. check-in: 8d3b009af1 user: js tags: trunk | |
Changes
Modified src/OFCountedSet.m from [564495dad9] to [931ec5d215].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #import "OFCountedSet.h" #import "OFCountedSet_hashtable.h" #import "OFNumber.h" #import "OFString.h" #import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" static struct { Class isa; } placeholder; | > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include "config.h" #import "OFCountedSet.h" #import "OFCountedSet_hashtable.h" #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" static struct { Class isa; } placeholder; |
︙ | ︙ | |||
59 60 61 62 63 64 65 66 67 68 69 70 71 72 | - initWithObject: (id)firstObject arguments: (va_list)arguments { return [[OFCountedSet_hashtable alloc] initWithObject: firstObject arguments: arguments]; } - retain { return self; } - autorelease | > > > > > | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | - initWithObject: (id)firstObject arguments: (va_list)arguments { return [[OFCountedSet_hashtable alloc] initWithObject: firstObject arguments: arguments]; } - initWithSerialization: (OFXMLElement*)element { return [[OFCountedSet_hashtable alloc] initWithSerialization: element]; } - retain { return self; } - autorelease |
︙ | ︙ | |||
162 163 164 165 166 167 168 169 170 171 172 173 174 175 | return [[OFCountedSet alloc] initWithSet: self]; } - mutableCopy { return [[OFCountedSet alloc] initWithSet: self]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (of_counted_set_enumeration_block_t)block { [self enumerateObjectsUsingBlock: ^ (id object, BOOL *stop) { block(object, [self countForObject: object], stop); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | return [[OFCountedSet alloc] initWithSet: self]; } - mutableCopy { return [[OFCountedSet alloc] initWithSet: self]; } - (OFXMLElement*)XMLElementBySerializing { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool2; OFXMLElement *element; OFEnumerator *enumerator; id <OFSerialization> object; element = [OFXMLElement elementWithName: @"OFCountedSet" namespace: OF_SERIALIZATION_NS]; enumerator = [self objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((object = [enumerator nextObject]) != nil) { OFXMLElement *objectElement; OFString *count; count = [OFString stringWithFormat: @"%zu", [self countForObject: object]]; objectElement = [OFXMLElement elementWithName: @"object" namespace: OF_SERIALIZATION_NS]; [objectElement addAttributeWithName: @"count" stringValue: count]; [objectElement addChild: [object XMLElementBySerializing]]; [element addChild: objectElement]; [pool2 releaseObjects]; } [element retain]; @try { [pool release]; } @finally { [element autorelease]; } return element; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (of_counted_set_enumeration_block_t)block { [self enumerateObjectsUsingBlock: ^ (id object, BOOL *stop) { block(object, [self countForObject: object], stop); |
︙ | ︙ |
Modified src/OFCountedSet_hashtable.m from [ecfe321ef8] to [fef635224c].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include "config.h" #define OF_COUNTED_SET_HASHTABLE_M #import "OFMutableSet_hashtable.h" #import "OFCountedSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFNumber.h" #import "OFArray.h" #import "OFAutoreleasePool.h" @implementation OFCountedSet_hashtable + (void)initialize { if (self == [OFCountedSet_hashtable class]) [self inheritMethodsFromClass: [OFMutableSet_hashtable class]]; } | > > > > > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include "config.h" #define OF_COUNTED_SET_HASHTABLE_M #import "OFMutableSet_hashtable.h" #import "OFCountedSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFString.h" #import "OFNumber.h" #import "OFArray.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @implementation OFCountedSet_hashtable + (void)initialize { if (self == [OFCountedSet_hashtable class]) [self inheritMethodsFromClass: [OFMutableSet_hashtable class]]; } |
︙ | ︙ | |||
96 97 98 99 100 101 102 103 104 105 106 107 108 109 | @try { id object; [self addObject: firstObject]; while ((object = va_arg(arguments, id)) != nil) [self addObject: object]; } @catch (id e) { [self release]; @throw e; } return self; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | @try { id object; [self addObject: firstObject]; while ((object = va_arg(arguments, id)) != nil) [self addObject: object]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool2; OFArray *objects; OFEnumerator *enumerator; OFXMLElement *objectElement; if (![[element name] isEqual: @"OFCountedSet"] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; objects = [element elementsForName: @"object" namespace: OF_SERIALIZATION_NS]; enumerator = [objects objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((objectElement = [enumerator nextObject]) != nil) { OFXMLElement *object; OFXMLAttribute *count; OFNumber *number; object = [[objectElement elementsForNamespace: OF_SERIALIZATION_NS] firstObject]; count = [objectElement attributeForName: @"count"]; if (object == nil || count == nil) @throw [OFInvalidFormatException newWithClass: isa]; number = [OFNumber numberWithSize: (size_t)[[count stringValue] decimalValue]]; [dictionary _setObject: number forKey: [object objectByDeserializing] copyKey: NO]; [pool2 releaseObjects]; } [pool release]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ |
Modified src/OFMutableSet.m from [781150565d] to [550e7fe687].
︙ | ︙ | |||
59 60 61 62 63 64 65 66 67 68 69 70 71 72 | - initWithObject: (id)firstObject arguments: (va_list)arguments { return [[OFMutableSet_hashtable alloc] initWithObject: firstObject arguments: arguments]; } - retain { return self; } - autorelease | > > > > > | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | - initWithObject: (id)firstObject arguments: (va_list)arguments { return [[OFMutableSet_hashtable alloc] initWithObject: firstObject arguments: arguments]; } - initWithSerialization: (OFXMLElement*)element { return [[OFMutableSet_hashtable alloc] initWithSerialization: element]; } - retain { return self; } - autorelease |
︙ | ︙ |
Modified src/OFSet.h from [9364338508] to [c63fa846e0].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * file. */ #include <stdarg.h> #import "OFObject.h" #import "OFCollection.h" @class OFArray; #ifdef OF_HAVE_BLOCKS typedef void (^of_set_enumeration_block_t)(id object, BOOL *stop); typedef BOOL (^of_set_filter_block_t)(id object); #endif /** * \brief An unordered set of unique objects. */ | > | > | 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 | * file. */ #include <stdarg.h> #import "OFObject.h" #import "OFCollection.h" #import "OFSerialization.h" @class OFArray; #ifdef OF_HAVE_BLOCKS typedef void (^of_set_enumeration_block_t)(id object, BOOL *stop); typedef BOOL (^of_set_filter_block_t)(id object); #endif /** * \brief An unordered set of unique objects. */ @interface OFSet: OFObject <OFCollection, OFCopying, OFMutableCopying, OFSerialization> /** * \brief Returns a new, autoreleased set. * * \return A new, autoreleased set */ + set; |
︙ | ︙ |
Modified src/OFSet.m from [2a40664f4e] to [61fa40e270].
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "config.h" #import "OFSet.h" #import "OFSet_hashtable.h" #import "OFString.h" #import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" static struct { Class isa; } placeholder; | > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | */ #include "config.h" #import "OFSet.h" #import "OFSet_hashtable.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" static struct { Class isa; } placeholder; |
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | - initWithObject: (id)firstObject arguments: (va_list)arguments { return [[OFSet_hashtable alloc] initWithObject: firstObject arguments: arguments]; } - retain { return self; } - autorelease | > > > > > | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | - initWithObject: (id)firstObject arguments: (va_list)arguments { return [[OFSet_hashtable alloc] initWithObject: firstObject arguments: arguments]; } - initWithSerialization: (OFXMLElement*)element { return [[OFSet_hashtable alloc] initWithSerialization: element]; } - retain { return self; } - autorelease |
︙ | ︙ | |||
168 169 170 171 172 173 174 175 176 177 178 179 180 181 | return ret; } - initWithObject: (id)firstObject arguments: (va_list)arguments { Class c = isa; [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - (size_t)count | > > > > > > > > | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | return ret; } - initWithObject: (id)firstObject arguments: (va_list)arguments { Class c = isa; [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithSerialization: (OFXMLElement*)element { Class c = isa; [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - (size_t)count |
︙ | ︙ | |||
312 313 314 315 316 317 318 319 320 321 322 323 324 325 | } } [pool release]; return NO; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFEnumerator *enumerator = [self objectEnumerator]; id object; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | } } [pool release]; return NO; } - (OFXMLElement*)XMLElementBySerializing { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool2; OFXMLElement *element; OFEnumerator *enumerator; id <OFSerialization> object; if ([self isKindOfClass: [OFMutableSet class]]) element = [OFXMLElement elementWithName: @"OFMutableSet" namespace: OF_SERIALIZATION_NS]; else element = [OFXMLElement elementWithName: @"OFSet" namespace: OF_SERIALIZATION_NS]; enumerator = [self objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((object = [enumerator nextObject]) != nil) { [element addChild: [object XMLElementBySerializing]]; [pool2 releaseObjects]; } [element retain]; @try { [pool release]; } @finally { [element autorelease]; } return element; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFEnumerator *enumerator = [self objectEnumerator]; id object; |
︙ | ︙ |
Modified src/OFSet_hashtable.m from [5a68e86a25] to [d4c54a82d9].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #define OF_SET_HASHTABLE_M #import "OFSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFArray.h" #import "OFString.h" #import "OFNumber.h" #import "OFAutoreleasePool.h" @implementation OFSet_hashtable - init { self = [super init]; @try { | > > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #define OF_SET_HASHTABLE_M #import "OFSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFArray.h" #import "OFString.h" #import "OFNumber.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" @implementation OFSet_hashtable - init { self = [super init]; @try { |
︙ | ︙ | |||
106 107 108 109 110 111 112 113 114 115 116 117 118 119 | forKey: firstObject copyKey: NO]; while ((object = va_arg(arguments, id)) != nil) [dictionary _setObject: one forKey: object copyKey: NO]; [pool release]; } @catch (id e) { [self release]; @throw e; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | forKey: firstObject copyKey: NO]; while ((object = va_arg(arguments, id)) != nil) [dictionary _setObject: one forKey: object copyKey: NO]; [pool release]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { OFAutoreleasePool *pool, *pool2; OFNumber *one; OFEnumerator *enumerator; OFXMLElement *child; pool = [[OFAutoreleasePool alloc] init]; if ((![[element name] isEqual: @"OFSet"] && ![[element name] isEqual: @"OFMutableSet"]) || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; one = [OFNumber numberWithSize: 1]; enumerator = [[element children] objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((child = [enumerator nextObject]) != nil) { if (![[child namespace] isEqual: OF_SERIALIZATION_NS]) continue; [dictionary _setObject: one forKey: [child objectByDeserializing] copyKey: NO]; [pool2 releaseObjects]; } [pool release]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ |
Modified tests/OFSerializationTests.m from [43de409da6] to [0948a92654].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #import "OFSerialization.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFList.h" #import "OFNumber.h" #import "OFDate.h" #import "OFURL.h" #import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFXMLElement.h" | > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include "config.h" #import "OFSerialization.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFSet.h" #import "OFCountedSet.h" #import "OFList.h" #import "OFNumber.h" #import "OFDate.h" #import "OFURL.h" #import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFXMLElement.h" |
︙ | ︙ | |||
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | forKey: @"Blub"]; [l appendObject: @"Hello"]; [l appendObject: @"Wo\rld!\nHow are you?"]; [l appendObject: [OFURL URLWithString: @"https://webkeks.org/"]]; [l appendObject: [OFXMLElement elementWithXMLString: @"<x><y/><![CDATA[<]]></x>"]]; [d setObject: @"list" forKey: l]; [da addNItems: 39 fromCArray: "0123456789:;<ABCDEFGHJIKLMNOPQRSTUVWXYZ"]; [d setObject: @"data" | > > > | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | forKey: @"Blub"]; [l appendObject: @"Hello"]; [l appendObject: @"Wo\rld!\nHow are you?"]; [l appendObject: [OFURL URLWithString: @"https://webkeks.org/"]]; [l appendObject: [OFXMLElement elementWithXMLString: @"<x><y/><![CDATA[<]]></x>"]]; [l appendObject: [OFSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [l appendObject: [OFCountedSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [d setObject: @"list" forKey: l]; [da addNItems: 39 fromCArray: "0123456789:;<ABCDEFGHJIKLMNOPQRSTUVWXYZ"]; [d setObject: @"data" |
︙ | ︙ |
Modified tests/serialization.xml from [50caace6dd] to [5739f59ed1].
1 2 3 4 5 6 7 8 9 10 | <?xml version='1.0' encoding='UTF-8'?> <serialization xmlns='https://webkeks.org/objfw/serialization' version='0'> <OFMutableDictionary> <key> <OFList> <OFString>Hello</OFString> <OFString>Wo
ld! How are you?</OFString> <OFURL>https://webkeks.org/</OFURL> <OFXMLElement name='x'> | > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 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 | <?xml version='1.0' encoding='UTF-8'?> <serialization xmlns='https://webkeks.org/objfw/serialization' version='0'> <OFMutableDictionary> <key> <OFDataArray>MDEyMzQ1Njc4OTo7PEFCQ0RFRkdISklLTE1OT1BRUlNUVVZXWFla</OFDataArray> </key> <object> <OFString>data</OFString> </object> <key> <OFArray> <OFString>Qu"xbar test</OFString> <OFNumber type='signed'>1234</OFNumber> <OFMutableString>asd</OFMutableString> <OFDate seconds='1234' microseconds='5678'/> </OFArray> </key> <object> <OFString>Hello</OFString> </object> <key> <OFString>Blub</OFString> </key> <object> <OFString>B"la</OFString> </object> <key> <OFList> <OFString>Hello</OFString> <OFString>Wo
ld! How are you?</OFString> <OFURL>https://webkeks.org/</OFURL> <OFXMLElement name='x'> |
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 57 | </OFXMLElement> <OFXMLElement> <CDATA><![CDATA[<]]></CDATA> </OFXMLElement> </OFMutableArray> </children> </OFXMLElement> </OFList> </key> <object> <OFString>list</OFString> </object> | > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | </OFXMLElement> <OFXMLElement> <CDATA><![CDATA[<]]></CDATA> </OFXMLElement> </OFMutableArray> </children> </OFXMLElement> <OFSet> <OFString>foo</OFString> <OFString>bar</OFString> </OFSet> <OFCountedSet> <object count='2'> <OFString>foo</OFString> </object> <object count='1'> <OFString>bar</OFString> </object> </OFCountedSet> </OFList> </key> <object> <OFString>list</OFString> </object> </OFMutableDictionary> </serialization> |