aboutsummaryrefslogtreecommitdiff
path: root/vector.inc.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-22 14:39:34 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-22 14:39:34 +0100
commita608b90f8c146430803871e20d043b60a278248b (patch)
tree194e6e80cd5403cc64d1e4915f9be45a462d3918 /vector.inc.h
parentstrbuf (diff)
downloadcalp-a608b90f8c146430803871e20d043b60a278248b.tar.gz
calp-a608b90f8c146430803871e20d043b60a278248b.tar.xz
rest
Diffstat (limited to 'vector.inc.h')
-rw-r--r--vector.inc.h68
1 files changed, 41 insertions, 27 deletions
diff --git a/vector.inc.h b/vector.inc.h
index 2b23eadc..76dd7ee4 100644
--- a/vector.inc.h
+++ b/vector.inc.h
@@ -1,51 +1,65 @@
-#ifndef TYPE
-#error "Set TYPE before including self file"
-#else
+#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)) {
- self->length = 0;
- self->alloc = 1;
- self->items = (TYPE**) calloc(sizeof(*self->items), self->alloc);
- return 0;
+// INIT_F(VECT(TYPE)) {
+template <class T>
+vect<T>::vect () {
+ this->length = 0;
+ this->alloc = 1;
+ this->items = (T**) calloc(sizeof(*this->items), this->alloc);
}
-FREE_F(VECT(TYPE)) {
- for (unsigned int i = 0; i < self->length; i++) {
- FFREE(TYPE, self->items[i]);
+template <class T>
+vect<T>::~vect() {
+// FREE_F(VECT(TYPE)) {
+ for (unsigned int i = 0; i < this->length; i++) {
+ delete this->items[i];
+ // FFREE(TYPE, this->items[i]);
}
- free(self->items);
- return 0;
+ free(this->items);
}
-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);
+template <class T>
+int vect<T>::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);
}
- self->items[self->length] = t;
- ++self->length;
+ this->items[this->length] = t;
+ ++this->length;
return 0;
}
-TYPE* GET(VECT(TYPE))(VECT(TYPE)* self, unsigned int idx) {
- if (idx >= self->length) {
+template <class T>
+T* vect<T>::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 self->items[idx];
+ return this->items[idx];
}
-int EMPTY(VECT(TYPE))(VECT(TYPE)* self) {
- return self->length == 0;
+template <class T>
+int vect<T>::empty () {
+//int EMPTY(VECT(TYPE))(VECT(TYPE)* this) {
+ return this->length == 0;
}
-unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* self) {
- return self->length;
+template <class T>
+unsigned int vect<T>::size () {
+//unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* this) {
+ return this->length;
}
-#endif /* TYPE */
+// #endif /* TYPE */