SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Types | Public Member Functions | Related Functions
RWTPtrVector< T > Class Template Reference

A pointer-based collection of values implemented as a vector. More...

#include <rw/tpvector.h>

Public Types

typedef const_pointer const_iterator
 
typedef const value_typeconst_pointer
 
typedef const value_typeconst_reference
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 
typedef ptrdiff_t difference_type
 
typedef pointer iterator
 
typedef value_typepointer
 
typedef value_typereference
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef size_t size_type
 
typedef T * value_type
 

Public Member Functions

 RWTPtrVector ()
 
 RWTPtrVector (size_type n)
 
 RWTPtrVector (const RWTPtrVector< T > &rhs)
 
 RWTPtrVector (RWTPtrVector< T > &&rhs)
 
 RWTPtrVector (size_type n, value_type ival)
 
template<typename InputIterator >
 RWTPtrVector (InputIterator first, InputIterator last)
 
void apply (void(*fn)(reference, void *), void *d)
 
void apply (void(*fn)(value_type, void *), void *d)
 
void apply (void(*fn)(const T *, void *), void *d) const
 
template<typename InputIterator >
void assign (InputIterator first, InputIterator last)
 
reference at (size_type i)
 
const_reference at (size_type i) const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
void clearAndDestroy ()
 
bool contains (bool(*fn)(const T *, void *), void *d) const
 
bool contains (const T *a) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
pointer data ()
 
const_pointer data () const
 
iterator end ()
 
const_iterator end () const
 
size_type entries () const
 
value_type find (bool(*fn)(const T *, void *), void *d) const
 
value_type find (const T *a) const
 
reference first ()
 
const_reference first () const
 
size_type index (const T *a) const
 
size_type index (bool(*fn)(const T *, void *), void *d) const
 
bool isEmpty () const
 
reference last ()
 
const_reference last () const
 
size_type length () const
 
reference maxElement ()
 
const_reference maxElement () const
 
reference minElement ()
 
const_reference minElement () const
 
size_type occurrencesOf (bool(*fn)(const T *, void *), void *d) const
 
size_type occurrencesOf (const T *a) const
 
reference operator() (size_type i)
 
const_reference operator() (size_type i) const
 
RWTPtrVector< T > & operator= (const RWTPtrVector< T > &rhs)
 
RWTPtrVector< T > & operator= (RWTPtrVector< T > &&rhs)
 
RWTPtrVector< T > & operator= (value_type p)
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
size_type replaceAll (bool(*fn)(const T *, void *), void *d, value_type newVal)
 
size_type replaceAll (const T *oldVal, value_type newVal)
 
void reshape (size_type N)
 
void resize (size_type N)
 
void sort ()
 
void swap (RWTPtrVector< T > &rhs)
 

Related Functions

(Note that these are not member functions.)

template<class T >
bool operator!= (const RWTPtrVector< T > &lhs, const RWTPtrVector< T > &rhs)
 
template<class T >
bool operator< (const RWTPtrVector< T > &lhs, const RWTPtrVector< T > &rhs)
 
template<class T >
bool operator<= (const RWTPtrVector< T > &lhs, const RWTPtrVector< T > &rhs)
 
template<class T >
bool operator== (const RWTPtrVector< T > &lhs, const RWTPtrVector< T > &rhs)
 
template<class T >
bool operator> (const RWTPtrVector< T > &lhs, const RWTPtrVector< T > &rhs)
 
template<class T >
bool operator>= (const RWTPtrVector< T > &lhs, const RWTPtrVector< T > &rhs)
 

Detailed Description

template<class T>
class RWTPtrVector< T >

Class RWTPtrVector is a simple parameterized vector of pointers to objects of type T. It is most useful when you know precisely how many pointers must be held in the collection. If the intention is to insert an unknown number of objects into a collection, then class RWTPtrOrderedVector may be a better choice. Class T can be of any type.

Synopsis
#include <rw/tpvector.h>
Persistence
Isomorphic
Example
#include <iostream>
#include <rw/tpvector.h>
#include <rw/tools/datetime.h>
int main ()
{
for (size_t i = 0; i < 7; ++i) {
week[i] = new RWDateTime(begin);
begin.incrementDay(1);
}
for (size_t i = 0; i < 7; ++i) {
std::cout << week[i]->asString('x') << std::endl;
delete week[i];
}
return 0;
}

Program output (if run on June 18, 2009):

06/18/09
06/19/09
06/20/09
06/21/09
06/22/09
06/23/09
06/24/09

Member Typedef Documentation

template<class T>
typedef const_pointer RWTPtrVector< T >::const_iterator

A type that provides a const random-access iterator over the elements in the container.

template<class T>
typedef const value_type* RWTPtrVector< T >::const_pointer

A type that provides a const pointer to an element in the container.

template<class T>
typedef const value_type& RWTPtrVector< T >::const_reference

A type that provides a const reference to an element in the container.

template<class T>
typedef std::reverse_iterator<const_iterator> RWTPtrVector< T >::const_reverse_iterator

A type that provides a const random-access, reverse-order iterator over the elements in the container.

template<class T>
typedef ptrdiff_t RWTPtrVector< T >::difference_type

A signed integral type used to indicate the distance between two valid iterators on the same container.

template<class T>
typedef pointer RWTPtrVector< T >::iterator

A type that provides a random-access iterator over the elements in the container.

template<class T>
typedef value_type* RWTPtrVector< T >::pointer

A type that provides a pointer to an element in the container.

template<class T>
typedef value_type& RWTPtrVector< T >::reference

A type that provides a reference to an element in the container.

template<class T>
typedef std::reverse_iterator<iterator> RWTPtrVector< T >::reverse_iterator

A type that provides a random-access, reverse-order iterator over the elements in the container.

template<class T>
typedef size_t RWTPtrVector< T >::size_type

An unsigned integral type used for counting the number of elements in the container.

template<class T>
typedef T* RWTPtrVector< T >::value_type

A type representing the container's data type.

Constructor & Destructor Documentation

template<class T>
RWTPtrVector< T >::RWTPtrVector ( )
inline

Constructs an empty vector of length zero.

template<class T>
RWTPtrVector< T >::RWTPtrVector ( size_type  n)
inline

Constructs a vector of length n. The initial values of the elements are undefined. Hence, they can (and probably will) be garbage.

template<class T>
RWTPtrVector< T >::RWTPtrVector ( size_type  n,
value_type  ival 
)
inline

Constructs a vector of length n, with each element pointing to the item ival.

template<class T>
RWTPtrVector< T >::RWTPtrVector ( const RWTPtrVector< T > &  rhs)
inline

Copy constructor. The constructed vector is a shallow copy of rhs. The two vectors will then have the same length, and pointers held by the two vectors will point to the same items.

template<class T>
RWTPtrVector< T >::RWTPtrVector ( RWTPtrVector< T > &&  rhs)
inline

Move constructor. The constructed vector takes ownership of the data owned by rhs.

Condition:
This method is available only on platforms with rvalue reference support.
template<class T>
template<typename InputIterator >
RWTPtrVector< T >::RWTPtrVector ( InputIterator  first,
InputIterator  last 
)
inline

Constructs a vector by copying elements from the range [first, last).

InputIterator is an input iterator type that points to elements that are convertible to value_type objects.

Member Function Documentation

template<class T>
void RWTPtrVector< T >::apply ( void(*)(reference, void *)  fn,
void *  d 
)
inline

Invokes the function pointer fn on each item in the collection. Client data may be passed through parameter d.

template<class T>
void RWTPtrVector< T >::apply ( void(*)(value_type, void *)  fn,
void *  d 
)
inline

Invokes the function pointer fn on each item in the collection. Client data may be passed through parameter d.

template<class T>
void RWTPtrVector< T >::apply ( void(*)(const T *, void *)  fn,
void *  d 
) const
inline

Invokes the function pointer fn on each item in the collection. Client data may be passed through parameter d.

template<class T>
template<typename InputIterator >
void RWTPtrVector< T >::assign ( InputIterator  first,
InputIterator  last 
)
inline

Copies each element in the range [first, last) into self, replacing any existing items.

InputIterator is an input iterator type that points to elements that are convertible to value_type objects.

Note
first and last must not be iterators into self.
template<class T>
reference RWTPtrVector< T >::at ( size_type  i)
inline

Returns a reference to the i th element of self.

Exceptions
RWBoundsErrThrown if index i is not between 0 and one less than the number of entries in self.
template<class T>
const_reference RWTPtrVector< T >::at ( size_type  i) const
inline

Returns a reference to the i th element of self.

Exceptions
RWBoundsErrThrown if index i is not between 0 and one less than the number of entries in self.
template<class T>
iterator RWTPtrVector< T >::begin ( )
inline

Returns an iterator referring to the first element in the container.

If the container is empty, returns end().

template<class T>
const_iterator RWTPtrVector< T >::begin ( ) const
inline

Returns an iterator referring to the first element in the container.

If the container is empty, returns end().

template<class T>
const_iterator RWTPtrVector< T >::cbegin ( ) const
inline

Returns an iterator referring to the first element in the container.

If the container is empty, returns end().

template<class T>
const_iterator RWTPtrVector< T >::cend ( ) const
inline

Returns an iterator referring to the element after the last element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<class T>
void RWTPtrVector< T >::clear ( void  )
inline

Clears the collection by removing all items from self. Does not call operator delete on the individual items.

template<class T>
void RWTPtrVector< T >::clearAndDestroy ( void  )
inline

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored.

template<class T>
bool RWTPtrVector< T >::contains ( bool(*)(const T *, void *)  fn,
void *  d 
) const
inline

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. Client data may be passed through parameter d.

template<class T>
bool RWTPtrVector< T >::contains ( const T *  a) const
inline

Returns true if there exists an element t in self such that the expression (*t == *a) is true, otherwise returns false.

template<class T>
const_reverse_iterator RWTPtrVector< T >::crbegin ( ) const
inline

Returns an iterator referring to the last element in the container.

If the container is empty, returns rend().

template<class T>
const_reverse_iterator RWTPtrVector< T >::crend ( ) const
inline

Returns an iterator referring to the element before the first element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<class T>
pointer RWTPtrVector< T >::data ( void  )
inline

Returns a pointer to the first element of the vector. The value returned is undefined if the vector is empty.

template<class T>
const_pointer RWTPtrVector< T >::data ( void  ) const
inline

Returns a pointer to the first element of the vector. The value returned is undefined if the vector is empty.

template<class T>
iterator RWTPtrVector< T >::end ( )
inline

Returns an iterator referring to the element after the last element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<class T>
const_iterator RWTPtrVector< T >::end ( ) const
inline

Returns an iterator referring to the element after the last element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<class T>
size_type RWTPtrVector< T >::entries ( void  ) const
inline

Returns the number of items in self.

template<class T>
value_type RWTPtrVector< T >::find ( bool(*)(const T *, void *)  fn,
void *  d 
) const
inline

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. Client data may be passed through parameter d.

template<class T>
value_type RWTPtrVector< T >::find ( const T *  a) const
inline

If there exists an element t in self such that the expression (*t == *a) is true, returns t. Otherwise, returns rwnil.

template<class T>
reference RWTPtrVector< T >::first ( void  )
inline

Returns a reference to the first item in the collection.

Calling this function on an empty collection results in undefined behavior.

template<class T>
const_reference RWTPtrVector< T >::first ( void  ) const
inline

Returns a reference to the first item in the collection.

Calling this function on an empty collection results in undefined behavior.

template<class T>
size_type RWTPtrVector< T >::index ( const T *  a) const
inline

Returns the position of the first item t in self such that (*t == *a), or returns RW_NPOS if no such item exists.

template<class T>
size_type RWTPtrVector< T >::index ( bool(*)(const T *, void *)  fn,
void *  d 
) const
inline

Returns the position of the first item t in self such that ((*fn)(t,d)) is true, or returns RW_NPOS if no such item exists. Client data may be passed through parameter d.

template<class T>
bool RWTPtrVector< T >::isEmpty ( ) const
inline

Returns true if there are no items in the collection, otherwise false.

template<class T>
reference RWTPtrVector< T >::last ( void  )
inline

Returns a reference to the last item in the collection.

Calling this function on an empty collection results in undefined behavior.

template<class T>
const_reference RWTPtrVector< T >::last ( void  ) const
inline

Returns a reference to the last item in the collection.

Calling this function on an empty collection results in undefined behavior.

template<class T>
size_type RWTPtrVector< T >::length ( ) const
inline

Returns the number of items in self.

Deprecated:
As of SourcePro 13, use entries() instead.
template<class T>
reference RWTPtrVector< T >::maxElement ( )
inline

Returns a reference to the maximum element in self.

template<class T>
const_reference RWTPtrVector< T >::maxElement ( ) const
inline

Returns a reference to the maximum element in self.

template<class T>
reference RWTPtrVector< T >::minElement ( )
inline

Returns a reference to the minimum element in self.

template<class T>
const_reference RWTPtrVector< T >::minElement ( ) const
inline

Returns a reference to the minimum element in self.

template<class T>
size_type RWTPtrVector< T >::occurrencesOf ( bool(*)(const T *, void *)  fn,
void *  d 
) const
inline

Returns the number of elements t in self such that the expression ((*fn)(t,d)) is true. Client data may be passed through parameter d.

template<class T>
size_type RWTPtrVector< T >::occurrencesOf ( const T *  a) const
inline

Returns the number of elements t in self such that the expression (*t == *a) is true.

template<class T>
reference RWTPtrVector< T >::operator() ( size_type  i)
inline

Returns the i th value in the vector. The index i must be between zero and the length of the vector, less one. No bounds checking is performed.

template<class T>
const_reference RWTPtrVector< T >::operator() ( size_type  i) const
inline

Returns the i th value in the vector. The index i must be between zero and the length of the vector, less one. No bounds checking is performed.

template<class T>
RWTPtrVector<T>& RWTPtrVector< T >::operator= ( const RWTPtrVector< T > &  rhs)
inline

Sets self to a shallow copy of rhs. The two vectors will then have the same length, and pointers held by the two vectors will point to the same items.

template<class T>
RWTPtrVector<T>& RWTPtrVector< T >::operator= ( RWTPtrVector< T > &&  rhs)
inline

Move assignment. Self takes ownership of the data owned by rhs.

Condition:
This method is available only on platforms with rvalue reference support.
template<class T>
RWTPtrVector<T>& RWTPtrVector< T >::operator= ( value_type  p)
inline

Sets all elements in self to point to the item p.

template<class T>
reference RWTPtrVector< T >::operator[] ( size_type  i)
inline

Returns the i th value in the vector.

Exceptions
RWBoundsErrThrown if the index i is not between zero and the length of the vector, less one.
template<class T>
const_reference RWTPtrVector< T >::operator[] ( size_type  i) const
inline

Returns the i th value in the vector.

Exceptions
RWBoundsErrThrown if the index i is not between zero and the length of the vector, less one.
template<class T>
reverse_iterator RWTPtrVector< T >::rbegin ( )
inline

Returns an iterator referring to the last element in the container.

If the container is empty, returns rend().

template<class T>
const_reverse_iterator RWTPtrVector< T >::rbegin ( ) const
inline

Returns an iterator referring to the last element in the container.

If the container is empty, returns rend().

template<class T>
reverse_iterator RWTPtrVector< T >::rend ( )
inline

Returns an iterator referring to the element before the first element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<class T>
const_reverse_iterator RWTPtrVector< T >::rend ( ) const
inline

Returns an iterator referring to the element before the first element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<class T>
size_type RWTPtrVector< T >::replaceAll ( bool(*)(const T *, void *)  fn,
void *  d,
value_type  newVal 
)
inline

Replaces with newVal all elements t in self such that the expression ((*fn)(t,d)) is true. Returns the number of items replaced. Client data may be passed through parameter d.

template<class T>
size_type RWTPtrVector< T >::replaceAll ( const T *  oldVal,
value_type  newVal 
)
inline

Replaces with newVal all elements t in self such that the expression (*t == *oldVal) is true. Returns the number of items replaced.

template<class T>
void RWTPtrVector< T >::reshape ( size_type  N)
inline

Changes the length of the vector to N. If this increases the length of the vector, then the initial value of the additional elements is undefined.

template<class T>
void RWTPtrVector< T >::resize ( size_type  N)
inline

Changes the length of the vector to N. If this increases the length of the vector, then the initial value of the additional elements is set to rwnil.

template<class T>
void RWTPtrVector< T >::sort ( )
inline

Sorts the collection using the less-than operator to compare elements. Elements are dereferenced before being compared.

template<class T>
void RWTPtrVector< T >::swap ( RWTPtrVector< T > &  rhs)
inline

Swaps the data owned by self with the data owned by rhs.

Friends And Related Function Documentation

template<class T >
bool operator!= ( const RWTPtrVector< T > &  lhs,
const RWTPtrVector< T > &  rhs 
)
related

Equivalent to !(lhs == rhs).

template<class T >
bool operator< ( const RWTPtrVector< T > &  lhs,
const RWTPtrVector< T > &  rhs 
)
related

Returns true if lhs is lexicographically less than rhs, otherwise false. Items in each collection are dereferenced before being compared. Assumes that type T has well-defined less-than semantics.

template<class T >
bool operator<= ( const RWTPtrVector< T > &  lhs,
const RWTPtrVector< T > &  rhs 
)
related

Equivalent to !(rhs < lhs).

template<class T >
bool operator== ( const RWTPtrVector< T > &  lhs,
const RWTPtrVector< T > &  rhs 
)
related

Returns true if lhs and rhs are equal, otherwise false. Two collections are equal if both have the same number of entries, and iterating through both collections produces individual elements that, in turn, compare equal to each other. Elements are dereferenced before being compared.

template<class T >
bool operator> ( const RWTPtrVector< T > &  lhs,
const RWTPtrVector< T > &  rhs 
)
related

Equivalent to (rhs < lhs).

template<class T >
bool operator>= ( const RWTPtrVector< T > &  lhs,
const RWTPtrVector< T > &  rhs 
)
related

Equivalent to !(lhs < rhs).

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.