g_array.c

来自「c语言是面向过程的程序语言」· C语言 代码 · 共 120 行

C
120
字号
/* ****************************** * 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 <g_array.h>/* simplify reading */#define  MEMBLOCK  GENERIC(memBlock)#define _MEMBLOCK  GENERIC_DTOR(memBlock)/*  Object implementation*/gType1methodDecl(*getData){  return this->m.data;}voidmethodDecl_(startAt) int i __{  this->m.data = MEMBLOCK.base(super(this,MEMBLOCK)) - i;}voidmethodDecl_(set) size_t i, gType1 x __{  /* should throw an exception 'out of range' if we store the size */  this->m.data[i] = x;}gType1constMethodDecl_(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_OBJECTclassMethodDecl_(*const new) size_t n __{  t_OBJECT *const this = OBJECT.alloc();  if (this) OBJECT.init(this, n);  return this;}t_OBJECTclassMethodDecl_(*const newRef) gType1 *const t __{  t_OBJECT *const this = OBJECT.alloc();  if (this) OBJECT.initRef(this, t);  return this;}voidmethodDecl_(init) size_t n __{  MEMBLOCK.init(super(this,MEMBLOCK), n);  this->m.data = MEMBLOCK.base(super(this,MEMBLOCK));}voidmethodDecl_(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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?