Switch array struct to class
[satune.git] / src / Collections / array.h
1 #ifndef ARRAY_H
2 #define ARRAY_H
3
4 template<typename type>
5 class Array {
6  public:
7  Array(uint _size) :
8         array((type *)ourcalloc(1, sizeof(type) * _size)),
9                 size(_size)
10                 {
11                 }
12   
13  Array(type * _array, uint _size) :
14         array((type *)ourcalloc(1, sizeof(type) * _size)),
15                 size(_size) {
16     memcpy(array, _array, _size * sizeof(type));
17   }
18
19   ~Array() {
20     ourfree(array);
21   }
22
23   void remove(uint index) {
24     size--;
25     for (; index < size; index++) {
26       array[index] = array[index + 1];
27     }
28   }
29   
30   type get(uint index) {
31     return array[index];
32   }
33
34   void set(uint index, type item) {
35     array[index] = item;
36   }
37   
38   uint getSize() {
39     return size;
40   }
41
42   type *expose() {
43     return array;
44   }
45
46  private:
47   type *array;
48   uint size;
49 };
50
51
52 #endif