Object
|
+---DTable
The table collection stores objects in an 2d 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/DTable.h"
#include "ofc/DInt.h"
int main(int argc, char *argv[])
{
DTable *tab1 = [DTable alloc];
DTable *tab2 = [DTable new ];
DInt *nr;
int c,r;
[tab1 init :5 :4]; // Init the table with 5 columns and 4 rows
printf("Length (%ld), columns(%d) and rows(%d) for table1.\n", [tab1 length], [tab1 columns], [tab1 rows]);
for (c = 0; c < [tab1 columns]; c++) // Fill the whole table with integers
{
for (r = 0; r < [tab1 rows]; r++)
{
nr = [DInt new];
[nr set :(c*r)];
[tab1 set :c :r :nr];
}
}
nr = [tab1 get :4 :3];
printf("Element (4,3) has value:%d.\n", [nr get]);
[tab2 columns :4]; // Set the dimensions of table2
[tab2 rows :4];
nr = [DInt alloc]; [nr init :7];
// Set the object in table2
[tab2 set :0 :0 :nr];
[tab2 set :1 :1 :nr];
[tab2 set :2 :2 :nr];
[tab2 set :3 :3 :nr];
printf("Table2 %s object nr7.\n", ([tab2 has :nr] ? "has" : "has not"));
printf("Table2 has object nr7 %ld times.\n", [tab2 count :nr]);
[tab1 free]; // Cleanup
[tab2 shallowFree]; // Cleanup only table, nr is repeated present
[nr free];
return 0;
}