Class DCube

Inherits from:
Object
Declared in:
DCube.h

Class Hierarchy

    Object
      |
      +---DCube

Class Description

The cube collection stores objects in a 3d array that can grow. Objects can be accessed by an index. Due to the easy access there is no iterator.

Example:
#include <stdio.h>
#include "ofc/DCube.h"
#include "ofc/DInt.h"

int main(int argc, char *argv[])
{
  DCube *cu1 = [DCube alloc];
  DCube *cu2 = [DCube new  ];

  DInt  *nr;
  DInt  *nr1;

  [cu1 init :5 :10 :2];                // Init cube with 5 columns, 10 rows and 2 layers

  printf("Index (4,9,1) is %s valid.\n", ([cu1 isValid :4 :9 :1] ? "" : "not"));
  printf("Index (5,9,1) is %s valid.\n", ([cu1 isValid :5 :9 :1] ? "" : "not"));

  printf("Length of cube1:%ld\n", [cu1 length]);

  nr1 = [DInt new]; [nr1 set :1];
  [cu1 set :3 :7 :0 :nr1];             // Set nr1 at (3,7,0)

  nr = [DInt new]; [nr set :2];
  [cu1 set :0 :0 :0 :nr];              // Set 2 at (0,0,0)

  nr = [DInt new]; [nr set :3];
  printf("Nr1 is %s present in the cube1.\n", ([cu1 has :nr1] ? "" : "not"));
  printf("Nr3 is %s present in the cube1.\n", ([cu1 has :nr]  ? "" : "not"));

  nr = [cu1 get :0 :0 :0];
  printf("Index: (0,0,0) has %d.\n", (nr != nil ? [nr get] : -1));
  nr = [cu1 get :1 :1 :1];
  printf("Index: (1,1,1) has %d.\n", (nr != nil ? [nr get] : -1));

  [cu2 columns :3];                    // Resize the columns of cube2

  printf("Length of cube2:%ld\n", [cu2 length]);

  [cu1 free];                          // Cleanup the cubes including the stored objects
  [cu2 free];

  return 0;
}
Last modified:
20-Jul-2008 (DCube.h)

Instance Variables

private id *_objects
the stored objects
private int _columns
the number of columns
private int _rows
the number of rows
private int _layers
the number of layers
private long _length
the length of the cube

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0