Class DArray

Inherits from:
Object
Declared in:
DArray.h

Class Hierarchy

    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

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0