RWTValVector(3C++) RWTValVector(3C++)
Name
RWTValVector<T> - Rogue Wave library class
Synopsis
#include <rw/tvvector.h>
RWTValVector<T> vec;
Descripton
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 into a collection, then class RWTValOrderedVector<T>
may be a better choice. The class T must have:
well-defined copy semantics (T::T(const T&) or equiv.);
well-defined assignment semantics (T::operator=(const T&) or
equiv.);
a default constructor.
Persistence
Isomorphic
Example
#include <rw/tvvector.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
main() {
RWTValVector<RWDate> week(7);
RWDate begin; // Today's date
for (int i=0; i<7; i++)
week[i] = begin++;
for (i=0; i<7; i++)
cout << week[i] << endl;
return 0;
}
Program output:
March 16, 1996
March 17, 1996
March 18, 1996
March 19, 1996
March 20, 1996
Page 1
RWTValVector(3C++) RWTValVector(3C++)
March 21, 1996
March 22, 1996
Public Constructors
RWTValVector<T>();
Constructs an empty vector of length zero.
RWTValVector<T>(size_t n);
Constructs a vector of length n. The values of the elements will be set
by the default constructor of class T. For a built in type this can (and
probably will) be garbage.
RWTValVector<T>(size_t n, const T& ival);
Constructs a vector of length n, with each element initialized to the
value ival.
RWTValVector<T>(const RWTValVector& v);
Constructs self as a copy of v. Each element in v will be copied into
self.
~RWTValVector<T>();
Calls the destructor for every element in self.
Public Operators
RWTValVector<T>&
operator=(const RWTValVector<T>& v);
Sets self to the same length as v and then copies all elements of v into
self.
RWTValVector<T>&
operator=(const T& ival);
Sets all elements in self to the value ival.
const T&
operator()(size_t i) const;
T&
operator()(size_t i);
Page 2
RWTValVector(3C++) RWTValVector(3C++)
Returns a reference to the ith value in the vector. The index i must be
between 0 and the length of the vector less one. No bounds checking is
performed.
const T&
operator[](size_t i) const;
T&
operator[](size_t i);
Returns a reference to the ith value in the vector. The index i must be
between 0 and the length of the vector less one. Bounds checking will be
performed.
Public Member Functions
const T*
data() const;
Returns a pointer to the raw data of self. Should be used with care.
size_t
length() const;
Returns the length of the vector.
void
reshape(size_t N);
Changes the length of the vector to N. If this results in the vector
being lengthened, then the initial value of the additional elements is
set by the default constructor of T.
Page 3