Artifact 340e813c878e7af8d98a18c609136ff68d124f523d7f44dd142b1c7a6d8f31f7:
- File
src/OFArray.m
— part of check-in
[9338313079]
at
2009-05-05 14:00:10
on branch trunk
— There is a good reason to return id and not OFObject*.
When using OFObject*, you have to cast to get rid of a warning when
calling methods on the returned object. (user: js, size: 1779) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008 - 2009 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import "config.h" #import "OFArray.h" #import "OFExceptions.h" @implementation OFArray + array { return [[[OFArray alloc] init] autorelease]; } - init { self = [super init]; @try { array = [[OFDataArray alloc] initWithItemSize: sizeof(OFObject*)]; } @catch (OFException *e) { /* * We can't use [super free] on OS X here. Compiler bug? * [self free] will do here as we check for nil in free. */ [self free]; @throw e; } return self; } - (size_t)objects { return [array items]; } - (id)copy { OFArray *new = [OFArray array]; OFObject **objs; size_t len, i; objs = [array data]; len = [array items]; [new->array addNItems: len fromCArray: objs]; for (i = 0; i < len; i++) [objs[i] retain]; return new; } - (id)object: (size_t)index { return *((OFObject**)[array item: index]); } - (id)last { return *((OFObject**)[array last]); } - add: (OFObject*)obj { [array add: &obj]; [obj retain]; return self; } - removeNObjects: (size_t)nobjects { OFObject **objs; size_t len, i; objs = [array data]; len = [array items]; if (nobjects > len) @throw [OFOutOfRangeException newWithClass: isa]; for (i = len - nobjects; i < len; i++) [objs[i] release]; [array removeNItems: nobjects]; return self; } - free { OFObject **objs; size_t len, i; if (array != nil) { objs = [array data]; len = [array items]; for (i = 0; i < len; i++) [objs[i] release]; [array release]; } return [super free]; } @end