Object
|
+---DCube
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.
#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;
}