From 33fa5b5d0c512c72c1d50b9420a36431cd10eb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 18 Feb 2019 22:39:56 +0100 Subject: Made to compile as C++. --- vector.inc.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'vector.inc.h') diff --git a/vector.inc.h b/vector.inc.h index f6d1c796..2b23eadc 100644 --- a/vector.inc.h +++ b/vector.inc.h @@ -1,51 +1,51 @@ #ifndef TYPE -#error "Set TYPE before including this file" +#error "Set TYPE before including self file" #else #include "macro.h" #include "err.h" INIT_F(VECT(TYPE)) { - this->length = 0; - this->alloc = 1; - this->items = calloc(sizeof(*this->items), this->alloc); + self->length = 0; + self->alloc = 1; + self->items = (TYPE**) calloc(sizeof(*self->items), self->alloc); return 0; } FREE_F(VECT(TYPE)) { - for (unsigned int i = 0; i < this->length; i++) { - FFREE(TYPE, this->items[i]); + for (unsigned int i = 0; i < self->length; i++) { + FFREE(TYPE, self->items[i]); } - free(this->items); + free(self->items); return 0; } -int PUSH(VECT(TYPE))(VECT(TYPE)* this, TYPE* t) { - if (this->length + 1 > this->alloc) { - this->alloc <<= 1; - this->items = realloc(this->items, sizeof(*this->items) * this->alloc); +int PUSH(VECT(TYPE))(VECT(TYPE)* self, TYPE* t) { + if (self->length + 1 > self->alloc) { + self->alloc <<= 1; + self->items = (TYPE**) realloc(self->items, sizeof(*self->items) * self->alloc); } - this->items[this->length] = t; - ++this->length; + self->items[self->length] = t; + ++self->length; return 0; } -TYPE* GET(VECT(TYPE))(VECT(TYPE)* this, unsigned int idx) { - if (idx >= this->length) { +TYPE* GET(VECT(TYPE))(VECT(TYPE)* self, unsigned int idx) { + if (idx >= self->length) { ERR("Index out of range"); return NULL; } - return this->items[idx]; + return self->items[idx]; } -int EMPTY(VECT(TYPE))(VECT(TYPE)* this) { - return this->length == 0; +int EMPTY(VECT(TYPE))(VECT(TYPE)* self) { + return self->length == 0; } -unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* this) { - return this->length; +unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* self) { + return self->length; } #endif /* TYPE */ -- cgit v1.2.3