/* ****************************** * Object Oriented Programming in C * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * For more information, please see the paper: * http://home.cern.ch/ldeniau/html/oopc/oopc.html * ****************************** */ /*----------------------------------*/ /* Generic array implementation */ /* inherit from memBlock */ /*----------------------------------*/ #define IMPLEMENTATION #include /* simplify reading */ #define MEMBLOCK GENERIC(memBlock) #define _MEMBLOCK GENERIC_DTOR(memBlock) /* Object implementation */ gType1 methodDecl(*getData) { return this->m.data; } void methodDecl_(startAt) int i __ { this->m.data = MEMBLOCK.base(super(this,MEMBLOCK)) - i; } void methodDecl_(set) size_t i, gType1 x __ { /* should throw an exception 'out of range' if we store the size */ this->m.data[i] = x; } gType1 constMethodDecl_(get) size_t i __ { /* should throw an exception 'out of range' if we store the size */ return this->m.data[i]; } OBJECT_IMPLEMENTATION SUPERCLASS(MEMBLOCK), methodName(getData), methodName(startAt), methodName(set), methodName(get) ENDOF_IMPLEMENTATION /* Class implementation */ initClassDecl() /* required */ { initSuper(MEMBLOCK); } dtorDecl() /* required */ { MEMBLOCK._MEMBLOCK(super(this,MEMBLOCK)); this->m.data = NULL; } t_OBJECT classMethodDecl_(*const new) size_t n __ { t_OBJECT *const this = OBJECT.alloc(); if (this) OBJECT.init(this, n); return this; } t_OBJECT classMethodDecl_(*const newRef) gType1 *const t __ { t_OBJECT *const this = OBJECT.alloc(); if (this) OBJECT.initRef(this, t); return this; } void methodDecl_(init) size_t n __ { MEMBLOCK.init(super(this,MEMBLOCK), n); this->m.data = MEMBLOCK.base(super(this,MEMBLOCK)); } void methodDecl_(initRef) gType1 *const t __ { MEMBLOCK.initRef(super(this,MEMBLOCK), t); this->m.data = MEMBLOCK.base(super(this,MEMBLOCK)); } CLASS_IMPLEMENTATION methodName(new), methodName(newRef), methodName(init), methodName(initRef), ENDOF_IMPLEMENTATION