SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (const RWTPtrVector< T > &rhs)
 
template<typename InputIterator >
 RWTPtrVector (InputIterator first, InputIterator last)
 
 RWTPtrVector (RWTPtrVector< T > &&rhs)
 
 RWTPtrVector (size_type n)
 
 RWTPtrVector (size_type n, value_type ival)
 
void apply (void(*fn)(const T *, void *), void *d) const
 
void apply (void(*fn)(reference, void *), void *d)
 
void apply (void(*fn)(value_type, void *), void *d)
 
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 (bool(*fn)(const T *, void *), void *d) const
 
size_type index (const T *a) 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 Symbols

(Note that these are not member symbols.)

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>
A pointer-based collection of values implemented as a vector.
Definition tpvector.h:87
Persistence
Isomorphic
Example
#include <rw/tools/datetime.h>
#include <rw/tpvector.h>
#include <iostream>
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;
}
Represents a date and time stored in milliseconds.
Definition tools/datetime.h:219
@ setCurrentTime
Definition tools/datetime.h:241
iterator begin()
Definition tpvector.h:322

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

◆ const_iterator

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.

◆ const_pointer

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

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

◆ const_reference

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

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

◆ const_reverse_iterator

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.

◆ difference_type

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.

◆ iterator

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

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

◆ pointer

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

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

◆ reference

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

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

◆ reverse_iterator

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.

◆ size_type

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

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

◆ value_type

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

A type representing the container's data type.

Constructor & Destructor Documentation

◆ RWTPtrVector() [1/6]

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

Constructs an empty vector of length zero.

◆ RWTPtrVector() [2/6]

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.

◆ RWTPtrVector() [3/6]

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.

◆ RWTPtrVector() [4/6]

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.

◆ RWTPtrVector() [5/6]

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.

◆ RWTPtrVector() [6/6]

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

◆ apply() [1/3]

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

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

◆ apply() [2/3]

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

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

◆ apply() [3/3]

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

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

◆ assign()

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.

◆ at() [1/2]

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.

◆ at() [2/2]

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.

◆ begin() [1/2]

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().

◆ begin() [2/2]

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().

◆ cbegin()

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().

◆ cend()

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.

◆ clear()

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

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

◆ clearAndDestroy()

template<class T >
void RWTPtrVector< T >::clearAndDestroy ( )
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.

◆ contains() [1/2]

template<class T >
bool RWTPtrVector< T >::contains ( bool(* fn )(const T *, void *),
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.

◆ contains() [2/2]

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.

◆ crbegin()

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().

◆ crend()

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.

◆ data() [1/2]

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

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

◆ data() [2/2]

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

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

◆ end() [1/2]

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.

◆ end() [2/2]

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.

◆ entries()

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

Returns the number of items in self.

◆ find() [1/2]

template<class T >
value_type RWTPtrVector< T >::find ( bool(* fn )(const T *, void *),
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.

◆ find() [2/2]

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.

◆ first() [1/2]

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

Returns a reference to the first item in the collection.

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

◆ first() [2/2]

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

Returns a reference to the first item in the collection.

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

◆ index() [1/2]

template<class T >
size_type RWTPtrVector< T >::index ( bool(* fn )(const T *, void *),
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.

◆ index() [2/2]

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.

◆ isEmpty()

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

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

◆ last() [1/2]

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

Returns a reference to the last item in the collection.

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

◆ last() [2/2]

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

Returns a reference to the last item in the collection.

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

◆ length()

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.

◆ maxElement() [1/2]

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

Returns a reference to the maximum element in self.

◆ maxElement() [2/2]

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

Returns a reference to the maximum element in self.

◆ minElement() [1/2]

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

Returns a reference to the minimum element in self.

◆ minElement() [2/2]

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

Returns a reference to the minimum element in self.

◆ occurrencesOf() [1/2]

template<class T >
size_type RWTPtrVector< T >::occurrencesOf ( bool(* fn )(const T *, void *),
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.

◆ occurrencesOf() [2/2]

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.

◆ operator()() [1/2]

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.

◆ operator()() [2/2]

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.

◆ operator=() [1/3]

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.

◆ operator=() [2/3]

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.

◆ operator=() [3/3]

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

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

◆ operator[]() [1/2]

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.

◆ operator[]() [2/2]

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.

◆ rbegin() [1/2]

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().

◆ rbegin() [2/2]

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().

◆ rend() [1/2]

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.

◆ rend() [2/2]

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.

◆ replaceAll() [1/2]

template<class T >
size_type RWTPtrVector< T >::replaceAll ( bool(* fn )(const T *, void *),
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.

◆ replaceAll() [2/2]

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.

◆ reshape()

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.

◆ resize()

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.

◆ sort()

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.

◆ swap()

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 Symbol Documentation

◆ operator!=()

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

Equivalent to !(lhs == rhs).

◆ operator<()

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.

◆ operator<=()

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

Equivalent to !(rhs < lhs).

◆ operator==()

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.

◆ operator>()

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

Equivalent to (rhs < lhs).

◆ operator>=()

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

Equivalent to !(lhs < rhs).

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