#ifndef HEADER_ONLY #error "Only include this file from the appropriate header." #endif // #ifndef TYPE // #error "Set TYPE before including this file" // #else #include "macro.h" #include "err.h" // INIT_F(VECT(TYPE)) { template vect::vect () { this->length = 0; this->alloc = 1; this->items = (T**) calloc(sizeof(*this->items), this->alloc); } template vect::~vect() { // FREE_F(VECT(TYPE)) { for (unsigned int i = 0; i < this->length; i++) { delete this->items[i]; // FFREE(TYPE, this->items[i]); } free(this->items); } template int vect::push (T* t) { // int PUSH(VECT(TYPE))(VECT(TYPE)* this, TYPE* t) { if (this->length + 1 > this->alloc) { this->alloc <<= 1; this->items = (T**) realloc(this->items, sizeof(*this->items) * this->alloc); } this->items[this->length] = t; ++this->length; return 0; } template T* vect::operator[] (unsigned int idx) { // TYPE* GET(VECT(TYPE))(VECT(TYPE)* this, unsigned int idx) { if (idx >= this->length) { ERR("Index out of range"); return NULL; } return this->items[idx]; } template int vect::empty () { //int EMPTY(VECT(TYPE))(VECT(TYPE)* this) { return this->length == 0; } template unsigned int vect::size () { //unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* this) { return this->length; } // #endif /* TYPE */