00001
00026 #ifndef _BODY2D_
00027 #define _BODY2D_
00028
00029 #include <Vector2D.h>
00030 #include <disableWarnings.h>
00031
00032 namespace sonus
00033 {
00046 template<class T>
00047 class Body2D
00048 {
00049
00050 public:
00051
00056 Body2D();
00057
00063 Body2D( int length );
00064
00068 ~Body2D();
00069
00076 int push( T* v );
00077
00083 T* pop();
00084
00092 T* getElementAt( int index );
00093
00097 void clear();
00098
00105 int getIndexOf( T* v );
00106
00112 int getLength();
00113
00119 int getSize();
00120
00121
00122 private:
00123
00124 int count;
00125 int length;
00126 T** data;
00127
00128 };
00129
00130 template<class T>
00131 Body2D<T>::Body2D()
00132 {
00133 this->count = 0;
00134 this->length = 10;
00135 this->data = new T*[ length ];
00136 }
00137
00138 template<class T>
00139 Body2D<T>::Body2D( int length )
00140 {
00141 this->count = 0;
00142 this->length = length;
00143 this->data = new T*[ length ];
00144 }
00145
00146 template<class T>
00147 Body2D<T>::~Body2D()
00148 {
00149 delete this->data;
00150 }
00151
00152 template<class T>
00153 int Body2D<T>::push( T* v )
00154 {
00155 if ( count < length )
00156 {
00157 data[ count++ ] = v;
00158 return count;
00159 }
00160 else
00161 {
00162 return -1;
00163 }
00164 }
00165
00166 template<class T>
00167 T* Body2D<T>::pop()
00168 {
00169 T* v = data[ --count ];
00170 data[ count ] = ( T* )0;
00171 return v;
00172 }
00173
00174 template<class T>
00175 T* Body2D<T>::getElementAt( int index )
00176 {
00177 if ( index <= count )
00178 {
00179 return data[ index ];
00180 }
00181 else
00182 {
00183 return ( T* )0;
00184 }
00185 }
00186
00187 template<class T>
00188 void Body2D<T>::clear()
00189 {
00190 for ( int i = 0; i < count; i++ )
00191 {
00192 data[ i ] = ( T* )0;
00193 }
00194 count = 0;
00195 }
00196
00197 template<class T>
00198 int Body2D<T>::getIndexOf( T* v )
00199 {
00200 for ( int i = 0; i < count; i++ )
00201 {
00202 if ( data[ i ] == v )
00203 {
00204 return i;
00205 }
00206 }
00207 return -1;
00208 }
00209
00210 template<class T>
00211 int Body2D<T>::getLength()
00212 {
00213 return length;
00214 }
00215
00216 template<class T>
00217 int Body2D<T>::getSize()
00218 {
00219 return count;
00220 }
00221
00222 }
00223
00224 #endif