#include <NodeVector.h>
Public Types | |
typedef vector< T > ::iterator | iterator |
iterator for this vector | |
typedef vector< T > ::const_iterator | const_iterator |
read-only iterator for this vector | |
Public Member Functions | |
BaseKeySortedVector (uint16_t maxSize=0, const Comparator< OverlayKey > *comparator=NULL) | |
constructor | |
virtual | ~BaseKeySortedVector () |
destructor | |
bool | isAddable (const T &element) const |
indicates if an object of type T can be added to the NodeVector | |
bool | isFull () const |
indicates if NodeVector holds maxSize nodes | |
bool | isEmpty () const |
indicates if NodeVector holds at least one node | |
bool | add (const T &element) |
adds an element of type T in increasing order to the NodeVector | |
const bool | contains (const OverlayKey &key) const |
Searches for an OverlayKey in NodeVector and returns true, if it is found. | |
const T & | find (const OverlayKey &key) const |
searches for an OverlayKey in NodeVector | |
iterator | findIterator (const OverlayKey &key) |
Searches for an OberlayKey in a NodeVector and returns an appropriate iterator. | |
void | downsizeTo (const uint maxElements) |
Downsize the vector to a maximum of maxElements. | |
Static Public Attributes | |
static const T | UNSPECIFIED_ELEMENT |
unspecified element of type T | |
Private Attributes | |
const Comparator < OverlayKey > * | comparator |
the OverlayKey Comparator for this vector | |
uint16_t | maxSize |
maximum nodes this vector holds |
typedef vector<T>::iterator BaseKeySortedVector< T, T_key >::iterator |
iterator for this vector
typedef vector<T>::const_iterator BaseKeySortedVector< T, T_key >::const_iterator |
read-only iterator for this vector
BaseKeySortedVector< T, T_key >::BaseKeySortedVector | ( | uint16_t | maxSize = 0 , |
|
const Comparator< OverlayKey > * | comparator = NULL | |||
) | [inline] |
constructor
maxSize | maximum nodes this vector holds | |
comparator | OverlayKey Comparator for this vector |
00108 : 00109 vector<T>(), 00110 comparator(comparator), 00111 maxSize(maxSize) {};
virtual BaseKeySortedVector< T, T_key >::~BaseKeySortedVector | ( | ) | [inline, virtual] |
bool BaseKeySortedVector< T, T_key >::isAddable | ( | const T & | element | ) | const [inline] |
indicates if an object of type T can be added to the NodeVector
element | the element to add |
00133 { 00134 if (maxSize == 0) { 00135 return false; 00136 } 00137 00138 return( vector<T>::size() != maxSize || 00139 (comparator && ( comparator->compare( T_key::key(element), 00140 T_key::key(vector<T>::back()) ) < 0 ))); 00141 };
bool BaseKeySortedVector< T, T_key >::isFull | ( | ) | const [inline] |
indicates if NodeVector holds maxSize nodes
00149 { 00150 return(vector<T>::size() == maxSize); 00151 };
bool BaseKeySortedVector< T, T_key >::isEmpty | ( | ) | const [inline] |
indicates if NodeVector holds at least one node
00159 { 00160 return(vector<T>::size() == 0); 00161 };
bool BaseKeySortedVector< T, T_key >::add | ( | const T & | element | ) | [inline] |
adds an element of type T in increasing order to the NodeVector
element | the element to add |
00170 { 00171 // check if handle is addable 00172 if ( isAddable(element) ) { // yes -> 00173 00174 // add handle to the appropriate position 00175 if ( ( vector<T>::size() != 0 ) && comparator ) { 00176 iterator i; 00177 for ( i = vector<T>::begin(); 00178 i != vector<T>::end(); i++ ) { 00179 if ( comparator->compare(T_key::key(element), 00180 T_key::key(*i)) <= 0 ) { 00181 if (T_key::key(element) != T_key::key(*i)) 00182 vector<T>::insert( i, element ); 00183 break; 00184 } 00185 } 00186 if (i == vector<T>::end()) { 00187 push_back(element); 00188 } 00189 } else { 00190 push_back(element); 00191 } 00192 00193 // adjust size 00194 if ((maxSize != 0) && (vector<T>::size() > maxSize)) { 00195 vector<T>::resize(maxSize); 00196 } 00197 00198 return true; 00199 } else { 00200 return false; 00201 } 00202 00203 };
const bool BaseKeySortedVector< T, T_key >::contains | ( | const OverlayKey & | key | ) | const [inline] |
Searches for an OverlayKey in NodeVector and returns true, if it is found.
key | the OverlayKey to find |
00212 { 00213 for ( const_iterator i = vector<T>::begin(); 00214 i != vector<T>::end(); i++) { 00215 if (T_key::key(*i) == key) return true; 00216 } 00217 return false; 00218 }
const T& BaseKeySortedVector< T, T_key >::find | ( | const OverlayKey & | key | ) | const [inline] |
searches for an OverlayKey in NodeVector
key | the OverlayKey to find |
00228 { 00229 for ( const_iterator i = vector<T>::begin(); 00230 i != vector<T>::end(); i++) { 00231 if (T_key::key(*i) == key) return *i; 00232 } 00233 return UNSPECIFIED_ELEMENT; 00234 };
iterator BaseKeySortedVector< T, T_key >::findIterator | ( | const OverlayKey & | key | ) | [inline] |
Searches for an OberlayKey in a NodeVector and returns an appropriate iterator.
key | The key to search |
00244 { 00245 iterator i; 00246 for ( i = vector<T>::begin(); i != vector<T>::end(); i++) 00247 if (T_key::key(*i) == key) break; 00248 return i; 00249 }
void BaseKeySortedVector< T, T_key >::downsizeTo | ( | const uint | maxElements | ) | [inline] |
Downsize the vector to a maximum of maxElements.
maxElements | The maximum number of elements after downsizing |
00257 { 00258 if (vector<T>::size() > maxElements) { 00259 vector<T>::erase(vector<T>::begin()+maxElements, vector<T>::end()); 00260 } 00261 }
const Comparator<OverlayKey>* BaseKeySortedVector< T, T_key >::comparator [private] |
the OverlayKey Comparator for this vector
uint16_t BaseKeySortedVector< T, T_key >::maxSize [private] |
maximum nodes this vector holds
const T BaseKeySortedVector< T, T_key >::UNSPECIFIED_ELEMENT [inline, static] |
unspecified element of type T
an unspecified element of the NodeVector