⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g_memblock.c

📁 c语言是面向过程的程序语言
💻 C
字号:
/* ****************************** * 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 memBlock implementation  *//*          [abstract class]          *//*------------------------------------*/#define IMPLEMENTATION#include <g_memBlock.h>/*  Object implementation*/voidmethodDecl_(set) size_t n, gType1 x __{  size_t i;  for(i=0; i<n; i++) this->m.base[i] = x;}voidmethodDecl_(copy) size_t n, gType1 const* t __{  size_t i;  for(i=0; i<n; i++) this->m.base[i] = t[i];}voidmethodDecl_(resize) size_t n __{  if (this == this->m.owner) { /* only owner can resize */    this->m.base = realloc(this->m.base, n*sizeof(gType1));  }}BASEOBJECT_IMPLEMENTATION  methodName(set),  methodName(copy),  methodName(resize)ENDOF_IMPLEMENTATION/*  Abstract Class implementation*/initClassDecl() {} /* required */dtorDecl() /* required */{  if (this == this->m.owner) { /* only owner can destroy */    free(this->m.base);    this->m.owner = NULL;    this->m.base  = NULL;    --OBJECT.total;  }}intclassMethodDecl(numBlock){  return OBJECT.total;}voidmethodDecl_(init) size_t n __{  this->m.owner = this;  this->m.base  = calloc(n, sizeof(gType1));  ++OBJECT.total;}voidmethodDecl_(initRef) gType1 *const t __{  this->m.owner = NULL;  this->m.base  = t;}gType1 constconstMethodDecl(*const_base){  return this->m.base;}gType1methodDecl(*base){  return this->m.base;}ABSTRACTCLASS_IMPLEMENTATION  /* init total */  0,  methodName(numBlock),  methodName(init),  methodName(initRef),  methodName(const_base),  methodName(base)ENDOF_IMPLEMENTATION

⌨️ 快捷键说明

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