BaseKeySortedVector< T, T_key > Class Template Reference

#include <NodeVector.h>

List of all members.


Detailed Description

template<class T, class T_key>
class BaseKeySortedVector< T, T_key >

A STL-vector that supports inserts sorted by an OverlayKey found somewhere in the type.

Author:
Sebastian Mies


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
 ~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.

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


Member Typedef Documentation

template<class T, class T_key>
typedef vector<T>::iterator BaseKeySortedVector< T, T_key >::iterator

iterator for this vector

template<class T, class T_key>
typedef vector<T>::const_iterator BaseKeySortedVector< T, T_key >::const_iterator

read-only iterator for this vector


Constructor & Destructor Documentation

template<class T, class T_key>
BaseKeySortedVector< T, T_key >::BaseKeySortedVector ( uint16_t  maxSize = 0,
const Comparator< OverlayKey > *  comparator = NULL 
) [inline]

constructor

Parameters:
maxSize maximum nodes this vector holds
comparator OverlayKey Comparator for this vector
00085                                                                            :
00086     vector<T>(),
00087     comparator(comparator),
00088     maxSize(maxSize) {};

template<class T, class T_key>
BaseKeySortedVector< T, T_key >::~BaseKeySortedVector (  )  [inline]

destructor

00093 {};


Member Function Documentation

template<class T, class T_key>
bool BaseKeySortedVector< T, T_key >::isAddable ( const T &  element  )  const [inline]

indicates if an object of type T can be added to the NodeVector

Parameters:
element the element to add
Returns:
true if element can be added to the NodeVector, false otherwise
00110     {
00111         return( vector<T>::size() != maxSize ||
00112                 (comparator && ( comparator->compare( T_key::key(element),
00113                                                       T_key::key(vector<T>::back()) ) < 0 )));
00114     };

template<class T, class T_key>
bool BaseKeySortedVector< T, T_key >::isFull (  )  const [inline]

indicates if NodeVector holds maxSize nodes

Returns:
true if the actual size of NodeVector has reached its maxSize, false otherwise
00122     {
00123         return(vector<T>::size() == maxSize);
00124     };

template<class T, class T_key>
bool BaseKeySortedVector< T, T_key >::isEmpty (  )  const [inline]

indicates if NodeVector holds at least one node

Returns:
true if NodeVector does not hold any node, false otherwise
00132     {
00133         return(vector<T>::size() == 0);
00134     };

template<class T, class T_key>
bool BaseKeySortedVector< T, T_key >::add ( const T &  element  )  [inline]

adds an element of type T in increasing order to the NodeVector

Parameters:
element the element to add
Returns:
true if if adding was successful, false otherwise
00143     {
00144         // check if handle is addable
00145         if ( isAddable(element) ) { // yes ->
00146 
00147             // add handle to the appropriate position
00148             if ( ( vector<T>::size() != 0 ) && comparator ) {
00149                 iterator i;
00150                 for ( i = vector<T>::begin();
00151                     i != vector<T>::end(); i++ )
00152                     if ( comparator->compare(T_key::key(element),
00153                                              T_key::key(*i)) < 0 ) {
00154                         vector<T>::insert( i, element );
00155                         break;
00156                     }
00157                 if (i == vector<T>::end()) {
00158                     push_back(element);
00159                 }
00160             } else {
00161                 push_back(element);
00162             }
00163 
00164             // adjust size
00165             if ((maxSize != 0) && (vector<T>::size() > maxSize)) {
00166                 vector<T>::resize(maxSize);
00167             }
00168 
00169             return true;
00170         } else {
00171             return false;
00172         }
00173 
00174     };

template<class T, class T_key>
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.

Parameters:
key the OverlayKey to find
Returns:
true, if the vector contains the key
00183                                                        {
00184         for ( const_iterator i = vector<T>::begin(); 
00185             i != vector<T>::end(); i++) {
00186             if (T_key::key(*i) == key) return true;
00187         }
00188         return false;
00189     }

template<class T, class T_key>
const T& BaseKeySortedVector< T, T_key >::find ( const OverlayKey key  )  const [inline]

searches for an OverlayKey in NodeVector

Parameters:
key the OverlayKey to find
Returns:
the UNSPECIFIED_ELEMENT if there is no element with the defined key, the found element of type T otherwise
00199     {
00200         for ( const_iterator i = vector<T>::begin(); 
00201             i != vector<T>::end(); i++) {
00202             if (T_key::key(*i) == key) return *i;
00203         }
00204         return UNSPECIFIED_ELEMENT;
00205     };

template<class T, class T_key>
iterator BaseKeySortedVector< T, T_key >::findIterator ( const OverlayKey key  )  [inline]

Searches for an OberlayKey in a NodeVector and returns an appropriate iterator.

Parameters:
key The key to search
Returns:
iterator The iterator
00215     {
00216         iterator i;
00217         for ( i = vector<T>::begin(); i != vector<T>::end(); i++)
00218             if (T_key::key(*i) == key) break;
00219         return i;
00220     }


Member Data Documentation

template<class T, class T_key>
const Comparator<OverlayKey>* BaseKeySortedVector< T, T_key >::comparator [private]

the OverlayKey Comparator for this vector

template<class T, class T_key>
uint16_t BaseKeySortedVector< T, T_key >::maxSize [private]

maximum nodes this vector holds

template<class T, class T_key>
const T BaseKeySortedVector< T, T_key >::UNSPECIFIED_ELEMENT [static]

unspecified element of type T


The documentation for this class was generated from the following file:
Generated on Tue Jul 24 16:51:17 2007 for ITM OverSim by  doxygen 1.5.1