Class DCircle

Inherits from:
Object
Conforms to:
DQueuable, DStackable
Declared in:
DCircle.h

Class Hierarchy

    Object
      |
      +---DCircle

Class Description

The circular buffer collection stores objects in an circular buffer that can grow. Objects can be read by an index, which can be negative for accessing elements from the end. This collection can be used for implementing a queue (FIFO) or a stack (LIFO).

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

int main(int argc, char *argv[])
{
  DCircle *fifo = [DCircle alloc];
  DCircle *lifo = [DCircle new  ];
  DInt    *val;

  [fifo init :20];                     // Init with size 20

  val = [DInt new]; [val set :1];
  [fifo enqueue :val];                 // Enqueue value 1 in lifo

  val = [DInt new]; [val set :2];      // Enqueue value 2 in lifo
  [fifo enqueue :val];

  val = [fifo dequeue];
  printf("First value in fifo:%d\n", (val != nil ? [val get] : -1));

  [lifo size :20];                     // Insure size in lifo

  val = [DInt new]; [val set :3];
  [lifo push :val];                    // Push value 3 in lifo

  val = [DInt new]; [val set :4];      // Push value 4 in lifo
  [lifo push :val];

  printf("Lifo length:%ld\n", [lifo length]);

  val = [lifo tos];
  printf("TOS in lifo:%d\n", (val != nil ? [val get] : -1));

  [fifo free];                         // Cleanup incl. stored objects
  [lifo free];

  return 0;
}
Last modified:
19-Jul-2008 (DCircle.h)

Instance Variables

private id *_objects
the stored objects
private long _size
the size of the buffer
private long _first
the first element in the buffer (or -1 for empty)
private long _next
the next element in the buffer

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0