rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTPtrVector< T > Class Template Reference
[Traditional Collections]

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

#include <rw/tpvector.h>

Inherits RWPtrVector.

List of all members.

Public Member Functions

 RWTPtrVector ()
 RWTPtrVector (size_t n)
 RWTPtrVector (size_t n, T *ival)
 RWTPtrVector (const RWTPtrVector< T > &v)
 RWTPtrVector (RWTPtrVector< T > &&v)
RWTPtrVector< T > & operator= (const RWTPtrVector< T > &v)
RWTPtrVector< T > & operator= (RWTPtrVector< T > &&v)
RWTPtrVector< T > & operator= (T *p)
T *& operator() (size_t i)
T *const & operator() (size_t i) const
T *& operator[] (size_t i)
T *const & operator[] (size_t i) const
T *const * data () const
size_t length () const
void reshape (size_t N)
void resize (size_t N)
void swap (RWTPtrVector< T > &v)

Detailed Description

template<class T>
class RWTPtrVector< T >

Class RWTPtrVector<T> 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<T,A> may be a better choice. Class T can be of any type.

Synopsis

 #include <rw/tpvector.h>
 RWTPtrVector<T> vec;

Persistence

Isomorphic

Examples

 #include <iostream>
 #include <rw/tpvector.h>
 #include <rw/tools/datetime.h>

 int main ()
 {
     RWTPtrVector<RWDateTime> week(7);

     RWDateTime begin(RWDateTime::setCurrentTime); // Today's date

     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

Constructor & Destructor Documentation

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

Constructs an empty vector of length zero.

template<class T>
RWTPtrVector< T >::RWTPtrVector ( size_t  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_t  n,
T *  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 > &  v  )  [inline]

Copy constructor. The constructed vector is a shallow copy of v. 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 > &&  v  )  [inline]

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

Condition:
This method is only available on platforms with rvalue reference support.

Member Function Documentation

template<class T>
T* const* RWTPtrVector< T >::data ( void   )  const [inline]

Returns a pointer to the raw data of the vector.

template<class T>
size_t RWTPtrVector< T >::length (  )  const [inline]

Returns the length of the vector.

template<class T>
T* const& RWTPtrVector< T >::operator() ( size_t  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>
T*& RWTPtrVector< T >::operator() ( size_t  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>
RWTPtrVector<T>& RWTPtrVector< T >::operator= ( T *  p  )  [inline]

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

template<class T>
RWTPtrVector<T>& RWTPtrVector< T >::operator= ( RWTPtrVector< T > &&  v  )  [inline]

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

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

Sets self to a shallow copy of v. 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>
T* const& RWTPtrVector< T >::operator[] ( size_t  i  )  const [inline]

Returns the i th value in the vector.

Exceptions:
RWBoundsErr Thrown if the index i is not between zero and the length of the vector, less one.

template<class T>
T*& RWTPtrVector< T >::operator[] ( size_t  i  )  [inline]

Returns the i th value in the vector.

Exceptions:
RWBoundsErr Thrown if the index i is not between zero and the length of the vector, less one.
template<class T>
void RWTPtrVector< T >::reshape ( size_t  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_t  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 >::swap ( RWTPtrVector< T > &  v  )  [inline]

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

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.