Overview
Comment: | A few more convenience methods for OFArray. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
b3a8c9c4dd615944e3d42e071547edc9 |
User & Date: | js on 2009-05-18 18:42:40 |
Other Links: | manifest | tags |
Context
2009-05-18
| ||
18:45 | Only let - copy create an actual copy if necessary. check-in: 6ba395bacb user: js tags: trunk | |
18:42 | A few more convenience methods for OFArray. check-in: b3a8c9c4dd user: js tags: trunk | |
18:24 | Remove useless convenience method. check-in: 577023d300 user: js tags: trunk | |
Changes
Modified src/OFArray.h from [5f3c2228b9] to [0cd7239c8e].
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 | /* * 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 "OFObject.h" #import "OFDataArray.h" /** * The OFArray class provides a class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying> { OFDataArray *array; } /** * \return A new autoreleased OFArray */ + array; /** * \return The number of objects in the OFArray */ - (size_t)count; /** * \return The objects of the array as a C array | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 | /* * 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. */ #include <stdarg.h> #import "OFObject.h" #import "OFDataArray.h" /** * The OFArray class provides a class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying> { OFDataArray *array; } /** * \return A new autoreleased OFArray */ + array; /** * \param obj An object * \return A new autoreleased OFArray */ + arrayWithObject: (OFObject*)obj; /** * \param first The first object in the array * \return A new autoreleased OFArray */ + arrayWithObjects: (OFObject*)first, ...; /** * Initializes an OFArray with the specified object. * * \param obj An object * \return An initialized OFArray */ - initWithObject: (OFObject*)obj; /** * Initializes an OFArray with the specified objects. * * \param obj The first object * \return An initialized OFArray */ - initWithObjects: (OFObject*)first, ...; /** * Initializes an OFArray with the specified object and a va_list. * * \param first The first object * \param args A va_list * \return An initialized OFArray */ - initWithObject: (OFObject*)first andArgList: (va_list)args; /** * \return The number of objects in the OFArray */ - (size_t)count; /** * \return The objects of the array as a C array |
︙ | ︙ |
Modified src/OFArray.m from [bacc2fea00] to [39b19454f4].
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 35 36 37 38 39 40 41 42 43 44 45 | /* * 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 [[[self alloc] init] autorelease]; } - init { self = [super init]; @try { array = [[OFDataArray alloc] initWithItemSize: sizeof(OFObject*)]; } @catch (OFException *e) { /* * We can't use [super dealloc] on OS X here. Compiler bug? * [self dealloc] will do here as we check for nil in dealloc. */ [self dealloc]; @throw e; } return self; } - (size_t)count { return [array count]; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | /* * 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" #include <stdarg.h> #import "OFArray.h" #import "OFExceptions.h" @implementation OFArray + array { return [[[self alloc] init] autorelease]; } + arrayWithObject: (OFObject*)obj { return [[[self alloc] initWithObject: obj] autorelease]; } + arrayWithObjects: (OFObject*)first, ... { id ret; va_list args; va_start(args, first); ret = [[[self alloc] initWithObject: first andArgList: args] autorelease]; va_end(args); return ret; } - init { self = [super init]; @try { array = [[OFDataArray alloc] initWithItemSize: sizeof(OFObject*)]; } @catch (OFException *e) { /* * We can't use [super dealloc] on OS X here. Compiler bug? * [self dealloc] will do here as we check for nil in dealloc. */ [self dealloc]; @throw e; } return self; } - initWithObject: (OFObject*)obj { self = [self init]; @try { [array add: &obj]; } @catch (OFException *e) { [self dealloc]; @throw e; } [obj retain]; return self; } - initWithObjects: (OFObject*)first, ... { id ret; va_list args; va_start(args, first); ret = [self initWithObject: first andArgList: args]; va_end(args); return ret; } - initWithObject: (OFObject*)first andArgList: (va_list)args { id obj; OFObject **objs; size_t len, i; self = [self init]; @try { [array add: &first]; while ((obj = va_arg(args, id)) != nil) [array add: &obj]; } @catch (OFException *e) { [self dealloc]; @throw e; } /* Retain objects after adding them for the case adding failed */ objs = [array data]; len = [array count]; [first retain]; for (i = 0; i < len; i++) [objs[i] retain]; return self; } - (size_t)count { return [array count]; } |
︙ | ︙ |