- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Mers::Utils::Containers::Vector< T * > Class Template Reference

`#include <Vector.h>`

Inheritance diagram for Mers::Utils::Containers::Vector< T * >:

[legend]
Collaboration diagram for Mers::Utils::Containers::Vector< T * >:

[legend]
List of all members.

## Public Types
typedef T *& | reference
typedef VectorImpl::size_type | size_type
typedef VectorImpl::difference_type | difference_type
typedef VectorIterator< Vector< T * >, reference > | iterator
typedef VectorIterator< const Vector< T * >, const T * > | const_iterator
## Public Member Functions
| Vector (ObjectType myObjectType=Unknown)
| Creates a new, empty vector.
| Vector (size_type count, ObjectType myObjectType=Unknown)
| Creates an empty vector with reserved space for <count> elements.
| Vector (const Vector< T * > &other)
| Creates a (deep) copy of the vector and the objects in it.
| ~Vector ()
| Deletes this vector and the objects in it.
reference | operator[] (size_type index)
reference | operator[] (int index)
const T * | operator[] (size_type index) const
const T * | operator[] (int index) const
Vector< T * > & | operator+= (const Vector< T * > &other)
Vector< T * > & | operator+= (T *ptr)
reference | at (size_type index)
const T * | at (size_type index) const
iterator | begin ()
const_iterator | begin () const
iterator | end ()
const_iterator | end () const
size_type | size () const
| Returns the number of elements in this vector.
size_type | maxSize () const
| Returns the largest possible size of the vector.
size_type | max_size () const
| Same as maxSize().
size_type | capacity () const
bool | empty () const
| Returns true if the vector has no elements. Same as size()==0.
void | reserve (size_type n)
reference | front ()
| Returns a reference to the first element in the vector.
const T * | front () const
| Returns the first element in the vector.
reference | back ()
| Returns a reference to the last element in the vector.
const T * | back () const
| Returns the last element in the vector.
virtual void | pushBack (T *ptr)
void | push_back (T *ptr)
T * | popBack ()
T * | pop_back ()
| Same as popBack().
virtual void | insert (size_type index, T *ptr)
virtual void | insert (size_type index, const Vector< T * > &other)
void | erase (size_type index)
void | erase (size_type first, size_type last)
void | clear ()
| Clear and delete the contained objects.
void | resize (size_t newSize)
Vector< T * > * | duplicate () const
virtual void | print (std::ostream &out) const
virtual void | print (std::ostream &out, char const *separator) const

## Detailed Description

### template<class T>
class Mers::Utils::Containers::Vector< T * >

An STL-like vector with dynamic resizing and additional capabilities for classes in the Base model framework. Each element in Vector is a pointer to a subclass of Object.

Vector provides the following capabilities in addition to those in the STL vector:

- index checking
- deep copy
- automatic deletion of objects owned by this vector
- printing of the vector and its elements to an output stream
- deep comparison
- looking up the objects by their name (if applicable)
- common code base for all Object descendants

Usage:

     Vector<Type *> v;

The only requirement is that Type is a (non-const) descendant of Object.

This template serves as wrapper to the VectorImpl class and the underlying implementation of the STL vector to provide type safety. Only the functions specific for each templated class (deep comparison, looking up objects by their name) are implemented separately. All access through this class is range checked. The out_of_range exception is thrown if the index is not valid for this vector.

Finally, for const Vector objects, the template only provides a const access to the objects in the vector.This is where Vector differs from the STL vector. The STL vector simply prevents modifications of pointers in the vector. In Vector, we prevent modifications of the underlying objects, pointed to by the elements in the vector.

Definition at line 368 of file Vector.h.

## Member Typedef Documentation

template<class T>

typedef T* & Mers::Utils::Containers::Vector< T * >::reference

Reference to an element (pointer) in the vector.

Definition at line 381 of file Vector.h.

template<class T>

typedef VectorImpl::size_type Mers::Utils::Containers::Vector< T * >::size_type

Type of subscripts, element counts, etc. This type is guaranteed to be unsigned int.

Definition at line 387 of file Vector.h.

template<class T>

typedef VectorImpl::difference_type Mers::Utils::Containers::Vector< T * >::difference_type

Type of difference between iterators. This type is guaranteed to be int.

Definition at line 393 of file Vector.h.

template<class T>

typedef VectorIterator<Vector<T*>, reference> Mers::Utils::Containers::Vector< T * >::iterator

Iterator used to iterate through a vector.

Definition at line 398 of file Vector.h.

template<class T>

typedef VectorIterator<const Vector<T*>, const T*> Mers::Utils::Containers::Vector< T * >::const_iterator

Iterator used to iterate through a const vector. When dereferenced (operator*()), returns a pointer to the contained object that prevents its modification.

Definition at line 405 of file Vector.h.

## Member Function Documentation

template<class T>

reference Mers::Utils::Containers::Vector< T * >::operator[] | ( | size_type | index | ) | `[inline]`

Returns a reference to the element at the specified index.

Returns:
  the element requested if index is in range

Definition at line 434 of file Vector.h.

template<class T>

reference Mers::Utils::Containers::Vector< T * >::operator[] | ( | int | index | ) | `[inline]`

Returns a reference to the element at the specified index.

Returns:
  the element requested if index is in range, otherwise NULL

Definition at line 443 of file Vector.h.

template<class T>

const T* Mers::Utils::Containers::Vector< T * >::operator[] | ( | size_type | index | ) | const`[inline]`

Returns a const pointer to the object at the specified index.

Returns:
  the element requested if index is in range, otherwise NULL

Definition at line 452 of file Vector.h.

template<class T>

const T* Mers::Utils::Containers::Vector< T * >::operator[] | ( | int | index | ) | const`[inline]`

Returns a const pointer to the object at the specified index.

Returns:
  the element requested if index is in range, otherwise NULL

Definition at line 461 of file Vector.h.

template<class T>

Vector<T*>& Mers::Utils::Containers::Vector< T * >::operator+= | ( | const Vector< T * > & | other | ) | `[inline]`

Appends a copy of the data from the other vector. This operation is expensive for large data structures.

Parameters:

  | other | the vector supplying the data for this vector

Returns:
  this vector

Definition at line 472 of file Vector.h.

template<class T>

Vector<T*>& Mers::Utils::Containers::Vector< T * >::operator+= | ( | T * | ptr | ) | `[inline]`

Appends a the specified object at the end of this vector (i.e., does not make a copy).

Parameters:

  | ptr | pointer to the added object

Returns:
  this vector

Definition at line 484 of file Vector.h.

template<class T>

reference Mers::Utils::Containers::Vector< T * >::at | ( | size_type | index | ) | `[inline]`

Returns a reference to the element at the specified index.

Returns:
  the element requested if index is in range

Definition at line 498 of file Vector.h.

template<class T>

const T* Mers::Utils::Containers::Vector< T * >::at | ( | size_type | index | ) | const`[inline]`

Returns a const pointer to the object at the specified index.

Returns:
  the element requested if index is in range, otherwise NULL

Definition at line 507 of file Vector.h.

template<class T>

iterator Mers::Utils::Containers::Vector< T * >::begin | ( |  | ) | `[inline]`

Returns an iterator that points to the first element of this vector.

Definition at line 515 of file Vector.h.

template<class T>

const_iterator Mers::Utils::Containers::Vector< T * >::begin | ( |  | ) | const`[inline]`

Returns a const iterator that points to the first element of this vector.

Definition at line 523 of file Vector.h.

template<class T>

iterator Mers::Utils::Containers::Vector< T * >::end | ( |  | ) | `[inline]`

Returns an iterator that points to one element past the end of the vector.

Definition at line 531 of file Vector.h.

template<class T>

const_iterator Mers::Utils::Containers::Vector< T * >::end | ( |  | ) | const`[inline]`

Returns a constant iterator that points to one element past the end of the vector.

Definition at line 540 of file Vector.h.

template<class T>

size_type Mers::Utils::Containers::Vector< T * >::capacity | ( |  | ) | const`[inline]`

Returns the number of elements, for which memory is currently allocated in this vector. This value is always grater than size().

Definition at line 566 of file Vector.h.

template<class T>

void Mers::Utils::Containers::Vector< T * >::reserve | ( | size_type | n | ) | `[inline]`

Reserves memory for the given number of elements. If capacity()>=n, this function has no effect.

Definition at line 581 of file Vector.h.

template<class T>

virtual void Mers::Utils::Containers::Vector< T * >::pushBack | ( | T * | ptr | ) | `[inline, virtual]`

Inserts the pointer at the end of the vector. The object pointed to by this element will be deleted automatically when it's removed from the vector or when the vector is deleted.

Attention:
  Change from Base model v. 1: pushBack() does not delete the object pointed to by <ptr> if it fails.

Definition at line 618 of file Vector.h.

template<class T>

void Mers::Utils::Containers::Vector< T * >::push_back | ( | T * | ptr | ) | `[inline]`

Same as pushBack(). Calls pushBack(), so overriding one will make the other one work fine, too.

Definition at line 625 of file Vector.h.

template<class T>

T* Mers::Utils::Containers::Vector< T * >::popBack | ( |  | ) | `[inline]`

Removes the last element in the vector. The element itself is not deleted. Throws out_of_range exception if the vector is empty.

Definition at line 634 of file Vector.h.

template<class T>

virtual void Mers::Utils::Containers::Vector< T * >::insert | ( | size_type | index,
|  | T * | ptr |
| ) |  |  | `[inline, virtual]`

Inserts the element at the specified index.

Parameters:

  | index | the index that the item should be inserted at
  | ptr | the pointer to the data being inserted

Definition at line 650 of file Vector.h.

template<class T>

virtual void Mers::Utils::Containers::Vector< T * >::insert | ( | size_type | index,
|  | const Vector< T * > & | other |
| ) |  |  | `[inline, virtual]`

Inserts a copy of the objects in the specified vector at the given position in this vector.

Parameters:

  | index | the position where the copied objects are inserted
  | other | the vector that contains the copied objects

Definition at line 661 of file Vector.h.

template<class T>

void Mers::Utils::Containers::Vector< T * >::erase | ( | size_type | index | ) | `[inline]`

Removes the element at the specified index and deletes the object it points to.

Definition at line 671 of file Vector.h.

template<class T>

void Mers::Utils::Containers::Vector< T * >::erase | ( | size_type | first,
|  | size_type | last |
| ) |  |  | `[inline]`

Removes the elements in the specified range [first;last) and deletes the objects they point to.

Definition at line 680 of file Vector.h.

template<class T>

void Mers::Utils::Containers::Vector< T * >::resize | ( | size_t | newSize | ) | `[inline]`

Resizes the vector to the specified size. If the vector is shrinking, elements at the end of the vector are deleted. If the vector is growing, the new elements are initialized to NULL.

Parameters:

  | newSize | the new size of the vector.

Definition at line 696 of file Vector.h.

References Mers::Utils::Containers::VectorImpl::resize().

Here is the call graph for this function:

template<class T>

Vector<T*>* Mers::Utils::Containers::Vector< T * >::duplicate | ( |  | ) | const`[inline, virtual]`

Creates a deep copy of this vector and the objects in it.

Exceptions:

  | UnsupportedOperationException | if one or more objects in this vector cannot be copied.

Todo:
  can we provide memory clean-up guarantees?

Reimplemented from Mers::Utils::Lang::Object.

Definition at line 707 of file Vector.h.

template<class T>

virtual void Mers::Utils::Containers::Vector< T * >::print | ( | std::ostream & | out | ) | const`[inline, virtual]`

Prints out the elements of the vector, one per line. The default behavior is to call the method print(out, separator) with separator==NULL. Override this function and/or print(out, separator) to get a different behavior.

Parameters:

  | out | the ostream being written to

Implements Mers::Utils::Lang::Object.

Definition at line 722 of file Vector.h.

template<class T>

virtual void Mers::Utils::Containers::Vector< T * >::print | ( | std::ostream & | out,
|  | char const * | separator |
| ) |  |  | const`[inline, virtual]`

Prints out the elements of the vector, separated by the given string.

Parameters:

  | out | the ostream being written to
  | seperator | the seperator used between the elements

Reimplemented from Mers::Utils::Containers::VectorImpl.

Definition at line 733 of file Vector.h.

References Mers::Utils::Containers::VectorImpl::print().

Here is the call graph for this function:

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

- /Users/fpy/titan-1-5-MBARI/Mers/Utils/Containers/Vector.h