diff options
Diffstat (limited to 'src/kernel/lib/earray.h')
-rw-r--r-- | src/kernel/lib/earray.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/kernel/lib/earray.h b/src/kernel/lib/earray.h new file mode 100644 index 0000000..b6d0a55 --- /dev/null +++ b/src/kernel/lib/earray.h @@ -0,0 +1,35 @@ +#ifndef DEF_EARRAY_H +#define DEF_EARRAY_H + +#include <sched.h> + +/* + * This class implements a simple extensible array structure. + * An entry with a 0 value is considered free and can be allocated. + * The array will free as much space when elements are removed. + */ + +template <typename T> +struct earray { + private: + int ref_vect_init_len; + int vect_len; // NEVER CHANGE THIS AFTER INITIALISATION!!!! + + int ref_vect_len; + int elements; + T ***data; + + mutex_t mutex; + + public: + earray(int refvectinitlen, int vectlen); + ~earray(); + + int add(T* ptr); // return element number or -1 if fail + T* at(int num); // returns 0 when nothing + void set(int num, T* ptr); +}; + + + +#endif |