@@ -36,12 +36,13 @@ static struct { Class isa; } placeholder; @interface OFArray () -- (OFString *)of_JSONRepresentationWithOptions: (int)options - depth: (size_t)depth; +- (OFString *) + of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options + depth: (size_t)depth; @end @interface OFPlaceholderArray: OFArray @end @@ -193,12 +194,11 @@ { id ret; va_list arguments; va_start(arguments, firstObject); - ret = [self initWithObject: firstObject - arguments: arguments]; + ret = [self initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } @@ -227,32 +227,30 @@ - (size_t)count { OF_UNRECOGNIZED_SELECTOR } -- (void)getObjects: (id *)buffer - inRange: (of_range_t)range +- (void)getObjects: (id *)buffer inRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self objectAtIndex: range.location + i]; } - (id const *)objects { size_t count = self.count; - id *buffer = of_alloc(count, sizeof(id)); + id *buffer = OFAllocMemory(count, sizeof(id)); @try { - [self getObjects: buffer - inRange: of_range(0, count)]; + [self getObjects: buffer inRange: OFRangeMake(0, count)]; return [[OFData dataWithItemsNoCopy: buffer count: count itemSize: sizeof(id) freeWhenDone: true] items]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } } - (id)copy @@ -296,60 +294,58 @@ [ret makeImmutable]; return ret; } -- (void)setValue: (id)value - forKey: (OFString *)key +- (void)setValue: (id)value forKey: (OFString *)key { for (id object in self) - [object setValue: value - forKey: key]; + [object setValue: value forKey: key]; } - (size_t)indexOfObject: (id)object { size_t i = 0; if (object == nil) - return OF_NOT_FOUND; + return OFNotFound; for (id objectIter in self) { if ([objectIter isEqual: object]) return i; i++; } - return OF_NOT_FOUND; + return OFNotFound; } - (size_t)indexOfObjectIdenticalTo: (id)object { size_t i = 0; if (object == nil) - return OF_NOT_FOUND; + return OFNotFound; for (id objectIter in self) { if (objectIter == object) return i; i++; } - return OF_NOT_FOUND; + return OFNotFound; } - (bool)containsObject: (id)object { - return ([self indexOfObject: object] != OF_NOT_FOUND); + return ([self indexOfObject: object] != OFNotFound); } - (bool)containsObjectIdenticalTo: (id)object { - return ([self indexOfObjectIdenticalTo: object] != OF_NOT_FOUND); + return ([self indexOfObjectIdenticalTo: object] != OFNotFound); } - (id)firstObject { if (self.count > 0) @@ -366,32 +362,29 @@ return [self objectAtIndex: count - 1]; return nil; } -- (OFArray *)objectsInRange: (of_range_t)range +- (OFArray *)objectsInRange: (OFRange)range { OFArray *ret; id *buffer; if (range.length > SIZE_MAX - range.location || range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) - return [OFSubarray arrayWithArray: self - range: range]; + return [OFSubarray arrayWithArray: self range: range]; - buffer = of_alloc(range.length, sizeof(*buffer)); + buffer = OFAllocMemory(range.length, sizeof(*buffer)); @try { - [self getObjects: buffer - inRange: range]; + [self getObjects: buffer inRange: range]; - ret = [OFArray arrayWithObjects: buffer - count: range.length]; + ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } @@ -401,11 +394,11 @@ usingSelector: @selector(description) options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator - options: (int)options + options: (OFArrayJoinOptions)options { return [self componentsJoinedByString: separator usingSelector: @selector(description) options: options]; } @@ -418,11 +411,11 @@ options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector - options: (int)options + options: (OFArrayJoinOptions)options { OFMutableString *ret; if (separator == nil) @throw [OFInvalidArgumentException exception]; @@ -430,21 +423,21 @@ if (self.count == 0) return @""; if (self.count == 1) { OFString *component = - [[self firstObject] performSelector: selector]; + [[self objectAtIndex: 0] performSelector: selector]; if (component == nil) @throw [OFInvalidArgumentException exception]; return component; } ret = [OFMutableString string]; - if (options & OF_ARRAY_SKIP_EMPTY) { + if (options & OFArraySkipEmptyComponents) { for (id object in self) { void *pool = objc_autoreleasePoolPush(); OFString *component = [object performSelector: selector]; @@ -513,18 +506,18 @@ return true; } - (unsigned long)hash { - uint32_t hash; + unsigned long hash; - OF_HASH_INIT(hash); + OFHashInit(&hash); for (id object in self) - OF_HASH_ADD_HASH(hash, [object hash]); + OFHashAddHash(&hash, [object hash]); - OF_HASH_FINALIZE(hash); + OFHashFinalize(&hash); return hash; } - (OFString *)description @@ -538,12 +531,11 @@ pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret prependString: @"(\n"]; - [ret replaceOccurrencesOfString: @"\n" - withString: @"\n\t"]; + [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)"]; } @catch (id e) { [ret release]; @throw e; } @@ -560,14 +552,14 @@ void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; if ([self isKindOfClass: [OFMutableArray class]]) element = [OFXMLElement elementWithName: @"OFMutableArray" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFArray" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [element addChild: object.XMLElementBySerializing]; @@ -582,28 +574,28 @@ return [element autorelease]; } - (OFString *)JSONRepresentation { - return [self of_JSONRepresentationWithOptions: 0 - depth: 0]; + return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } -- (OFString *)JSONRepresentationWithOptions: (int)options +- (OFString *)JSONRepresentationWithOptions: + (OFJSONRepresentationOptions)options { - return [self of_JSONRepresentationWithOptions: options - depth: 0]; + return [self of_JSONRepresentationWithOptions: options depth: 0]; } -- (OFString *)of_JSONRepresentationWithOptions: (int)options - depth: (size_t)depth +- (OFString *) + of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options + depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"["]; void *pool = objc_autoreleasePoolPush(); size_t i, count = self.count; - if (options & OF_JSON_REPRESENTATION_PRETTY) { + if (options & OFJSONRepresentationOptionPretty) { OFMutableString *indentation = [OFMutableString string]; for (i = 0; i < depth; i++) [indentation appendString: @"\t"]; @@ -664,22 +656,20 @@ if (count <= 15) { uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; - uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count); + uint16_t tmp = OFToBigEndian16((uint16_t)count); [data addItem: &type]; - [data addItems: &tmp - count: sizeof(tmp)]; + [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDD; - uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count); + uint32_t tmp = OFToBigEndian32((uint32_t)count); [data addItem: &type]; - [data addItems: &tmp - count: sizeof(tmp)]; + [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); @@ -689,12 +679,11 @@ OFData *child; i++; child = [object messagePackRepresentation]; - [data addItems: child.items - count: child.count]; + [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } assert(i == count); @@ -714,78 +703,62 @@ - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { for (id objectIter in self) - [objectIter performSelector: selector - withObject: object]; + [objectIter performSelector: selector withObject: object]; } - (OFArray *)sortedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; - [new sort]; - [new makeImmutable]; - return new; } - (OFArray *)sortedArrayUsingSelector: (SEL)selector - options: (int)options + options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; - - [new sortUsingSelector: selector - options: options]; - + [new sortUsingSelector: selector options: options]; [new makeImmutable]; - return new; } #ifdef OF_HAVE_BLOCKS -- (OFArray *)sortedArrayUsingComparator: (of_comparator_t)comparator - options: (int)options +- (OFArray *)sortedArrayUsingComparator: (OFComparator)comparator + options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; - - [new sortUsingComparator: comparator - options: options]; - + [new sortUsingComparator: comparator options: options]; [new makeImmutable]; - return new; } #endif - (OFArray *)reversedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; - [new reverse]; - [new makeImmutable]; - return new; } -- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state +- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { - of_range_t range = of_range(state->state, count); + OFRange range = OFRangeMake(state->state, count); if (range.length > SIZE_MAX - range.location) @throw [OFOutOfRangeException exception]; if (range.location + range.length > self.count) range.length = self.count - range.location; - [self getObjects: objects - inRange: range]; + [self getObjects: objects inRange: range]; if (range.location + range.length > ULONG_MAX) @throw [OFOutOfRangeException exception]; state->state = (unsigned long)(range.location + range.length); @@ -800,11 +773,11 @@ return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: NULL] autorelease]; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { size_t i = 0; bool stop = false; for (id object in self) { @@ -822,64 +795,59 @@ if (object == nil) @throw [OFInvalidArgumentException exception]; ret = [[self mutableCopy] autorelease]; - [ret addObject: object]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByAddingObjectsFromArray: (OFArray *)array { OFMutableArray *ret = [[self mutableCopy] autorelease]; - [ret addObjectsFromArray: array]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByRemovingObject: (id)object { OFMutableArray *ret = [[self mutableCopy] autorelease]; - [ret removeObject: object]; [ret makeImmutable]; - return ret; } #ifdef OF_HAVE_BLOCKS -- (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block +- (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block { OFArray *ret; size_t count = self.count; - id *tmp = of_alloc(count, sizeof(id)); + id *tmp = OFAllocMemory(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); }]; - ret = [OFArray arrayWithObjects: tmp - count: count]; + ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { - free(tmp); + OFFreeMemory(tmp); } return ret; } -- (OFArray *)filteredArrayUsingBlock: (of_array_filter_block_t)block +- (OFArray *)filteredArrayUsingBlock: (OFArrayFilterBlock)block { OFArray *ret; size_t count = self.count; - id *tmp = of_alloc(count, sizeof(id)); + id *tmp = OFAllocMemory(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, @@ -886,28 +854,27 @@ bool *stop) { if (block(object, idx)) tmp[i++] = object; }]; - ret = [OFArray arrayWithObjects: tmp - count: i]; + ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { - free(tmp); + OFFreeMemory(tmp); } return ret; } -- (id)foldUsingBlock: (of_array_fold_block_t)block +- (id)foldUsingBlock: (OFArrayFoldBlock)block { size_t count = self.count; __block id current; if (count == 0) return nil; if (count == 1) - return [[[self firstObject] retain] autorelease]; + return [[[self objectAtIndex: 0] retain] autorelease]; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new;