idaeim studio
 PVL: Parameter Value Language

Vectal< T > Class Template Reference

A Vectal is a vector of virtual objects of any type. More...

#include <Vectal.hh>

Inheritance diagram for Vectal< T >:

Inheritance graph
[legend]
Collaboration diagram for Vectal< T >:

Collaboration graph
[legend]

List of all members.

Classes

class  Const_Iterator
 Const_Iterator. More...
class  Const_Reverse_Iterator
 Const_Reverse_Iterator. More...
class  Iterator
 Iterator. More...
class  Reverse_Iterator
 Reverse_Iterator. More...

Public Types

typedef Base::allocator_type allocator_type
 Storage allocate type (pointer allocator).
typedef std::vector< T * > Base
 Base vector class.
typedef Base::const_iterator Base_const_iterator
 Base vector const interator.
typedef
Base::const_reverse_iterator 
Base_const_reverse_iterator
 Base vector const reverse iterator.
typedef Base::iterator Base_iterator
 Base vector iterator.
typedef Base::reverse_iterator Base_reverse_iterator
 Base vector reverse iterator.
typedef Const_Iterator const_iterator
 Vectal const iterator.
typedef const pointer const_pointer
 Element const pointer.
typedef const value_typeconst_reference
 Element const reference.
typedef Const_Reverse_Iterator const_reverse_iterator
 Vectal const reverse iterator.
typedef const value_type const_value_type
 Element const type.
typedef Base::difference_type difference_type
 Element pointer difference type.
typedef Iterator iterator
 Vectal iterator.
typedef value_typepointer
 Element pointer type.
typedef value_typereference
 Element reference.
typedef Reverse_Iterator reverse_iterator
 Vectal reverse iterator.
typedef Base::size_type size_type
 Element size (base pointer size).
typedef T value_type
 Element virtual class type.

Public Member Functions

void assign (iterator start, iterator stop)
 Assigns values from an iterator range.
void assign (size_type number, const_reference value)
 Assigns a number of value copies.
const_reference at (size_type index) const
 Gets the indexed element.
reference at (size_type index)
 Gets the indexed element.
const_reference back () const
 Gets the last element.
reference back ()
 Gets the last element.
Const_Iterator begin () const
 Gets an Iterator for this Vectal positioned at the first value.
Iterator begin ()
 Gets an Iterator for this Vectal positioned at the first value.
void clear ()
 Removes, and destroys, all values.
Const_Iterator end () const
 Gets an Iterator for this Vectal positioned after the last value.
Iterator end ()
 Gets an Iterator for this Vectal positioned after the last value.
iterator erase (iterator start, iterator stop)
iterator erase (iterator position)
 Removes a value at an iterator position.
const_reference front () const
 Gets the first element.
reference front ()
 Gets the first element.
template<typename InputIterator >
void insert (iterator position, InputIterator start, InputIterator stop)
void insert (iterator position, size_type number, const_reference value)
 Inserts a number of value copies starting at an iterator position.
iterator insert (iterator position, const_reference value)
 Inserts a value at an iterator position.
Vectaloperator= (const Vectal< value_type > &vectal)
 Assigns values from another Vectal.
const_reference operator[] (size_type index) const
 Gets the indexed element.
reference operator[] (size_type index)
 Gets the indexed element.
const_pointer peek (const_iterator position) const
 Gets a value pointer at an iterator position.
pointer peek (iterator position)
 Gets a value pointer at an iterator position.
const_pointer peek_back () const
 Gets the last value pointer.
pointer peek_back ()
 Gets the last value pointer.
iterator poke (iterator position, iterator start, iterator stop)
iterator poke (iterator position, pointer value_pointer)
 Inserts a value pointer (not a value copy) at an iterator position.
void poke_back (pointer value_pointer)
 Pushes a value pointer (not a value copy) on the end of the Vectal.
void pop_back ()
 Removes the last value.
iterator pull (iterator start, iterator stop)
iterator pull (iterator position)
pointer pull_back ()
 Removes and returns the last value pointer.
pointer pull_out (iterator position)
 Removes the value pointer at an iterator position.
void push_back (const_reference value)
 Pushes a value on the end of the Vectal.
Const_Reverse_Iterator rbegin () const
 Gets an Iterator for this Vectal positioned at the last value.
Reverse_Iterator rbegin ()
 Gets an Iterator for this Vectal positioned at the last value.
Const_Reverse_Iterator rend () const
 Gets an Iterator for this Vectal positioned before the first value.
Reverse_Iterator rend ()
 Gets an Iterator for this Vectal positioned before the first value.
pointer replace (iterator position, pointer value_pointer)
 Replaces an existing element.
void resize (size_type new_size, const_reference value)
void resize (size_type new_size)
 Resizes by removing excess elements, or adding new ones.
template<typename Iterator >
 Vectal (Iterator start, Iterator stop)
 Construct from an iterator range of values.
 Vectal (size_type size, const_reference value)
 Construct with with a number of value copies.
 Vectal (const Vectal &vectal)
 Copy constructor.
 Vectal ()
 Constructs an empty Vectal.
Basevector_base ()
 Provides access to the base vector.
void wipe ()
 Removes all of the value pointers, but does not destroy the values.
 ~Vectal ()
 Destroys the Vectal and its contents.

Protected Member Functions

virtual void entering (pointer value_pointer)
 Catches values as they are being entered into the Vectal.
virtual void removing (pointer value_pointer)
 Catches values as they are being removed from the Vectal.


Detailed Description

template<typename T>
class idaeim::Vectal< T >

A Vectal is a vector of virtual objects of any type.

From the user's point of view a Vectal is a vector of objects of the class specified by the template parameter. The interface is essentially the same. The Vectal provides efficient storage of, and access to, objects by only storing their pointers into the corresponding vector from which it is derived. This also allows the Vectal to contain objects of pure virtual polymorphic classes which can only be used with pointers or references (since they can not be constructed directly).

Cloning

More importantly, when an object is inserted into a Vectal it makes a copy of the object for internal storage. It does not copy the pointer. Since an abstract class can not be copied directly it must provide a "virtual constructor" (see Stroustrup, "The C++ Programming Language", [special edition] sect. 15.6.2) as a method named clone which takes no arguments and returns a pointer to a copy of the object. Note: The presence of the clone method is the only special requirement of a class contained in a Vectal. This method is typically implemented as follows:

	class Abstract_Class {
	public:
	Abstract_Class (const Abstract_Class&);	// Copy constructor.
	virtual Abstract_Class* clone () const = 0;
...
	};

	class Implementing_Class : public Abstract_Class {
	public:
	Implementing_Class (const Implementing_Class&);	// Copy constructor.
	Implementing_Class* clone () {return new Implementing_Class (*this);}
...
	};

Element pointers

Methods are provided to manipulate the object value pointers directly in the backing vector:

Note: These methods copy and delete pointers - not the objects they point to - into and out of the backing vector. The two erase methods delete the value object(s) in the Vectal before they erase the value pointer(s) directly from the Vectal; they do not use the pull methods because the intent is to destroy the erased objects, not just to remove their pointers from the Vectal.

Classes that want to control what happens to an object when it is entered or removed should subclass Vectal to override these virtual methods:

	void entering (pointer value);
	void removing (pointer value);

Iterator reference semantics

The vector iterators have been subclassed so that their dereference (*), pointer (->) and indexing ([]) operators automatically dereference the object pointers in the backing vector. Thus, from the user's perspective the iterators appear to reference object values directly just as vector iterators do. However, instead of copying out objects as do vectors, direct object value references to the contents of the Vectal are provided.

Caveats

The current Vectal has many flaws. One could easily make the argument that there is no need for a Vectal; a vector of pointers to virtual types should be sufficient. However, the author wanted to provide the convenience of reference semantics, transparent reusability with different subclasses, and insert and removal hooks to the virtual class being managed to allow them to take special action for their own purposes. Thus the justification for the Vectal. Nevertheless the implementation flaws need to be considered.

The problem of the copy constructor for virtual classes poses a major challenge. The effect of this is that Vectals do not always work well with STL algorithms. Sorting is an excellent example: It is obviously necessary to be able to compare the values of the elments being sorted; thus using a vector of pointers to the objects to be sorted will not do. This is solved by having the Vectal iterators implement reference semantics. However, reordering elements requires that temporary copies of elements must be made. It would be fine to copy and reorder the backing pointers, but the Vectal iterators reference semantics brings up the copy constructor problem. Many STL algorithms will still work just fine with a Vectal as long as they do not have to make copies of the Vectal elements.

Member Typedef Documentation

typedef std::vector<T*> Base

Base vector class.

typedef Base::iterator Base_iterator

Base vector iterator.

typedef Base::const_iterator Base_const_iterator

Base vector const interator.

typedef Base::reverse_iterator Base_reverse_iterator

Base vector reverse iterator.

typedef Base::const_reverse_iterator Base_const_reverse_iterator

Base vector const reverse iterator.

typedef T value_type

Element virtual class type.

Element const type.

Element reference.

typedef const value_type& const_reference

Element const reference.

typedef value_type* pointer

Element pointer type.

typedef const pointer const_pointer

Element const pointer.

typedef Base::size_type size_type

Element size (base pointer size).

typedef Base::difference_type difference_type

Element pointer difference type.

typedef Base::allocator_type allocator_type

Storage allocate type (pointer allocator).

typedef Iterator iterator

Vectal iterator.

Vectal const iterator.

Vectal reverse iterator.

Vectal const reverse iterator.


Constructor & Destructor Documentation

Vectal (  )  [inline]

Constructs an empty Vectal.

Vectal ( const Vectal< T > &  vectal  )  [inline, explicit]

Copy constructor.

Parameters:
vectal The Vectal to be copied.
See also:
operator=(const Vectal&)

Vectal ( size_type  size,
const_reference  value 
) [inline]

Construct with with a number of value copies.

Parameters:
size The number of value copies with which to initialize the contents.
value The value to be copied.

Vectal ( Iterator  start,
Iterator  stop 
) [inline]

Construct from an iterator range of values.

The values in the range [start, stop) are used to intialize the contents.

Parameters:
start Where the range starts (inclusive).
stop Where the range stops (exclusive).
See also:
assign(iterator, iterator)

~Vectal (  )  [inline]

Destroys the Vectal and its contents.

The value elements are destoryed before destroying the Vectal.

See also:
clear()


Member Function Documentation

reference at ( size_type  index  )  [inline]

Gets the indexed element.

Parameters:
index The range checked index of an element.
Returns:
A reference to the value at the indexed element.

Referenced by Vectal< Value >::at().

const_reference at ( size_type  index  )  const [inline]

Gets the indexed element.

Parameters:
index The range checked index of an element.
Returns:
A const reference to the value at the indexed element.

reference operator[] ( size_type  index  )  [inline]

Gets the indexed element.

Unchecked - faster, but not safe - access to an indexed element.

Parameters:
index The index of an element.
Returns:
A reference to the value at the indexed element.

Referenced by Vectal< Value >::assign(), Vectal< Value >::back(), Vectal< Value >::front(), and Vectal< Value >::operator[]().

const_reference operator[] ( size_type  index  )  const [inline]

Gets the indexed element.

Unchecked - faster, but not safe - access to an indexed element.

Parameters:
index The index of an element.
Returns:
A const reference to the value at the indexed element.

reference front (  )  [inline]

Gets the first element.

Returns:
A reference to the first value.
See also:
operator[](size_type)

const_reference front (  )  const [inline]

Gets the first element.

Returns:
A const reference to the first value.
See also:
operator[](size_type)

reference back (  )  [inline]

Gets the last element.

Returns:
A reference to the last value.
See also:
operator[](size_type)

Referenced by Vectal< Value >::peek_back(), Vectal< Value >::pull_back(), and Vectal< Value >::resize().

const_reference back (  )  const [inline]

Gets the last element.

Returns:
A const reference to the last value.
See also:
operator[](size_type)

pointer peek ( iterator  position  )  [inline]

Gets a value pointer at an iterator position.

Parameters:
position The position to peek at. The position is not range checked.
Returns:
A pointer to the value at the position. This will be NULL if the Vectal is empty.
See also:
Iterator::operator->()

Referenced by Vectal< Value >::erase(), Vectal< Value >::pull_out(), and Vectal< Value >::replace().

const_pointer peek ( const_iterator  position  )  const [inline]

Gets a value pointer at an iterator position.

Parameters:
position The position to peek at. The position is not range checked.
Returns:
A const pointer to the value at the position. This will be NULL if the Vectal is empty.
See also:
Const_Iterator::operator->()

pointer peek_back (  )  [inline]

Gets the last value pointer.

Returns:
A pointer to the last value. This will be NULL if the Vectal is empty.

const_pointer peek_back (  )  const [inline]

Gets the last value pointer.

Returns:
A pointer to the last value. This will be NULL if the

Base& vector_base (  )  [inline]

Provides access to the base vector.

Returns:
A reference to the base vector of object pointers. This is equivalent to dynamic_cast<Base&>(*this).

Referenced by Array::move_in(), and Aggregate::move_in().

virtual void entering ( pointer  value_pointer  )  [inline, protected, virtual]

Catches values as they are being entered into the Vectal.

This stub does nothing by default. It should be overridden by classes that want to apply special handling to the object before they are entered into the Vectal.

Parameters:
value_pointer The value pointer that is being entered into the Vectal.

Referenced by Vectal< Value >::poke(), Vectal< Value >::poke_back(), and Vectal< Value >::replace().

void assign ( size_type  number,
const_reference  value 
) [inline]

Assigns a number of value copies.

Any existing values, up to the number being assigned, are assigned from the value provided. The value's own assignment operator is used. Any excess values are removed. A shortfall is filled with copies of the value.

Parameters:
number The number of value copies to assign.
value The value to be assigned.
See also:
resize(size_type, const_reference)

Referenced by Vectal< Value >::operator=(), and Vectal< Value >::Vectal().

void assign ( iterator  start,
iterator  stop 
) [inline]

Assigns values from an iterator range.

Existing values are replaced by assignment. Excess input values are appended. Excess existing elements are erased.

Parameters:
start Where the range starts (inclusive). The position is not range checked.
stop Where the range stops (exclusive). The position is not range checked.
See also:
push_back(const_reference)

erase(iterator, iterator)

Vectal& operator= ( const Vectal< value_type > &  vectal  )  [inline]

Assigns values from another Vectal.

Parameters:
vectal A Vectal of the same type as this Vectal.
Returns:
This Vectal.
See also:
assign(iterator, iterator)

Referenced by Vectal< Value >::Vectal().

iterator insert ( iterator  position,
const_reference  value 
) [inline]

Inserts a value at an iterator position.

A clone pointer of the value is poked into the backing vector.

Parameters:
position The iterator position where the value is to be inserted.
value The value to be inserted.
Returns:
The position of the inserted value.
See also:
poke(iterator, pointer)

Referenced by Vectal< Value >::insert(), and Vectal< Value >::poke().

void insert ( iterator  position,
size_type  number,
const_reference  value 
) [inline]

Inserts a number of value copies starting at an iterator position.

Parameters:
position The position at which to start inserting the values.
number The number of values to insert.
value The value to be inserted.
See also:
insert(iterator, const_reference)

void insert ( iterator  position,
InputIterator  start,
InputIterator  stop 
) [inline]

void push_back ( const_reference  value  )  [inline]

Pushes a value on the end of the Vectal.

A clone pointer of the value is poked into the end of the backing vector.

Parameters:
value A value reference.
See also:
poke_back(pointer).

Referenced by Vectal< Value >::assign(), Vectal< Value >::poke_back(), and Vectal< Value >::resize().

iterator poke ( iterator  position,
pointer  value_pointer 
) [inline]

Inserts a value pointer (not a value copy) at an iterator position.

N.B.: The value pointer is provided to the entering method before being inserted into the backing vector.

If the VECTAL_CAPACITY_MARGIN is not 0 and the allocated storage capacity has been reached, then storage reserve is increased to the next largest multiple of the margin amount.

Parameters:
position The iterator position where the value pointer will be placed. The position is not range checked.
value_pointer The value pointer to be stored.
Returns:
The iterator positioned at the new value.

Referenced by Vectal< Value >::insert(), and Vectal< Value >::poke().

iterator poke ( iterator  position,
iterator  start,
iterator  stop 
) [inline]

void poke_back ( pointer  value_pointer  )  [inline]

Pushes a value pointer (not a value copy) on the end of the Vectal.

N.B.: The value pointer is provided to the entering method before being pushed on the end of the backing vector.

If the VECTAL_CAPACITY_MARGIN is not 0 and the allocated storage capacity has been reached, then storage reserve is increased to the next largest multiple of the margin amount.

Parameters:
value_pointer The value pointer to be stored.

Referenced by Parser::add_values(), Parser::get_value(), Parser::ingest_parameters(), and Vectal< Value >::push_back().

virtual void removing ( pointer  value_pointer  )  [inline, protected, virtual]

Catches values as they are being removed from the Vectal.

This stub does nothing by default. It should be overridden by classes that want to apply special handling to the object before they are removed from the Vectal.

Parameters:
value_pointer The value pointer that is being removed from the Vectal.

Referenced by Vectal< Value >::erase(), Vectal< Value >::pull(), and Vectal< Value >::replace().

iterator erase ( iterator  position  )  [inline]

Removes a value at an iterator position.

Parameters:
position The iterator position of the value to be removed.
Returns:
The position of the next value. If the Vectal was empty then nothing is done and the original position is returned.
See also:
peek(iterator)

pull(iterator)

Referenced by Vectal< Value >::assign(), Vectal< Value >::clear(), Vectal< Value >::erase(), Vectal< Value >::pop_back(), Vectal< Value >::pull(), and Vectal< Value >::resize().

iterator erase ( iterator  start,
iterator  stop 
) [inline]

void clear (  )  [inline]

Removes, and destroys, all values.

See also:
erase(iterator, iterator)

Referenced by Vectal< Value >::wipe(), and Vectal< Value >::~Vectal().

void wipe (  )  [inline]

Removes all of the value pointers, but does not destroy the values.

Warning: It is the user's responsibility to make sure that the value objects are properly managed to prevent a memory leak.

This method might be used if the value pointers have been copied elsewhere, or the value objects have already been destroyed.

Referenced by Array::move_in(), and Aggregate::move_in().

void pop_back (  )  [inline]

Removes the last value.

Does nothing if the Vectal is empty.

See also:
erase(iterator)

iterator pull ( iterator  position  )  [inline]

iterator pull ( iterator  start,
iterator  stop 
) [inline]

pointer pull_out ( iterator  position  )  [inline]

Removes the value pointer at an iterator position.

The value itself is not destroyed.

Parameters:
position The iterator position of the value.
Returns:
The value pointer removed. This will be NULL if the Vectal is empty.
See also:
peek (position)

pull (position)

pointer pull_back (  )  [inline]

Removes and returns the last value pointer.

The value itself is not destroyed.

Returns:
A pointer to the last value. This will be NULL if the Vectal is empty.

Referenced by Parser::get_parameters(), and Parser::get_value().

void resize ( size_type  new_size  )  [inline]

Resizes by removing excess elements, or adding new ones.

To increase the size a value is needed to fill the space. Virtual classes have no default constructor so the last value is used to copy into the extra space. However, if the Vectal is empty there's nothing to copy so an out_of_range error will be thrown in this case.

Parameters:
new_size The new size for the Vectal.
See also:
resize(size_type, const_reference)

Referenced by Vectal< Value >::assign(), and Vectal< Value >::resize().

void resize ( size_type  new_size,
const_reference  value 
) [inline]

pointer replace ( iterator  position,
pointer  value_pointer 
) [inline]

Replaces an existing element.

Nothing is done if the Vecatal is empty.

N.B.: The previous value pointer at the iterator position is provided to the removing method. The value is not destroyed. The new value pointer is provided to the entering method before replacing the previous pointer in the backing vector.

Parameters:
position The iterator position of the value. The position is not range checked.
value_pointer The value pointer to be stored.
Returns:
The value pointer replaced. This will be NULL if the Vectal is empty.

Iterator begin (  )  [inline]

Iterator end (  )  [inline]

Const_Iterator begin (  )  const [inline]

Gets an Iterator for this Vectal positioned at the first value.

Returns:
An Iterator positioned at the first value.

Const_Iterator end (  )  const [inline]

Gets an Iterator for this Vectal positioned after the last value.

Returns:
An Iterator positioned after the last value.

Reverse_Iterator rbegin (  )  [inline]

Gets an Iterator for this Vectal positioned at the last value.

Returns:
An Iterator positioned at the last value.

Referenced by Vectal< Value >::rbegin().

Reverse_Iterator rend (  )  [inline]

Gets an Iterator for this Vectal positioned before the first value.

Returns:
An Iterator positioned before the first value.

Referenced by Vectal< Value >::rend().

Const_Reverse_Iterator rbegin (  )  const [inline]

Gets an Iterator for this Vectal positioned at the last value.

Returns:
An Iterator positioned at the last value.

Const_Reverse_Iterator rend (  )  const [inline]

Gets an Iterator for this Vectal positioned before the first value.

Returns:
An Iterator positioned before the first value.


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

Generated on Mon Oct 12 19:59:44 2009 for PVL by  doxygen 1.5.8