rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTValVector< T > Class Template Reference
[Traditional Collections]

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

#include <rw/tvvector.h>

Inherited by RWClassicTValOrderedVector< T > [private].

List of all members.

Public Member Functions

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

Detailed Description

template<class T>
class RWTValVector< T >

Class RWTValVector<T> 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<T,A> may be a better choice.

The class T must have:

Synopsis

 #include <rw/tvvector.h>
 RWTValVector<T> vec;

Persistence

Isomorphic

Examples

 //
 // tvvector.cpp
 //
 #include <iostream>
 
 #include <rw/tvvector.h>
 #include <rw/tools/datetime.h>
 
 int main ()
 {
     RWTValVector<RWDateTime> week(7);
 
     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

Constructor & Destructor Documentation

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

Constructs an empty vector of length zero.

template<class T>
RWTValVector< T >::RWTValVector ( size_t  n  )  [inline]

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

template<class T>
RWTValVector< T >::RWTValVector ( size_t  n,
const T &  ival 
)

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

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

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

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

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.
template<class T>
RWTValVector< T >::~RWTValVector (  )  [inline]

Calls the destructor for every element in self.


Member Function Documentation

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

Returns a pointer to the raw data of self.

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

Returns the length of the vector.

template<class T>
const T& RWTValVector< T >::operator() ( size_t  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>
T& RWTValVector< T >::operator() ( size_t  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>
RWTValVector<T>& RWTValVector< T >::operator= ( const T &  ival  ) 

Sets all elements in self to the value ival.

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

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

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

template<class T>
const T& RWTValVector< T >::operator[] ( size_t  i  )  const [inline]

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

Exceptions:
RWBoundsErr Thrown if index i is not between 0 and one less than the number of entries in self.

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

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

Exceptions:
RWBoundsErr Thrown if index i is not between 0 and one less than the number of entries in self.
template<class T>
void RWTValVector< T >::reshape ( size_t  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 T.

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

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.