summaryrefslogtreecommitdiffstats
path: root/src/core/templates.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/templates.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/core/templates.h b/src/core/templates.h
index 51a24e4c..4f7b8490 100644
--- a/src/core/templates.h
+++ b/src/core/templates.h
@@ -17,6 +17,16 @@ public:
void clear(void){
this->allocPtr = 0;
}
+ int getIndex(T *item){
+ assert(item >= &this->store[0]);
+ assert(item < &this->store[n]);
+ return item - this->store;
+ }
+ T *getItem(int index){
+ assert(index >= 0);
+ assert(index < n);
+ return &this->store[index];
+ }
};
template<typename T, typename U = T>
@@ -35,6 +45,7 @@ class CPool
public:
CPool(int size){
+ // TODO: use new here
m_entries = (U*)malloc(sizeof(U)*size);
m_flags = (Flags*)malloc(sizeof(Flags)*size);
m_size = size;
@@ -44,6 +55,7 @@ public:
m_flags[i].free = 1;
}
}
+
~CPool() {
Flush();
}
@@ -119,7 +131,7 @@ public:
// TODO: the cast is unsafe
return (int)((U*)entry - m_entries);
}
- int GetNoOfUsedSpaces(void){
+ int GetNoOfUsedSpaces(void) const{
int i;
int n = 0;
for(i = 0; i < m_size; i++)