]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Vector.hpp
Use SG_LOG for debugging messages from the YASim helicopter model.
[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     int   add(void* p);
14     void* get(int i);
15     void  set(int i, void* p);
16     int   size();
17 private:
18     void realloc();
19
20     int _nelem;
21     int _sz;
22     void** _array;
23 };
24
25 inline Vector::Vector()
26 {
27     _nelem = 0;
28     _sz = 0;
29     _array = 0;
30 }
31
32 inline int Vector::add(void* p)
33 {
34     if(_nelem == _sz)
35         realloc();
36     _array[_sz] = p;
37     return _sz++;
38 }
39
40 inline void* Vector::get(int i)
41 {
42     return _array[i];
43 }
44
45 inline void Vector::set(int i, void* p)
46 {
47     _array[i] = p;
48 }
49
50 inline int Vector::size()
51 {
52     return _sz;
53 }
54
55 inline void Vector::realloc()
56 {
57     _nelem = 2*_nelem + 1;
58     void** array = new void*[_nelem];
59     for(int i=0; i<_sz; i++)
60         array[i] = _array[i];
61     delete[] _array;
62     _array = array;
63 }
64
65 #endif // _VECTOR_HPP