Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgVectorOf< T > Class Template Reference

#include <SgVector.h>

Inheritance diagram for SgVectorOf< T >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class T>
class SgVectorOf< T >

Typed vector of pointers to T.

Pointers cannot be 0.

Definition at line 365 of file SgVector.h.

Public Member Functions

T * operator[] (int index) const
 Return const reference to element.
T * Back () const
 Returns the last element of the vector.
bool Contains (const T *element) const
void Include (const T *element)
 Push elt to the back of the vector unless it is already included.
bool Exclude (const T *element)
void Exclude (const SgVectorOf< T > &vector)
T * Front () const
 Returns the first element of the vector.
bool Insert (const T *element)
void PushFront (const T *element)
void PushBack (const T *element)
T * PopFront ()
 Remove element[0] of the vector.
void *& operator[] (int index)
 Return reference to element.
bool operator== (const SgVector< void * > &rhs) const
 Compare whether the contents of two vectors are identical.
bool operator!= (const SgVector &rhs) const
 Compare whether the contents of two vectors are not identical.
void * BackAndPop ()
void Clear ()
 Remove all elements in this vector.
void Concat (SgVector< void * > *tail)
 Push all of *tail to the back of this vector, and clear the *tail vector.
bool Contains (const void *&elt) const
 Check if element is in vector.
void DeleteAt (int index)
 delete element at specified index
bool Exclude (const void *&elt)
 Remove the first occurence of element.
void Exclude (const SgVector< void * > &vector)
 Exclude each element of vector from this vector.
int Index (const void *&elt) const
 Find position of element.
void Include (const void *&elt)
 Push elt to the back of the vector only if it is not included yet.
bool Insert (const void *&elt)
 Includes the element in a ascending sorted vector at the right place.
bool IsEmpty () const
 Return whether this vector contains zero elements.
bool IsLength (int length) const
 Test whether a vector is as long as a given length.
bool IsSorted (bool ascending=true) const
 Returns whether the vector is sorted in given order.
bool IsSortedAndUnique (bool ascending=true) const
 Returns whether the vector is sorted and has no duplicates.
int Length () const
 Return the number of elements in this vector.
void LimitListLength (int limit)
 Cut off vector after at most length elements.
bool MaxLength (int length) const
 Test whether a vector is shorter than or equal to a given length.
void Merge (const SgVector< void * > &vector)
 Merges two sorted vectors into this.
bool MinLength (int length) const
 Test whether a vector is as long as or longer than a given length.
bool NonEmpty () const
 Return whether this vector contains more than zero elements.
void PopBack ()
 Remove the last element of the vector.
void PushFront (const void *&elt)
 Insert element at the beginning of the vector.
void PushBack (const void *&elt)
 Add a single element at the end of the vector.
void PushBackList (const SgVector< void * > &vector)
 Push all elements from vector to the back of this.
bool RemoveDuplicates ()
 Removes all but the first copy of each element from the vector.
void Reverse ()
void SetTo (const void *&elt)
 Clear this vector and set it to contain only elt.
void SetTo (const void **array, int count)
 Clear this vector and set it to contain the count elements from array[0] to array[count - 1].
bool SetsAreEqual (const SgVector< void * > &other) const
 Do vectors contain the same elements, possibly in different order?
void Sort ()
void SortedRemoveDuplicates ()
 remove duplicates in a sorted vector
void SwapWith (SgVector< void * > *vector)
 Swap the entire contents of this vector with *vector.
const void *& TopNth (int index) const
 Returns the Nth-last element of the vector.
void Union (const SgVector< void * > &set)
 Include all elements from set into this vector.
bool UniqueElements () const
 Check for duplicate elements.
std::vector< void * > & Vector ()
const std::vector< void * > & Vector () const

Static Private Member Functions

static void * GetVoidPtr (const T *element)
 Conversion of element pointer to non-const void pointer.


Member Function Documentation

template<class T>
T* SgVectorOf< T >::Back (  )  const

Returns the last element of the vector.

Asserts if the vector is empty.

Reimplemented from SgVector< void * >.

Definition at line 375 of file SgVector.h.

void * SgVector< void * >::BackAndPop (  )  [inherited]

Definition at line 69 of file SgVector.h.

void SgVector< void * >::Clear (  )  [inherited]

Remove all elements in this vector.

Definition at line 78 of file SgVector.h.

Referenced by SgNode::PathToRoot(), SgGameReader::ReadGames(), and SgNode::ShortestPathTo().

void SgVector< void * >::Concat ( SgVector< void * > *  tail  )  [inherited]

Push all of *tail to the back of this vector, and clear the *tail vector.

Remark: this operation is efficient for lists but not so meaningful for vectors. PushBackList may be more appropriate in most cases.

bool SgVector< void * >::Contains ( const void * &  elt  )  const [inherited]

Check if element is in vector.

Returns:
true if elt is included in this vector, false if not.

template<class T>
bool SgVectorOf< T >::Contains ( const T *  element  )  const

Definition at line 380 of file SgVector.h.

Referenced by SgVectorOf< std::string >::Include().

void SgVector< void * >::DeleteAt ( int  index  )  [inherited]

delete element at specified index

void SgVector< void * >::Exclude ( const SgVector< void * > &  vector  )  [inherited]

Exclude each element of vector from this vector.

bool SgVector< void * >::Exclude ( const void * &  elt  )  [inherited]

Remove the first occurence of element.

If elt is in the vector, remove the first occurence of elt from the vector, and return true. Otherwise do nothing and return false.

template<class T>
void SgVectorOf< T >::Exclude ( const SgVectorOf< T > &  vector  ) 

Definition at line 400 of file SgVector.h.

template<class T>
bool SgVectorOf< T >::Exclude ( const T *  element  ) 

Definition at line 395 of file SgVector.h.

Referenced by SgPropList::MoveToFront(), and SgPropList::Remove().

template<class T>
T* SgVectorOf< T >::Front (  )  const

Returns the first element of the vector.

Asserts if the vector is empty.

Reimplemented from SgVector< void * >.

Definition at line 405 of file SgVector.h.

template<class T>
static void* SgVectorOf< T >::GetVoidPtr ( const T *  element  )  [static, private]

Conversion of element pointer to non-const void pointer.

Note:
Not sure if there is a better way without needing the const cast.

Definition at line 451 of file SgVector.h.

Referenced by SgVectorOf< std::string >::Contains(), SgVectorOf< std::string >::Exclude(), SgVectorOf< std::string >::Insert(), SgVectorOf< std::string >::PushBack(), and SgVectorOf< std::string >::PushFront().

void SgVector< void * >::Include ( const void * &  elt  )  [inherited]

Push elt to the back of the vector only if it is not included yet.

Definition at line 129 of file SgVector.h.

template<class T>
void SgVectorOf< T >::Include ( const T *  element  ) 

Push elt to the back of the vector unless it is already included.

Definition at line 388 of file SgVector.h.

Referenced by SgPropList::Add().

int SgVector< void * >::Index ( const void * &  elt  )  const [inherited]

Find position of element.

Returns:
The position of elt in the vector, in range 0..length-1. Returns -1 if elt is not in the vector.

bool SgVector< void * >::Insert ( const void * &  elt  )  [inherited]

Includes the element in a ascending sorted vector at the right place.

Does nothing and returns false if the element is already in the vector; returns true if the element is inserted.

Todo:
made two separate functions for efficiency, should be a template taking a compare template arg. Same for Merge() below.

template<class T>
bool SgVectorOf< T >::Insert ( const T *  element  ) 

Definition at line 410 of file SgVector.h.

bool SgVector< void * >::IsEmpty (  )  const [inherited]

Return whether this vector contains zero elements.

Definition at line 146 of file SgVector.h.

bool SgVector< void * >::IsLength ( int  length  )  const [inherited]

Test whether a vector is as long as a given length.

Definition at line 152 of file SgVector.h.

bool SgVector< void * >::IsSorted ( bool  ascending = true  )  const [inherited]

Returns whether the vector is sorted in given order.

bool SgVector< void * >::IsSortedAndUnique ( bool  ascending = true  )  const [inherited]

Returns whether the vector is sorted and has no duplicates.

int SgVector< void * >::Length (  )  const [inherited]

Return the number of elements in this vector.

Definition at line 164 of file SgVector.h.

void SgVector< void * >::LimitListLength ( int  limit  )  [inherited]

Cut off vector after at most length elements.

bool SgVector< void * >::MaxLength ( int  length  )  const [inherited]

Test whether a vector is shorter than or equal to a given length.

Definition at line 173 of file SgVector.h.

void SgVector< void * >::Merge ( const SgVector< void * > &  vector  )  [inherited]

Merges two sorted vectors into this.

Equivalent to, but faster than:

        for (SgVectorIterator<T> it(vector); it; ++it)
            Insert(*it);
        

bool SgVector< void * >::MinLength ( int  length  )  const [inherited]

Test whether a vector is as long as or longer than a given length.

Definition at line 187 of file SgVector.h.

bool SgVector< void * >::NonEmpty (  )  const [inherited]

Return whether this vector contains more than zero elements.

Definition at line 193 of file SgVector.h.

bool SgVector< void * >::operator!= ( const SgVector< void * > &  rhs  )  const [inherited]

Compare whether the contents of two vectors are not identical.

Definition at line 55 of file SgVector.h.

bool SgVector< void * >::operator== ( const SgVector< void * > &  rhs  )  const [inherited]

Compare whether the contents of two vectors are identical.

Same length, and the same elements in the same sequence.

Definition at line 49 of file SgVector.h.

void * & SgVector< void * >::operator[] ( int  index  )  [inherited]

Return reference to element.

Parameters:
index Position of element in range 0..length-1.

Definition at line 28 of file SgVector.h.

template<class T>
T* SgVectorOf< T >::operator[] ( int  index  )  const

Return const reference to element.

Parameters:
index Position of element in range 0..length-1.

Reimplemented from SgVector< void * >.

Definition at line 370 of file SgVector.h.

void SgVector< void * >::PopBack (  )  [inherited]

Remove the last element of the vector.

The vector must not be empty.

template<class T>
T* SgVectorOf< T >::PopFront (  ) 

Remove element[0] of the vector.

The vector must not be empty.

Returns:
The element[0] of the original vector before removal.
Deprecated:
Don't use this function; it is slow. Only exists for SgList compatibility.

Reimplemented from SgVector< void * >.

Definition at line 427 of file SgVector.h.

void SgVector< void * >::PushBack ( const void * &  elt  )  [inherited]

Add a single element at the end of the vector.

Definition at line 218 of file SgVector.h.

template<class T>
void SgVectorOf< T >::PushBack ( const T *  element  ) 

Definition at line 421 of file SgVector.h.

Referenced by SgPropTextList::AddStringAtPoint(), SgVectorOf< std::string >::Include(), SgNode::PathToRoot(), SgGameReader::ReadGames(), SgPropList::Remove(), SgPropTextList::SgPropTextList(), and SgNode::ShortestPathTo().

void SgVector< void * >::PushBackList ( const SgVector< void * > &  vector  )  [inherited]

Push all elements from vector to the back of this.

void SgVector< void * >::PushFront ( const void * &  elt  )  [inherited]

Insert element at the beginning of the vector.

Deprecated:
Don't use this function; it is slow. Only exists for SgList compatibility.

template<class T>
void SgVectorOf< T >::PushFront ( const T *  element  ) 

Definition at line 415 of file SgVector.h.

Referenced by SgPropList::MoveToFront().

bool SgVector< void * >::RemoveDuplicates (  )  [inherited]

Removes all but the first copy of each element from the vector.

After calling RemoveDuplicates(), UniqueElements() is true.

Returns:
true, if at least one duplicate was removed

void SgVector< void * >::Reverse (  )  [inherited]

Definition at line 232 of file SgVector.h.

Referenced by SgNode::ShortestPathTo().

bool SgVector< void * >::SetsAreEqual ( const SgVector< void * > &  other  )  const [inherited]

Do vectors contain the same elements, possibly in different order?

void SgVector< void * >::SetTo ( const void * *  array,
int  count 
) [inherited]

Clear this vector and set it to contain the count elements from array[0] to array[count - 1].

If count is zero, the vector is just cleared.

void SgVector< void * >::SetTo ( const void * &  elt  )  [inherited]

Clear this vector and set it to contain only elt.

Definition at line 238 of file SgVector.h.

void SgVector< void * >::Sort (  )  [inherited]

void SgVector< void * >::SortedRemoveDuplicates (  )  [inherited]

remove duplicates in a sorted vector

void SgVector< void * >::SwapWith ( SgVector< void * > *  vector  )  [inherited]

Swap the entire contents of this vector with *vector.

Definition at line 260 of file SgVector.h.

const void * & SgVector< void * >::TopNth ( int  index  )  const [inherited]

Returns the Nth-last element of the vector.

It must exist.

Definition at line 267 of file SgVector.h.

void SgVector< void * >::Union ( const SgVector< void * > &  set  )  [inherited]

Include all elements from set into this vector.

Appends new elements at the end of this vector.

bool SgVector< void * >::UniqueElements (  )  const [inherited]

Check for duplicate elements.

Returns:
true if there are no duplicate elements in the vector. Useful for debugging.
Todo:
speed it up

const std::vector<void * >& SgVector< void * >::Vector (  )  const [inherited]

Definition at line 293 of file SgVector.h.

std::vector<void * >& SgVector< void * >::Vector (  )  [inherited]

Definition at line 288 of file SgVector.h.


The documentation for this class was generated from the following file:


17 Jun 2010 Doxygen 1.4.7