- Inherits from:
- Object
- Declared in:
- DArray.h
Object
|
+---DArray
Class Description
The array collection stores objects in an array that can grow. Objects
can be accessed by an index. Due to the easy access there is no iterator.
- Example:
#include "ofc/DArray.h"
#include "ofc/DText.h"
#include "ofc/DInt.h"
int main(int argc, char *argv[])
{
DArray *array = [DArray alloc];
DText *str;
DInt *nr;
id obj;
[array init : 10]; // Start with length 10
// Put objects in the array
str = [DText new]; [str set :"String1"];
[array set :0 :str];
str = [DText new]; [str set :"String2"];
[array set :1 :str];
nr = [DInt alloc]; [nr init :3];
[array set :2 :nr];
nr = [DInt alloc]; [nr init :4];
[array set :3 :nr];
// Get objects from the array
obj = [array get :4]; // id = nil
obj = [array get :1]; // id = DText("String2")
if ([obj isKindOf :[DText class]])
printf("Text:%s\n", [obj cstring]);
if ([obj isKindOf :[DInt class]])
printf("Number:%d\n", [obj get]);
[array free]; // Free the array and the stored objects
return 0;
}
- Last modified:
- 19-Jul-2008 (DArray.h)
Instance Variables
- private id *_objects
- the stored objects
- private long _length
- the length of the array
- Constructors
- - (DArray *) init
- Initialise to an empty array
- Returns:
- the object
- - (DArray *) init :(long) length
- Initialise to an array with an initial length
- Parameters:
- length - the length of the array
- Returns:
- the object
- Copy related methods
- - deepen
- Deepen a copy of the array
- Returns:
- the object
- - shallowCopy
- Do a shallow copy of the array
- Returns:
- the object
- Destructor
- - free
- (Deep) free the array (incl. the objects)
- Returns:
- the object
- - shallowFree
- Free the array, not the stored objects
- Returns:
- the object
- Member methods
- - (BOOL) isValid :(long) index
- Test if an index is valid
- Parameters:
- index - the index to be tested
- Returns:
- is it valid ?
- - (long) length
- Return the length of the array
- Returns:
- the length
- - (DArray *) length :(long) length
- Set the length for the array
- Parameters:
- length - the new length
- Returns:
- the object
- Main methods
- - (id) get :(long) index
- Get an object from the array
- Parameters:
- index - the index in the array
- Returns:
- the object in the array (or nil)
- - (id) set :(long) index :(id) obj
- Set an object in the array
- Parameters:
- index - the index in the array
obj - the object to be set
- Returns:
- the previous object in the array (or nil)
- Object location methods
- - (long) count :(id) obj
- Count the number of occurences of an object
- Parameters:
- obj - the object to be counted
- Returns:
- the number of occurences
- - (DArray *) each :(SEL) sel
- Perform a selector on each object in the array
- Parameters:
- sel - the selector
- Returns:
- the object
- - (BOOL) has :(id) obj
- Test if an object is in an array
- Parameters:
- obj - the object to be checked
- Returns:
- is it in the array ?
- - (long) index :(id) obj
- Find the first occurence of an object
- Parameters:
- obj - the object to be found
- Returns:
- the first occurence of the object (or -1 for not found)
- - (long) rindex :(id) obj
- Find the last occurence of an object
- Parameters:
- obj - the object to be found
- Returns:
- the last occurence of the object (or -1 for not found)
generated 06-Sep-2008 by ObjcDoc 3.0.0