Class DTable

Inherits from:
Object
Declared in:
DTable.h

Class Hierarchy

    Object
      |
      +---DTable

Class Description

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.

Example:
#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;
}
Last modified:
05-Aug-2008 (DTable.h)

Instance Variables

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

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0