]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Vector.hpp
Fix bug 141, by ensuring certain subsystems are assigned to the 'post FDM' group...
[flightgear.git] / src / FDM / YASim / Vector.hpp
1 #ifndef _VECTOR_HPP
2 #define _VECTOR_HPP
3
4 //
5 // Excruciatingly simple vector-of-pointers class.  Easy & useful.
6 // No support for addition of elements anywhere but at the end of the
7 // list, nor for removal of elements.  Does not delete (or interpret
8 // in any way) its contents.
9 //
10 class Vector {
11 public:
12     Vector();
13     ~Vector();
14     int   add(void* p);
15     void* get(int i);
16     void  set(int i, void* p);
17     int   size();
18 private:
19     void realloc();
20
21     int _nelem;
22     int _sz;
23     void** _array;
24 };
25
26 inline Vector::Vector()
27 {
28     _nelem = 0;
29     _sz = 0;
30     _array = 0;
31 }
32
33 inline Vector::~Vector()
34 {
35     delete[] _array;
36 }
37
38 inline int Vector::add(void* p)
39 {
40     if(_nelem == _sz)
41         realloc();
42     _array[_sz] = p;
43     return _sz++;
44 }
45
46 inline void* Vector::get(int i)
47 {
48     return _array[i];
49 }
50
51 inline void Vector::set(int i, void* p)
52 {
53     _array[i] = p;
54 }
55
56 inline int Vector::size()
57 {
58     return _sz;
59 }
60
61 inline void Vector::realloc()
62 {
63     _nelem = 2*_nelem + 1;
64     void** array = new void*[_nelem];
65     for(int i=0; i<_sz; i++)
66         array[i] = _array[i];
67     delete[] _array;
68     _array = array;
69 }
70
71 #endif // _VECTOR_HPP