|
PVL: Parameter Value Language
|
#include <Vectal.hh>


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_type & | const_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_type * | pointer |
| Element pointer type. | |
| typedef value_type & | reference |
| 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. | |
| Vectal & | operator= (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. | |
| Base & | vector_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. | |
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).
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);}
...
};
Methods are provided to manipulate the object value pointers directly in the backing vector:
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);
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.
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.
| 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.
| typedef const value_type const_value_type |
Element const type.
| typedef value_type& reference |
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 Const_Iterator const_iterator |
Vectal const iterator.
| typedef Reverse_Iterator reverse_iterator |
Vectal reverse iterator.
Vectal const reverse iterator.
| Vectal | ( | size_type | size, | |
| const_reference | value | |||
| ) | [inline] |
Construct with with a number of value copies.
| size | The number of value copies with which to initialize the contents. | |
| value | The value to be copied. |
Construct from an iterator range of values.
The values in the range [start, stop) are used to intialize the contents.
| start | Where the range starts (inclusive). | |
| stop | Where the range stops (exclusive). |
| ~Vectal | ( | ) | [inline] |
Gets the indexed element.
| index | The range checked index of an element. |
Referenced by Vectal< Value >::at().
| const_reference at | ( | size_type | index | ) | const [inline] |
Gets the indexed element.
| index | The range checked index of an element. |
Gets the indexed element.
Unchecked - faster, but not safe - access to an indexed element.
| index | The index of an 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.
| index | The index of an element. |
| reference front | ( | ) | [inline] |
| const_reference front | ( | ) | const [inline] |
Gets the first element.
| reference back | ( | ) | [inline] |
Gets the last element.
Referenced by Vectal< Value >::peek_back(), Vectal< Value >::pull_back(), and Vectal< Value >::resize().
| const_reference back | ( | ) | const [inline] |
Gets a value pointer at an iterator position.
| position | The position to peek at. The position is not range checked. |
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.
| position | The position to peek at. The position is not range checked. |
| pointer peek_back | ( | ) | [inline] |
Gets the last value pointer.
| const_pointer peek_back | ( | ) | const [inline] |
Gets the last value pointer.
| Base& vector_base | ( | ) | [inline] |
Provides access to the base vector.
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.
| 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.
| number | The number of value copies to assign. | |
| value | The value to be assigned. |
Referenced by Vectal< Value >::operator=(), and Vectal< Value >::Vectal().
Assigns values from an iterator range.
Existing values are replaced by assignment. Excess input values are appended. Excess existing elements are erased.
| start | Where the range starts (inclusive). The position is not range checked. | |
| stop | Where the range stops (exclusive). The position is not range checked. |
| Vectal& operator= | ( | const Vectal< value_type > & | vectal | ) | [inline] |
Assigns values from another Vectal.
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.
| position | The iterator position where the value is to be inserted. | |
| value | The value to be inserted. |
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.
| position | The position at which to start inserting the values. | |
| number | The number of values to insert. | |
| value | The value to be inserted. |
| 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.
| value | A value reference. |
Referenced by Vectal< Value >::assign(), Vectal< Value >::poke_back(), and Vectal< Value >::resize().
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.
| 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. |
Referenced by Vectal< Value >::insert(), and Vectal< Value >::poke().
| 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.
| 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.
| value_pointer | The value pointer that is being removed from the Vectal. |
Referenced by Vectal< Value >::erase(), Vectal< Value >::pull(), and Vectal< Value >::replace().
Removes a value at an iterator position.
| position | The iterator position of the value to be removed. |
Referenced by Vectal< Value >::assign(), Vectal< Value >::clear(), Vectal< Value >::erase(), Vectal< Value >::pop_back(), Vectal< Value >::pull(), and Vectal< Value >::resize().
| void clear | ( | ) | [inline] |
Removes, and destroys, all values.
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] |
Referenced by Vectal< Value >::erase(), Vectal< Value >::pull_back(), and Vectal< Value >::pull_out().
| pointer pull_back | ( | ) | [inline] |
Removes and returns the last value pointer.
The value itself is not destroyed.
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.
| new_size | The new size for the Vectal. |
Referenced by Vectal< Value >::assign(), and Vectal< Value >::resize().
| void resize | ( | size_type | new_size, | |
| const_reference | value | |||
| ) | [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.
| position | The iterator position of the value. The position is not range checked. | |
| value_pointer | The value pointer to be stored. |
| Iterator begin | ( | ) | [inline] |
Gets an Iterator for this Vectal positioned at the first value.
Referenced by Aggregate::Aggregate(), Vectal< Value >::assign(), Vectal< Value >::begin(), Vectal< Value >::clear(), Array::compare(), Aggregate::compare(), Array::copy_in(), Aggregate::copy_in(), Array::Depth_Iterator::operator++(), Aggregate::Depth_Iterator::operator++(), Array::Depth_Iterator::operator--(), Aggregate::Depth_Iterator::operator--(), Vectal< Value >::operator=(), Vectal< Value >::poke(), and Lister::write().
| Iterator end | ( | ) | [inline] |
Gets an Iterator for this Vectal positioned after the last value.
Referenced by Aggregate::Aggregate(), Vectal< Value >::assign(), Vectal< Value >::clear(), Array::copy_in(), Aggregate::copy_in(), Vectal< Value >::end(), Array::Depth_Iterator::end_depth(), Aggregate::Depth_Iterator::end_depth(), Array::Depth_Iterator::operator++(), Aggregate::Depth_Iterator::operator++(), Array::Depth_Iterator::operator--(), Aggregate::Depth_Iterator::operator--(), Vectal< Value >::operator=(), Vectal< Value >::pop_back(), Vectal< Value >::pull_back(), Vectal< Value >::resize(), and Lister::write().
| Const_Iterator begin | ( | ) | const [inline] |
| Const_Iterator end | ( | ) | const [inline] |
| Reverse_Iterator rbegin | ( | ) | [inline] |
Gets an Iterator for this Vectal 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.
Referenced by Vectal< Value >::rend().
| Const_Reverse_Iterator rbegin | ( | ) | const [inline] |
| Const_Reverse_Iterator rend | ( | ) | const [inline] |
1.5.8