SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions | Related Functions
RWTValVector< T > Class Template Reference

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

#include <rw/tvvector.h>

Inherited by RWClassicTValOrderedVector< T > [private].

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

 RWTValVector ()
 
 RWTValVector (size_type n)
 
 RWTValVector (size_type n, const_reference ival)
 
 RWTValVector (const RWTValVector< T > &rhs)
 
 RWTValVector (RWTValVector< T > &&rhs)
 
template<typename InputIterator >
 RWTValVector (InputIterator first, InputIterator last, typename RWTEnableIf< !RWTIsIntegral< InputIterator >::value >::type **=0)
 
 ~RWTValVector ()
 
void apply (void(*fn)(reference, void *), void *d)
 
void apply (void(*fn)(const_reference, 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 ()
 
bool contains (bool(*fn)(const_reference, void *), void *d) const
 
bool contains (const_reference 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
 
bool find (bool(*fn)(const_reference, void *), void *d, value_type &k) const
 
bool find (const_reference a, value_type &k) const
 
reference first ()
 
const_reference first () const
 
size_type index (const_reference a) const
 
size_type index (bool(*fn)(const_reference, 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_reference, void *), void *d) const
 
size_type occurrencesOf (const_reference a) const
 
reference operator() (size_type i)
 
const_reference operator() (size_type i) const
 
RWTValVector< T > & operator= (const RWTValVector< T > &rhs)
 
RWTValVector< T > & operator= (RWTValVector< T > &&rhs)
 
RWTValVector< T > & operator= (const_reference ival)
 
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 value_type &, void *), void *d, const value_type &newVal)
 
size_type replaceAll (const value_type &oldVal, const value_type &newVal)
 
void reshape (size_type N)
 
void sort ()
 
void swap (RWTValVector< T > &rhs)
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

template<class T>
class RWTValVector< T >

Class RWTValVector is a simple parameterized vector of objects of type T. It is most useful when you know precisely how many objects have to be held in the collection. If the intention is to "insert" an unknown number of objects, then class RWTValOrderedVector may be a better choice.

The class T must have:

Synopsis
#include <rw/tvvector.h>
Persistence
Isomorphic
Example
//
// tvvector.cpp
//
#include <iostream>
#include <rw/tvvector.h>
#include <rw/tools/datetime.h>
int main ()
{
RWDateTime begin(RWDateTime::setCurrentTime); // Today's date
for (size_t i = 0; i < 7; ++i) {
begin.incrementDay(1);
week[i] = begin;
}
for (size_t i = 0; i < 7; ++i) {
std::cout << week[i].asString('x') << "\n";
}
return 0;
}

Program output (if this is run on June 19, 2009):

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

Member Typedef Documentation

template<class T>
typedef const_pointer RWTValVector< 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* RWTValVector< T >::const_pointer

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

template<class T>
typedef const value_type& RWTValVector< 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> RWTValVector< 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 RWTValVector< 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 RWTValVector< T >::iterator

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

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

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

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

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

template<class T>
typedef std::reverse_iterator<iterator> RWTValVector< 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 RWTValVector< T >::size_type

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

template<class T>
typedef T RWTValVector< T >::value_type

A type representing the container's data type.

Constructor & Destructor Documentation

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

Constructs an empty vector of length zero.

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

Constructs a vector of length n. The values of the elements are set by the default constructor of class value_type.

template<class T>
RWTValVector< T >::RWTValVector ( size_type  n,
const_reference  ival 
)

Constructs a vector of length n, with each element initialized to the value ival.

template<class T>
RWTValVector< T >::RWTValVector ( const RWTValVector< T > &  rhs)

Constructs self as a copy of rhs. Each element in rhs is copied into self.

template<class T>
RWTValVector< T >::RWTValVector ( RWTValVector< T > &&  rhs)

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 >
RWTValVector< T >::RWTValVector ( InputIterator  first,
InputIterator  last,
typename RWTEnableIf< !RWTIsIntegral< InputIterator >::value >::type **  = 0 
)
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.

template<class T>
RWTValVector< T >::~RWTValVector ( )
inline

Calls the destructor for every element in self.

Member Function Documentation

template<class T>
void RWTValVector< 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 RWTValVector< T >::apply ( void(*)(const_reference, 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< T >::clear ( void  )
inline

Clears the collection by removing all items from self. Each item has its destructor called.

template<class T>
bool RWTValVector< T >::contains ( bool(*)(const_reference, 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 RWTValVector< T >::contains ( const_reference  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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< T >::entries ( void  ) const
inline

Returns the number of elements in self.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. Client data may be passed through parameter d.

template<class T>
bool RWTValVector< T >::find ( const_reference  a,
value_type k 
) const
inline

If there exists an element t in self such that the expression (t == a) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

template<class T>
reference RWTValVector< 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 RWTValVector< 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 RWTValVector< T >::index ( const_reference  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 RWTValVector< T >::index ( bool(*)(const_reference, 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 RWTValVector< T >::isEmpty ( ) const
inline

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

template<class T>
reference RWTValVector< 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 RWTValVector< 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 RWTValVector< T >::length ( ) const
inline

Returns the number of elements in self.

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

Returns a reference to the maximum element in the collection. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

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

Returns a reference to the maximum element in the collection. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

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

Returns a reference to the minimum element in the collection. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

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

Returns a reference to the minimum element in the collection. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

template<class T>
size_type RWTValVector< T >::occurrencesOf ( bool(*)(const_reference, 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 RWTValVector< T >::occurrencesOf ( const_reference  a) const
inline

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

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

Returns a reference to the i th value in the vector. Index i should be between 0 and one less than the number of entries, otherwise the results are undefined.

Note
No bounds checking is performed.
template<class T>
const_reference RWTValVector< T >::operator() ( size_type  i) const
inline

Returns a reference to the i th value in the vector. Index i should be between 0 and one less than the number of entries, otherwise the results are undefined.

Note
No bounds checking is performed.
template<class T>
RWTValVector<T>& RWTValVector< T >::operator= ( const RWTValVector< T > &  rhs)

Sets self to the same length as rhs and then copies all elements of rhs into self.

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

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>
RWTValVector<T>& RWTValVector< T >::operator= ( const_reference  ival)

Sets all elements in self to the value ival.

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

Returns a reference to the i th value in the vector.

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

Returns a reference to the i th value in the vector.

Exceptions
RWBoundsErrThrown if index i is not between 0 and one less than the number of entries in self.
template<class T>
reverse_iterator RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< 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 RWTValVector< T >::replaceAll ( bool(*)(const value_type &, void *)  fn,
void *  d,
const value_type newVal 
)
inline

Replaces 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 RWTValVector< T >::replaceAll ( const value_type oldVal,
const value_type newVal 
)
inline

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

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

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 by the default constructor of value_type.

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

Sorts the collection using the less-than operator to compare elements.

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

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

Friends And Related Function Documentation

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

Equivalent to !(lhs == rhs).

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

Returns true if lhs is lexicographically less than rhs, otherwise false. Assumes that type T has well-defined less-than semantics.

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

Equivalent to !(rhs < lhs).

template<class T >
bool operator== ( const RWTValVector< T > &  lhs,
const RWTValVector< 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.

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

Equivalent to (rhs < lhs).

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

Equivalent to !(lhs < rhs).

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